update.module

You are here

  1. 7 modules/update/update.module
  2. 6 modules/update/update.module
  3. 8 core/modules/update/update.module

The "Update status" module checks for available updates of Drupal core and any installed contributed modules and themes. It warns site administrators if newer releases are available via the system status report (admin/reports/status), the module and theme pages, and optionally via email.

Functions

Namesort descending Description
update_cron Implementation of hook_cron().
update_flush_caches Implementation of hook_flush_caches().
update_form_alter Implementation of hook_form_alter().
update_get_available Internal helper to try to get the update information from the cache if possible, and to refresh the cache when necessary.
update_help Implementation of hook_help().
update_invalidate_cache Invalidates all cached data relating to update status.
update_mail Implementation of hook_mail().
update_menu Implementation of hook_menu().
update_refresh Wrapper to load the include file and then refresh the release data.
update_requirements Implementation of hook_requirements().
update_theme Implementation of the hook_theme() registry.
_update_cache_clear Invalidates specific cached data relating to update status.
_update_cache_get Retrieve data from the private update status cache table.
_update_cache_set Store data in the private update status cache table.
_update_message_text Helper function to return the appropriate message text when the site is out of date or missing a security update.
_update_no_data Prints a warning message when there is no data about available updates.
_update_project_status_sort Private sort function to order projects based on their status.
_update_requirement_check Private helper method to fill in the requirements array.

Constants

Namesort descending Description
UPDATE_CURRENT Project is up to date.
UPDATE_DEFAULT_URL URL to check for updates, if a given project doesn't define its own.
UPDATE_MAX_FETCH_ATTEMPTS Maximum number of attempts to fetch available update data from a given host.
UPDATE_NOT_CHECKED Project's status cannot be checked.
UPDATE_NOT_CURRENT Project has a new release available, but it is not a security release.
UPDATE_NOT_FETCHED There was a failure fetching available update data for this project.
UPDATE_NOT_SECURE Project is missing security update(s).
UPDATE_NOT_SUPPORTED Current release is no longer supported by the project maintainer.
UPDATE_REVOKED Current release has been unpublished and is no longer available.
UPDATE_UNKNOWN No available update data was found for project.

File

modules/update/update.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * The "Update status" module checks for available updates of Drupal core and
  5. * any installed contributed modules and themes. It warns site administrators
  6. * if newer releases are available via the system status report
  7. * (admin/reports/status), the module and theme pages, and optionally via email.
  8. */
  9. /**
  10. * URL to check for updates, if a given project doesn't define its own.
  11. */
  12. define('UPDATE_DEFAULT_URL', 'http://updates.drupal.org/release-history');
  13. // These are internally used constants for this code, do not modify.
  14. /**
  15. * Project is missing security update(s).
  16. */
  17. define('UPDATE_NOT_SECURE', 1);
  18. /**
  19. * Current release has been unpublished and is no longer available.
  20. */
  21. define('UPDATE_REVOKED', 2);
  22. /**
  23. * Current release is no longer supported by the project maintainer.
  24. */
  25. define('UPDATE_NOT_SUPPORTED', 3);
  26. /**
  27. * Project has a new release available, but it is not a security release.
  28. */
  29. define('UPDATE_NOT_CURRENT', 4);
  30. /**
  31. * Project is up to date.
  32. */
  33. define('UPDATE_CURRENT', 5);
  34. /**
  35. * Project's status cannot be checked.
  36. */
  37. define('UPDATE_NOT_CHECKED', -1);
  38. /**
  39. * No available update data was found for project.
  40. */
  41. define('UPDATE_UNKNOWN', -2);
  42. /**
  43. * There was a failure fetching available update data for this project.
  44. */
  45. define('UPDATE_NOT_FETCHED', -3);
  46. /**
  47. * Maximum number of attempts to fetch available update data from a given host.
  48. */
  49. define('UPDATE_MAX_FETCH_ATTEMPTS', 2);
  50. /**
  51. * Implementation of hook_help().
  52. */
  53. function update_help($path, $arg) {
  54. switch ($path) {
  55. case 'admin/reports/updates':
  56. $output = '<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>';
  57. $output .= '<p>'. t('To extend the functionality or to change the look of your site, a number of contributed <a href="@modules">modules</a> and <a href="@themes">themes</a> are available.', array('@modules' => 'http://drupal.org/project/modules', '@themes' => 'http://drupal.org/project/themes')) .'</p>';
  58. return $output;
  59. case 'admin/build/themes':
  60. case 'admin/build/modules':
  61. include_once './includes/install.inc';
  62. $status = update_requirements('runtime');
  63. foreach (array('core', 'contrib') as $report_type) {
  64. $type = 'update_'. $report_type;
  65. if (isset($status[$type]['severity'])) {
  66. if ($status[$type]['severity'] == REQUIREMENT_ERROR) {
  67. drupal_set_message($status[$type]['description'], 'error');
  68. }
  69. elseif ($status[$type]['severity'] == REQUIREMENT_WARNING) {
  70. drupal_set_message($status[$type]['description'], 'warning');
  71. }
  72. }
  73. }
  74. return '<p>'. t('See the <a href="@available_updates">available updates</a> page for information on installed modules and themes with new versions released.', array('@available_updates' => url('admin/reports/updates'))) .'</p>';
  75. case 'admin/reports/updates/settings':
  76. case 'admin/reports/status':
  77. // These two pages don't need additional nagging.
  78. break;
  79. case 'admin/help#update':
  80. $output = '<p>'. t("The Update status module periodically checks for new versions of your site's software (including contributed modules and themes), and alerts you to available updates.") .'</p>';
  81. $output .= '<p>'. t('The <a href="@update-report">report of available updates</a> will alert you when new releases are available for download. You may configure options for update checking frequency and notifications at the <a href="@update-settings">Update status module settings page</a>.', array('@update-report' => url('admin/reports/updates'), '@update-settings' => url('admin/reports/updates/settings'))) .'</p>';
  82. $output .= '<p>'. t('Please note that in order to provide this information, anonymous usage statistics are sent to drupal.org. If desired, you may disable the Update status module from the <a href="@modules">module administration page</a>.', array('@modules' => url('admin/build/modules'))) .'</p>';
  83. $output .= '<p>'. t('For more information, see the online handbook entry for <a href="@update">Update status module</a>.', array('@update' => 'http://drupal.org/handbook/modules/update')) .'</p>';
  84. return $output;
  85. default:
  86. // Otherwise, if we're on *any* admin page and there's a security
  87. // update missing, print an error message about it.
  88. if (arg(0) == 'admin' && strpos($path, '#') === FALSE
  89. && user_access('administer site configuration')) {
  90. include_once './includes/install.inc';
  91. $status = update_requirements('runtime');
  92. foreach (array('core', 'contrib') as $report_type) {
  93. $type = 'update_'. $report_type;
  94. if (isset($status[$type])
  95. && isset($status[$type]['reason'])
  96. && $status[$type]['reason'] === UPDATE_NOT_SECURE) {
  97. drupal_set_message($status[$type]['description'], 'error');
  98. }
  99. }
  100. }
  101. }
  102. }
  103. /**
  104. * Implementation of hook_menu().
  105. */
  106. function update_menu() {
  107. $items = array();
  108. $items['admin/reports/updates'] = array(
  109. 'title' => 'Available updates',
  110. 'description' => 'Get a status report about available updates for your installed modules and themes.',
  111. 'page callback' => 'update_status',
  112. 'access arguments' => array('administer site configuration'),
  113. 'file' => 'update.report.inc',
  114. 'weight' => 10,
  115. );
  116. $items['admin/reports/updates/list'] = array(
  117. 'title' => 'List',
  118. 'page callback' => 'update_status',
  119. 'access arguments' => array('administer site configuration'),
  120. 'file' => 'update.report.inc',
  121. 'type' => MENU_DEFAULT_LOCAL_TASK,
  122. );
  123. $items['admin/reports/updates/settings'] = array(
  124. 'title' => 'Settings',
  125. 'page callback' => 'drupal_get_form',
  126. 'page arguments' => array('update_settings'),
  127. 'access arguments' => array('administer site configuration'),
  128. 'file' => 'update.settings.inc',
  129. 'type' => MENU_LOCAL_TASK,
  130. );
  131. $items['admin/reports/updates/check'] = array(
  132. 'title' => 'Manual update check',
  133. 'page callback' => 'update_manual_status',
  134. 'access arguments' => array('administer site configuration'),
  135. 'file' => 'update.fetch.inc',
  136. 'type' => MENU_CALLBACK,
  137. );
  138. return $items;
  139. }
  140. /**
  141. * Implementation of the hook_theme() registry.
  142. */
  143. function update_theme() {
  144. return array(
  145. 'update_settings' => array(
  146. 'arguments' => array('form' => NULL),
  147. ),
  148. 'update_report' => array(
  149. 'arguments' => array('data' => NULL),
  150. ),
  151. 'update_version' => array(
  152. 'arguments' => array('version' => NULL, 'tag' => NULL, 'class' => NULL),
  153. ),
  154. );
  155. }
  156. /**
  157. * Implementation of hook_requirements().
  158. *
  159. * @return
  160. * An array describing the status of the site regarding available updates.
  161. * If there is no update data, only one record will be returned, indicating
  162. * that the status of core can't be determined. If data is available, there
  163. * will be two records: one for core, and another for all of contrib
  164. * (assuming there are any contributed modules or themes enabled on the
  165. * site). In addition to the fields expected by hook_requirements ('value',
  166. * 'severity', and optionally 'description'), this array will contain a
  167. * 'reason' attribute, which is an integer constant to indicate why the
  168. * given status is being returned (UPDATE_NOT_SECURE, UPDATE_NOT_CURRENT, or
  169. * UPDATE_UNKNOWN). This is used for generating the appropriate e-mail
  170. * notification messages during update_cron(), and might be useful for other
  171. * modules that invoke update_requirements() to find out if the site is up
  172. * to date or not.
  173. *
  174. * @see _update_message_text()
  175. * @see _update_cron_notify()
  176. */
  177. function update_requirements($phase) {
  178. if ($phase == 'runtime') {
  179. if ($available = update_get_available(FALSE)) {
  180. module_load_include('inc', 'update', 'update.compare');
  181. $data = update_calculate_project_data($available);
  182. // First, populate the requirements for core:
  183. $requirements['update_core'] = _update_requirement_check($data['drupal'], 'core');
  184. // We don't want to check drupal a second time.
  185. unset($data['drupal']);
  186. if (!empty($data)) {
  187. // Now, sort our $data array based on each project's status. The
  188. // status constants are numbered in the right order of precedence, so
  189. // we just need to make sure the projects are sorted in ascending
  190. // order of status, and we can look at the first project we find.
  191. uasort($data, '_update_project_status_sort');
  192. $first_project = reset($data);
  193. $requirements['update_contrib'] = _update_requirement_check($first_project, 'contrib');
  194. }
  195. }
  196. else {
  197. $requirements['update_core']['title'] = t('Drupal core update status');
  198. $requirements['update_core']['value'] = t('No update data available');
  199. $requirements['update_core']['severity'] = REQUIREMENT_WARNING;
  200. $requirements['update_core']['reason'] = UPDATE_UNKNOWN;
  201. $requirements['update_core']['description'] = _update_no_data();
  202. }
  203. return $requirements;
  204. }
  205. }
  206. /**
  207. * Private helper method to fill in the requirements array.
  208. *
  209. * This is shared for both core and contrib to generate the right elements in
  210. * the array for hook_requirements().
  211. *
  212. * @param $project
  213. * Array of information about the project we're testing as returned by
  214. * update_calculate_project_data().
  215. * @param $type
  216. * What kind of project is this ('core' or 'contrib').
  217. *
  218. * @return
  219. * An array to be included in the nested $requirements array.
  220. *
  221. * @see hook_requirements()
  222. * @see update_requirements()
  223. * @see update_calculate_project_data()
  224. */
  225. function _update_requirement_check($project, $type) {
  226. $requirement = array();
  227. if ($type == 'core') {
  228. $requirement['title'] = t('Drupal core update status');
  229. }
  230. else {
  231. $requirement['title'] = t('Module and theme update status');
  232. }
  233. $status = $project['status'];
  234. if ($status != UPDATE_CURRENT) {
  235. $requirement['reason'] = $status;
  236. $requirement['description'] = _update_message_text($type, $status, TRUE);
  237. $requirement['severity'] = REQUIREMENT_ERROR;
  238. }
  239. switch ($status) {
  240. case UPDATE_NOT_SECURE:
  241. $requirement_label = t('Not secure!');
  242. break;
  243. case UPDATE_REVOKED:
  244. $requirement_label = t('Revoked!');
  245. break;
  246. case UPDATE_NOT_SUPPORTED:
  247. $requirement_label = t('Unsupported release');
  248. break;
  249. case UPDATE_NOT_CURRENT:
  250. $requirement_label = t('Out of date');
  251. $requirement['severity'] = REQUIREMENT_WARNING;
  252. break;
  253. case UPDATE_UNKNOWN:
  254. case UPDATE_NOT_CHECKED:
  255. case UPDATE_NOT_FETCHED:
  256. $requirement_label = isset($project['reason']) ? $project['reason'] : t('Can not determine status');
  257. $requirement['severity'] = REQUIREMENT_WARNING;
  258. break;
  259. default:
  260. $requirement_label = t('Up to date');
  261. }
  262. if ($status != UPDATE_CURRENT && $type == 'core' && isset($project['recommended'])) {
  263. $requirement_label .= ' '. t('(version @version available)', array('@version' => $project['recommended']));
  264. }
  265. $requirement['value'] = l($requirement_label, 'admin/reports/updates');
  266. return $requirement;
  267. }
  268. /**
  269. * Implementation of hook_cron().
  270. */
  271. function update_cron() {
  272. $frequency = variable_get('update_check_frequency', 1);
  273. $interval = 60 * 60 * 24 * $frequency;
  274. // Cron should check for updates if there is no update data cached or if the
  275. // configured update interval has elapsed.
  276. if (!_update_cache_get('update_available_releases') || ((time() - variable_get('update_last_check', 0)) > $interval)) {
  277. update_refresh();
  278. _update_cron_notify();
  279. }
  280. }
  281. /**
  282. * Implementation of hook_form_alter().
  283. *
  284. * Adds a submit handler to the system modules and themes forms, so that if a
  285. * site admin saves either form, we invalidate the cache of available updates.
  286. *
  287. * @see update_invalidate_cache()
  288. */
  289. function update_form_alter(&$form, $form_state, $form_id) {
  290. if ($form_id == 'system_modules' || $form_id == 'system_themes_form' ) {
  291. $form['#submit'][] = 'update_invalidate_cache';
  292. }
  293. }
  294. /**
  295. * Prints a warning message when there is no data about available updates.
  296. */
  297. function _update_no_data() {
  298. $destination = drupal_get_destination();
  299. return t('No information is available about potential new releases for currently installed modules and themes. To check for updates, you may need to <a href="@run_cron">run cron</a> or you can <a href="@check_manually">check manually</a>. Please note that checking for available updates can take a long time, so please be patient.', array(
  300. '@run_cron' => url('admin/reports/status/run-cron', array('query' => $destination)),
  301. '@check_manually' => url('admin/reports/updates/check', array('query' => $destination)),
  302. ));
  303. }
  304. /**
  305. * Internal helper to try to get the update information from the cache
  306. * if possible, and to refresh the cache when necessary.
  307. *
  308. * In addition to checking the cache lifetime, this function also ensures that
  309. * there are no .info files for enabled modules or themes that have a newer
  310. * modification timestamp than the last time we checked for available update
  311. * data. If any .info file was modified, it almost certainly means a new
  312. * version of something was installed. Without fresh available update data,
  313. * the logic in update_calculate_project_data() will be wrong and produce
  314. * confusing, bogus results.
  315. *
  316. * @param $refresh
  317. * Boolean to indicate if this method should refresh the cache automatically
  318. * if there's no data.
  319. *
  320. * @see update_refresh()
  321. * @see update_get_projects()
  322. */
  323. function update_get_available($refresh = FALSE) {
  324. module_load_include('inc', 'update', 'update.compare');
  325. $available = array();
  326. // First, make sure that none of the .info files have a change time
  327. // newer than the last time we checked for available updates.
  328. $needs_refresh = FALSE;
  329. $last_check = variable_get('update_last_check', 0);
  330. $projects = update_get_projects();
  331. foreach ($projects as $key => $project) {
  332. if ($project['info']['_info_file_ctime'] > $last_check) {
  333. $needs_refresh = TRUE;
  334. break;
  335. }
  336. }
  337. if (!$needs_refresh && ($cache = _update_cache_get('update_available_releases')) && $cache->expire > time()) {
  338. $available = $cache->data;
  339. }
  340. elseif ($needs_refresh || $refresh) {
  341. // If we need to refresh due to a newer .info file, ignore the argument
  342. // and force the refresh (e.g., even for update_requirements()) to prevent
  343. // bogus results.
  344. $available = update_refresh();
  345. }
  346. return $available;
  347. }
  348. /**
  349. * Wrapper to load the include file and then refresh the release data.
  350. */
  351. function update_refresh() {
  352. module_load_include('inc', 'update', 'update.fetch');
  353. return _update_refresh();
  354. }
  355. /**
  356. * Implementation of hook_mail().
  357. *
  358. * Constructs the email notification message when the site is out of date.
  359. *
  360. * @param $key
  361. * Unique key to indicate what message to build, always 'status_notify'.
  362. * @param $message
  363. * Reference to the message array being built.
  364. * @param $params
  365. * Array of parameters to indicate what kind of text to include in the
  366. * message body. This is a keyed array of message type ('core' or 'contrib')
  367. * as the keys, and the status reason constant (UPDATE_NOT_SECURE, etc) for
  368. * the values.
  369. *
  370. * @see drupal_mail()
  371. * @see _update_cron_notify()
  372. * @see _update_message_text()
  373. */
  374. function update_mail($key, &$message, $params) {
  375. $language = $message['language'];
  376. $langcode = $language->language;
  377. $message['subject'] .= t('New release(s) available for !site_name', array('!site_name' => variable_get('site_name', 'Drupal')), $langcode);
  378. foreach ($params as $msg_type => $msg_reason) {
  379. $message['body'][] = _update_message_text($msg_type, $msg_reason, FALSE, $language);
  380. }
  381. $message['body'][] = t('See the available updates page for more information:', array(), $langcode) ."\n". url('admin/reports/updates', array('absolute' => TRUE, 'language' => $language));
  382. }
  383. /**
  384. * Helper function to return the appropriate message text when the site is out
  385. * of date or missing a security update.
  386. *
  387. * These error messages are shared by both update_requirements() for the
  388. * site-wide status report at admin/reports/status and in the body of the
  389. * notification emails generated by update_cron().
  390. *
  391. * @param $msg_type
  392. * String to indicate what kind of message to generate. Can be either
  393. * 'core' or 'contrib'.
  394. * @param $msg_reason
  395. * Integer constant specifying why message is generated.
  396. * @param $report_link
  397. * Boolean that controls if a link to the updates report should be added.
  398. * @param $language
  399. * An optional language object to use.
  400. * @return
  401. * The properly translated error message for the given key.
  402. */
  403. function _update_message_text($msg_type, $msg_reason, $report_link = FALSE, $language = NULL) {
  404. $langcode = isset($language) ? $language->language : NULL;
  405. $text = '';
  406. switch ($msg_reason) {
  407. case UPDATE_NOT_SECURE:
  408. if ($msg_type == 'core') {
  409. $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(), $langcode);
  410. }
  411. else {
  412. $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(), $langcode);
  413. }
  414. break;
  415. case UPDATE_REVOKED:
  416. if ($msg_type == 'core') {
  417. $text = t('Your version of Drupal has been revoked and is no longer available for download. Upgrading is strongly recommended!', array(), $langcode);
  418. }
  419. else {
  420. $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(), $langcode);
  421. }
  422. break;
  423. case UPDATE_NOT_SUPPORTED:
  424. if ($msg_type == 'core') {
  425. $text = t('Your version of Drupal is no longer supported. Upgrading is strongly recommended!', array(), $langcode);
  426. }
  427. else {
  428. $text = t('The installed version of at least one of your modules or themes is no longer supported. Upgrading or disabling is strongly recommended! Please see the project homepage for more details.', array(), $langcode);
  429. }
  430. break;
  431. case UPDATE_NOT_CURRENT:
  432. if ($msg_type == 'core') {
  433. $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(), $langcode);
  434. }
  435. else {
  436. $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(), $langcode);
  437. }
  438. break;
  439. case UPDATE_UNKNOWN:
  440. case UPDATE_NOT_CHECKED:
  441. case UPDATE_NOT_FETCHED:
  442. if ($msg_type == 'core') {
  443. $text = t('There was a problem determining the status of available updates for your version of Drupal.', array(), $langcode);
  444. }
  445. else {
  446. $text = t('There was a problem determining the status of available updates for one or more of your modules or themes.', array(), $langcode);
  447. }
  448. break;
  449. }
  450. if ($report_link) {
  451. $text .= ' '. t('See the <a href="@available_updates">available updates</a> page for more information.', array('@available_updates' => url('admin/reports/updates', array('language' => $language))), $langcode);
  452. }
  453. return $text;
  454. }
  455. /**
  456. * Private sort function to order projects based on their status.
  457. *
  458. * @see update_requirements()
  459. * @see uasort()
  460. */
  461. function _update_project_status_sort($a, $b) {
  462. // The status constants are numerically in the right order, so we can
  463. // usually subtract the two to compare in the order we want. However,
  464. // negative status values should be treated as if they are huge, since we
  465. // always want them at the bottom of the list.
  466. $a_status = $a['status'] > 0 ? $a['status'] : (-10 * $a['status']);
  467. $b_status = $b['status'] > 0 ? $b['status'] : (-10 * $b['status']);
  468. return $a_status - $b_status;
  469. }
  470. /**
  471. * @defgroup update_status_cache Private update status cache system
  472. * @{
  473. *
  474. * We specifically do NOT use the core cache API for saving the fetched data
  475. * about available updates. It is vitally important that this cache is only
  476. * cleared when we're populating it after successfully fetching new available
  477. * update data. Usage of the core cache API results in all sorts of potential
  478. * problems that would result in attempting to fetch available update data all
  479. * the time, including if a site has a "minimum cache lifetime" (which is both
  480. * a minimum and a maximum) defined, or if a site uses memcache or another
  481. * plug-able cache system that assumes volatile caches.
  482. *
  483. * Update module still uses the {cache_update} table, but instead of using
  484. * cache_set(), cache_get(), and cache_clear_all(), there are private helper
  485. * functions that implement these same basic tasks but ensure that the cache
  486. * is not prematurely cleared, and that the data is always stored in the
  487. * database, even if memcache or another cache backend is in use.
  488. */
  489. /**
  490. * Store data in the private update status cache table.
  491. *
  492. * Note: this function completely ignores the {cache_update}.headers field
  493. * since that is meaningless for the kinds of data we're caching.
  494. *
  495. * @param $cid
  496. * The cache ID to save the data with.
  497. * @param $data
  498. * The data to store.
  499. * @param $expire
  500. * One of the following values:
  501. * - CACHE_PERMANENT: Indicates that the item should never be removed except
  502. * by explicitly using _update_cache_clear() or update_invalidate_cache().
  503. * - A Unix timestamp: Indicates that the item should be kept at least until
  504. * the given time, after which it will be invalidated.
  505. */
  506. function _update_cache_set($cid, $data, $expire) {
  507. $serialized = 0;
  508. if (is_object($data) || is_array($data)) {
  509. $data = serialize($data);
  510. $serialized = 1;
  511. }
  512. $created = time();
  513. db_query("UPDATE {cache_update} SET data = %b, created = %d, expire = %d, serialized = %d WHERE cid = '%s'", $data, $created, $expire, $serialized, $cid);
  514. if (!db_affected_rows()) {
  515. @db_query("INSERT INTO {cache_update} (cid, data, created, expire, serialized) VALUES ('%s', %b, %d, %d, %d)", $cid, $data, $created, $expire, $serialized);
  516. }
  517. }
  518. /**
  519. * Retrieve data from the private update status cache table.
  520. *
  521. * @param $cid
  522. * The cache ID to retrieve.
  523. * @return
  524. * The data for the given cache ID, or NULL if the ID was not found.
  525. */
  526. function _update_cache_get($cid) {
  527. $cache = db_fetch_object(db_query("SELECT data, created, expire, serialized FROM {cache_update} WHERE cid = '%s'", $cid));
  528. if (isset($cache->data)) {
  529. $cache->data = db_decode_blob($cache->data);
  530. if ($cache->serialized) {
  531. $cache->data = unserialize($cache->data);
  532. }
  533. }
  534. return $cache;
  535. }
  536. /**
  537. * Invalidates specific cached data relating to update status.
  538. *
  539. * @param $cid
  540. * Optional cache ID of the record to clear from the private update module
  541. * cache. If empty, all records will be cleared from the table.
  542. */
  543. function _update_cache_clear($cid = NULL) {
  544. if (empty($cid)) {
  545. db_query("TRUNCATE TABLE {cache_update}");
  546. }
  547. else {
  548. db_query("DELETE FROM {cache_update} WHERE cid = '%s'", $cid);
  549. }
  550. }
  551. /**
  552. * Implementation of hook_flush_caches().
  553. *
  554. * Called from update.php (among others) to flush the caches.
  555. * Since we're running update.php, we are likely to install a new version of
  556. * something, in which case, we want to check for available update data again.
  557. * However, because we have our own caching system, we need to directly clear
  558. * the database table ourselves at this point and return nothing, for example,
  559. * on sites that use memcache where cache_clear_all() won't know how to purge
  560. * this data.
  561. *
  562. * However, we only want to do this from update.php, since otherwise, we'd
  563. * lose all the available update data on every cron run. So, we specifically
  564. * check if the site is in MAINTENANCE_MODE == 'update' (which indicates
  565. * update.php is running, not update module... alas for overloaded names).
  566. */
  567. function update_flush_caches() {
  568. if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update') {
  569. _update_cache_clear();
  570. }
  571. return array();
  572. }
  573. /**
  574. * Invalidates all cached data relating to update status.
  575. */
  576. function update_invalidate_cache() {
  577. _update_cache_clear();
  578. }
  579. /**
  580. * @} End of "defgroup update_status_cache".
  581. */