2007-07-11 15:15:40 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Code required only when fetching information about available updates.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2012-06-06 15:33:53 +00:00
|
|
|
* Attempts to drain the queue of tasks for release history data to fetch.
|
2014-01-24 20:03:38 +00:00
|
|
|
*
|
|
|
|
* @see \Drupal\update\UpdateFetcher::fetchData()
|
2014-02-20 13:49:37 +00:00
|
|
|
*
|
|
|
|
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
|
|
|
|
* Use \Drupal::service('update.processor')->fetchData().
|
2007-07-11 15:15:40 +00:00
|
|
|
*/
|
2009-10-13 02:14:05 +00:00
|
|
|
function _update_fetch_data() {
|
2014-01-24 20:03:38 +00:00
|
|
|
\Drupal::service('update.processor')->fetchData();
|
2009-10-13 02:14:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-03-20 11:51:03 +00:00
|
|
|
* Clears out all the available update data and initiates re-fetching.
|
2014-01-24 20:03:38 +00:00
|
|
|
*
|
|
|
|
* @see \Drupal\update\UpdateManager::refreshUpdateData()
|
2014-02-20 13:49:37 +00:00
|
|
|
*
|
|
|
|
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
|
|
|
|
* Use \Drupal::service('update.manager')->refreshUpdateData().
|
2009-10-13 02:14:05 +00:00
|
|
|
*/
|
|
|
|
function _update_refresh() {
|
2014-01-24 20:03:38 +00:00
|
|
|
\Drupal::service('update.manager')->refreshUpdateData();
|
2009-10-13 02:14:05 +00:00
|
|
|
}
|
2007-07-11 15:15:40 +00:00
|
|
|
|
2009-10-13 02:14:05 +00:00
|
|
|
/**
|
2012-06-06 15:33:53 +00:00
|
|
|
* Adds a task to the queue for fetching release history data for a project.
|
2009-10-13 02:14:05 +00:00
|
|
|
*
|
|
|
|
* We only create a new fetch task if there's no task already in the queue for
|
2013-03-20 11:51:03 +00:00
|
|
|
* this particular project (based on 'update_fetch_task' key-value collection).
|
2009-10-13 02:14:05 +00:00
|
|
|
*
|
|
|
|
* @param $project
|
|
|
|
* Associative array of information about a project as created by
|
2012-06-06 15:33:53 +00:00
|
|
|
* update_get_projects(), including keys such as 'name' (short name), and the
|
2013-03-06 22:51:39 +00:00
|
|
|
* 'info' array with data from a .info.yml file for the project.
|
2009-10-13 02:14:05 +00:00
|
|
|
*
|
2014-01-24 20:03:38 +00:00
|
|
|
* @see \Drupal\update\UpdateFetcher::createFetchTask()
|
2014-02-20 13:49:37 +00:00
|
|
|
*
|
|
|
|
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
|
|
|
|
* Use \Drupal::service('update.processor')->createFetchTask().
|
2009-10-13 02:14:05 +00:00
|
|
|
*/
|
|
|
|
function _update_create_fetch_task($project) {
|
2014-01-24 20:03:38 +00:00
|
|
|
\Drupal::service('update.processor')->createFetchTask($project);
|
2007-07-11 15:15:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-06 15:33:53 +00:00
|
|
|
* Performs any notifications that should be done once cron fetches new data.
|
2007-07-11 15:15:40 +00:00
|
|
|
*
|
2012-06-06 15:33:53 +00:00
|
|
|
* This method checks the status of the site using the new data and, depending
|
2014-06-09 21:47:53 +00:00
|
|
|
* on the configuration of the site, notifies administrators via email if there
|
2007-07-11 15:15:40 +00:00
|
|
|
* are new releases or missing security updates.
|
|
|
|
*
|
|
|
|
* @see update_requirements()
|
|
|
|
*/
|
|
|
|
function _update_cron_notify() {
|
2013-09-16 03:58:06 +00:00
|
|
|
$update_config = \Drupal::config('update.settings');
|
2009-12-29 07:21:34 +00:00
|
|
|
module_load_install('update');
|
2007-07-11 15:15:40 +00:00
|
|
|
$status = update_requirements('runtime');
|
|
|
|
$params = array();
|
2012-08-03 16:52:07 +00:00
|
|
|
$notify_all = ($update_config->get('notification.threshold') == 'all');
|
2007-07-11 15:15:40 +00:00
|
|
|
foreach (array('core', 'contrib') as $report_type) {
|
2008-04-14 17:48:46 +00:00
|
|
|
$type = 'update_' . $report_type;
|
2007-07-11 15:15:40 +00:00
|
|
|
if (isset($status[$type]['severity'])
|
2009-04-29 03:57:21 +00:00
|
|
|
&& ($status[$type]['severity'] == REQUIREMENT_ERROR || ($notify_all && $status[$type]['reason'] == UPDATE_NOT_CURRENT))) {
|
2007-07-11 15:15:40 +00:00
|
|
|
$params[$report_type] = $status[$type]['reason'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!empty($params)) {
|
2012-08-03 16:52:07 +00:00
|
|
|
$notify_list = $update_config->get('notification.emails');
|
2007-07-11 15:15:40 +00:00
|
|
|
if (!empty($notify_list)) {
|
2014-03-31 17:29:01 +00:00
|
|
|
$default_langcode = \Drupal::languageManager()->getDefaultLanguage()->id;
|
2007-07-11 15:15:40 +00:00
|
|
|
foreach ($notify_list as $target) {
|
2009-03-14 23:01:38 +00:00
|
|
|
if ($target_user = user_load_by_mail($target)) {
|
2013-07-09 13:46:44 +00:00
|
|
|
$target_langcode = $target_user->getPreferredLangcode();
|
2007-07-11 15:15:40 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-09-13 08:48:24 +00:00
|
|
|
$target_langcode = $default_langcode;
|
2007-07-11 15:15:40 +00:00
|
|
|
}
|
2012-09-13 08:48:24 +00:00
|
|
|
$message = drupal_mail('update', 'status_notify', $target, $target_langcode, $params);
|
2012-06-14 04:58:22 +00:00
|
|
|
// Track when the last mail was successfully sent to avoid sending
|
2014-06-09 21:47:53 +00:00
|
|
|
// too many emails.
|
2012-06-14 04:58:22 +00:00
|
|
|
if ($message['result']) {
|
2013-09-16 03:58:06 +00:00
|
|
|
\Drupal::state()->set('update.last_email_notification', REQUEST_TIME);
|
2012-06-14 04:58:22 +00:00
|
|
|
}
|
2007-07-11 15:15:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|