diff --git a/core/modules/dblog/dblog.install b/core/modules/dblog/dblog.install index f226ed0..22b17b2 100644 --- a/core/modules/dblog/dblog.install +++ b/core/modules/dblog/dblog.install @@ -5,6 +5,8 @@ * Install, update and uninstall functions for the dblog module. */ +use Drupal\views\Entity\View; + /** * Implements hook_schema(). */ @@ -90,3 +92,17 @@ function dblog_schema() { return $schema; } + +/** + * Use standard plugin for wid and uid fields. Use dblog_types for type filter. + */ +function dblog_update_8400() { + // The fields and filters are fixed automatically in dblog_view_presave() so + // we just need to re-save all views that use watchdog as base table. + $views = View::loadMultiple(); + array_walk($views, function(View $view) { + if ($view->get('base_table') == 'watchdog') { + $view->save(); + } + }); +} diff --git a/core/modules/dblog/dblog.module b/core/modules/dblog/dblog.module index 4af8a62..74bc1a3 100644 --- a/core/modules/dblog/dblog.module +++ b/core/modules/dblog/dblog.module @@ -129,6 +129,17 @@ function dblog_view_presave(ViewEntityInterface $view) { return; } + $numeric_attributes_to_delete = [ + 'set_precision', + 'precision', + 'decimal', + 'separator', + 'format_plural', + 'format_plural_string', + 'prefix', + 'suffix', + ]; + foreach ($view->get('display') as $display_name => $display) { // Iterate through all the fields of watchdog views based tables. if (isset($display['display_options']['fields'])) { @@ -144,16 +155,11 @@ function dblog_view_presave(ViewEntityInterface $view) { $new_value['plugin_id'] = 'standard'; // Delete all the attributes related to numeric fields. - unset( - $new_value['set_precision'], - $new_value['precision'], - $new_value['decimal'], - $new_value['separator'], - $new_value['format_plural'], - $new_value['format_plural_string'], - $new_value['prefix'], - $new_value['suffix'] - ); + foreach ($numeric_attributes_to_delete as $key) { + if (isset($new_value[$key])) { + unset($new_value[$key]); + } + } foreach ($numeric_attributes_to_delete as $key) { if (isset($new_value[$key])) { unset($new_value[$key]); diff --git a/core/modules/dblog/dblog.post_update.php b/core/modules/dblog/dblog.post_update.php deleted file mode 100644 index caf86de..0000000 --- a/core/modules/dblog/dblog.post_update.php +++ /dev/null @@ -1,22 +0,0 @@ -get('base_table') == 'watchdog') { - $view->save(); - } - }); -} diff --git a/core/modules/dblog/src/Tests/Update/DblogFiltersAndFieldsUpgradeTest.php b/core/modules/dblog/src/Tests/Update/DblogFiltersAndFieldsUpgradeTest.php index fc903f1..11992b3 100644 --- a/core/modules/dblog/src/Tests/Update/DblogFiltersAndFieldsUpgradeTest.php +++ b/core/modules/dblog/src/Tests/Update/DblogFiltersAndFieldsUpgradeTest.php @@ -8,7 +8,7 @@ /** * Tests the upgrade path for views field and filter handlers. * - * @see dblog_post_update_wid_uid_from_numeric_to_standard_fields_and_type_filter() + * @see dblog_update_8400() * * @group Update */