Skip to content
Snippets Groups Projects
Commit 95bdbbe9 authored by Adam G-H's avatar Adam G-H Committed by Ted Bowman
Browse files

Issue #3280923 by phenaproxima: CronUpdater::begin() should throw an exception...

Issue #3280923 by phenaproxima: CronUpdater::begin() should throw an exception of if cron updates are disabled
parent f8c1ea38
No related branches found
No related tags found
No related merge requests found
...@@ -93,6 +93,19 @@ class CronUpdater extends Updater { ...@@ -93,6 +93,19 @@ class CronUpdater extends Updater {
} }
} }
/**
* {@inheritdoc}
*/
public function begin(array $project_versions, ?int $timeout = 300): string {
// Prevent mischievous callers from starting an update even if unattended
// updates are disabled. To start an update programmatically, use
// \Drupal\automatic_updates\Updater::begin().
if ($this->getMode() === static::DISABLED) {
throw new \LogicException('Unattended updates are disabled.');
}
return parent::begin($project_versions, $timeout);
}
/** /**
* Performs the update. * Performs the update.
* *
......
...@@ -57,6 +57,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -57,6 +57,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
'access site in maintenance mode', 'access site in maintenance mode',
'administer modules', 'administer modules',
'access site reports', 'access site reports',
'view update notifications',
]); ]);
$this->drupalLogin($user); $this->drupalLogin($user);
$this->checkForUpdates(); $this->checkForUpdates();
......
...@@ -38,6 +38,7 @@ class CronUpdaterTest extends AutomaticUpdatesKernelTestBase { ...@@ -38,6 +38,7 @@ class CronUpdaterTest extends AutomaticUpdatesKernelTestBase {
protected static $modules = [ protected static $modules = [
'automatic_updates', 'automatic_updates',
'automatic_updates_test', 'automatic_updates_test',
'user',
]; ];
/** /**
...@@ -328,4 +329,17 @@ class CronUpdaterTest extends AutomaticUpdatesKernelTestBase { ...@@ -328,4 +329,17 @@ class CronUpdaterTest extends AutomaticUpdatesKernelTestBase {
} }
} }
/**
* Tests that the cron updater throws an exception if started while disabled.
*/
public function testExceptionWhenDisabled(): void {
$this->config('automatic_updates.settings')
->set('cron', CronUpdater::DISABLED)
->save();
$this->expectExceptionMessage('Unattended updates are disabled.');
$this->container->get('automatic_updates.cron_updater')
->begin(['drupal' => '9.8.1']);
}
} }
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