2009-10-15 21:19:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
2012-06-06 15:33:53 +00:00
|
|
|
* Callbacks and related functions invoked by authorize.php to update projects.
|
|
|
|
*
|
|
|
|
* We use the Batch API to actually update each individual project on the site.
|
|
|
|
* All of the code in this file is run at a low bootstrap level (modules are not
|
|
|
|
* loaded), so these functions cannot assume access to the rest of the code of
|
|
|
|
* the Update Manager module.
|
2009-10-15 21:19:31 +00:00
|
|
|
*/
|
|
|
|
|
Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9, jpatel657, quietone, jonathanshaw, alexpott, joachim, rajeshwari10, RajeevK, Yogesh Pawar, James.Shee, lcngeo, borisson_, time2buzzthetower, ccasals, kavo: Update core modules to use the new batch builder
2021-06-28 12:30:58 +00:00
|
|
|
use Drupal\Core\Batch\BatchBuilder;
|
2012-03-11 00:23:05 +00:00
|
|
|
use Drupal\Core\Updater\UpdaterException;
|
Issue #1885564 by joelpittet, SebCorbin, Cottser, mpdonadio, David_Rothstein, drupalninja99, jenlampton, lauriii, rteijeiro, mbrett5062, akalata, Devin Carlson, trevorkjorlien, longwave, socketwench, shanethehat, aboros: theme.maintenance.inc (authorize.php) - Convert theme_ functions to Twig
2015-08-11 22:54:49 +00:00
|
|
|
use Drupal\Core\Url;
|
2012-03-11 00:23:05 +00:00
|
|
|
|
2009-10-15 21:19:31 +00:00
|
|
|
/**
|
2012-06-06 15:33:53 +00:00
|
|
|
* Updates existing projects when invoked by authorize.php.
|
|
|
|
*
|
|
|
|
* Callback for system_authorized_init() in
|
|
|
|
* update_manager_update_ready_form_submit().
|
2009-10-15 21:19:31 +00:00
|
|
|
*
|
|
|
|
* @param $filetransfer
|
|
|
|
* The FileTransfer object created by authorize.php for use during this
|
|
|
|
* operation.
|
|
|
|
* @param $projects
|
|
|
|
* A nested array of projects to install into the live webroot, keyed by
|
|
|
|
* project name. Each subarray contains the following keys:
|
2012-06-06 15:33:53 +00:00
|
|
|
* - project: The canonical project short name.
|
|
|
|
* - updater_name: The name of the Drupal\Core\Updater\Updater class to use
|
2012-03-11 00:23:05 +00:00
|
|
|
* for this project.
|
2012-06-06 15:33:53 +00:00
|
|
|
* - local_url: The locally installed location of new code to update with.
|
Issue #2042447 by David_Rothstein, joelpittet, stefan.r, SebCorbin, mpdonadio, steinmb, webchick, Cottser, miniwebs2, Vj, Gilbert Rehling, nuwe, yched, StuartJNCC, Fabianx, yktdan, herom: Install a module user interface does not install modules (or themes)
2015-08-07 09:02:58 +00:00
|
|
|
*
|
|
|
|
* @return \Symfony\Component\HttpFoundation\Response|null
|
|
|
|
* The result of processing the batch that updates the projects. If this is
|
|
|
|
* an instance of \Symfony\Component\HttpFoundation\Response the calling code
|
|
|
|
* should use that response for the current page request.
|
2009-10-15 21:19:31 +00:00
|
|
|
*/
|
|
|
|
function update_authorize_run_update($filetransfer, $projects) {
|
Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9, jpatel657, quietone, jonathanshaw, alexpott, joachim, rajeshwari10, RajeevK, Yogesh Pawar, James.Shee, lcngeo, borisson_, time2buzzthetower, ccasals, kavo: Update core modules to use the new batch builder
2021-06-28 12:30:58 +00:00
|
|
|
$batch_builder = (new BatchBuilder())
|
Issue #2347783 by kim.pepper, andypost, almaudoh, gumanist, aleevas, rodrigoaguilera, Berdir, saurabh-2k17, Spokje, dhirendra.mishra, alexpott, paulocs, izus, Wim Leers, KapilV, naveenvalecha, anmolgoyal74, subson, yo30, harsha012, mrinalini9, daffie, voleger, dww, fietserwin, tim.plunkett, joachim, larowlan: Deprecate drupal_get_path() and drupal_get_filename() and replace with ExtensionList::getPath() and ExtensionList::getPathname()
2021-07-15 10:20:33 +00:00
|
|
|
->setFile(\Drupal::service('extension.list.module')->getPath('update') . '/update.authorize.inc')
|
Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9, jpatel657, quietone, jonathanshaw, alexpott, joachim, rajeshwari10, RajeevK, Yogesh Pawar, James.Shee, lcngeo, borisson_, time2buzzthetower, ccasals, kavo: Update core modules to use the new batch builder
2021-06-28 12:30:58 +00:00
|
|
|
->setInitMessage(t('Preparing to update your site'))
|
|
|
|
->setFinishCallback('update_authorize_update_batch_finished');
|
|
|
|
|
Issue #2002650 by mrsinguyen, chertzog, legolasbo, Erik Erskine, rhm50, sandergo90, grisendo, targoo, janstoeckler, maximpodorov, beowulf1416: Improve maintainability by removing unused local variables.
2013-10-02 13:52:21 +00:00
|
|
|
foreach ($projects as $project_info) {
|
Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9, jpatel657, quietone, jonathanshaw, alexpott, joachim, rajeshwari10, RajeevK, Yogesh Pawar, James.Shee, lcngeo, borisson_, time2buzzthetower, ccasals, kavo: Update core modules to use the new batch builder
2021-06-28 12:30:58 +00:00
|
|
|
$batch_builder->addOperation('update_authorize_batch_copy_project', [
|
|
|
|
$project_info['project'],
|
|
|
|
$project_info['updater_name'],
|
|
|
|
$project_info['local_url'],
|
|
|
|
$filetransfer,
|
|
|
|
]);
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
|
Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9, jpatel657, quietone, jonathanshaw, alexpott, joachim, rajeshwari10, RajeevK, Yogesh Pawar, James.Shee, lcngeo, borisson_, time2buzzthetower, ccasals, kavo: Update core modules to use the new batch builder
2021-06-28 12:30:58 +00:00
|
|
|
batch_set($batch_builder->toArray());
|
Issue #2042447 by David_Rothstein, joelpittet, stefan.r, SebCorbin, mpdonadio, steinmb, webchick, Cottser, miniwebs2, Vj, Gilbert Rehling, nuwe, yched, StuartJNCC, Fabianx, yktdan, herom: Install a module user interface does not install modules (or themes)
2015-08-07 09:02:58 +00:00
|
|
|
|
2015-08-29 06:46:46 +00:00
|
|
|
// Since authorize.php has its own method for setting the page title, set it
|
|
|
|
// manually here rather than passing it in to batch_set() as would normally
|
|
|
|
// be done.
|
2020-02-20 21:38:33 +00:00
|
|
|
\Drupal::request()->getSession()->set('authorize_page_title', t('Installing updates'));
|
2015-08-29 06:46:46 +00:00
|
|
|
|
2009-10-15 21:19:31 +00:00
|
|
|
// Invoke the batch via authorize.php.
|
Issue #1668866 by ParisLiakos, aspilicious, tim.plunkett, pdrake, g.oechsler, dawehner, Berdir, corvus_ch, damiankloip, disasm, marcingy, neclimdul: Replace drupal_goto() with RedirectResponse.
2013-06-19 16:07:30 +00:00
|
|
|
return system_authorized_batch_process();
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-06 15:33:53 +00:00
|
|
|
* Installs a new project when invoked by authorize.php.
|
|
|
|
*
|
|
|
|
* Callback for system_authorized_init() in
|
|
|
|
* update_manager_install_form_submit().
|
2009-10-15 21:19:31 +00:00
|
|
|
*
|
2022-01-02 11:42:14 +00:00
|
|
|
* @param \Drupal\Core\FileTransfer\FileTransfer $filetransfer
|
2009-10-15 21:19:31 +00:00
|
|
|
* The FileTransfer object created by authorize.php for use during this
|
|
|
|
* operation.
|
|
|
|
* @param string $project
|
2012-10-09 20:32:40 +00:00
|
|
|
* The canonical project short name; i.e., the name of the module, theme, or
|
|
|
|
* profile.
|
2009-10-15 21:19:31 +00:00
|
|
|
* @param string $updater_name
|
2012-03-11 00:23:05 +00:00
|
|
|
* The name of the Drupal\Core\Updater\Updater class to use for installing
|
|
|
|
* this project.
|
2009-10-15 21:19:31 +00:00
|
|
|
* @param string $local_url
|
|
|
|
* The URL to the locally installed temp directory where the project has
|
|
|
|
* already been downloaded and extracted into.
|
Issue #2042447 by David_Rothstein, joelpittet, stefan.r, SebCorbin, mpdonadio, steinmb, webchick, Cottser, miniwebs2, Vj, Gilbert Rehling, nuwe, yched, StuartJNCC, Fabianx, yktdan, herom: Install a module user interface does not install modules (or themes)
2015-08-07 09:02:58 +00:00
|
|
|
*
|
|
|
|
* @return \Symfony\Component\HttpFoundation\Response|null
|
|
|
|
* The result of processing the batch that installs the project. If this is
|
|
|
|
* an instance of \Symfony\Component\HttpFoundation\Response the calling code
|
|
|
|
* should use that response for the current page request.
|
2009-10-15 21:19:31 +00:00
|
|
|
*/
|
|
|
|
function update_authorize_run_install($filetransfer, $project, $updater_name, $local_url) {
|
Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9, jpatel657, quietone, jonathanshaw, alexpott, joachim, rajeshwari10, RajeevK, Yogesh Pawar, James.Shee, lcngeo, borisson_, time2buzzthetower, ccasals, kavo: Update core modules to use the new batch builder
2021-06-28 12:30:58 +00:00
|
|
|
// @todo Instantiate our Updater to set the human-readable title?
|
|
|
|
$batch_builder = (new BatchBuilder())
|
Issue #2347783 by kim.pepper, andypost, almaudoh, gumanist, aleevas, rodrigoaguilera, Berdir, saurabh-2k17, Spokje, dhirendra.mishra, alexpott, paulocs, izus, Wim Leers, KapilV, naveenvalecha, anmolgoyal74, subson, yo30, harsha012, mrinalini9, daffie, voleger, dww, fietserwin, tim.plunkett, joachim, larowlan: Deprecate drupal_get_path() and drupal_get_filename() and replace with ExtensionList::getPath() and ExtensionList::getPathname()
2021-07-15 10:20:33 +00:00
|
|
|
->setFile(\Drupal::service('extension.list.module')->getPath('update') . '/update.authorize.inc')
|
Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9, jpatel657, quietone, jonathanshaw, alexpott, joachim, rajeshwari10, RajeevK, Yogesh Pawar, James.Shee, lcngeo, borisson_, time2buzzthetower, ccasals, kavo: Update core modules to use the new batch builder
2021-06-28 12:30:58 +00:00
|
|
|
->setInitMessage(t('Preparing to install'))
|
|
|
|
->addOperation('update_authorize_batch_copy_project', [
|
2009-10-15 21:19:31 +00:00
|
|
|
$project,
|
|
|
|
$updater_name,
|
|
|
|
$local_url,
|
|
|
|
$filetransfer,
|
Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9, jpatel657, quietone, jonathanshaw, alexpott, joachim, rajeshwari10, RajeevK, Yogesh Pawar, James.Shee, lcngeo, borisson_, time2buzzthetower, ccasals, kavo: Update core modules to use the new batch builder
2021-06-28 12:30:58 +00:00
|
|
|
])
|
2009-10-15 21:19:31 +00:00
|
|
|
// @todo Use a different finished callback for different messages?
|
Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9, jpatel657, quietone, jonathanshaw, alexpott, joachim, rajeshwari10, RajeevK, Yogesh Pawar, James.Shee, lcngeo, borisson_, time2buzzthetower, ccasals, kavo: Update core modules to use the new batch builder
2021-06-28 12:30:58 +00:00
|
|
|
->setFinishCallback('update_authorize_install_batch_finished');
|
|
|
|
batch_set($batch_builder->toArray());
|
2009-10-15 21:19:31 +00:00
|
|
|
|
2015-08-29 06:46:46 +00:00
|
|
|
// Since authorize.php has its own method for setting the page title, set it
|
|
|
|
// manually here rather than passing it in to batch_set() as would normally
|
|
|
|
// be done.
|
Issue #2577407 by vulcanr, jhodgdon, Sagar Ramgade, snehi, brahmjeet789, Manjit.Singh, Tony-Mac, ressa, xjm, cilefen, sajosh, ifrik, Charles Belov, Bojhan, David_Rothstein, Gábor Hojtsy, tkoleary, longwave, NickDickinsonWilde, nishantkumar155, shell_cm, greta_drupal, YesCT: Action of uploading module/theme files should consistently be called "Add", not "Install"
2020-12-06 19:02:44 +00:00
|
|
|
\Drupal::request()->getSession()->set('authorize_page_title', t('Adding %project', ['%project' => $project]));
|
2015-08-29 06:46:46 +00:00
|
|
|
|
2009-10-15 21:19:31 +00:00
|
|
|
// Invoke the batch via authorize.php.
|
Issue #1668866 by ParisLiakos, aspilicious, tim.plunkett, pdrake, g.oechsler, dawehner, Berdir, corvus_ch, damiankloip, disasm, marcingy, neclimdul: Replace drupal_goto() with RedirectResponse.
2013-06-19 16:07:30 +00:00
|
|
|
return system_authorized_batch_process();
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-02-13 19:51:15 +00:00
|
|
|
* Implements callback_batch_operation().
|
|
|
|
*
|
|
|
|
* Copies project to its proper place when authorized to do so.
|
2009-10-15 21:19:31 +00:00
|
|
|
*
|
|
|
|
* @param string $project
|
2009-10-22 00:52:03 +00:00
|
|
|
* The canonical short name of the project being installed.
|
2009-10-15 21:19:31 +00:00
|
|
|
* @param string $updater_name
|
2012-03-11 00:23:05 +00:00
|
|
|
* The name of the Drupal\Core\Updater\Updater class to use for installing
|
|
|
|
* this project.
|
2009-10-15 21:19:31 +00:00
|
|
|
* @param string $local_url
|
|
|
|
* The URL to the locally installed temp directory where the project has
|
|
|
|
* already been downloaded and extracted into.
|
2022-01-02 11:42:14 +00:00
|
|
|
* @param \Drupal\Core\FileTransfer\FileTransfer $filetransfer
|
2009-10-15 21:19:31 +00:00
|
|
|
* The FileTransfer object to use for performing this operation.
|
2011-05-08 19:50:38 +00:00
|
|
|
* @param array $context
|
2012-06-06 15:33:53 +00:00
|
|
|
* Reference to an array used for Batch API storage.
|
2009-10-15 21:19:31 +00:00
|
|
|
*/
|
|
|
|
function update_authorize_batch_copy_project($project, $updater_name, $local_url, $filetransfer, &$context) {
|
|
|
|
|
|
|
|
// Initialize some variables in the Batch API $context array.
|
|
|
|
if (!isset($context['results']['log'])) {
|
2017-03-04 01:20:24 +00:00
|
|
|
$context['results']['log'] = [];
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
if (!isset($context['results']['log'][$project])) {
|
2017-03-04 01:20:24 +00:00
|
|
|
$context['results']['log'][$project] = [];
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($context['results']['tasks'])) {
|
2017-03-04 01:20:24 +00:00
|
|
|
$context['results']['tasks'] = [];
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
|
2012-06-06 15:33:53 +00:00
|
|
|
// The batch API uses a session, and since all the arguments are serialized
|
|
|
|
// and unserialized between requests, although the FileTransfer object itself
|
|
|
|
// will be reconstructed, the connection pointer itself will be lost. However,
|
|
|
|
// the FileTransfer object will still have the connection variable, even
|
|
|
|
// though the connection itself is now gone. So, although it's ugly, we have
|
|
|
|
// to unset the connection variable at this point so that the FileTransfer
|
|
|
|
// object will re-initiate the actual connection.
|
2009-10-15 21:19:31 +00:00
|
|
|
unset($filetransfer->connection);
|
|
|
|
|
|
|
|
if (!empty($context['results']['log'][$project]['#abort'])) {
|
2010-10-30 04:06:45 +00:00
|
|
|
$context['finished'] = 1;
|
2009-10-15 21:19:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Issue #2042447 by David_Rothstein, joelpittet, stefan.r, SebCorbin, mpdonadio, steinmb, webchick, Cottser, miniwebs2, Vj, Gilbert Rehling, nuwe, yched, StuartJNCC, Fabianx, yktdan, herom: Install a module user interface does not install modules (or themes)
2015-08-07 09:02:58 +00:00
|
|
|
$updater = new $updater_name($local_url, \Drupal::getContainer()->get('update.root'));
|
2009-10-15 21:19:31 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
if ($updater->isInstalled()) {
|
|
|
|
// This is an update.
|
|
|
|
$tasks = $updater->update($filetransfer);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$tasks = $updater->install($filetransfer);
|
|
|
|
}
|
|
|
|
}
|
2009-10-22 00:52:03 +00:00
|
|
|
catch (UpdaterException $e) {
|
Issue #2577407 by vulcanr, jhodgdon, Sagar Ramgade, snehi, brahmjeet789, Manjit.Singh, Tony-Mac, ressa, xjm, cilefen, sajosh, ifrik, Charles Belov, Bojhan, David_Rothstein, Gábor Hojtsy, tkoleary, longwave, NickDickinsonWilde, nishantkumar155, shell_cm, greta_drupal, YesCT: Action of uploading module/theme files should consistently be called "Add", not "Install"
2020-12-06 19:02:44 +00:00
|
|
|
_update_batch_create_message($context['results']['log'][$project], t('Error adding / updating'), FALSE);
|
2009-10-15 21:19:31 +00:00
|
|
|
_update_batch_create_message($context['results']['log'][$project], $e->getMessage(), FALSE);
|
|
|
|
$context['results']['log'][$project]['#abort'] = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Issue #2577407 by vulcanr, jhodgdon, Sagar Ramgade, snehi, brahmjeet789, Manjit.Singh, Tony-Mac, ressa, xjm, cilefen, sajosh, ifrik, Charles Belov, Bojhan, David_Rothstein, Gábor Hojtsy, tkoleary, longwave, NickDickinsonWilde, nishantkumar155, shell_cm, greta_drupal, YesCT: Action of uploading module/theme files should consistently be called "Add", not "Install"
2020-12-06 19:02:44 +00:00
|
|
|
_update_batch_create_message($context['results']['log'][$project], t('Added / updated %project_name successfully', ['%project_name' => $project]));
|
|
|
|
|
2010-04-10 09:49:49 +00:00
|
|
|
if (!empty($tasks)) {
|
|
|
|
$context['results']['tasks'] += $tasks;
|
|
|
|
}
|
2009-10-15 21:19:31 +00:00
|
|
|
|
|
|
|
// This particular operation is now complete, even though the batch might
|
|
|
|
// have other operations to perform.
|
|
|
|
$context['finished'] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-06 15:33:53 +00:00
|
|
|
* Batch callback: Performs actions when the authorized update batch is done.
|
2009-10-15 21:19:31 +00:00
|
|
|
*
|
|
|
|
* This processes the results and stashes them into SESSION such that
|
|
|
|
* authorize.php will render a report. Also responsible for putting the site
|
2013-03-20 11:51:03 +00:00
|
|
|
* back online and clearing the update status storage after a successful update.
|
2012-06-06 15:33:53 +00:00
|
|
|
*
|
|
|
|
* @param $success
|
|
|
|
* TRUE if the batch operation was successful; FALSE if there were errors.
|
|
|
|
* @param $results
|
|
|
|
* An associative array of results from the batch operation.
|
2009-10-15 21:19:31 +00:00
|
|
|
*/
|
|
|
|
function update_authorize_update_batch_finished($success, $results) {
|
Issue #2002650 by mrsinguyen, chertzog, legolasbo, Erik Erskine, rhm50, sandergo90, grisendo, targoo, janstoeckler, maximpodorov, beowulf1416: Improve maintainability by removing unused local variables.
2013-10-02 13:52:21 +00:00
|
|
|
foreach ($results['log'] as $messages) {
|
2009-10-15 21:19:31 +00:00
|
|
|
if (!empty($messages['#abort'])) {
|
|
|
|
$success = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2013-09-16 03:58:06 +00:00
|
|
|
$offline = \Drupal::state()->get('system.maintenance_mode');
|
2020-02-20 21:38:33 +00:00
|
|
|
$session = \Drupal::request()->getSession();
|
|
|
|
// Unset the variable since it is no longer needed.
|
|
|
|
$maintenance_mode = $session->remove('maintenance_mode');
|
2009-10-15 21:19:31 +00:00
|
|
|
if ($success) {
|
2013-03-20 11:51:03 +00:00
|
|
|
// Now that the update completed, we need to clear the available update data
|
|
|
|
// and recompute our status, so prevent show bogus results.
|
2009-10-15 21:19:31 +00:00
|
|
|
_update_authorize_clear_update_status();
|
|
|
|
|
2011-01-03 02:53:07 +00:00
|
|
|
// Take the site out of maintenance mode if it was previously that way.
|
2020-02-20 21:38:33 +00:00
|
|
|
if ($offline && $maintenance_mode === FALSE) {
|
2013-09-16 03:58:06 +00:00
|
|
|
\Drupal::state()->set('system.maintenance_mode', FALSE);
|
2017-03-04 01:20:24 +00:00
|
|
|
$page_message = [
|
2009-10-15 21:19:31 +00:00
|
|
|
'message' => t('Update was completed successfully. Your site has been taken out of maintenance mode.'),
|
|
|
|
'type' => 'status',
|
2017-03-04 01:20:24 +00:00
|
|
|
];
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2017-03-04 01:20:24 +00:00
|
|
|
$page_message = [
|
2009-10-15 21:19:31 +00:00
|
|
|
'message' => t('Update was completed successfully.'),
|
|
|
|
'type' => 'status',
|
2017-03-04 01:20:24 +00:00
|
|
|
];
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif (!$offline) {
|
2017-03-04 01:20:24 +00:00
|
|
|
$page_message = [
|
2009-10-15 21:19:31 +00:00
|
|
|
'message' => t('Update failed! See the log below for more information.'),
|
|
|
|
'type' => 'error',
|
2017-03-04 01:20:24 +00:00
|
|
|
];
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2017-03-04 01:20:24 +00:00
|
|
|
$page_message = [
|
2009-10-15 21:19:31 +00:00
|
|
|
'message' => t('Update failed! See the log below for more information. Your site is still in maintenance mode.'),
|
|
|
|
'type' => 'error',
|
2017-03-04 01:20:24 +00:00
|
|
|
];
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
2010-04-10 09:49:49 +00:00
|
|
|
// Since we're doing an update of existing code, always add a task for
|
|
|
|
// running update.php.
|
2016-04-26 11:15:16 +00:00
|
|
|
$url = Url::fromRoute('system.db_update');
|
2010-04-10 09:49:49 +00:00
|
|
|
$results['tasks'][] = t('Your modules have been downloaded and updated.');
|
Issue #1885564 by joelpittet, SebCorbin, Cottser, mpdonadio, David_Rothstein, drupalninja99, jenlampton, lauriii, rteijeiro, mbrett5062, akalata, Devin Carlson, trevorkjorlien, longwave, socketwench, shanethehat, aboros: theme.maintenance.inc (authorize.php) - Convert theme_ functions to Twig
2015-08-11 22:54:49 +00:00
|
|
|
$results['tasks'][] = [
|
|
|
|
'#type' => 'link',
|
2016-04-26 11:15:16 +00:00
|
|
|
'#url' => $url,
|
Issue #1885564 by joelpittet, SebCorbin, Cottser, mpdonadio, David_Rothstein, drupalninja99, jenlampton, lauriii, rteijeiro, mbrett5062, akalata, Devin Carlson, trevorkjorlien, longwave, socketwench, shanethehat, aboros: theme.maintenance.inc (authorize.php) - Convert theme_ functions to Twig
2015-08-11 22:54:49 +00:00
|
|
|
'#title' => t('Run database updates'),
|
Issue #2829185 by vaplas, Jo Fitzgerald, anmolgoyal74, chipway, gaurav.kapoor, mark_fullmer, amit.drupal, cilefen, longwave, xjm, wturrell, anavarre: Fix spelling errors in Drupal core comments
2018-09-20 16:12:38 +00:00
|
|
|
// Since this is being called outside of the primary front controller,
|
Issue #1885564 by joelpittet, SebCorbin, Cottser, mpdonadio, David_Rothstein, drupalninja99, jenlampton, lauriii, rteijeiro, mbrett5062, akalata, Devin Carlson, trevorkjorlien, longwave, socketwench, shanethehat, aboros: theme.maintenance.inc (authorize.php) - Convert theme_ functions to Twig
2015-08-11 22:54:49 +00:00
|
|
|
// the base_url needs to be set explicitly to ensure that links are
|
|
|
|
// relative to the site root.
|
|
|
|
// @todo Simplify with https://www.drupal.org/node/2548095
|
|
|
|
'#options' => [
|
|
|
|
'absolute' => TRUE,
|
|
|
|
'base_url' => $GLOBALS['base_url'],
|
|
|
|
],
|
2018-05-11 09:40:33 +00:00
|
|
|
'#access' => $url->access(\Drupal::currentUser()),
|
Issue #1885564 by joelpittet, SebCorbin, Cottser, mpdonadio, David_Rothstein, drupalninja99, jenlampton, lauriii, rteijeiro, mbrett5062, akalata, Devin Carlson, trevorkjorlien, longwave, socketwench, shanethehat, aboros: theme.maintenance.inc (authorize.php) - Convert theme_ functions to Twig
2015-08-11 22:54:49 +00:00
|
|
|
];
|
2009-10-15 21:19:31 +00:00
|
|
|
|
|
|
|
// Set all these values into the SESSION so authorize.php can display them.
|
2020-02-20 21:38:33 +00:00
|
|
|
$session->set('authorize_results', [
|
|
|
|
'success' => $success,
|
|
|
|
'page_message' => $page_message,
|
|
|
|
'messages' => $results['log'],
|
|
|
|
'tasks' => $results['tasks'],
|
|
|
|
]);
|
|
|
|
$session->set('authorize_page_title', t('Update manager'));
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-02-13 19:51:15 +00:00
|
|
|
* Implements callback_batch_finished().
|
|
|
|
*
|
|
|
|
* Performs actions when the authorized install batch is done.
|
2009-10-15 21:19:31 +00:00
|
|
|
*
|
|
|
|
* This processes the results and stashes them into SESSION such that
|
|
|
|
* authorize.php will render a report. Also responsible for putting the site
|
|
|
|
* back online after a successful install if necessary.
|
2012-06-06 15:33:53 +00:00
|
|
|
*
|
|
|
|
* @param $success
|
|
|
|
* TRUE if the batch operation was a success; FALSE if there were errors.
|
|
|
|
* @param $results
|
|
|
|
* An associative array of results from the batch operation.
|
2009-10-15 21:19:31 +00:00
|
|
|
*/
|
|
|
|
function update_authorize_install_batch_finished($success, $results) {
|
Issue #2002650 by mrsinguyen, chertzog, legolasbo, Erik Erskine, rhm50, sandergo90, grisendo, targoo, janstoeckler, maximpodorov, beowulf1416: Improve maintainability by removing unused local variables.
2013-10-02 13:52:21 +00:00
|
|
|
foreach ($results['log'] as $messages) {
|
2009-10-15 21:19:31 +00:00
|
|
|
if (!empty($messages['#abort'])) {
|
|
|
|
$success = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2013-09-16 03:58:06 +00:00
|
|
|
$offline = \Drupal::state()->get('system.maintenance_mode');
|
2020-02-20 21:38:33 +00:00
|
|
|
$session = \Drupal::request()->getSession();
|
|
|
|
// Unset the variable since it is no longer needed.
|
|
|
|
$maintenance_mode = $session->remove('maintenance_mode');
|
2011-01-03 02:53:07 +00:00
|
|
|
if ($success) {
|
|
|
|
// Take the site out of maintenance mode if it was previously that way.
|
2020-02-20 21:38:33 +00:00
|
|
|
if ($offline && $maintenance_mode === FALSE) {
|
2013-09-16 03:58:06 +00:00
|
|
|
\Drupal::state()->set('system.maintenance_mode', FALSE);
|
2017-03-04 01:20:24 +00:00
|
|
|
$page_message = [
|
Issue #2577407 by vulcanr, jhodgdon, Sagar Ramgade, snehi, brahmjeet789, Manjit.Singh, Tony-Mac, ressa, xjm, cilefen, sajosh, ifrik, Charles Belov, Bojhan, David_Rothstein, Gábor Hojtsy, tkoleary, longwave, NickDickinsonWilde, nishantkumar155, shell_cm, greta_drupal, YesCT: Action of uploading module/theme files should consistently be called "Add", not "Install"
2020-12-06 19:02:44 +00:00
|
|
|
'message' => t('Files were added successfully. Your site has been taken out of maintenance mode.'),
|
2011-01-03 02:53:07 +00:00
|
|
|
'type' => 'status',
|
2017-03-04 01:20:24 +00:00
|
|
|
];
|
2011-01-03 02:53:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2017-03-04 01:20:24 +00:00
|
|
|
$page_message = [
|
Issue #2577407 by vulcanr, jhodgdon, Sagar Ramgade, snehi, brahmjeet789, Manjit.Singh, Tony-Mac, ressa, xjm, cilefen, sajosh, ifrik, Charles Belov, Bojhan, David_Rothstein, Gábor Hojtsy, tkoleary, longwave, NickDickinsonWilde, nishantkumar155, shell_cm, greta_drupal, YesCT: Action of uploading module/theme files should consistently be called "Add", not "Install"
2020-12-06 19:02:44 +00:00
|
|
|
'message' => t('Files were added successfully.'),
|
2011-01-03 02:53:07 +00:00
|
|
|
'type' => 'status',
|
2017-03-04 01:20:24 +00:00
|
|
|
];
|
2011-01-03 02:53:07 +00:00
|
|
|
}
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
elseif (!$success && !$offline) {
|
2017-03-04 01:20:24 +00:00
|
|
|
$page_message = [
|
Issue #2577407 by vulcanr, jhodgdon, Sagar Ramgade, snehi, brahmjeet789, Manjit.Singh, Tony-Mac, ressa, xjm, cilefen, sajosh, ifrik, Charles Belov, Bojhan, David_Rothstein, Gábor Hojtsy, tkoleary, longwave, NickDickinsonWilde, nishantkumar155, shell_cm, greta_drupal, YesCT: Action of uploading module/theme files should consistently be called "Add", not "Install"
2020-12-06 19:02:44 +00:00
|
|
|
'message' => t('File add failed! See the log below for more information.'),
|
2009-10-15 21:19:31 +00:00
|
|
|
'type' => 'error',
|
2017-03-04 01:20:24 +00:00
|
|
|
];
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2017-03-04 01:20:24 +00:00
|
|
|
$page_message = [
|
Issue #2577407 by vulcanr, jhodgdon, Sagar Ramgade, snehi, brahmjeet789, Manjit.Singh, Tony-Mac, ressa, xjm, cilefen, sajosh, ifrik, Charles Belov, Bojhan, David_Rothstein, Gábor Hojtsy, tkoleary, longwave, NickDickinsonWilde, nishantkumar155, shell_cm, greta_drupal, YesCT: Action of uploading module/theme files should consistently be called "Add", not "Install"
2020-12-06 19:02:44 +00:00
|
|
|
'message' => t('File add failed! See the log below for more information. Your site is still in maintenance mode.'),
|
2009-10-15 21:19:31 +00:00
|
|
|
'type' => 'error',
|
2017-03-04 01:20:24 +00:00
|
|
|
];
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set all these values into the SESSION so authorize.php can display them.
|
2020-02-20 21:38:33 +00:00
|
|
|
$session->set('authorize_results', [
|
|
|
|
'success' => $success,
|
|
|
|
'page_message' => $page_message,
|
|
|
|
'messages' => $results['log'],
|
|
|
|
'tasks' => $results['tasks'],
|
|
|
|
]);
|
|
|
|
$session->set('authorize_page_title', t('Update manager'));
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-06 15:33:53 +00:00
|
|
|
* Creates a structure of log messages.
|
2009-10-15 21:19:31 +00:00
|
|
|
*
|
|
|
|
* @param array $project_results
|
2012-06-06 15:33:53 +00:00
|
|
|
* An associative array of results from the batch operation.
|
2009-10-15 21:19:31 +00:00
|
|
|
* @param string $message
|
2012-06-06 15:33:53 +00:00
|
|
|
* A string containing a log message.
|
2009-10-15 21:19:31 +00:00
|
|
|
* @param bool $success
|
2012-06-06 15:33:53 +00:00
|
|
|
* (optional) TRUE if the operation the message is about was a success, FALSE
|
|
|
|
* if there were errors. Defaults to TRUE.
|
2009-10-15 21:19:31 +00:00
|
|
|
*/
|
|
|
|
function _update_batch_create_message(&$project_results, $message, $success = TRUE) {
|
2017-03-04 01:20:24 +00:00
|
|
|
$project_results[] = ['message' => $message, 'success' => $success];
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-03-20 11:51:03 +00:00
|
|
|
* Clears available update status data.
|
2009-10-15 21:19:31 +00:00
|
|
|
*
|
2012-06-06 15:33:53 +00:00
|
|
|
* Since this function is run at such a low bootstrap level, the Update Manager
|
2013-03-20 11:51:03 +00:00
|
|
|
* module is not loaded. So, we can't just call update_storage_clear(). However,
|
|
|
|
* the key-value backend is available, so we just call that.
|
2009-10-15 21:19:31 +00:00
|
|
|
*
|
2013-03-20 11:51:03 +00:00
|
|
|
* Note that we do not want to delete items related to currently pending fetch
|
|
|
|
* attempts.
|
2009-10-15 21:19:31 +00:00
|
|
|
*
|
|
|
|
* @see update_authorize_update_batch_finished()
|
2013-03-20 11:51:03 +00:00
|
|
|
* @see update_storage_clear()
|
2009-10-15 21:19:31 +00:00
|
|
|
*/
|
|
|
|
function _update_authorize_clear_update_status() {
|
2013-09-16 03:58:06 +00:00
|
|
|
\Drupal::keyValueExpirable('update')->deleteAll();
|
|
|
|
\Drupal::keyValueExpirable('update_available_release')->deleteAll();
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|