diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-12-29 07:21:34 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-12-29 07:21:34 +0000 |
commit | c7d326de48558617c4a7c0e9f38196c22329622a (patch) | |
tree | ee5e4cc7e53f84e7f137030a94d972088470156e /modules/update | |
parent | d163389230febfae9114493f3688cce73087b4af (diff) | |
download | brdo-c7d326de48558617c4a7c0e9f38196c22329622a.tar.gz brdo-c7d326de48558617c4a7c0e9f38196c22329622a.tar.bz2 |
#669556 by Dave Reid: Move update_requirements() to update.install.
Diffstat (limited to 'modules/update')
-rw-r--r-- | modules/update/update.fetch.inc | 2 | ||||
-rw-r--r-- | modules/update/update.install | 125 | ||||
-rw-r--r-- | modules/update/update.module | 119 |
3 files changed, 122 insertions, 124 deletions
diff --git a/modules/update/update.fetch.inc b/modules/update/update.fetch.inc index a7a344813..4f55f0a10 100644 --- a/modules/update/update.fetch.inc +++ b/modules/update/update.fetch.inc @@ -309,7 +309,7 @@ function _update_get_fetch_url_base($project) { * @see update_requirements() */ function _update_cron_notify() { - include_once DRUPAL_ROOT . '/includes/install.inc'; + module_load_install('update'); $status = update_requirements('runtime'); $params = array(); $notify_all = (variable_get('update_notification_threshold', 'all') == 'all'); diff --git a/modules/update/update.install b/modules/update/update.install index 441118ef8..7fcbf2ab8 100644 --- a/modules/update/update.install +++ b/modules/update/update.install @@ -7,6 +7,66 @@ */ /** + * Implements hook_requirements(). + * + * @return + * 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 returned (UPDATE_NOT_SECURE, UPDATE_NOT_CURRENT, or + * UPDATE_UNKNOWN). This is used for generating the appropriate e-mail + * notification messages during update_cron(), and might be useful for other + * modules that invoke update_requirements() to find out if the site is up + * to date or not. + * + * @see _update_message_text() + * @see _update_cron_notify() + */ +function update_requirements($phase) { + 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; + $requirements['update_core']['reason'] = UPDATE_UNKNOWN; + $requirements['update_core']['description'] = _update_no_data(); + } + return $requirements; + } +} + +/** + * Implements hook_schema(). + */ +function update_schema() { + $schema['cache_update'] = drupal_get_schema_unprocessed('system', 'cache'); + $schema['cache_update']['description'] = 'Cache table for the Update module to store information about available releases, fetched from central server.'; + return $schema; +} + +/** * Implements hook_install(). */ function update_install() { @@ -36,12 +96,66 @@ function update_uninstall() { } /** - * Implements hook_schema(). + * Private helper method to fill in the requirements array. + * + * This is shared for both core and contrib to generate the right elements in + * the array for hook_requirements(). + * + * @param $project + * Array of information about the project we're testing as returned by + * update_calculate_project_data(). + * @param $type + * What kind of project is this ('core' or 'contrib'). + * + * @return + * An array to be included in the nested $requirements array. + * + * @see hook_requirements() + * @see update_requirements() + * @see update_calculate_project_data() */ -function update_schema() { - $schema['cache_update'] = drupal_get_schema_unprocessed('system', 'cache'); - $schema['cache_update']['description'] = 'Cache table for the Update module to store information about available releases, fetched from central server.'; - return $schema; +function _update_requirement_check($project, $type) { + $requirement = array(); + if ($type == 'core') { + $requirement['title'] = t('Drupal core update status'); + } + else { + $requirement['title'] = t('Module and theme update status'); + } + $status = $project['status']; + if ($status != UPDATE_CURRENT) { + $requirement['reason'] = $status; + $requirement['description'] = _update_message_text($type, $status, TRUE); + $requirement['severity'] = REQUIREMENT_ERROR; + } + switch ($status) { + case UPDATE_NOT_SECURE: + $requirement_label = t('Not secure!'); + break; + case UPDATE_REVOKED: + $requirement_label = t('Revoked!'); + break; + case UPDATE_NOT_SUPPORTED: + $requirement_label = t('Unsupported release'); + break; + case UPDATE_NOT_CURRENT: + $requirement_label = t('Out of date'); + $requirement['severity'] = REQUIREMENT_WARNING; + break; + case UPDATE_UNKNOWN: + case UPDATE_NOT_CHECKED: + case UPDATE_NOT_FETCHED: + $requirement_label = isset($project['reason']) ? $project['reason'] : t('Can not determine status'); + $requirement['severity'] = REQUIREMENT_WARNING; + break; + default: + $requirement_label = t('Up to date'); + } + if ($status != UPDATE_CURRENT && $type == 'core' && isset($project['recommended'])) { + $requirement_label .= ' ' . t('(version @version available)', array('@version' => $project['recommended'])); + } + $requirement['value'] = l($requirement_label, update_manager_access() ? 'admin/reports/updates/update' : 'admin/reports/updates'); + return $requirement; } /** @@ -52,4 +166,3 @@ function update_update_7000() { $queue = DrupalQueue::get('update_fetch_tasks'); $queue->createQueue(); } - diff --git a/modules/update/update.module b/modules/update/update.module index 83c0ae3f0..9611a45c4 100644 --- a/modules/update/update.module +++ b/modules/update/update.module @@ -81,7 +81,7 @@ function update_help($path, $arg) { case 'admin/appearance': case 'admin/config/modules': - include_once DRUPAL_ROOT . '/includes/install.inc'; + module_load_install('update'); $status = update_requirements('runtime'); foreach (array('core', 'contrib') as $report_type) { $type = 'update_' . $report_type; @@ -134,7 +134,7 @@ function update_help($path, $arg) { // update missing, print an error message about it. if (arg(0) == 'admin' && strpos($path, '#') === FALSE && user_access('administer site configuration')) { - include_once DRUPAL_ROOT . '/includes/install.inc'; + module_load_install('update'); $status = update_requirements('runtime'); foreach (array('core', 'contrib') as $report_type) { $type = 'update_' . $report_type; @@ -145,7 +145,6 @@ function update_help($path, $arg) { } } } - } } @@ -277,120 +276,6 @@ function update_theme() { } /** - * Implements hook_requirements(). - * - * @return - * 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 returned (UPDATE_NOT_SECURE, UPDATE_NOT_CURRENT, or - * UPDATE_UNKNOWN). This is used for generating the appropriate e-mail - * notification messages during update_cron(), and might be useful for other - * modules that invoke update_requirements() to find out if the site is up - * to date or not. - * - * @see _update_message_text() - * @see _update_cron_notify() - */ -function update_requirements($phase) { - 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; - $requirements['update_core']['reason'] = UPDATE_UNKNOWN; - $requirements['update_core']['description'] = _update_no_data(); - } - return $requirements; - } -} - -/** - * Private helper method to fill in the requirements array. - * - * This is shared for both core and contrib to generate the right elements in - * the array for hook_requirements(). - * - * @param $project - * Array of information about the project we're testing as returned by - * update_calculate_project_data(). - * @param $type - * What kind of project is this ('core' or 'contrib'). - * - * @return - * An array to be included in the nested $requirements array. - * - * @see hook_requirements() - * @see update_requirements() - * @see update_calculate_project_data() - */ -function _update_requirement_check($project, $type) { - $requirement = array(); - if ($type == 'core') { - $requirement['title'] = t('Drupal core update status'); - } - else { - $requirement['title'] = t('Module and theme update status'); - } - $status = $project['status']; - if ($status != UPDATE_CURRENT) { - $requirement['reason'] = $status; - $requirement['description'] = _update_message_text($type, $status, TRUE); - $requirement['severity'] = REQUIREMENT_ERROR; - } - switch ($status) { - case UPDATE_NOT_SECURE: - $requirement_label = t('Not secure!'); - break; - case UPDATE_REVOKED: - $requirement_label = t('Revoked!'); - break; - case UPDATE_NOT_SUPPORTED: - $requirement_label = t('Unsupported release'); - break; - case UPDATE_NOT_CURRENT: - $requirement_label = t('Out of date'); - $requirement['severity'] = REQUIREMENT_WARNING; - break; - case UPDATE_UNKNOWN: - case UPDATE_NOT_CHECKED: - case UPDATE_NOT_FETCHED: - $requirement_label = isset($project['reason']) ? $project['reason'] : t('Can not determine status'); - $requirement['severity'] = REQUIREMENT_WARNING; - break; - default: - $requirement_label = t('Up to date'); - } - if ($status != UPDATE_CURRENT && $type == 'core' && isset($project['recommended'])) { - $requirement_label .= ' ' . t('(version @version available)', array('@version' => $project['recommended'])); - } - $requirement['value'] = l($requirement_label, update_manager_access() ? 'admin/reports/updates/update' : 'admin/reports/updates'); - return $requirement; -} - -/** * Implements hook_cron(). */ function update_cron() { |