123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943 |
- <?php
- function update_manager_update_form($form, $form_state = array(), $context) {
- if (!_update_manager_check_backends($form, 'update')) {
- return $form;
- }
- $form['#theme'] = 'update_manager_update_form';
- $available = update_get_available(TRUE);
- if (empty($available)) {
- $form['message'] = array(
- '#markup' => t('There was a problem getting update information. Try again later.'),
- );
- return $form;
- }
- $form['#attached']['css'][] = drupal_get_path('module', 'update') . '/update.css';
-
-
-
-
-
- $projects = array();
-
-
- $form['project_downloads'] = array('#tree' => TRUE);
- module_load_include('inc', 'update', 'update.compare');
- $project_data = update_calculate_project_data($available);
- foreach ($project_data as $name => $project) {
-
- if ($project['status'] == UPDATE_CURRENT) {
- continue;
- }
-
- if (!empty($project['title'])) {
- if (!empty($project['link'])) {
- $project_name = l($project['title'], $project['link']);
- }
- 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 ($project['project_type'] == 'theme' || $project['project_type'] == 'theme-disabled') {
- $project_name .= ' ' . t('(Theme)');
- }
- if (empty($project['recommended'])) {
-
-
- continue;
- }
- $recommended_release = $project['releases'][$project['recommended']];
- $recommended_version = $recommended_release['version'] . ' ' . l(t('(Release notes)'), $recommended_release['release_link'], array('attributes' => array('title' => t('Release notes for @project_title', array('@project_title' => $project['title'])))));
- if ($recommended_release['version_major'] != $project['existing_major']) {
- $recommended_version .= '<div title="Major upgrade warning" 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>';
- }
-
- $entry = array(
- 'title' => $project_name,
- 'installed_version' => $project['existing_version'],
- 'recommended_version' => $recommended_version,
- );
- switch ($project['status']) {
- case UPDATE_NOT_SECURE:
- case UPDATE_REVOKED:
- $entry['title'] .= ' ' . t('(Security update)');
- $entry['#weight'] = -2;
- $type = 'security';
- break;
- case UPDATE_NOT_SUPPORTED:
- $type = 'unsupported';
- $entry['title'] .= ' ' . t('(Unsupported)');
- $entry['#weight'] = -1;
- break;
- case UPDATE_UNKNOWN:
- case UPDATE_NOT_FETCHED:
- case UPDATE_NOT_CHECKED:
- case UPDATE_NOT_CURRENT:
- $type = 'recommended';
- break;
- default:
-
- continue 2;
- }
- $entry['#attributes'] = array('class' => array('update-' . $type));
-
- $needs_manual = $project['project_type'] == 'core';
- if ($needs_manual) {
-
-
-
-
- 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'],
- );
- }
-
-
- switch ($project['project_type']) {
- case 'core':
-
- $projects['manual'][$name] = $entry;
- break;
- case 'module':
- case 'theme':
- $projects['enabled'][$name] = $entry;
- break;
- case 'module-disabled':
- case 'theme-disabled':
- $projects['disabled'][$name] = $entry;
- break;
- }
- }
- if (empty($projects)) {
- $form['message'] = array(
- '#markup' => t('All of your projects are up to date.'),
- );
- return $form;
- }
- $headers = array(
- 'title' => array(
- 'data' => t('Name'),
- 'class' => array('update-project-name'),
- ),
- 'installed_version' => t('Installed version'),
- 'recommended_version' => t('Recommended version'),
- );
- if (!empty($projects['enabled'])) {
- $form['projects'] = array(
- '#type' => 'tableselect',
- '#header' => $headers,
- '#options' => $projects['enabled'],
- );
- if (!empty($projects['disabled'])) {
- $form['projects']['#prefix'] = '<h2>' . t('Enabled') . '</h2>';
- }
- }
- if (!empty($projects['disabled'])) {
- $form['disabled_projects'] = array(
- '#type' => 'tableselect',
- '#header' => $headers,
- '#options' => $projects['disabled'],
- '#weight' => 1,
- '#prefix' => '<h2>' . t('Disabled') . '</h2>',
- );
- }
-
-
- if (!empty($projects['enabled']) || !empty($projects['disabled'])) {
- $form['actions'] = array('#type' => 'actions');
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Download these updates'),
- );
- $form['#validate'][] = 'update_manager_update_form_validate';
- }
- if (!empty($projects['manual'])) {
- $prefix = '<h2>' . t('Manual updates required') . '</h2>';
- $prefix .= '<p>' . t('Updates of Drupal core are not supported at this time.') . '</p>';
- $form['manual_updates'] = array(
- '#type' => 'markup',
- '#markup' => theme('table', array('header' => $headers, 'rows' => $projects['manual'])),
- '#prefix' => $prefix,
- '#weight' => 120,
- );
- }
- return $form;
- }
- function theme_update_manager_update_form($variables) {
- $form = $variables['form'];
- $last = variable_get('update_last_check', 0);
- $output = theme('update_last_check', array('last' => $last));
- $output .= drupal_render_children($form);
- return $output;
- }
- function update_manager_update_form_validate($form, &$form_state) {
- if (!empty($form_state['values']['projects'])) {
- $enabled = array_filter($form_state['values']['projects']);
- }
- if (!empty($form_state['values']['disabled_projects'])) {
- $disabled = array_filter($form_state['values']['disabled_projects']);
- }
- if (empty($enabled) && empty($disabled)) {
- form_set_error('projects', t('You must select at least one project to update.'));
- }
- }
- function update_manager_update_form_submit($form, &$form_state) {
- $projects = array();
- foreach (array('projects', 'disabled_projects') as $type) {
- if (!empty($form_state['values'][$type])) {
- $projects = array_merge($projects, array_keys(array_filter($form_state['values'][$type])));
- }
- }
- $operations = array();
- foreach ($projects as $project) {
- $operations[] = array(
- 'update_manager_batch_project_get',
- array(
- $project,
- $form_state['values']['project_downloads'][$project],
- ),
- );
- }
- $batch = array(
- 'title' => t('Downloading updates'),
- 'init_message' => t('Preparing to download selected updates'),
- 'operations' => $operations,
- 'finished' => 'update_manager_download_batch_finished',
- 'file' => drupal_get_path('module', 'update') . '/update.manager.inc',
- );
- batch_set($batch);
- }
- function update_manager_download_batch_finished($success, $results) {
- if (!empty($results['errors'])) {
- $error_list = array(
- 'title' => t('Downloading updates failed:'),
- 'items' => $results['errors'],
- );
- drupal_set_message(theme('item_list', $error_list), 'error');
- }
- elseif ($success) {
- drupal_set_message(t('Updates downloaded successfully.'));
- $_SESSION['update_manager_update_projects'] = $results['projects'];
- drupal_goto('admin/update/ready');
- }
- else {
-
-
- drupal_set_message(t('Fatal error trying to download.'), 'error');
- }
- }
- function update_manager_update_ready_form($form, &$form_state) {
- if (!_update_manager_check_backends($form, 'update')) {
- return $form;
- }
- $form['backup'] = array(
- '#prefix' => '<strong>',
- '#markup' => t('Back up your database and site before you continue. <a href="@backup_url">Learn how</a>.', array('@backup_url' => url('http://drupal.org/node/22281'))),
- '#suffix' => '</strong>',
- );
- $form['maintenance_mode'] = array(
- '#title' => t('Perform updates with site in maintenance mode (strongly recommended)'),
- '#type' => 'checkbox',
- '#default_value' => TRUE,
- );
- $form['actions'] = array('#type' => 'actions');
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Continue'),
- );
- return $form;
- }
- function update_manager_update_ready_form_submit($form, &$form_state) {
-
- $_SESSION['maintenance_mode'] = variable_get('maintenance_mode', FALSE);
- if ($form_state['values']['maintenance_mode'] == TRUE) {
- variable_set('maintenance_mode', TRUE);
- }
- if (!empty($_SESSION['update_manager_update_projects'])) {
-
- drupal_get_updaters();
- $updates = array();
- $directory = _update_manager_extract_directory();
- $projects = $_SESSION['update_manager_update_projects'];
- unset($_SESSION['update_manager_update_projects']);
- foreach ($projects as $project => $url) {
- $project_location = $directory . '/' . $project;
- $updater = Updater::factory($project_location);
- $project_real_location = drupal_realpath($project_location);
- $updates[] = array(
- 'project' => $project,
- 'updater_name' => get_class($updater),
- 'local_url' => $project_real_location,
- );
- }
-
-
-
-
-
- if (fileowner($project_real_location) == fileowner(conf_path())) {
- module_load_include('inc', 'update', 'update.authorize');
- $filetransfer = new FileTransferLocal(DRUPAL_ROOT);
- update_authorize_run_update($filetransfer, $updates);
- }
-
-
-
- else {
- system_authorized_init('update_authorize_run_update', drupal_get_path('module', 'update') . '/update.authorize.inc', array($updates), t('Update manager'));
- $form_state['redirect'] = system_authorized_get_url();
- }
- }
- }
- function update_manager_install_form($form, &$form_state, $context) {
- if (!_update_manager_check_backends($form, 'install')) {
- return $form;
- }
- $form['help_text'] = array(
- '#prefix' => '<p>',
- '#markup' => t('You can find <a href="@module_url">modules</a> and <a href="@theme_url">themes</a> on <a href="@drupal_org_url">drupal.org</a>. The following file extensions are supported: %extensions.', array(
- '@module_url' => 'http://drupal.org/project/modules',
- '@theme_url' => 'http://drupal.org/project/themes',
- '@drupal_org_url' => 'http://drupal.org',
- '%extensions' => archiver_get_extensions(),
- )),
- '#suffix' => '</p>',
- );
- $form['project_url'] = array(
- '#type' => 'textfield',
- '#title' => t('Install from a URL'),
- '#description' => t('For example: %url', array('%url' => 'http://ftp.drupal.org/files/projects/name.tar.gz')),
- );
- $form['information'] = array(
- '#prefix' => '<strong>',
- '#markup' => t('Or'),
- '#suffix' => '</strong>',
- );
- $form['project_upload'] = array(
- '#type' => 'file',
- '#title' => t('Upload a module or theme archive to install'),
- '#description' => t('For example: %filename from your local computer', array('%filename' => 'name.tar.gz')),
- );
- $form['actions'] = array('#type' => 'actions');
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Install'),
- );
- return $form;
- }
- function _update_manager_check_backends(&$form, $operation) {
-
-
-
-
- if (update_manager_local_transfers_allowed()) {
- return TRUE;
- }
-
- $form['available_backends'] = array(
- '#prefix' => '<p>',
- '#suffix' => '</p>',
- );
- $available_backends = drupal_get_filetransfer_info();
- if (empty($available_backends)) {
- if ($operation == 'update') {
- $form['available_backends']['#markup'] = t('Your server does not support updating modules and themes from this interface. Instead, update modules and themes by uploading the new versions directly to the server, as described in the <a href="@handbook_url">handbook</a>.', array('@handbook_url' => 'http://drupal.org/getting-started/install-contrib'));
- }
- else {
- $form['available_backends']['#markup'] = t('Your server does not support installing modules and themes from this interface. Instead, install modules and themes by uploading them directly to the server, as described in the <a href="@handbook_url">handbook</a>.', array('@handbook_url' => 'http://drupal.org/getting-started/install-contrib'));
- }
- return FALSE;
- }
- $backend_names = array();
- foreach ($available_backends as $backend) {
- $backend_names[] = $backend['title'];
- }
- if ($operation == 'update') {
- $form['available_backends']['#markup'] = format_plural(
- count($available_backends),
- 'Updating modules and themes requires <strong>@backends access</strong> to your server. See the <a href="@handbook_url">handbook</a> for other update methods.',
- 'Updating modules and themes requires access to your server via one of the following methods: <strong>@backends</strong>. See the <a href="@handbook_url">handbook</a> for other update methods.',
- array(
- '@backends' => implode(', ', $backend_names),
- '@handbook_url' => 'http://drupal.org/getting-started/install-contrib',
- ));
- }
- else {
- $form['available_backends']['#markup'] = format_plural(
- count($available_backends),
- 'Installing modules and themes requires <strong>@backends access</strong> to your server. See the <a href="@handbook_url">handbook</a> for other installation methods.',
- 'Installing modules and themes requires access to your server via one of the following methods: <strong>@backends</strong>. See the <a href="@handbook_url">handbook</a> for other installation methods.',
- array(
- '@backends' => implode(', ', $backend_names),
- '@handbook_url' => 'http://drupal.org/getting-started/install-contrib',
- ));
- }
- return TRUE;
- }
- function update_manager_install_form_validate($form, &$form_state) {
- if (!($form_state['values']['project_url'] XOR !empty($_FILES['files']['name']['project_upload']))) {
- form_set_error('project_url', t('You must either provide a URL or upload an archive file to install.'));
- }
- if ($form_state['values']['project_url']) {
- if (!valid_url($form_state['values']['project_url'], TRUE)) {
- form_set_error('project_url', t('The provided URL is invalid.'));
- }
- }
- }
- function update_manager_install_form_submit($form, &$form_state) {
- if ($form_state['values']['project_url']) {
- $field = 'project_url';
- $local_cache = update_manager_file_get($form_state['values']['project_url']);
- if (!$local_cache) {
- form_set_error($field, t('Unable to retrieve Drupal project from %url.', array('%url' => $form_state['values']['project_url'])));
- return;
- }
- }
- elseif ($_FILES['files']['name']['project_upload']) {
- $validators = array('file_validate_extensions' => array(archiver_get_extensions()));
- $field = 'project_upload';
- if (!($finfo = file_save_upload($field, $validators, NULL, FILE_EXISTS_REPLACE))) {
-
-
- return;
- }
- $local_cache = $finfo->uri;
- }
- $directory = _update_manager_extract_directory();
- try {
- $archive = update_manager_archive_extract($local_cache, $directory);
- }
- catch (Exception $e) {
- form_set_error($field, $e->getMessage());
- return;
- }
- $files = $archive->listContents();
- if (!$files) {
- form_set_error($field, t('Provided archive contains no files.'));
- return;
- }
-
-
-
- $project = strtok($files[0], '/\\');
- $archive_errors = update_manager_archive_verify($project, $local_cache, $directory);
- if (!empty($archive_errors)) {
- form_set_error($field, array_shift($archive_errors));
-
-
- if (!empty($archive_errors)) {
- foreach ($archive_errors as $error) {
- drupal_set_message($error, 'error');
- }
- }
- return;
- }
-
- drupal_get_updaters();
- $project_location = $directory . '/' . $project;
- try {
- $updater = Updater::factory($project_location);
- }
- catch (Exception $e) {
- form_set_error($field, $e->getMessage());
- return;
- }
- try {
- $project_title = Updater::getProjectTitle($project_location);
- }
- catch (Exception $e) {
- form_set_error($field, $e->getMessage());
- return;
- }
- if (!$project_title) {
- form_set_error($field, t('Unable to determine %project name.', array('%project' => $project)));
- }
- if ($updater->isInstalled()) {
- form_set_error($field, t('%project is already installed.', array('%project' => $project_title)));
- return;
- }
- $project_real_location = drupal_realpath($project_location);
- $arguments = array(
- 'project' => $project,
- 'updater_name' => get_class($updater),
- 'local_url' => $project_real_location,
- );
-
-
-
-
-
- if (fileowner($project_real_location) == fileowner(conf_path())) {
- module_load_include('inc', 'update', 'update.authorize');
- $filetransfer = new FileTransferLocal(DRUPAL_ROOT);
- call_user_func_array('update_authorize_run_install', array_merge(array($filetransfer), $arguments));
- }
-
-
-
- else {
- system_authorized_init('update_authorize_run_install', drupal_get_path('module', 'update') . '/update.authorize.inc', $arguments, t('Update manager'));
- $form_state['redirect'] = system_authorized_get_url();
- }
- }
- function update_manager_archive_extract($file, $directory) {
- $archiver = archiver_get_archiver($file);
- if (!$archiver) {
- throw new Exception(t('Cannot extract %file, not a valid archive.', array ('%file' => $file)));
- }
-
-
-
- $files = $archiver->listContents();
-
-
-
- $project = strtok($files[0], '/\\');
- $extract_location = $directory . '/' . $project;
- if (file_exists($extract_location)) {
- file_unmanaged_delete_recursive($extract_location);
- }
- $archiver->extract($directory);
- return $archiver;
- }
- function update_manager_archive_verify($project, $archive_file, $directory) {
- return module_invoke_all('verify_update_archive', $project, $archive_file, $directory);
- }
- function update_manager_file_get($url) {
- $parsed_url = parse_url($url);
- $remote_schemes = array('http', 'https', 'ftp', 'ftps', 'smb', 'nfs');
- if (!in_array($parsed_url['scheme'], $remote_schemes)) {
-
- return drupal_realpath($url);
- }
-
- $cache_directory = _update_manager_cache_directory();
- $local = $cache_directory . '/' . drupal_basename($parsed_url['path']);
- if (!file_exists($local) || update_delete_file_if_stale($local)) {
- return system_retrieve_file($url, $local, FALSE, FILE_EXISTS_REPLACE);
- }
- else {
- return $local;
- }
- }
- function update_manager_batch_project_get($project, $url, &$context) {
-
- if (!isset($context['sandbox']['started'])) {
- $context['sandbox']['started'] = TRUE;
- $context['message'] = t('Downloading %project', array('%project' => $project));
- $context['finished'] = 0;
- return;
- }
-
- if (!($local_cache = update_manager_file_get($url))) {
- $context['results']['errors'][$project] = t('Failed to download %project from %url', array('%project' => $project, '%url' => $url));
- return;
- }
-
- $extract_directory = _update_manager_extract_directory();
- try {
- update_manager_archive_extract($local_cache, $extract_directory);
- }
- catch (Exception $e) {
- $context['results']['errors'][$project] = $e->getMessage();
- return;
- }
-
- $archive_errors = update_manager_archive_verify($project, $local_cache, $extract_directory);
- if (!empty($archive_errors)) {
-
-
- foreach ($archive_errors as $key => $error) {
- $context['results']['errors']["$project-$key"] = $error;
- }
- return;
- }
-
- $context['results']['projects'][$project] = $url;
- $context['finished'] = 1;
- }
- function update_manager_local_transfers_allowed() {
-
-
-
- $temporary_file = drupal_tempnam('temporary://', 'update_');
- $local_transfers_allowed = fileowner($temporary_file) === fileowner(conf_path());
-
-
- @drupal_unlink($temporary_file);
- return $local_transfers_allowed;
- }
|