Skip to content
Snippets Groups Projects
Commit 6240c602 authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3248527 by phenaproxima: Clean up Updater

parent acc33a18
No related branches found
No related tags found
1 merge request!110Issue #3248527: Clean up Updater
...@@ -96,11 +96,11 @@ class BatchProcessor { ...@@ -96,11 +96,11 @@ class BatchProcessor {
* @param array $context * @param array $context
* The current context of the batch job. * 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 { public static function commit(array &$context): void {
try { try {
static::getUpdater()->commit(); static::getUpdater()->apply();
} }
catch (\Throwable $e) { catch (\Throwable $e) {
static::handleException($e, $context); static::handleException($e, $context);
......
...@@ -131,7 +131,7 @@ class CronUpdater implements ContainerInjectionInterface { ...@@ -131,7 +131,7 @@ class CronUpdater implements ContainerInjectionInterface {
'drupal' => $recommended_version, 'drupal' => $recommended_version,
]); ]);
$this->updater->stage(); $this->updater->stage();
$this->updater->commit(); $this->updater->apply();
$this->updater->clean(); $this->updater->clean();
} }
catch (\Throwable $e) { catch (\Throwable $e) {
......
...@@ -19,7 +19,7 @@ class Updater extends Stage { ...@@ -19,7 +19,7 @@ class Updater extends Stage {
* *
* @var string * @var string
*/ */
public const STATE_KEY = 'AUTOMATIC_UPDATES_CURRENT'; protected const STATE_KEY = 'AUTOMATIC_UPDATES_CURRENT';
/** /**
* The state service. * The state service.
...@@ -77,7 +77,11 @@ class Updater extends Stage { ...@@ -77,7 +77,11 @@ class Updater extends Stage {
foreach ($composer->getCorePackageNames() as $package) { foreach ($composer->getCorePackageNames() as $package) {
$packages[$package] = $project_versions['drupal']; $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(); $this->create();
return $stage_key; return $stage_key;
} }
...@@ -107,13 +111,6 @@ class Updater extends Stage { ...@@ -107,13 +111,6 @@ class Updater extends Stage {
$this->require($requirements); $this->require($requirements);
} }
/**
* Commits the current update.
*/
public function commit(): void {
$this->apply();
}
/** /**
* Cleans the current update. * Cleans the current update.
*/ */
...@@ -122,25 +119,6 @@ class Updater extends Stage { ...@@ -122,25 +119,6 @@ class Updater extends Stage {
$this->state->delete(static::STATE_KEY); $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} * {@inheritdoc}
*/ */
......
...@@ -33,7 +33,7 @@ class TestController extends ControllerBase { ...@@ -33,7 +33,7 @@ class TestController extends ControllerBase {
try { try {
$updater->begin(['drupal' => $to_version]); $updater->begin(['drupal' => $to_version]);
$updater->stage(); $updater->stage();
$updater->commit(); $updater->apply();
$updater->clean(); $updater->clean();
$project = (new UpdateRecommender())->getProjectInfo(); $project = (new UpdateRecommender())->getProjectInfo();
......
...@@ -107,7 +107,7 @@ class CronUpdaterTest extends AutomaticUpdatesKernelTestBase { ...@@ -107,7 +107,7 @@ class CronUpdaterTest extends AutomaticUpdatesKernelTestBase {
$updater->begin(['drupal' => '9.8.1'])->shouldBeCalledTimes($will_update); $updater->begin(['drupal' => '9.8.1'])->shouldBeCalledTimes($will_update);
$updater->stage()->shouldBeCalledTimes($will_update); $updater->stage()->shouldBeCalledTimes($will_update);
$updater->commit()->shouldBeCalledTimes($will_update); $updater->apply()->shouldBeCalledTimes($will_update);
$updater->clean()->shouldBeCalledTimes($will_update); $updater->clean()->shouldBeCalledTimes($will_update);
$this->container->set('automatic_updates.updater', $updater->reveal()); $this->container->set('automatic_updates.updater', $updater->reveal());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment