update.module
Same filename and directory in other branches
File
-
core/
modules/ update/ update.module
View source
<?php
/**
* @file
*/
use Drupal\Core\Url;
use Drupal\update\UpdateFetcherInterface;
use Drupal\update\UpdateManagerInterface;
/**
* Returns a warning message when there is no data about available updates.
*
* @deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. Use
* \Drupal\update\UpdateMessageTrait::noData() instead.
*
* @see https://www.drupal.org/node/3592959
*/
function _update_no_data() {
@trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. Use \\Drupal\\update\\UpdateMessageTrait::noData() instead. See https://www.drupal.org/node/3592959', E_USER_DEPRECATED);
$destination = \Drupal::destination()->getAsArray();
return t('No update information available. <a href=":run_cron">Run cron</a> or <a href=":check_manually">check manually</a>.', [
':run_cron' => Url::fromRoute('system.run_cron', [], [
'query' => $destination,
])->toString(),
':check_manually' => Url::fromRoute('update.manual_status', [], [
'query' => $destination,
])->toString(),
]);
}
/**
* 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 installed 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 \Drupal\update\UpdateManagerInterface::calculateProjectData() will
* be wrong and produce confusing, bogus results.
*
* @param bool $refresh
* (optional) Boolean to indicate if this method should refresh automatically
* if there's no data. Defaults to FALSE.
*
* @return array
* Array of data about available releases, keyed by project shortname.
*
* @see \Drupal\update\UpdateManagerInterface::refreshUpdateData()
* @see \Drupal\update\UpdateManagerInterface::getProjects()
*
* @deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. Use
* \Drupal\update\UpdateManagerInterface::getAvailable() instead.
*
* @see https://www.drupal.org/node/3592959
*/
function update_get_available($refresh = FALSE) {
@trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. Use \\Drupal\\update\\UpdateManagerInterface::getAvailable() instead. See https://www.drupal.org/node/3592959', E_USER_DEPRECATED);
return \Drupal::service(UpdateManagerInterface::class)->getAvailable($refresh);
}
/**
* Adds a task to the queue for fetching release history data for a project.
*
* We only create a new fetch task if there's no task already in the queue for
* this particular project (based on 'update_fetch_task' key-value collection).
*
* @param array $project
* Associative array of information about a project as created by
* \Drupal\update\UpdateManagerInterface::getProjects(), including keys such
* as 'name' (short name), and the 'info' array with data from a .info.yml
* file for the project.
*
* @see \Drupal\update\UpdateFetcher::createFetchTask()
*
* @deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. Use
* \Drupal\update\UpdateProcessor::createFetchTask() instead.
*
* @see https://www.drupal.org/node/3592959
*/
function update_create_fetch_task($project) : void {
@trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. Use \\Drupal\\update\\UpdateProcessor::createFetchTask() instead. See https://www.drupal.org/node/3592959', E_USER_DEPRECATED);
\Drupal::service('update.processor')->createFetchTask($project);
}
/**
* Refreshes the release data after loading the necessary include file.
*
* @deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. Use
* \Drupal\update\UpdateManagerInterface::refreshUpdateData() instead.
*
* @see https://www.drupal.org/node/3592959
*/
function update_refresh() : void {
@trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. Use \\Drupal\\update\\UpdateManagerInterface::refreshUpdateData() instead. See https://www.drupal.org/node/3592959', E_USER_DEPRECATED);
\Drupal::service(UpdateManagerInterface::class)->refreshUpdateData();
}
/**
* Attempts to fetch update data after loading the necessary include file.
*
* @see \Drupal\update\UpdateProcessor::fetchData()
*
* @deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. Use
* \Drupal\update\UpdateProcessor::fetchData() instead.
*
* @see https://www.drupal.org/node/3592959
*/
function update_fetch_data() : void {
@trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. Use \\Drupal\\update\\UpdateProcessor::fetchData() instead. See https://www.drupal.org/node/3592959', E_USER_DEPRECATED);
\Drupal::service('update.processor')->fetchData();
}
/**
* Batch callback: Performs actions when all fetch tasks have been completed.
*
* @param bool $success
* TRUE if the batch operation was successful; FALSE if there were errors.
* @param array $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.
*
* @deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. There
* is no replacement.
*
* @see https://www.drupal.org/node/3592959
*/
function update_fetch_data_finished($success, $results) : void {
@trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. There is no replacement. See https://www.drupal.org/node/3592959', E_USER_DEPRECATED);
if ($success) {
if (!empty($results)) {
if (!empty($results['updated'])) {
\Drupal::messenger()->addStatus(\Drupal::translation()->formatPlural($results['updated'], 'Checked available update data for one project.', 'Checked available update data for @count projects.'));
}
if (!empty($results['failures'])) {
\Drupal::messenger()->addError(\Drupal::translation()->formatPlural($results['failures'], 'Failed to get available update data for one project.', 'Failed to get available update data for @count projects.'));
}
}
}
else {
\Drupal::messenger()->addError(t('An error occurred trying to get available update data.'), 'error');
}
}
/**
* 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 string $msg_type
* String to indicate what kind of message to generate. Can be either 'core'
* or 'contrib'.
* @param int $msg_reason
* Integer constant specifying why message is generated.
* @param string $langcode
* (optional) A language code to use. Defaults to NULL.
* @param bool $is_email
* (optional) Controls if this function is used for generating mail. If TRUE,
* URLs will be absolute and will be included without access checks. If FALSE,
* links will be relative and will only be included if the current user can
* access them. Defaults to FALSE.
*
* @return \Drupal\Core\StringTranslation\TranslatableMarkup
* The properly translated error message for the given key.
*
* @deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. Use
* \Drupal\update\UpdateMessageTrait::getText() instead.
*
* @see https://www.drupal.org/node/3592959
*/
function _update_message_text($msg_type, $msg_reason, $langcode = NULL, bool $is_email = FALSE) {
@trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. Use \\Drupal\\update\\UpdateMessageTrait::getText() instead. See https://www.drupal.org/node/3592959', E_USER_DEPRECATED);
$text = '';
switch ($msg_reason) {
case UpdateManagerInterface::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!', [], [
'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!', [], [
'langcode' => $langcode,
]);
}
break;
case UpdateManagerInterface::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!', [], [
'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 uninstalling is strongly recommended!', [], [
'langcode' => $langcode,
]);
}
break;
case UpdateManagerInterface::NOT_SUPPORTED:
if ($msg_type == 'core') {
$text = t('Your version of Drupal is no longer supported. Upgrading is strongly recommended!', [], [
'langcode' => $langcode,
]);
}
else {
$text = t('The installed version of at least one of your modules or themes is no longer supported. Upgrading or uninstalling is strongly recommended. See the project homepage for more details.', [], [
'langcode' => $langcode,
]);
}
break;
case UpdateManagerInterface::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.', [], [
'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.', [], [
'langcode' => $langcode,
]);
}
break;
case UpdateFetcherInterface::UNKNOWN:
case UpdateFetcherInterface::NOT_CHECKED:
case UpdateFetcherInterface::NOT_FETCHED:
case UpdateFetcherInterface::FETCH_PENDING:
$url = Url::fromRoute('update.status', [], [
'absolute' => $is_email,
'language' => $langcode,
]);
if ($msg_type == 'core') {
if ($url->access() || $is_email) {
return t('There was a problem checking <a href=":update-report">available updates</a> for Drupal.', [
':update-report' => $url->toString(),
], [
'langcode' => $langcode,
]);
}
return t('There was a problem checking available updates for Drupal.', [], [
'langcode' => $langcode,
]);
}
else {
if ($url->access() || $is_email) {
return t('There was a problem checking <a href=":update-report">available updates</a> for your modules or themes.', [
':update-report' => $url->toString(),
], [
'langcode' => $langcode,
]);
}
return t('There was a problem checking available updates for Drupal.', [], [
'langcode' => $langcode,
]);
}
break;
}
return $text;
}
/**
* Orders projects based on their status.
*
* Callback for uasort() within update_requirements().
*
* @deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. There
* is no replacement.
*
* @see https://www.drupal.org/node/3592959
*/
function _update_project_status_sort($a, $b) {
@trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. There is no replacement. See https://www.drupal.org/node/3592959', E_USER_DEPRECATED);
// 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;
}
/**
* Invalidates stored data relating to update status.
*
* @deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. Use
* \Drupal\update\UpdateManagerInterface::reset() instead.
*
* @see https://www.drupal.org/node/3592959
*/
function update_storage_clear() : void {
@trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:13.0.0. Use \\Drupal\\update\\UpdateManagerInterface::reset() instead. See https://www.drupal.org/node/3592959', E_USER_DEPRECATED);
\Drupal::service(UpdateManagerInterface::class)->reset();
}
Functions
| Title | Deprecated | Summary |
|---|---|---|
| update_create_fetch_task | in drupal:11.5.0 and is removed from drupal:13.0.0. Use \Drupal\update\UpdateProcessor::createFetchTask() instead. |
Adds a task to the queue for fetching release history data for a project. |
| update_fetch_data | in drupal:11.5.0 and is removed from drupal:13.0.0. Use \Drupal\update\UpdateProcessor::fetchData() instead. |
Attempts to fetch update data after loading the necessary include file. |
| update_fetch_data_finished | in drupal:11.5.0 and is removed from drupal:13.0.0. There is no replacement. |
Batch callback: Performs actions when all fetch tasks have been completed. |
| update_get_available | in drupal:11.5.0 and is removed from drupal:13.0.0. Use \Drupal\update\UpdateManagerInterface::getAvailable() instead. |
Tries to get update information and refreshes it when necessary. |
| update_refresh | in drupal:11.5.0 and is removed from drupal:13.0.0. Use \Drupal\update\UpdateManagerInterface::refreshUpdateData() instead. |
Refreshes the release data after loading the necessary include file. |
| update_storage_clear | in drupal:11.5.0 and is removed from drupal:13.0.0. Use \Drupal\update\UpdateManagerInterface::reset() instead. |
Invalidates stored data relating to update status. |
| _update_message_text | in drupal:11.5.0 and is removed from drupal:13.0.0. Use \Drupal\update\UpdateMessageTrait::getText() instead. |
Returns the appropriate message text when site is out of date or not secure. |
| _update_no_data | in drupal:11.5.0 and is removed from drupal:13.0.0. Use \Drupal\update\UpdateMessageTrait::noData() instead. |
Returns a warning message when there is no data about available updates. |
| _update_project_status_sort | in drupal:11.5.0 and is removed from drupal:13.0.0. There is no replacement. |
Orders projects based on their status. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.