Skip to content
Snippets Groups Projects
Commit f4003c12 authored by Lucas Hedding's avatar Lucas Hedding Committed by Lucas Hedding
Browse files

Issue #3053804 by heddn, catch: Checker: Are there pending updates (update.php needs to be run)

parent d98203c7
No related branches found
No related tags found
No related merge requests found
...@@ -61,3 +61,7 @@ services: ...@@ -61,3 +61,7 @@ services:
- '@automatic_updates.drupal_finder' - '@automatic_updates.drupal_finder'
tags: tags:
- { name: readiness_checker, category: warning} - { name: readiness_checker, category: warning}
automatic_updates.pending_db_updates:
class: Drupal\automatic_updates\ReadinessChecker\PendingDbUpdates
tags:
- { name: readiness_checker, category: error}
<?php
namespace Drupal\automatic_updates\ReadinessChecker;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
* Pending database updates checker.
*/
class PendingDbUpdates implements ReadinessCheckerInterface {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function run() {
$messages = [];
if ($this->areDbUpdatesPending()) {
$messages[] = $this->t('There are pending database updates, therefore updates cannot be applied. Please run update.php.');
}
return $messages;
}
/**
* Checks if there are pending database updates.
*
* @return bool
* TRUE if there are pending updates, otherwise FALSE.
*/
protected function areDbUpdatesPending() {
require_once DRUPAL_ROOT . '/core/includes/install.inc';
require_once DRUPAL_ROOT . '/core/includes/update.inc';
drupal_load_updates();
return (bool) update_get_update_list();
}
}
<?php
namespace Drupal\Tests\automatic_updates\Kernel\ReadinessChecker;
use Drupal\automatic_updates\ReadinessChecker\PendingDbUpdates;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests pending db updates readiness checking.
*
* @group automatic_updates
*/
class PendingDbUpdatesTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'automatic_updates',
];
/**
* Tests pending db updates readiness checks.
*/
public function testPendingDbUpdates() {
$messages = $this->container->get('automatic_updates.pending_db_updates')->run();
$this->assertEmpty($messages);
$messages = (new TestPendingDbUpdates())->run();
$this->assertEquals('There are pending database updates, therefore updates cannot be applied. Please run update.php.', $messages[0]);
}
}
/**
* Class TestPendingDbUpdates.
*/
class TestPendingDbUpdates extends PendingDbUpdates {
/**
* {@inheritdoc}
*/
protected function areDbUpdatesPending() {
return TRUE;
}
}
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