1.20.x installer.manager.inc | installer_manager_update_form($form, $form_state) |
Form constructor for the update form of the Installer module.
This presents a table with all projects that have available updates with checkboxes to select which ones to upgrade.
See also
installer_manager_update_form_validate()
installer_manager_update_form_submit()
Related topics
File
- modules/
installer/ installer.manager.inc, line 57 - Administrative screens and processing functions of the Installer module.
Code
function installer_manager_update_form($form, $form_state) {
if (!_installer_manager_check_backends($form, 'update')) {
return $form;
}
$form['#theme'] = 'installer_manager_update_form';
$available = update_get_available(TRUE);
// Run some basic health checks, and show messages/warnings accordingly.
$settings_link = url('admin/reports/updates/settings');
$update_config = config('update.settings');
$update_interval_days = $update_config->get('update_interval_days');
if ($update_interval_days != 0) {
$frequency = array(1 => t('daily'), 7 => t('weekly'));
$frequency_message = t('<a href="@link">Automatic update checks are configured to run @frequency</a>.', array('@link' => $settings_link, '@frequency' => $frequency[$update_interval_days]));
$message_type = 'info';
}
else {
$frequency_message = t('<a href="@link">Automatic update checks are disabled</a> and will need to be run manually.', array('@link' => $settings_link));
$message_type = 'warning';
}
backdrop_set_message($frequency_message, $message_type);
$update_threshold = $update_config->get('update_threshold');
if ($update_threshold == 'none') {
$email_notifications_message = t('<a href="@link">Email notifications are disabled</a> for available updates.', array('@link' => $settings_link));
$message_type = 'warning';
}
else {
$update_emails = $update_config->get('update_emails');
if (empty($update_emails)) {
$email_notifications_message = t('<a href="@link">No email address has been provided</a> for notifications about available updates.', array('@link' => $settings_link));
$message_type = 'warning';
}
else {
$recipients = implode(', ', $update_emails);
$email_notifications_message = t('<a href="@link">Update notifications will be sent</a> to: @recipients', array('@link' => $settings_link, '@recipients' => $recipients));
$message_type = 'info';
}
}
backdrop_set_message($email_notifications_message, $message_type);
$last = state_get('update_last_check', 0);
$form['last_check'] = array(
'#markup' => theme('update_last_check__install', array('last' => $last)),
);
if (empty($available)) {
$form['message'] = array(
'#markup' => t('There was a problem getting update information. Try again later.'),
);
return $form;
}
$form['#attached']['css'][] = backdrop_get_path('module', 'installer') . '/css/installer.css';
$form['#attached']['js'][] = backdrop_get_path('module', 'installer') . '/js/installer.select_updates.js';
// This will be a nested array. The first key is the kind of project, which
// can be either 'enabled', 'disabled', 'manual' (projects which require
// manual updates, such as core). Then, each subarray is an array of
// projects of that type, indexed by project short name, and containing an
// array of data for cells in that project's row in the appropriate table.
$projects = array();
// This stores the actual download link we're going to update from for each
// project in the form, regardless of if it's enabled or disabled.
$form['project_downloads'] = array('#tree' => TRUE);
module_load_include('inc', 'update', 'update.compare');
$project_data = update_calculate_project_data($available);
$project_types = array(
'core' => t('Core'),
'module' => t('Module'),
'theme' => t('Theme'),
'layout' => t('Layout template'),
'driver' => t('Driver'),
);
foreach ($project_data as $name => $project) {
// Filter out projects which are up to date already.
if ($project['status'] == UPDATE_CURRENT) {
continue;
}
// The project name to display can vary based on the info we have.
if (!empty($project['title'])) {
if (!empty($project['link'])) {
$project_name = l($project['title'], $project['link'], array('attributes' => array('target' => '_blank')));
}
else {
$project_name = check_plain($project['title']);
}
}
elseif (!empty($project['info']['name'])) {
$project_name = check_plain($project['info']['name']);
}
else {
$project_name = check_plain($name);
}
if (empty($project['recommended'])) {
// If we don't know what to recommend they upgrade to, we should skip
// the project entirely.
continue;
}
$recommended_release = $project['releases'][$project['recommended']];
$title_attribute = t('Release notes for @project_title', array('@project_title' => $project['title']));
$link_attributes = array('attributes' => array('title' => $title_attribute, 'target' => '_blank'));
$release_notes_link = l(t('release notes'), $recommended_release['release_link'], $link_attributes);
$recommended_version = $recommended_release['version'] . ' (' . $release_notes_link . ')';
if ($recommended_release['version_major'] != $project['existing_major']) {
$recommended_version .= '<div class="update-major-version-warning">' . t('This update is a major version update which means that it may not be backwards compatible with your currently running version. It is recommended that you read the release notes and proceed at your own risk.') . '</div>';
}
// Create an entry for this project.
$entry = array(
'title' => $project_name,
'project_type' => $project_types[$project['project_type']],
'project_status' => $project['project_status'] ? t('Enabled') : t('Disabled'),
'installed_version' => $project['existing_version'],
'recommended_version' => $recommended_version,
);
$update_types = array(
'security' => t('security update available'),
'unsupported' => t('unsupported version installed'),
);
switch ($project['status']) {
case UPDATE_NOT_SECURE:
case UPDATE_REVOKED:
$type = 'security';
$entry['#weight'] = -2;
break;
case UPDATE_NOT_SUPPORTED:
$type = 'unsupported';
$entry['#weight'] = -1;
break;
case UPDATE_UNKNOWN:
case UPDATE_NOT_FETCHED:
case UPDATE_NOT_CHECKED:
case UPDATE_NOT_CURRENT:
$type = 'recommended';
break;
default:
// Jump out of the switch and onto the next project in foreach.
continue 2;
}
if (isset($type) && isset($update_types[$type])) {
$entry['title'] .= ' <span class="update-type">(' . $update_types[$type] . ')</span>';
}
$entry['#attributes'] = array('class' => array('update-' . $type));
// Backdrop CMS core and contrib projects are to be able to be updated from
// the administrative interface. Set this option as default.
$update_method = 'admin_ui';
// If self-update is disabled, Backdrop core needs to be updated manually.
if ($project['project_type'] == 'core' && !config_get('installer.settings', 'core_update')) {
$update_method = 'manual';
}
if ($update_method == 'manual') {
// We don't need checkboxes in the "Manual updates" table, so it will be
// rendered by theme('table') instead of theme('tableselect'). Since the
// data formats are incompatible, we convert to the format expected by
// theme('table').
unset($entry['#weight']);
$attributes = $entry['#attributes'];
unset($entry['#attributes']);
$entry = array(
'data' => $entry,
) + $attributes;
}
else {
$form['project_downloads'][$name] = array(
'#type' => 'value',
'#value' => $recommended_release['download_link'],
);
}
// Split projects based on method of update.
$projects[$update_method][$name] = $entry;
}
if (empty($projects)) {
backdrop_set_message(t('Your site is up to date.'));
return $form;
}
// The table header is common for both the manual and the UI updates.
$header = array(
'title' => array(
'data' => t('Name'),
'class' => array('installer-project-name'),
),
'project_type' => t('Project type'),
'project_status' => t('Project status'),
'installed_version' => t('Installed version'),
'recommended_version' => t('Recommended version'),
);
if (!empty($projects['admin_ui'])) {
$form['projects'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $projects['admin_ui'],
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Download selected updates'),
'#id' => 'installer-download-updates',
);
$form['#validate'][] = 'installer_manager_update_form_validate';
}
if (!empty($projects['manual'])) {
$prefix = '<h2>' . t('Manual updates required') . '</h2>';
$prefix .= '<p>' . t('Updates of Silkscreen CMS core using the web interface are disabled.') . '</p>';
$prefix .= '<p>' . t('You can update Silkscreen CMS by replacing the old <code>/core</code> directory inside your docroot with the one included in the <a href="https://backdropcms.org/" title="Home page with download option">latest release</a>. For detailed instructions, see the <a href="https://backdropcms.org/upgrade" title="Handbook article">Upgrading Backdrop CMS</a> document online.') . '</p>';
$form['manual_updates'] = array(
'#type' => 'markup',
'#markup' => theme('table', array('header' => $header, 'rows' => $projects['manual'])),
'#prefix' => $prefix,
'#weight' => 120,
);
}
return $form;
}