comparison core/modules/update/update.module @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
9 * releases are available via the system status report (admin/reports/status), 9 * releases are available via the system status report (admin/reports/status),
10 * the module and theme pages, and optionally via email. It also provides the 10 * the module and theme pages, and optionally via email. It also provides the
11 * ability to install contributed modules and themes via an user interface. 11 * ability to install contributed modules and themes via an user interface.
12 */ 12 */
13 13
14 use Drupal\Core\File\Exception\FileException;
14 use Drupal\Core\Url; 15 use Drupal\Core\Url;
15 use Drupal\Core\Form\FormStateInterface; 16 use Drupal\Core\Form\FormStateInterface;
16 use Drupal\Core\Routing\RouteMatchInterface; 17 use Drupal\Core\Routing\RouteMatchInterface;
17 use Drupal\Core\Site\Settings; 18 use Drupal\Core\Site\Settings;
18 19
114 function update_help($route_name, RouteMatchInterface $route_match) { 115 function update_help($route_name, RouteMatchInterface $route_match) {
115 switch ($route_name) { 116 switch ($route_name) {
116 case 'help.page.update': 117 case 'help.page.update':
117 $output = ''; 118 $output = '';
118 $output .= '<h3>' . t('About') . '</h3>'; 119 $output .= '<h3>' . t('About') . '</h3>';
119 $output .= '<p>' . 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. The Update Manager system is also used by some other modules to manage updates and downloads; for example, the Interface Translation module uses the Update Manager to download translations from the localization server. Note that whenever the Update Manager system is used, anonymous usage statistics are sent to Drupal.org. If desired, you may disable the Update Manager module from the <a href=":modules">Extend page</a>; if you do so, functionality that depends on the Update Manager system will not work. For more information, see the <a href=":update">online documentation for the Update Manager module</a>.', [':update' => 'https://www.drupal.org/documentation/modules/update', ':modules' => \Drupal::url('system.modules_list')]) . '</p>'; 120 $output .= '<p>' . 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. The Update Manager system is also used by some other modules to manage updates and downloads; for example, the Interface Translation module uses the Update Manager to download translations from the localization server. Note that whenever the Update Manager system is used, anonymous usage statistics are sent to Drupal.org. If desired, you may disable the Update Manager module from the <a href=":modules">Extend page</a>; if you do so, functionality that depends on the Update Manager system will not work. For more information, see the <a href=":update">online documentation for the Update Manager module</a>.', [':update' => 'https://www.drupal.org/documentation/modules/update', ':modules' => Url::fromRoute('system.modules_list')->toString()]) . '</p>';
120 // Only explain the Update manager if it has not been disabled. 121 // Only explain the Update manager if it has not been disabled.
121 if (_update_manager_access()) { 122 if (_update_manager_access()) {
122 $output .= '<p>' . t('The Update Manager also allows administrators to update and install modules and themes through the administration interface.') . '</p>'; 123 $output .= '<p>' . t('The Update Manager also allows administrators to update and install modules and themes through the administration interface.') . '</p>';
123 } 124 }
124 $output .= '<h3>' . t('Uses') . '</h3>'; 125 $output .= '<h3>' . t('Uses') . '</h3>';
125 $output .= '<dl>'; 126 $output .= '<dl>';
126 $output .= '<dt>' . t('Checking for available updates') . '</dt>'; 127 $output .= '<dt>' . t('Checking for available updates') . '</dt>';
127 $output .= '<dd>' . t('The <a href=":update-report">Available updates report</a> displays core, contributed modules, and themes for which there are new releases available for download. On the report page, you can also check manually for updates. You can configure the frequency of update checks, which are performed during cron runs, and whether notifications are sent on the <a href=":update-settings">Update Manager settings page</a>.', [':update-report' => \Drupal::url('update.status'), ':update-settings' => \Drupal::url('update.settings')]) . '</dd>'; 128 $output .= '<dd>' . t('The <a href=":update-report">Available updates report</a> displays core, contributed modules, and themes for which there are new releases available for download. On the report page, you can also check manually for updates. You can configure the frequency of update checks, which are performed during cron runs, and whether notifications are sent on the <a href=":update-settings">Update Manager settings page</a>.', [':update-report' => Url::fromRoute('update.status')->toString(), ':update-settings' => Url::fromRoute('update.settings')->toString()]) . '</dd>';
128 // Only explain the Update manager if it has not been disabled. 129 // Only explain the Update manager if it has not been disabled.
129 if (_update_manager_access()) { 130 if (_update_manager_access()) {
130 $output .= '<dt>' . t('Performing updates through the Update page') . '</dt>'; 131 $output .= '<dt>' . t('Performing updates through the Update page') . '</dt>';
131 $output .= '<dd>' . t('The Update Manager module allows administrators to perform updates directly from the <a href=":update-page">Update page</a>. It lists all available updates, and you can confirm whether you want to download them. If you don\'t have sufficient access rights to your web server, you could be prompted for your FTP/SSH password. Afterwards the files are transferred into your site installation, overwriting your old files. Direct links to the Update page are also displayed on the <a href=":modules_page">Extend page</a> and the <a href=":themes_page">Appearance page</a>.', [':modules_page' => \Drupal::url('system.modules_list'), ':themes_page' => \Drupal::url('system.themes_page'), ':update-page' => \Drupal::url('update.report_update')]) . '</dd>'; 132 $output .= '<dd>' . t('The Update Manager module allows administrators to perform updates directly from the <a href=":update-page">Update page</a>. It lists all available updates, and you can confirm whether you want to download them. If you don\'t have sufficient access rights to your web server, you could be prompted for your FTP/SSH password. Afterwards the files are transferred into your site installation, overwriting your old files. Direct links to the Update page are also displayed on the <a href=":modules_page">Extend page</a> and the <a href=":themes_page">Appearance page</a>.', [':modules_page' => Url::fromRoute('system.modules_list')->toString(), ':themes_page' => Url::fromRoute('system.themes_page')->toString(), ':update-page' => Url::fromRoute('update.report_update')->toString()]) . '</dd>';
132 $output .= '<dt>' . t('Installing new modules and themes through the Install page') . '</dt>'; 133 $output .= '<dt>' . t('Installing new modules and themes through the Install page') . '</dt>';
133 $output .= '<dd>' . t('You can also install new modules and themes in the same fashion, through the <a href=":install">Install page</a>, or by clicking the <em>Install new module/theme</em> links at the top of the <a href=":modules_page">Extend page</a> and the <a href=":themes_page">Appearance page</a>. In this case, you are prompted to provide either the URL to the download, or to upload a packaged release file from your local computer.', [':modules_page' => \Drupal::url('system.modules_list'), ':themes_page' => \Drupal::url('system.themes_page'), ':install' => \Drupal::url('update.report_install')]) . '</dd>'; 134 $output .= '<dd>' . t('You can also install new modules and themes in the same fashion, through the <a href=":install">Install page</a>, or by clicking the <em>Install new module/theme</em> links at the top of the <a href=":modules_page">Extend page</a> and the <a href=":themes_page">Appearance page</a>. In this case, you are prompted to provide either the URL to the download, or to upload a packaged release file from your local computer.', [':modules_page' => Url::fromRoute('system.modules_list')->toString(), ':themes_page' => Url::fromRoute('system.themes_page')->toString(), ':install' => Url::fromRoute('update.report_install')->toString()]) . '</dd>';
134 } 135 }
135 $output .= '</dl>'; 136 $output .= '</dl>';
136 return $output; 137 return $output;
137 138
138 case 'update.status': 139 case 'update.status':
139 return '<p>' . 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.') . '</p>'; 140 return '<p>' . 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.') . '</p>';
140 141
141 case 'system.modules_list': 142 case 'system.modules_list':
142 if (_update_manager_access()) { 143 if (_update_manager_access()) {
143 $output = '<p>' . t('Regularly review and install <a href=":updates">available updates</a> to maintain a secure and current site. Always run the <a href=":update-php">update script</a> each time a module is updated.', [':update-php' => \Drupal::url('system.db_update'), ':updates' => \Drupal::url('update.status')]) . '</p>'; 144 $output = '<p>' . t('Regularly review and install <a href=":updates">available updates</a> to maintain a secure and current site. Always run the <a href=":update-php">update script</a> each time a module is updated.', [':update-php' => Url::fromRoute('system.db_update')->toString(), ':updates' => Url::fromRoute('update.status')->toString()]) . '</p>';
144 } 145 }
145 else { 146 else {
146 $output = '<p>' . t('Regularly review <a href=":updates">available updates</a> to maintain a secure and current site. Always run the <a href=":update-php">update script</a> each time a module is updated.', [':update-php' => \Drupal::url('system.db_update'), ':updates' => \Drupal::url('update.status')]) . '</p>'; 147 $output = '<p>' . t('Regularly review <a href=":updates">available updates</a> to maintain a secure and current site. Always run the <a href=":update-php">update script</a> each time a module is updated.', [':update-php' => Url::fromRoute('system.db_update')->toString(), ':updates' => Url::fromRoute('update.status')->toString()]) . '</p>';
147 } 148 }
148 return $output; 149 return $output;
149 } 150 }
150 } 151 }
151 152
330 * Returns a warning message when there is no data about available updates. 331 * Returns a warning message when there is no data about available updates.
331 */ 332 */
332 function _update_no_data() { 333 function _update_no_data() {
333 $destination = \Drupal::destination()->getAsArray(); 334 $destination = \Drupal::destination()->getAsArray();
334 return t('No update information available. <a href=":run_cron">Run cron</a> or <a href=":check_manually">check manually</a>.', [ 335 return t('No update information available. <a href=":run_cron">Run cron</a> or <a href=":check_manually">check manually</a>.', [
335 ':run_cron' => \Drupal::url('system.run_cron', [], ['query' => $destination]), 336 ':run_cron' => Url::fromRoute('system.run_cron', [], ['query' => $destination])->toString(),
336 ':check_manually' => \Drupal::url('update.manual_status', [], ['query' => $destination]), 337 ':check_manually' => Url::fromRoute('update.manual_status', [], ['query' => $destination])->toString(),
337 ]); 338 ]);
338 } 339 }
339 340
340 /** 341 /**
341 * Tries to get update information and refreshes it when necessary. 342 * Tries to get update information and refreshes it when necessary.
531 $language = \Drupal::languageManager()->getLanguage($langcode); 532 $language = \Drupal::languageManager()->getLanguage($langcode);
532 $message['subject'] .= t('New release(s) available for @site_name', ['@site_name' => \Drupal::config('system.site')->get('name')], ['langcode' => $langcode]); 533 $message['subject'] .= t('New release(s) available for @site_name', ['@site_name' => \Drupal::config('system.site')->get('name')], ['langcode' => $langcode]);
533 foreach ($params as $msg_type => $msg_reason) { 534 foreach ($params as $msg_type => $msg_reason) {
534 $message['body'][] = _update_message_text($msg_type, $msg_reason, $langcode); 535 $message['body'][] = _update_message_text($msg_type, $msg_reason, $langcode);
535 } 536 }
536 $message['body'][] = t('See the available updates page for more information:', [], ['langcode' => $langcode]) . "\n" . \Drupal::url('update.status', [], ['absolute' => TRUE, 'language' => $language]); 537 $message['body'][] = t('See the available updates page for more information:', [], ['langcode' => $langcode]) . "\n" . Url::fromRoute('update.status', [], ['absolute' => TRUE, 'language' => $language])->toString();
537 if (_update_manager_access()) { 538 if (_update_manager_access()) {
538 $message['body'][] = t('You can automatically install your missing updates using the Update manager:', [], ['langcode' => $langcode]) . "\n" . \Drupal::url('update.report_update', [], ['absolute' => TRUE, 'language' => $language]); 539 $message['body'][] = t('You can automatically install your missing updates using the Update manager:', [], ['langcode' => $langcode]) . "\n" . Url::fromRoute('update.report_update', [], ['absolute' => TRUE, 'language' => $language])->toString();
539 } 540 }
540 $settings_url = \Drupal::url('update.settings', [], ['absolute' => TRUE]); 541 $settings_url = Url::fromRoute('update.settings', [], ['absolute' => TRUE])->toString();
541 if (\Drupal::config('update.settings')->get('notification.threshold') == 'all') { 542 if (\Drupal::config('update.settings')->get('notification.threshold') == 'all') {
542 $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.', ['@url' => $settings_url]); 543 $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.', ['@url' => $settings_url]);
543 } 544 }
544 else { 545 else {
545 $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.', ['@url' => $settings_url]); 546 $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.', ['@url' => $settings_url]);
606 case UPDATE_UNKNOWN: 607 case UPDATE_UNKNOWN:
607 case UPDATE_NOT_CHECKED: 608 case UPDATE_NOT_CHECKED:
608 case UPDATE_NOT_FETCHED: 609 case UPDATE_NOT_FETCHED:
609 case UPDATE_FETCH_PENDING: 610 case UPDATE_FETCH_PENDING:
610 if ($msg_type == 'core') { 611 if ($msg_type == 'core') {
611 $text = t('There was a problem checking <a href=":update-report">available updates</a> for Drupal.', [':update-report' => \Drupal::url('update.status')], ['langcode' => $langcode]); 612 $text = t('There was a problem checking <a href=":update-report">available updates</a> for Drupal.', [':update-report' => Url::fromRoute('update.status')->toString()], ['langcode' => $langcode]);
612 } 613 }
613 else { 614 else {
614 $text = t('There was a problem checking <a href=":update-report">available updates</a> for your modules or themes.', [':update-report' => \Drupal::url('update.status')], ['langcode' => $langcode]); 615 $text = t('There was a problem checking <a href=":update-report">available updates</a> for your modules or themes.', [':update-report' => Url::fromRoute('update.status')->toString()], ['langcode' => $langcode]);
615 } 616 }
616 break; 617 break;
617 } 618 }
618 619
619 return $text; 620 return $text;
702 $compatible_project = TRUE; 703 $compatible_project = TRUE;
703 break; 704 break;
704 } 705 }
705 } 706 }
706 707
708 /** @var \Drupal\Core\File\FileSystemInterface $file_system */
709 $file_system = \Drupal::service('file_system');
707 if (empty($files)) { 710 if (empty($files)) {
708 $errors[] = t('%archive_file does not contain any .info.yml files.', ['%archive_file' => drupal_basename($archive_file)]); 711 $errors[] = t('%archive_file does not contain any .info.yml files.', ['%archive_file' => $file_system->basename($archive_file)]);
709 } 712 }
710 elseif (!$compatible_project) { 713 elseif (!$compatible_project) {
711 $errors[] = \Drupal::translation()->formatPlural( 714 $errors[] = \Drupal::translation()->formatPlural(
712 count($incompatible), 715 count($incompatible),
713 '%archive_file contains a version of %names that is not compatible with Drupal @version.', 716 '%archive_file contains a version of %names that is not compatible with Drupal @version.',
714 '%archive_file contains versions of modules or themes that are not compatible with Drupal @version: %names', 717 '%archive_file contains versions of modules or themes that are not compatible with Drupal @version: %names',
715 ['@version' => \Drupal::CORE_COMPATIBILITY, '%archive_file' => drupal_basename($archive_file), '%names' => implode(', ', $incompatible)] 718 [
719 '@version' => \Drupal::CORE_COMPATIBILITY,
720 '%archive_file' => $file_system->basename($archive_file),
721 '%names' => implode(', ', $incompatible),
722 ]
716 ); 723 );
717 } 724 }
718 725
719 return $errors; 726 return $errors;
720 } 727 }
824 if (file_exists($path)) { 831 if (file_exists($path)) {
825 $filectime = filectime($path); 832 $filectime = filectime($path);
826 $max_age = \Drupal::config('system.file')->get('temporary_maximum_age'); 833 $max_age = \Drupal::config('system.file')->get('temporary_maximum_age');
827 834
828 if (REQUEST_TIME - $filectime > $max_age || (preg_match('/.*-dev\.(tar\.gz|zip)/i', $path) && REQUEST_TIME - $filectime > 300)) { 835 if (REQUEST_TIME - $filectime > $max_age || (preg_match('/.*-dev\.(tar\.gz|zip)/i', $path) && REQUEST_TIME - $filectime > 300)) {
829 file_unmanaged_delete_recursive($path); 836 try {
830 } 837 \Drupal::service('file_system')->deleteRecursive($path);
831 } 838 }
832 } 839 catch (FileException $e) {
840 // Ignore failed deletes.
841 }
842 }
843 }
844 }