Skip to content

Commit

Permalink
Skip the /admin/update/ready page
Browse files Browse the repository at this point in the history
The page suggests backing up the site and offers to put the site into
maintenance mode, but even webmaster administrators is allowed
neither.

So we copy the important part from UpdateReady::submitForm.

Ref DDFHER-183
  • Loading branch information
xendk committed Dec 19, 2024
1 parent 01fdcdd commit 693e11d
Showing 1 changed file with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ public function submitForm(array &$form, FormStateInterface $form_state): void {
// MODULE/) and others list an actual file (i.e., MODULE/README.TXT).
$project = strtok($files[0], '/\\');

if (!$project) {
throw new \RuntimeException('Could not determine module name from archive');
}

$archive_errors = $this->moduleHandler->invokeAll('verify_update_archive', [$project, $local_cache, $directory]);
if (!empty($archive_errors)) {
$this->messenger()->addError(array_shift($archive_errors));
Expand Down Expand Up @@ -240,15 +244,11 @@ public function submitForm(array &$form, FormStateInterface $form_state): void {
return;
}

// This is where we diverge from UpdateManagerInstall. It simply errors out,
// we set a session variable to tell /admin/update/ready which module to
// update and redirect to it instead. It'll pick up the files for the module
// as we've already extracted it in the directory where it expects to find
// it.
// This is where we diverge from UpdateManagerInstall and pass over control
// to update.php. It'll pick up the files for the module as we've already
// extracted it in the directory where it expects to find it.
if ($updater->isInstalled()) {
// Tell UpdateReady form which projects to update.
$this->session->set('update_manager_update_projects', [$project => $project]);
$form_state->setRedirect('update.confirmation_page');
$this->redirectToUpdates([$project], $form_state);
return;
}

Expand Down Expand Up @@ -291,4 +291,42 @@ public function submitForm(array &$form, FormStateInterface $form_state): void {
}
}

/**
* Copy uploaded module into place and run updates.
*
* @param string[] $projects
* List of projects to update.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* Form state to set redirect on.
*/
protected function redirectToUpdates(array $projects, FormStateInterface $form_state): void {
// Most of this has been lifted from UpdateReady::submitForm().
drupal_get_updaters();

$updates = [];
$directory = _update_manager_extract_directory();

$project_real_location = NULL;
foreach ($projects as $project) {
$project_location = $directory . '/' . $project;
$updater = Updater::factory($project_location, $this->root);
$project_real_location = $this->fileSystem->realpath($project_location);
$updates[] = [
'project' => $project,
'updater_name' => get_class($updater),
'local_url' => $project_real_location,
];
}

// Contrary to UpdateReady::submitForm(), we don't check file owners or
// support FTP method.
$this->moduleHandler->loadInclude('update', 'inc', 'update.authorize');
$filetransfer = new Local($this->root, $this->fileSystem);
// @phpstan-ignore function.notFound (It's loaded by the loadInclude)
$response = update_authorize_run_update($filetransfer, $updates);
if ($response instanceof Response) {
$form_state->setResponse($response);
}
}

}

0 comments on commit 693e11d

Please sign in to comment.