' . t('About') . ''; $output .= '
' . t("The Update Manager module periodically checks for new versions of your site's software (including contributed modules and themes), and alerts administrators to available updates. In order to provide update information, anonymous usage statistics are sent to Drupal.org. If desired, you may disable the Update Manager module from the Module administration page. For more information, see the online handbook entry for Update Manager module.", array('@update' => 'http://drupal.org/documentation/modules/update', '@modules' => url('admin/modules'))) . '
'; // Only explain the Update manager if it has not been disabled. if (update_manager_access()) { $output .= '' . t('The Update manager also allows administrators to update and install modules and themes through the administration interface.') . '
'; } $output .= '' . t('Here you can find information about available updates for your installed modules and themes. Note that each module or theme is part of a "project", which may or may not have the same name, and might include multiple modules or themes within it.') . '
'; } } /** * Implements hook_page_build(). */ function update_page_build() { /** @var \Drupal\Core\Routing\AdminContext $admin_context */ $admin_context = \Drupal::service('router.admin_context'); if ($admin_context->isAdminRoute(\Drupal::request()->attributes->get(RouteObjectInterface::ROUTE_OBJECT)) && \Drupal::currentUser()->hasPermission('administer site configuration')) { $current_path = current_path(); switch ($current_path) { // These pages don't need additional nagging. case 'admin/appearance/update': case 'admin/appearance/install': case 'admin/modules/update': case 'admin/modules/install': case 'admin/reports/updates': case 'admin/reports/updates/update': case 'admin/reports/updates/install': case 'admin/reports/updates/settings': case 'admin/reports/status': case 'admin/update/ready': return; // If we are on the appearance or modules list, display a detailed report // of the update status. case 'admin/appearance': case 'admin/modules': $verbose = TRUE; break; } module_load_install('update'); $status = update_requirements('runtime'); foreach (array('core', 'contrib') as $report_type) { $type = 'update_' . $report_type; if (!empty($verbose)) { if (isset($status[$type]['severity'])) { if ($status[$type]['severity'] == REQUIREMENT_ERROR) { drupal_set_message($status[$type]['description'], 'error'); } elseif ($status[$type]['severity'] == REQUIREMENT_WARNING) { drupal_set_message($status[$type]['description'], 'warning'); } } } // Otherwise, if we're on *any* admin page and there's a security // update missing, print an error message about it. else { if (isset($status[$type]) && isset($status[$type]['reason']) && $status[$type]['reason'] === UPDATE_NOT_SECURE) { drupal_set_message($status[$type]['description'], 'error'); } } } } } /** * Access callback: Resolves if the current user can access updater menu items. * * It both enforces the 'administer software updates' permission and the global * kill switch for the authorize.php script. * * @return * TRUE if the current user can access the updater menu items; FALSE * otherwise. * * @see update_menu() */ function update_manager_access() { return Settings::get('allow_authorize_operations', TRUE) && user_access('administer software updates'); } /** * Implements hook_theme(). */ function update_theme() { return array( 'update_manager_update_form' => array( 'render element' => 'form', 'file' => 'update.manager.inc', ), 'update_last_check' => array( 'variables' => array('last' => NULL), ), 'update_report' => array( 'variables' => array('data' => NULL), 'file' => 'update.report.inc', ), 'update_version' => array( 'variables' => array('version' => NULL, 'tag' => NULL, 'class' => array()), 'file' => 'update.report.inc', ), 'update_status_label' => array( 'variables' => array('status' => NULL), 'file' => 'update.report.inc', ), ); } /** * Implements hook_cron(). */ function update_cron() { $update_config = \Drupal::config('update.settings'); $frequency = $update_config->get('check.interval_days'); $interval = 60 * 60 * 24 * $frequency; $last_check = \Drupal::state()->get('update.last_check') ?: 0; if ((REQUEST_TIME - $last_check) > $interval) { // If the configured update interval has elapsed, we want to invalidate // the data for all projects, attempt to re-fetch, and trigger any // configured notifications about the new status. update_refresh(); update_fetch_data(); } else { // Otherwise, see if any individual projects are now stale or still // missing data, and if so, try to fetch the data. update_get_available(TRUE); } $last_email_notice = \Drupal::state()->get('update.last_email_notification') ?: 0; if ((REQUEST_TIME - $last_email_notice) > $interval) { // If configured time between notifications elapsed, send email about // updates possibly available. module_load_include('inc', 'update', 'update.fetch'); _update_cron_notify(); } // Clear garbage from disk. update_clear_update_disk_cache(); } /** * Implements hook_themes_enabled(). * * If themes are enabled, we invalidate the information of available updates. */ function update_themes_enabled($themes) { // Clear all update module data. update_storage_clear(); } /** * Implements hook_themes_disabled(). * * If themes are disabled, we invalidate the information of available updates. */ function update_themes_disabled($themes) { // Clear all update module data. update_storage_clear(); } /** * Implements hook_form_FORM_ID_alter() for system_modules(). * * Adds a form submission handler to the system modules form, so that if a site * admin saves the form, we invalidate the information of available updates. * * @see _update_cache_clear() */ function update_form_system_modules_alter(&$form, $form_state) { $form['#submit'][] = 'update_storage_clear_submit'; } /** * Form submission handler for system_modules(). * * @see update_form_system_modules_alter() */ function update_storage_clear_submit($form, &$form_state) { // Clear all update module data. update_storage_clear(); } /** * Returns a warning message when there is no data about available updates. */ function _update_no_data() { $destination = drupal_get_destination(); return t('No update information available. Run cron or check manually.', array( '@run_cron' => url('admin/reports/status/run-cron', array('query' => $destination)), '@check_manually' => url('admin/reports/updates/check', array('query' => $destination)), )); } /** * Tries to get update information and refreshes it when necessary. * * In addition to checking the lifetime, this function also ensures that * there are no .info.yml files for enabled modules or themes that have a newer * modification timestamp than the last time we checked for available update * data. If any .info.yml file was modified, it almost certainly means a new * version of something was installed. Without fresh available update data, the * logic in update_calculate_project_data() will be wrong and produce confusing, * bogus results. * * @param $refresh * (optional) Boolean to indicate if this method should refresh automatically * if there's no data. Defaults to FALSE. * * @return * Array of data about available releases, keyed by project shortname. * * @see update_refresh() * @see update_get_projects() */ function update_get_available($refresh = FALSE) { module_load_include('inc', 'update', 'update.compare'); $needs_refresh = FALSE; // Grab whatever data we currently have. $available = \Drupal::keyValueExpirable('update_available_releases')->getAll(); $projects = \Drupal::service('update.manager')->getProjects(); foreach ($projects as $key => $project) { // If there's no data at all, we clearly need to fetch some. if (empty($available[$key])) { //update_create_fetch_task($project); \Drupal::service('update.processor')->createFetchTask($project); $needs_refresh = TRUE; continue; } // See if the .info.yml file is newer than the last time we checked for // data, and if so, mark this project's data as needing to be re-fetched. // Any time an admin upgrades their local installation, the .info.yml file // will be changed, so this is the only way we can be sure we're not showing // bogus information right after they upgrade. if ($project['info']['_info_file_ctime'] > $available[$key]['last_fetch']) { $available[$key]['fetch_status'] = UPDATE_FETCH_PENDING; } // If we have project data but no release data, we need to fetch. This // can be triggered when we fail to contact a release history server. if (empty($available[$key]['releases'])) { $available[$key]['fetch_status'] = UPDATE_FETCH_PENDING; } // If we think this project needs to fetch, actually create the task now // and remember that we think we're missing some data. if (!empty($available[$key]['fetch_status']) && $available[$key]['fetch_status'] == UPDATE_FETCH_PENDING) { \Drupal::service('update.processor')->createFetchTask($project); $needs_refresh = TRUE; } } if ($needs_refresh && $refresh) { // Attempt to drain the queue of fetch tasks. update_fetch_data(); // After processing the queue, we've (hopefully) got better data, so pull // the latest data again and use that directly. $available = \Drupal::keyValueExpirable('update_available_releases')->getAll(); } return $available; } /** * Creates a new fetch task after loading the necessary include file. * * @param $project * Associative array of information about a project. See update_get_projects() * for the keys used. * * @see _update_create_fetch_task() */ function update_create_fetch_task($project) { module_load_include('inc', 'update', 'update.fetch'); _update_create_fetch_task($project); } /** * Refreshes the release data after loading the necessary include file. * * @see _update_refresh() */ function update_refresh() { module_load_include('inc', 'update', 'update.fetch'); _update_refresh(); } /** * Attempts to fetch update data after loading the necessary include file. * * @see _update_fetch_data() */ function update_fetch_data() { module_load_include('inc', 'update', 'update.fetch'); _update_fetch_data(); } /** * Batch callback: Performs actions when all fetch tasks have been completed. * * @param $success * TRUE if the batch operation was successful; FALSE if there were errors. * @param $results * An associative array of results from the batch operation, including the key * 'updated' which holds the total number of projects we fetched available * update data for. */ function update_fetch_data_finished($success, $results) { if ($success) { if (!empty($results)) { if (!empty($results['updated'])) { drupal_set_message(format_plural($results['updated'], 'Checked available update data for one project.', 'Checked available update data for @count projects.')); } if (!empty($results['failures'])) { drupal_set_message(format_plural($results['failures'], 'Failed to get available update data for one project.', 'Failed to get available update data for @count projects.'), 'error'); } } } else { drupal_set_message(t('An error occurred trying to get available update data.'), 'error'); } } /** * Implements hook_mail(). * * Constructs the email notification message when the site is out of date. * * @param $key * Unique key to indicate what message to build, always 'status_notify'. * @param $message * Reference to the message array being built. * @param $params * Array of parameters to indicate what kind of text to include in the message * body. This is a keyed array of message type ('core' or 'contrib') as the * keys, and the status reason constant (UPDATE_NOT_SECURE, etc) for the * values. * * @see drupal_mail() * @see _update_cron_notify() * @see _update_message_text() */ function update_mail($key, &$message, $params) { $langcode = $message['langcode']; $language = \Drupal::languageManager()->getLanguage($langcode); $message['subject'] .= t('New release(s) available for !site_name', array('!site_name' => \Drupal::config('system.site')->get('name')), array('langcode' => $langcode)); foreach ($params as $msg_type => $msg_reason) { $message['body'][] = _update_message_text($msg_type, $msg_reason, FALSE, $langcode); } $message['body'][] = t('See the available updates page for more information:', array(), array('langcode' => $langcode)) . "\n" . url('admin/reports/updates', array('absolute' => TRUE, 'language' => $language)); if (update_manager_access()) { $message['body'][] = t('You can automatically install your missing updates using the Update manager:', array(), array('langcode' => $langcode)) . "\n" . url('admin/reports/updates/update', array('absolute' => TRUE, 'language' => $language)); } $settings_url = url('admin/reports/updates/settings', array('absolute' => TRUE)); if (\Drupal::config('update.settings')->get('notification.threshold') == 'all') { $message['body'][] = t('Your site is currently configured to send these emails when any updates are available. To get notified only for security updates, !url.', array('!url' => $settings_url)); } else { $message['body'][] = t('Your site is currently configured to send these emails only when security updates are available. To get notified for any available updates, !url.', array('!url' => $settings_url)); } } /** * Returns the appropriate message text when site is out of date or not secure. * * These error messages are shared by both update_requirements() for the * site-wide status report at admin/reports/status and in the body of the * notification email messages generated by update_cron(). * * @param $msg_type * String to indicate what kind of message to generate. Can be either 'core' * or 'contrib'. * @param $msg_reason * Integer constant specifying why message is generated. * @param $report_link * (optional) Boolean that controls if a link to the updates report should be * added. Defaults to FALSE. * @param $langcode * (optional) A language code to use. Defaults to NULL. * * @return * The properly translated error message for the given key. */ function _update_message_text($msg_type, $msg_reason, $report_link = FALSE, $langcode = NULL) { $text = ''; switch ($msg_reason) { case UPDATE_NOT_SECURE: if ($msg_type == 'core') { $text = t('There is a security update available for your version of Drupal. To ensure the security of your server, you should update immediately!', array(), array('langcode' => $langcode)); } else { $text = t('There are security updates available for one or more of your modules or themes. To ensure the security of your server, you should update immediately!', array(), array('langcode' => $langcode)); } break; case UPDATE_REVOKED: if ($msg_type == 'core') { $text = t('Your version of Drupal has been revoked and is no longer available for download. Upgrading is strongly recommended!', array(), array('langcode' => $langcode)); } else { $text = t('The installed version of at least one of your modules or themes has been revoked and is no longer available for download. Upgrading or disabling is strongly recommended!', array(), array('langcode' => $langcode)); } break; case UPDATE_NOT_SUPPORTED: if ($msg_type == 'core') { $text = t('Your version of Drupal is no longer supported. Upgrading is strongly recommended!', array(), array('langcode' => $langcode)); } else { $text = t('The installed version of at least one of your modules or themes is no longer supported. Upgrading or disabling is strongly recommended. See the project homepage for more details.', array(), array('langcode' => $langcode)); } break; case UPDATE_NOT_CURRENT: if ($msg_type == 'core') { $text = t('There are updates available for your version of Drupal. To ensure the proper functioning of your site, you should update as soon as possible.', array(), array('langcode' => $langcode)); } else { $text = t('There are updates available for one or more of your modules or themes. To ensure the proper functioning of your site, you should update as soon as possible.', array(), array('langcode' => $langcode)); } break; case UPDATE_UNKNOWN: case UPDATE_NOT_CHECKED: case UPDATE_NOT_FETCHED: case UPDATE_FETCH_PENDING: if ($msg_type == 'core') { $text = t('There was a problem checking available updates for Drupal.', array('@update-report' => url('admin/reports/updates')), array('langcode' => $langcode)); } else { $text = t('There was a problem checking available updates for your modules or themes.', array('@update-report' => url('admin/reports/updates')), array('langcode' => $langcode)); } break; } if (!empty($langcode)) { $language = \Drupal::languageManager()->getLanguage($langcode); } else { $language = NULL; } if ($report_link) { if (update_manager_access()) { $text .= ' ' . t('See the available updates page for more information and to install your missing updates.', array('@available_updates' => url('admin/reports/updates/update', array('language' => $language))), array('langcode' => $langcode)); } else { $text .= ' ' . t('See the available updates page for more information.', array('@available_updates' => url('admin/reports/updates', array('language' => $language))), array('langcode' => $langcode)); } } return $text; } /** * Orders projects based on their status. * * Callback for uasort() within update_requirements(). */ function _update_project_status_sort($a, $b) { // The status constants are numerically in the right order, so we can // usually subtract the two to compare in the order we want. However, // negative status values should be treated as if they are huge, since we // always want them at the bottom of the list. $a_status = $a['status'] > 0 ? $a['status'] : (-10 * $a['status']); $b_status = $b['status'] > 0 ? $b['status'] : (-10 * $b['status']); return $a_status - $b_status; } /** * Returns HTML for the last time we checked for update data. * * In addition to properly formatting the given timestamp, this function also * provides a "Check manually" link that refreshes the available update and * redirects back to the same page. * * @param $variables * An associative array containing: * - last: The timestamp when the site last checked for available updates. * * @see theme_update_report() * @see theme_update_available_updates_form() * @ingroup themeable */ function theme_update_last_check($variables) { $last = $variables['last']; $output = '