2007-07-11 15:15:40 +00:00
<?php
2009-05-13 19:42:18 +00:00
/**
* @file
2012-06-06 15:33:53 +00:00
* Install, update, and uninstall functions for the Update Manager module.
2009-05-13 19:42:18 +00:00
*/
2019-07-24 15:48:42 +00:00
use Drupal\Core\Link;
2014-09-29 13:41:29 +00:00
use Drupal\Core\Url;
2019-12-05 09:27:43 +00:00
use Drupal\update\UpdateFetcherInterface;
use Drupal\update\UpdateManagerInterface;
2014-09-29 13:41:29 +00:00
2009-12-29 07:21:34 +00:00
/**
* Implements hook_requirements().
*
* @return
2012-06-06 15:33:53 +00:00
* An array describing the status of the site regarding available updates. If
* there is no update data, only one record will be returned, indicating that
* the status of core can't be determined. If data is available, there will be
* two records: one for core, and another for all of contrib (assuming there
* are any contributed modules or themes enabled on the site). In addition to
* the fields expected by hook_requirements ('value', 'severity', and
* optionally 'description'), this array will contain a 'reason' attribute,
* which is an integer constant to indicate why the given status is being
2019-12-04 11:57:25 +00:00
* returned (UpdateManagerInterface::NOT_SECURE,
* UpdateManagerInterface::NOT_CURRENT, or UpdateManagerInterface::UNKNOWN).
* This is used for generating the appropriate email notification messages
* during update_cron(), and might be useful for other modules that invoke
2012-06-06 15:33:53 +00:00
* update_requirements() to find out if the site is up to date or not.
2009-12-29 07:21:34 +00:00
*
* @see _update_message_text()
* @see _update_cron_notify()
2019-12-04 11:57:25 +00:00
* @see \Drupal\update\UpdateManagerInterface
2009-12-29 07:21:34 +00:00
*/
function update_requirements($phase) {
2017-03-04 01:20:24 +00:00
$requirements = [];
2009-12-29 07:21:34 +00:00
if ($phase == 'runtime') {
if ($available = update_get_available(FALSE)) {
module_load_include('inc', 'update', 'update.compare');
$data = update_calculate_project_data($available);
// First, populate the requirements for core:
$requirements['update_core'] = _update_requirement_check($data['drupal'], 'core');
// We don't want to check drupal a second time.
unset($data['drupal']);
if (!empty($data)) {
// Now, sort our $data array based on each project's status. The
// status constants are numbered in the right order of precedence, so
// we just need to make sure the projects are sorted in ascending
// order of status, and we can look at the first project we find.
uasort($data, '_update_project_status_sort');
$first_project = reset($data);
$requirements['update_contrib'] = _update_requirement_check($first_project, 'contrib');
}
}
else {
$requirements['update_core']['title'] = t('Drupal core update status');
$requirements['update_core']['value'] = t('No update data available');
$requirements['update_core']['severity'] = REQUIREMENT_WARNING;
2019-12-04 11:57:25 +00:00
$requirements['update_core']['reason'] = UpdateFetcherInterface::UNKNOWN;
2009-12-29 07:21:34 +00:00
$requirements['update_core']['description'] = _update_no_data();
}
}
2010-01-15 10:12:36 +00:00
return $requirements;
2009-12-29 07:21:34 +00:00
}
2009-10-13 02:14:05 +00:00
/**
2009-12-04 16:49:48 +00:00
* Implements hook_install().
2009-10-13 02:14:05 +00:00
*/
function update_install() {
2013-09-16 03:58:06 +00:00
$queue = \Drupal::queue('update_fetch_tasks', TRUE);
2009-10-13 02:14:05 +00:00
$queue->createQueue();
}
2007-07-11 15:15:40 +00:00
/**
2009-12-04 16:49:48 +00:00
* Implements hook_uninstall().
2007-07-11 15:15:40 +00:00
*/
function update_uninstall() {
2014-01-17 22:05:58 +00:00
\Drupal::state()->delete('update.last_check');
\Drupal::state()->delete('update.last_email_notification');
2012-08-03 16:52:07 +00:00
2013-09-16 03:58:06 +00:00
$queue = \Drupal::queue('update_fetch_tasks');
2009-10-13 02:14:05 +00:00
$queue->deleteQueue();
2007-07-11 15:15:40 +00:00
}
2007-10-05 14:43:26 +00:00
/**
2012-06-06 15:33:53 +00:00
* Fills in the requirements array.
2009-12-29 07:21:34 +00:00
*
* This is shared for both core and contrib to generate the right elements in
* the array for hook_requirements().
*
* @param $project
2012-06-06 15:33:53 +00:00
* Array of information about the project we're testing as returned by
* update_calculate_project_data().
2009-12-29 07:21:34 +00:00
* @param $type
2012-06-06 15:33:53 +00:00
* What kind of project this is ('core' or 'contrib').
2009-12-29 07:21:34 +00:00
*
* @return
2012-06-06 15:33:53 +00:00
* An array to be included in the nested $requirements array.
2009-12-29 07:21:34 +00:00
*
* @see hook_requirements()
* @see update_requirements()
* @see update_calculate_project_data()
2007-10-05 14:43:26 +00:00
*/
2009-12-29 07:21:34 +00:00
function _update_requirement_check($project, $type) {
2017-03-04 01:20:24 +00:00
$requirement = [];
2009-12-29 07:21:34 +00:00
if ($type == 'core') {
$requirement['title'] = t('Drupal core update status');
}
else {
$requirement['title'] = t('Module and theme update status');
}
$status = $project['status'];
2019-12-04 11:57:25 +00:00
if ($status != UpdateManagerInterface::CURRENT) {
2009-12-29 07:21:34 +00:00
$requirement['reason'] = $status;
$requirement['severity'] = REQUIREMENT_ERROR;
Issue #2545520 by sdstyles, BarisW, David_Rothstein, owenpm3, mgifford, xjm, rovo, xlin, lukas.fischer, Anicky, tar_inet, a11y.matters, hussainweb, benjifisher, NikitaJain, steverossnyc, shwetaneelsharma, mradcliffe, rosschive, jhodgdon, yoroy, drnikki, YesCT, Gábor Hojtsy, edorsini: The same link "available updates" links to two different pages in the same paragraph when there is a problem checking available updates
2017-10-31 19:43:35 +00:00
// When updates are available, append the available updates link to the
// message from _update_message_text(), and format the two translated
// strings together in a single paragraph.
2015-08-13 23:19:28 +00:00
$requirement['description'][] = ['#markup' => _update_message_text($type, $status)];
2019-12-04 11:57:25 +00:00
if (!in_array($status, [UpdateFetcherInterface::UNKNOWN, UpdateFetcherInterface::NOT_CHECKED, UpdateFetcherInterface::NOT_FETCHED, UpdateFetcherInterface::FETCH_PENDING])) {
Issue #2545520 by sdstyles, BarisW, David_Rothstein, owenpm3, mgifford, xjm, rovo, xlin, lukas.fischer, Anicky, tar_inet, a11y.matters, hussainweb, benjifisher, NikitaJain, steverossnyc, shwetaneelsharma, mradcliffe, rosschive, jhodgdon, yoroy, drnikki, YesCT, Gábor Hojtsy, edorsini: The same link "available updates" links to two different pages in the same paragraph when there is a problem checking available updates
2017-10-31 19:43:35 +00:00
if (_update_manager_access()) {
2019-04-16 05:38:27 +00:00
$requirement['description'][] = ['#prefix' => ' ', '#markup' => t('See the <a href=":available_updates">available updates</a> page for more information and to install your missing updates.', [':available_updates' => Url::fromRoute('update.report_update')->toString()])];
Issue #2545520 by sdstyles, BarisW, David_Rothstein, owenpm3, mgifford, xjm, rovo, xlin, lukas.fischer, Anicky, tar_inet, a11y.matters, hussainweb, benjifisher, NikitaJain, steverossnyc, shwetaneelsharma, mradcliffe, rosschive, jhodgdon, yoroy, drnikki, YesCT, Gábor Hojtsy, edorsini: The same link "available updates" links to two different pages in the same paragraph when there is a problem checking available updates
2017-10-31 19:43:35 +00:00
}
else {
2019-04-16 05:38:27 +00:00
$requirement['description'][] = ['#prefix' => ' ', '#markup' => t('See the <a href=":available_updates">available updates</a> page for more information.', [':available_updates' => Url::fromRoute('update.status')->toString()])];
Issue #2545520 by sdstyles, BarisW, David_Rothstein, owenpm3, mgifford, xjm, rovo, xlin, lukas.fischer, Anicky, tar_inet, a11y.matters, hussainweb, benjifisher, NikitaJain, steverossnyc, shwetaneelsharma, mradcliffe, rosschive, jhodgdon, yoroy, drnikki, YesCT, Gábor Hojtsy, edorsini: The same link "available updates" links to two different pages in the same paragraph when there is a problem checking available updates
2017-10-31 19:43:35 +00:00
}
2015-08-13 23:19:28 +00:00
}
2009-12-29 07:21:34 +00:00
}
switch ($status) {
2019-12-04 11:57:25 +00:00
case UpdateManagerInterface::NOT_SECURE:
2009-12-29 07:21:34 +00:00
$requirement_label = t('Not secure!');
break;
2019-12-04 11:57:25 +00:00
case UpdateManagerInterface::REVOKED:
2009-12-29 07:21:34 +00:00
$requirement_label = t('Revoked!');
break;
2019-12-04 11:57:25 +00:00
case UpdateManagerInterface::NOT_SUPPORTED:
2009-12-29 07:21:34 +00:00
$requirement_label = t('Unsupported release');
break;
2019-12-04 11:57:25 +00:00
case UpdateManagerInterface::NOT_CURRENT:
2009-12-29 07:21:34 +00:00
$requirement_label = t('Out of date');
$requirement['severity'] = REQUIREMENT_WARNING;
break;
2019-12-04 11:57:25 +00:00
case UpdateFetcherInterface::UNKNOWN:
case UpdateFetcherInterface::NOT_CHECKED:
case UpdateFetcherInterface::NOT_FETCHED:
case UpdateFetcherInterface::FETCH_PENDING:
2009-12-29 07:21:34 +00:00
$requirement_label = isset($project['reason']) ? $project['reason'] : t('Can not determine status');
$requirement['severity'] = REQUIREMENT_WARNING;
break;
default:
$requirement_label = t('Up to date');
}
2019-12-04 11:57:25 +00:00
if ($status != UpdateManagerInterface::CURRENT && $type == 'core' && isset($project['recommended'])) {
2017-03-04 01:20:24 +00:00
$requirement_label .= ' ' . t('(version @version available)', ['@version' => $project['recommended']]);
2009-12-29 07:21:34 +00:00
}
2019-07-24 15:48:42 +00:00
$requirement['value'] = Link::fromTextAndUrl($requirement_label, Url::fromRoute(_update_manager_access() ? 'update.report_update' : 'update.status'))->toString();
2009-12-29 07:21:34 +00:00
return $requirement;
2007-10-05 14:43:26 +00:00
}
2016-05-23 10:15:39 +00:00
/**
Issue #3087644 by jibran, Berdir, alexpott, longwave, Wim Leers, amateescu, catch, xjm, larowlan, dpi, quietone: Remove Drupal 8 updates up to and including 88**
2020-01-24 23:52:03 +00:00
* Implements hook_update_last_removed().
2016-05-23 10:15:39 +00:00
*/
Issue #3087644 by jibran, Berdir, alexpott, longwave, Wim Leers, amateescu, catch, xjm, larowlan, dpi, quietone: Remove Drupal 8 updates up to and including 88**
2020-01-24 23:52:03 +00:00
function update_update_last_removed() {
return 8001;
2016-05-23 10:15:39 +00:00
}