dblog.post_update.php 1.1 KB

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