Loading core/includes/update.inc +1 −1 Original line number Diff line number Diff line Loading @@ -307,7 +307,7 @@ function update_invoke_post_update($function, &$context) { watchdog_exception('update', $e); $variables = Error::decodeException($e); unset($variables['backtrace'], $variables['exception']); unset($variables['backtrace'], $variables['exception'], $variables['severity_level']); $ret['#abort'] = [ 'success' => FALSE, 'query' => t(Error::DEFAULT_ERROR_MESSAGE, $variables), Loading core/modules/system/tests/modules/post_update_test_failing/post_update_test_failing.info.yml 0 → 100644 +5 −0 Original line number Diff line number Diff line name: 'Post Update test failing' type: module description: 'Support module for update testing when a post update is failing.' package: Testing version: VERSION core/modules/system/tests/modules/post_update_test_failing/post_update_test_failing.post_update.php 0 → 100644 +13 −0 Original line number Diff line number Diff line <?php /** * @file * Post update functions for test module. */ /** * Post update that throws an exception. */ function post_update_test_failing_post_update_exception() { throw new \RuntimeException('This post update fails'); } core/modules/system/tests/src/Functional/UpdateSystem/UpdatePostUpdateExceptionTest.php 0 → 100644 +68 −0 Original line number Diff line number Diff line <?php namespace Drupal\Tests\system\Functional\UpdateSystem; use Drupal\Core\Database\Database; use Drupal\Tests\BrowserTestBase; use Drupal\Tests\UpdatePathTestTrait; /** * Tests hook_post_update() when there is an exception in a post update. * * @group Update */ class UpdatePostUpdateExceptionTest extends BrowserTestBase { use UpdatePathTestTrait; /** * {@inheritdoc} */ protected $defaultTheme = 'stark'; /** * {@inheritdoc} */ protected function setUp(): void { parent::setUp(); $connection = Database::getConnection(); // Set the schema version. \Drupal::service('update.update_hook_registry')->setInstalledVersion('post_update_test_failing', 8000); // Update core.extension. $extensions = $connection->select('config') ->fields('config', ['data']) ->condition('collection', '') ->condition('name', 'core.extension') ->execute() ->fetchField(); $extensions = unserialize($extensions); $extensions['module']['post_update_test_failing'] = 8000; $connection->update('config') ->fields([ 'data' => serialize($extensions), ]) ->condition('collection', '') ->condition('name', 'core.extension') ->execute(); } /** * Tests hook_post_update_NAME(). */ public function testPostUpdate() { // There are expected to be failed updates. $this->checkFailedUpdates = FALSE; $this->runUpdates(); $this->assertSession()->pageTextContains('Failed: RuntimeException: This post update fails in post_update_test_failing_post_update_exception()'); } /** * {@inheritdoc} */ protected function doSelectionTest() { $this->assertSession()->assertEscaped("Post update that throws an exception."); } } Loading
core/includes/update.inc +1 −1 Original line number Diff line number Diff line Loading @@ -307,7 +307,7 @@ function update_invoke_post_update($function, &$context) { watchdog_exception('update', $e); $variables = Error::decodeException($e); unset($variables['backtrace'], $variables['exception']); unset($variables['backtrace'], $variables['exception'], $variables['severity_level']); $ret['#abort'] = [ 'success' => FALSE, 'query' => t(Error::DEFAULT_ERROR_MESSAGE, $variables), Loading
core/modules/system/tests/modules/post_update_test_failing/post_update_test_failing.info.yml 0 → 100644 +5 −0 Original line number Diff line number Diff line name: 'Post Update test failing' type: module description: 'Support module for update testing when a post update is failing.' package: Testing version: VERSION
core/modules/system/tests/modules/post_update_test_failing/post_update_test_failing.post_update.php 0 → 100644 +13 −0 Original line number Diff line number Diff line <?php /** * @file * Post update functions for test module. */ /** * Post update that throws an exception. */ function post_update_test_failing_post_update_exception() { throw new \RuntimeException('This post update fails'); }
core/modules/system/tests/src/Functional/UpdateSystem/UpdatePostUpdateExceptionTest.php 0 → 100644 +68 −0 Original line number Diff line number Diff line <?php namespace Drupal\Tests\system\Functional\UpdateSystem; use Drupal\Core\Database\Database; use Drupal\Tests\BrowserTestBase; use Drupal\Tests\UpdatePathTestTrait; /** * Tests hook_post_update() when there is an exception in a post update. * * @group Update */ class UpdatePostUpdateExceptionTest extends BrowserTestBase { use UpdatePathTestTrait; /** * {@inheritdoc} */ protected $defaultTheme = 'stark'; /** * {@inheritdoc} */ protected function setUp(): void { parent::setUp(); $connection = Database::getConnection(); // Set the schema version. \Drupal::service('update.update_hook_registry')->setInstalledVersion('post_update_test_failing', 8000); // Update core.extension. $extensions = $connection->select('config') ->fields('config', ['data']) ->condition('collection', '') ->condition('name', 'core.extension') ->execute() ->fetchField(); $extensions = unserialize($extensions); $extensions['module']['post_update_test_failing'] = 8000; $connection->update('config') ->fields([ 'data' => serialize($extensions), ]) ->condition('collection', '') ->condition('name', 'core.extension') ->execute(); } /** * Tests hook_post_update_NAME(). */ public function testPostUpdate() { // There are expected to be failed updates. $this->checkFailedUpdates = FALSE; $this->runUpdates(); $this->assertSession()->pageTextContains('Failed: RuntimeException: This post update fails in post_update_test_failing_post_update_exception()'); } /** * {@inheritdoc} */ protected function doSelectionTest() { $this->assertSession()->assertEscaped("Post update that throws an exception."); } }