update.post_update.php

Same filename and directory in other branches
  1. 11.x core/modules/update/update.post_update.php
  2. 10 core/modules/update/update.post_update.php
  3. 9 core/modules/update/update.post_update.php

Post update functions for Update Status.

File

core/modules/update/update.post_update.php

View source
<?php


/**
 * @file
 * Post update functions for Update Status.
 */

use Drupal\Core\Site\Settings;

/**
 * Implements hook_removed_post_updates().
 */
function update_remove_post_updates() {
  return [
    'update_post_update_add_view_update_notifications_permission' => '10.0.0',
    'update_post_update_set_blank_fetch_url_to_null' => '11.0.0',
  ];
}

/**
 * Removes the legacy 'Update Manager' disk cache.
 */
function update_post_update_clear_disk_cache() : void {
  // @see _update_manager_unique_id()
  $id = substr(hash('sha256', Settings::getHashSalt()), 0, 8);
  // List of legacy 'Update Manager' cache directories.
  $directories = [
    // @see _update_manager_cache_directory()
"temporary://update-cache-{$id}",
    // @see _update_manager_extract_directory()
"temporary://update-extraction-{$id}",
  ];
  foreach ($directories as $directory) {
    if (is_dir($directory)) {
      \Drupal::service('file_system')->deleteRecursive($directory);
    }
  }
}

/**
 * Remove empty email addresses from update.settings configuration.
 */
function update_post_update_fix_update_emails() : void {
  $config = \Drupal::configFactory()->getEditable('update.settings');
  $emails = $config->get('notification.emails');
  $filtered_emails = is_array($emails) ? array_filter($emails) : [];
  if ($emails !== $filtered_emails) {
    $config->set('notification.emails', $filtered_emails)
      ->save();
  }
}

/**
 * Removes the legacy 'Update Manager' disk cache (again).
 */
function update_post_update_clear_disk_cache_again() : void {
  // @see _update_manager_unique_id()
  $id = substr(hash('sha256', Settings::getHashSalt()), 0, 8);
  // List of legacy 'Update Manager' cache directories.
  $directories = [
    // @see _update_manager_cache_directory()
"temporary://update-cache-{$id}",
    // @see _update_manager_extract_directory()
"temporary://update-extraction-{$id}",
  ];
  foreach ($directories as $directory) {
    if (is_dir($directory)) {
      \Drupal::service('file_system')->deleteRecursive($directory);
    }
  }
}

Functions

Title Deprecated Summary
update_post_update_clear_disk_cache Removes the legacy 'Update Manager' disk cache.
update_post_update_clear_disk_cache_again Removes the legacy 'Update Manager' disk cache (again).
update_post_update_fix_update_emails Remove empty email addresses from update.settings configuration.
update_remove_post_updates Implements hook_removed_post_updates().

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.