annotate core/modules/dblog/dblog.post_update.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /**
Chris@0 4 * @file
Chris@0 5 * Post update functions for the Database Logging module.
Chris@0 6 */
Chris@0 7
Chris@0 8 use Drupal\Core\Config\FileStorage;
Chris@0 9 use Drupal\Core\Config\InstallStorage;
Chris@0 10 use Drupal\views\Entity\View;
Chris@0 11
Chris@0 12 /**
Chris@0 13 * Replace 'Recent log messages' with a view.
Chris@0 14 */
Chris@0 15 function dblog_post_update_convert_recent_messages_to_view() {
Chris@0 16 // Only create if the views module is enabled and the watchdog view doesn't
Chris@0 17 // exist.
Chris@0 18 if (\Drupal::moduleHandler()->moduleExists('views')) {
Chris@0 19 if (!View::load('watchdog')) {
Chris@0 20 // Save the watchdog view to config.
Chris@0 21 $module_handler = \Drupal::moduleHandler();
Chris@0 22 $optional_install_path = $module_handler->getModule('dblog')->getPath() . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
Chris@0 23 $storage = new FileStorage($optional_install_path);
Chris@0 24
Chris@0 25 \Drupal::entityTypeManager()
Chris@0 26 ->getStorage('view')
Chris@0 27 ->create($storage->read('views.view.watchdog'))
Chris@0 28 ->save();
Chris@0 29
Chris@0 30 return t('The watchdog view has been created.');
Chris@0 31 }
Chris@0 32
Chris@0 33 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");
Chris@0 34 }
Chris@0 35 }