123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- <?php
- function update_authorize_run_update($filetransfer, $projects) {
- $operations = array();
- foreach ($projects as $project => $project_info) {
- $operations[] = array(
- 'update_authorize_batch_copy_project',
- array(
- $project_info['project'],
- $project_info['updater_name'],
- $project_info['local_url'],
- $filetransfer,
- ),
- );
- }
- $batch = array(
- 'title' => t('Installing updates'),
- 'init_message' => t('Preparing to update your site'),
- 'operations' => $operations,
- 'finished' => 'update_authorize_update_batch_finished',
- 'file' => drupal_get_path('module', 'update') . '/update.authorize.inc',
- );
- batch_set($batch);
-
- system_authorized_batch_process();
- }
- function update_authorize_run_install($filetransfer, $project, $updater_name, $local_url) {
- $operations[] = array(
- 'update_authorize_batch_copy_project',
- array(
- $project,
- $updater_name,
- $local_url,
- $filetransfer,
- ),
- );
-
- $batch = array(
- 'title' => t('Installing %project', array('%project' => $project)),
- 'init_message' => t('Preparing to install'),
- 'operations' => $operations,
-
- 'finished' => 'update_authorize_install_batch_finished',
- 'file' => drupal_get_path('module', 'update') . '/update.authorize.inc',
- );
- batch_set($batch);
-
- system_authorized_batch_process();
- }
- function update_authorize_batch_copy_project($project, $updater_name, $local_url, $filetransfer, &$context) {
-
- if (!isset($context['results']['log'])) {
- $context['results']['log'] = array();
- }
- if (!isset($context['results']['log'][$project])) {
- $context['results']['log'][$project] = array();
- }
- if (!isset($context['results']['tasks'])) {
- $context['results']['tasks'] = array();
- }
-
-
-
-
-
-
-
- unset($filetransfer->connection);
- if (!empty($context['results']['log'][$project]['#abort'])) {
- $context['finished'] = 1;
- return;
- }
- $updater = new $updater_name($local_url);
- try {
- if ($updater->isInstalled()) {
-
- $tasks = $updater->update($filetransfer);
- }
- else {
- $tasks = $updater->install($filetransfer);
- }
- }
- catch (UpdaterException $e) {
- _update_batch_create_message($context['results']['log'][$project], t('Error installing / updating'), FALSE);
- _update_batch_create_message($context['results']['log'][$project], $e->getMessage(), FALSE);
- $context['results']['log'][$project]['#abort'] = TRUE;
- return;
- }
- _update_batch_create_message($context['results']['log'][$project], t('Installed %project_name successfully', array('%project_name' => $project)));
- if (!empty($tasks)) {
- $context['results']['tasks'] += $tasks;
- }
-
-
- $context['finished'] = 1;
- }
- function update_authorize_update_batch_finished($success, $results) {
- foreach ($results['log'] as $project => $messages) {
- if (!empty($messages['#abort'])) {
- $success = FALSE;
- }
- }
- $offline = variable_get('maintenance_mode', FALSE);
- if ($success) {
-
-
- _update_authorize_clear_update_status();
-
- if ($offline && isset($_SESSION['maintenance_mode']) && $_SESSION['maintenance_mode'] == FALSE) {
- variable_set('maintenance_mode', FALSE);
- $page_message = array(
- 'message' => t('Update was completed successfully. Your site has been taken out of maintenance mode.'),
- 'type' => 'status',
- );
- }
- else {
- $page_message = array(
- 'message' => t('Update was completed successfully.'),
- 'type' => 'status',
- );
- }
- }
- elseif (!$offline) {
- $page_message = array(
- 'message' => t('Update failed! See the log below for more information.'),
- 'type' => 'error',
- );
- }
- else {
- $page_message = array(
- 'message' => t('Update failed! See the log below for more information. Your site is still in maintenance mode.'),
- 'type' => 'error',
- );
- }
-
-
- $results['tasks'][] = t('Your modules have been downloaded and updated.');
- $results['tasks'][] = t('<a href="@update">Run database updates</a>', array('@update' => base_path() . 'update.php'));
-
- unset($_SESSION['maintenance_mode']);
-
- $_SESSION['authorize_results']['success'] = $success;
- $_SESSION['authorize_results']['page_message'] = $page_message;
- $_SESSION['authorize_results']['messages'] = $results['log'];
- $_SESSION['authorize_results']['tasks'] = $results['tasks'];
- $_SESSION['authorize_operation']['page_title'] = t('Update manager');
- }
- function update_authorize_install_batch_finished($success, $results) {
- foreach ($results['log'] as $project => $messages) {
- if (!empty($messages['#abort'])) {
- $success = FALSE;
- }
- }
- $offline = variable_get('maintenance_mode', FALSE);
- if ($success) {
-
- if ($offline && isset($_SESSION['maintenance_mode']) && $_SESSION['maintenance_mode'] == FALSE) {
- variable_set('maintenance_mode', FALSE);
- $page_message = array(
- 'message' => t('Installation was completed successfully. Your site has been taken out of maintenance mode.'),
- 'type' => 'status',
- );
- }
- else {
- $page_message = array(
- 'message' => t('Installation was completed successfully.'),
- 'type' => 'status',
- );
- }
- }
- elseif (!$success && !$offline) {
- $page_message = array(
- 'message' => t('Installation failed! See the log below for more information.'),
- 'type' => 'error',
- );
- }
- else {
- $page_message = array(
- 'message' => t('Installation failed! See the log below for more information. Your site is still in maintenance mode.'),
- 'type' => 'error',
- );
- }
-
- unset($_SESSION['maintenance_mode']);
-
- $_SESSION['authorize_results']['success'] = $success;
- $_SESSION['authorize_results']['page_message'] = $page_message;
- $_SESSION['authorize_results']['messages'] = $results['log'];
- $_SESSION['authorize_results']['tasks'] = $results['tasks'];
- $_SESSION['authorize_operation']['page_title'] = t('Update manager');
- }
- function _update_batch_create_message(&$project_results, $message, $success = TRUE) {
- $project_results[] = array('message' => $message, 'success' => $success);
- }
- function _update_authorize_clear_update_status() {
- $query = db_delete('cache_update');
- $query->condition(
- db_or()
- ->condition('cid', 'update_project_%', 'LIKE')
- ->condition('cid', 'available_releases::%', 'LIKE')
- );
- $query->execute();
- }
|