- <?php
- * @file
- * Install, update, and uninstall functions for the Update Manager module.
- */
-
- * 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 email 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) {
- $requirements = array();
- if ($phase == 'runtime') {
- if (_update_checking_enabled() && ($available = update_get_available(FALSE))) {
- module_load_include('inc', 'update', 'update.compare');
- $data = update_calculate_project_data($available);
-
- $requirements['update_core'] = _update_requirement_check($data['backdrop'], 'core');
- $core_status = $data['backdrop']['status'];
-
- unset($data['backdrop']);
- if (!empty($data) && $core_status !== UPDATE_NOT_IMPLEMENTED) {
-
-
-
-
- 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('Backdrop CMS core update status');
- $requirements['update_core']['value'] = t('No update data available');
- $requirements['update_core']['severity'] = REQUIREMENT_INFO;
- $requirements['update_core']['reason'] = UPDATE_UNKNOWN;
- $requirements['update_core']['description'] = _update_no_data();
- }
- }
- return $requirements;
- }
-
- * Implements hook_schema().
- */
- function update_schema() {
- $schema['cache_update'] = backdrop_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() {
- $queue = BackdropQueue::get('update_fetch_tasks', TRUE);
- $queue->createQueue();
- }
-
- * Implements hook_uninstall().
- */
- function update_uninstall() {
- state_del('update_last_check');
- state_del('update_last_email_notification');
-
- $queue = BackdropQueue::get('update_fetch_tasks');
- $queue->deleteQueue();
- }
-
- * Fills 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 this is ('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('Backdrop CMS update status');
- }
- else {
- $requirement['title'] = t('Module, theme, and layout updates');
- }
- $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:
- case UPDATE_FETCH_PENDING:
- $requirement_label = isset($project['reason']) ? $project['reason'] : t('Update information not available.');
- $requirement['severity'] = REQUIREMENT_INFO;
- break;
- case UPDATE_NOT_IMPLEMENTED:
- $text = t('Not yet implemented');
- $url = config_get('update.settings', 'update_not_implemented_url');
- $requirement['value'] = $url ? l($text, $url) : $text;
- $requirement['severity'] = REQUIREMENT_INFO;
- break;
- default:
- $requirement_label = t('Up to date');
- }
- if (isset($requirement_label)) {
- if ($status != UPDATE_CURRENT) {
- if ($type == 'core' && isset($project['recommended'])) {
- $version_available = t('version @version available', array('@version' => $project['recommended']));
- }
- else {
- $version_available = t('updates available');
- }
- if (update_manager_access() && module_exists('installer')) {
- $updates_path = 'admin/config/system/updates';
- }
- else {
- $updates_path = 'admin/reports/updates';
- }
- $requirement_label .= ' (' . l($version_available, $updates_path) . ')';
- }
- $requirement['value'] = $requirement_label;
- }
- return $requirement;
- }
-
- * @addtogroup updates-7.x-to-1.x
- * @{
- */
-
- * Moves update settings from variables to config.
- */
- function update_update_1000() {
-
- $config = config('update.settings');
- $config->set('update_disabled_extensions', update_variable_get('update_check_disabled', 0));
- $config->set('update_interval_days', update_variable_get('update_check_frequency', 1));
- $config->set('update_url', update_variable_get('update_fetch_url', ''));
- $config->set('update_max_attempts', update_variable_get('update_max_fetch_attempts', 2));
- $config->set('update_timeout', update_variable_get('update_max_fetch_time', 5));
- $config->set('update_emails', update_variable_get('update_notify_emails', array()));
- $config->set('update_threshold', update_variable_get('update_notification_threshold', 'all'));
- $config->set('update_projects', update_variable_get('update_advanced_project_settings', array()));
- $config->save();
-
-
- update_variable_del('update_check_disabled');
- update_variable_del('update_check_frequency');
- update_variable_del('update_fetch_url');
- update_variable_del('update_max_fetch_attempts');
- update_variable_del('update_max_fetch_time');
- update_variable_del('update_notify_emails');
- update_variable_del('update_notification_threshold');
- update_variable_del('update_advanced_project_settings');
- }
-
- * Add config default value for "update_not_implemented_url".
- */
- function update_update_1001() {
- $config = config('update.settings');
- $config->set('update_not_implemented_url', 'https://github.com/backdrop-ops/backdropcms.org/issues/22');
- $config->save();
- }
-
- * Enable static caching for update settings configuration file.
- */
- function update_update_1002() {
- $config = config('update.settings');
- $config->set('_config_static', true);
- $config->save();
- }
-
- * Removes the testing-only values from the update.settings config.
- */
- function update_update_1003() {
- $config = config('update.settings');
- $config->clear('update_xml_map');
- $config->clear('update_system_info');
- $config->save();
- }
-
- * Fix wrong default value for update_threshold setting.
- */
- function update_update_1004() {
- $config = config('update.settings');
- if ($config->get('update_threshold') === 0) {
- $config->set('update_threshold', 'all');
- }
- $config->save();
- }
-
- * Check for a faulty installer.settings.json and fix it or remove it if needed.
- */
- function update_update_1005() {
-
-
-
-
- $config = config('installer.settings');
-
-
-
- if (!$config->isNew()) {
-
-
-
- $schema_version = backdrop_get_installed_schema_version('installer');
- if ($schema_version < 0) {
-
- $config->delete();
- }
- elseif (empty($config->get('installer_server'))) {
-
-
- $config->set('installer_server', array(
- 'url' => 'https://projects.backdropcms.org',
- 'name' => 'Backdrop',
- ));
- $config->save();
- }
- }
- }
-
- * @} End of "addtogroup updates-7.x-to-1.x"
- * The next series of updates should start at 2000.
- */