From 6240c602033b7abbde1c57b7618f73fd65e6b560 Mon Sep 17 00:00:00 2001 From: phenaproxima <phenaproxima@205645.no-reply.drupal.org> Date: Tue, 9 Nov 2021 18:31:52 +0000 Subject: [PATCH] Issue #3248527 by phenaproxima: Clean up Updater --- src/BatchProcessor.php | 4 +-- src/CronUpdater.php | 2 +- src/Updater.php | 34 ++++--------------- .../src/TestController.php | 2 +- tests/src/Kernel/CronUpdaterTest.php | 2 +- 5 files changed, 11 insertions(+), 33 deletions(-) diff --git a/src/BatchProcessor.php b/src/BatchProcessor.php index 6e0ac4f158..fbf90ab015 100644 --- a/src/BatchProcessor.php +++ b/src/BatchProcessor.php @@ -96,11 +96,11 @@ class BatchProcessor { * @param array $context * The current context of the batch job. * - * @see \Drupal\automatic_updates\Updater::commit() + * @see \Drupal\automatic_updates\Updater::apply() */ public static function commit(array &$context): void { try { - static::getUpdater()->commit(); + static::getUpdater()->apply(); } catch (\Throwable $e) { static::handleException($e, $context); diff --git a/src/CronUpdater.php b/src/CronUpdater.php index c9392e5af2..ff111659af 100644 --- a/src/CronUpdater.php +++ b/src/CronUpdater.php @@ -131,7 +131,7 @@ class CronUpdater implements ContainerInjectionInterface { 'drupal' => $recommended_version, ]); $this->updater->stage(); - $this->updater->commit(); + $this->updater->apply(); $this->updater->clean(); } catch (\Throwable $e) { diff --git a/src/Updater.php b/src/Updater.php index 4df1e6b946..cc5daf6f81 100644 --- a/src/Updater.php +++ b/src/Updater.php @@ -19,7 +19,7 @@ class Updater extends Stage { * * @var string */ - public const STATE_KEY = 'AUTOMATIC_UPDATES_CURRENT'; + protected const STATE_KEY = 'AUTOMATIC_UPDATES_CURRENT'; /** * The state service. @@ -77,7 +77,11 @@ class Updater extends Stage { foreach ($composer->getCorePackageNames() as $package) { $packages[$package] = $project_versions['drupal']; } - $stage_key = $this->createActiveStage($packages); + $stage_key = static::STATE_KEY . microtime(); + $this->state->set(static::STATE_KEY, [ + 'id' => $stage_key, + 'package_versions' => $packages, + ]); $this->create(); return $stage_key; } @@ -107,13 +111,6 @@ class Updater extends Stage { $this->require($requirements); } - /** - * Commits the current update. - */ - public function commit(): void { - $this->apply(); - } - /** * Cleans the current update. */ @@ -122,25 +119,6 @@ class Updater extends Stage { $this->state->delete(static::STATE_KEY); } - /** - * Initializes an active update and returns its ID. - * - * @param string[] $package_versions - * The versions of the packages to stage, keyed by package name. - * - * @return string - * The active update ID. - */ - private function createActiveStage(array $package_versions): string { - $value = static::STATE_KEY . microtime(); - - $this->state->set(static::STATE_KEY, [ - 'id' => $value, - 'package_versions' => $package_versions, - ]); - return $value; - } - /** * {@inheritdoc} */ diff --git a/tests/modules/automatic_updates_test/src/TestController.php b/tests/modules/automatic_updates_test/src/TestController.php index 69308a467d..d96e56a01f 100644 --- a/tests/modules/automatic_updates_test/src/TestController.php +++ b/tests/modules/automatic_updates_test/src/TestController.php @@ -33,7 +33,7 @@ class TestController extends ControllerBase { try { $updater->begin(['drupal' => $to_version]); $updater->stage(); - $updater->commit(); + $updater->apply(); $updater->clean(); $project = (new UpdateRecommender())->getProjectInfo(); diff --git a/tests/src/Kernel/CronUpdaterTest.php b/tests/src/Kernel/CronUpdaterTest.php index d65f5e21db..e31a4f2c40 100644 --- a/tests/src/Kernel/CronUpdaterTest.php +++ b/tests/src/Kernel/CronUpdaterTest.php @@ -107,7 +107,7 @@ class CronUpdaterTest extends AutomaticUpdatesKernelTestBase { $updater->begin(['drupal' => '9.8.1'])->shouldBeCalledTimes($will_update); $updater->stage()->shouldBeCalledTimes($will_update); - $updater->commit()->shouldBeCalledTimes($will_update); + $updater->apply()->shouldBeCalledTimes($will_update); $updater->clean()->shouldBeCalledTimes($will_update); $this->container->set('automatic_updates.updater', $updater->reveal()); -- GitLab