diff --git a/core/modules/dblog/config/optional/views.view.watchdog.yml b/core/modules/dblog/config/optional/views.view.watchdog.yml index 51066a7d85..1500fedd33 100644 --- a/core/modules/dblog/config/optional/views.view.watchdog.yml +++ b/core/modules/dblog/config/optional/views.view.watchdog.yml @@ -654,7 +654,7 @@ display: header: { } footer: { } empty: - area: + area_text_custom: id: area_text_custom table: views field: area_text_custom diff --git a/core/modules/dblog/dblog.post_update.php b/core/modules/dblog/dblog.post_update.php index 6021ec6b52..264f3eff93 100644 --- a/core/modules/dblog/dblog.post_update.php +++ b/core/modules/dblog/dblog.post_update.php @@ -33,3 +33,35 @@ function dblog_post_update_convert_recent_messages_to_view() { return t("The watchdog view already exists and was not replaced. To replace the 'Recent log messages' with a view, rename the watchdog view and uninstall and install the 'Database Log' module"); } } + +/** + * Fixes the wrong plugin type introduced in dblog_update_8600(). + */ +function dblog_post_update_fix_dblog_update_8600() { + $view = \Drupal::configFactory()->getEditable('views.view.watchdog'); + if (empty($view)) { + return t('The database logging view was not found; no changes were made.'); + } + + $empty_text = $view->get('display.default.display_options.empty'); + if (!isset($empty_text['area']['content'])) { + return t('The database logging view did not need to be updated; no changes were made.'); + } + + // Only update the empty text if is untouched from dblog_update_8600 update. + if ($empty_text['area']['id'] == 'area_text_custom' && + $empty_text['area']['plugin_id'] == 'text_custom' && + $empty_text['area']['field'] == 'area_text_custom' && + $empty_text['area']['content'] == 'No log messages available.') { + $config = $empty_text['area']; + + // Unset old plugin type. + $view->clear('display.default.display_options.empty.area'); + + // Set new area_text_custom plugin type. + $view->set('display.default.display_options.empty.area_text_custom', $config); + $view->save(); + + return t('The database logging view has been corrected.'); + } +} diff --git a/core/modules/dblog/tests/src/Functional/DbLogViewsTest.php b/core/modules/dblog/tests/src/Functional/DbLogViewsTest.php index cbb86f8c54..d15bc949f6 100644 --- a/core/modules/dblog/tests/src/Functional/DbLogViewsTest.php +++ b/core/modules/dblog/tests/src/Functional/DbLogViewsTest.php @@ -54,8 +54,9 @@ protected function filterLogsEntries($type = NULL, $severity = NULL) { public function testEmptyText() { $view = Views::getView('watchdog'); $data = $view->storage->toArray(); - $area = $data['display']['default']['display_options']['empty']['area']; + $this->assertArrayHasKey('area_text_custom', $data['display']['default']['display_options']['empty']); + $area = $data['display']['default']['display_options']['empty']['area_text_custom']; $this->assertEqual('text_custom', $area['plugin_id']); $this->assertEqual('area_text_custom', $area['field']); $this->assertEqual('No log messages available.', $area['content']); diff --git a/core/modules/dblog/tests/src/Functional/Update/DblogNoLogsAvailableUpgradeTest.php b/core/modules/dblog/tests/src/Functional/Update/DblogNoLogsAvailableUpgradeTest.php index 5002f25164..8cd770c875 100644 --- a/core/modules/dblog/tests/src/Functional/Update/DblogNoLogsAvailableUpgradeTest.php +++ b/core/modules/dblog/tests/src/Functional/Update/DblogNoLogsAvailableUpgradeTest.php @@ -8,33 +8,52 @@ /** * Test the upgrade path of changing the empty text area for watchdog view. * - * @see dblog_update_8600() + * @see dblog_post_update_fix_dblog_update_8600() * * @group Update * @group legacy */ -class DblogNoLogsAvailableUpgradeTest extends UpdatePathTestBase { +class DblogNoLogsAvailablePluginTypeUpgradeTest extends UpdatePathTestBase { /** * {@inheritdoc} */ protected function setDatabaseDumpFiles() { $this->databaseDumpFiles = [ - __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.4.0.bare.standard.php.gz', + __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.8.0.bare.standard.php.gz', ]; } /** - * Tests that no logs available text is now using a custom area. + * Tests that "no logs available" text is now using a custom area. */ public function testDblogUpgradePath() { + // Before the updates run, load the default view and confirm it is in the + // expected structure. + $broken_view = Views::getView('watchdog'); + $data = $broken_view->storage->toArray(); + // Confirm the fixed view does have the broken plugin. + $this->assertArrayHasKey('area', $data['display']['default']['display_options']['empty']); + + // Confirm the fixed view does not have the fixed plugin yet. + $this->assertArrayNotHasKey('area_text_custom', $data['display']['default']['display_options']['empty']); + + // Run the updates so that the fix can be confirmed. $this->runUpdates(); - $view = Views::getView('watchdog'); - $data = $view->storage->toArray(); - $area = $data['display']['default']['display_options']['empty']['area']; + // Reload the view. + $fixed_view = Views::getView('watchdog'); + $data = $fixed_view->storage->toArray(); + // Confirm the fixed view does not have the broken plugin anymore + $this->assertArrayNotHasKey('area', $data['display']['default']['display_options']['empty']); + + // Confirm the fixed view does have the fixed plugin now. + $this->assertArrayHasKey('area_text_custom', $data['display']['default']['display_options']['empty']); + + // Confirm the display's definition is correct. + $area = $data['display']['default']['display_options']['empty']['area_text_custom']; $this->assertEqual('text_custom', $area['plugin_id']); $this->assertEqual('area_text_custom', $area['field']); $this->assertEqual('No log messages available.', $area['content']);