Commit b1e2ed55 authored by catch's avatar catch

Issue #2015149 by dagmar, Jo Fitzgerald, hanoii, pritish.kumar, Pol, Lendude,...

Issue #2015149 by dagmar, Jo Fitzgerald, hanoii, pritish.kumar, Pol, Lendude, damiankloip, nicolas.rafaelli, alansaviolobo, Psikik, mondrake, yoroy, dawehner, alexpott, catch, jibran: Replace dblog recent log entries with a view
parent 6eb59c81
This diff is collapsed.
......@@ -13,6 +13,7 @@
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\ViewEntityInterface;
use Drupal\views\ViewExecutable;
/**
* Implements hook_help().
......@@ -187,3 +188,12 @@ function dblog_view_presave(ViewEntityInterface $view) {
$view->set('display', $displays);
}
}
/**
* Implements hook_views_pre_render().
*/
function dblog_views_pre_render(ViewExecutable $view) {
if (isset($view) && ($view->storage->get('base_table') == 'watchdog')) {
$view->element['#attached']['library'][] = 'dblog/drupal.dblog';
}
}
<?php
/**
* @file
* Post update functions for the Database Logging module.
*/
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Config\InstallStorage;
use Drupal\views\Entity\View;
/**
* Replace 'Recent log messages' with a view.
*/
function dblog_post_update_convert_recent_messages_to_view() {
// Only create if the views module is enabled and the watchdog view doesn't
// exist.
if (\Drupal::moduleHandler()->moduleExists('views')) {
if (!View::load('watchdog')) {
// Save the watchdog view to config.
$module_handler = \Drupal::moduleHandler();
$optional_install_path = $module_handler->getModule('dblog')->getPath() . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
$storage = new FileStorage($optional_install_path);
\Drupal::entityTypeManager()
->getStorage('view')
->create($storage->read('views.view.watchdog'))
->save();
return t('The watchdog view has been created.');
}
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");
}
}
<?php
namespace Drupal\dblog\Tests\Update;
use Drupal\system\Tests\Update\UpdatePathTestBase;
/**
* Ensures that update hook that creates the watchdog view ran sucessfully.
*
* @group Update
*/
class DblogRecentLogsUsingViewsUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
];
}
/**
* Ensures that update hook is run for dblog module.
*/
public function testUpdate() {
// Make sure the watchog view doesn't exist before the updates.
$view = \Drupal::entityTypeManager()->getStorage('view')->load('watchdog');
$this->assertNull($view);
$this->runUpdates();
// Ensure the watchdog view is present after run updates.
$view = \Drupal::entityTypeManager()->getStorage('view')->load('watchdog');
$displays = $view->get('display');
$this->assertIdentical($displays['page']['display_options']['path'], 'admin/reports/dblog', 'Recent logs message view exists.');
}
}
......@@ -248,10 +248,10 @@ protected function clearLogsEntries() {
*/
protected function filterLogsEntries($type = NULL, $severity = NULL) {
$edit = [];
if (!is_null($type)) {
if (isset($type)) {
$edit['type[]'] = $type;
}
if (!is_null($severity)) {
if (isset($severity)) {
$edit['severity[]'] = $severity;
}
$this->drupalPostForm(NULL, $edit, t('Filter'));
......@@ -278,6 +278,12 @@ private function verifyReports($response = 200) {
$this->assertText(t('Recent log messages'), 'DBLog report was displayed');
}
$this->drupalGet('admin/reports/dblog/confirm');
$this->assertResponse($response);
if ($response == 200) {
$this->assertText(t('Are you sure you want to delete the recent logs?'), 'DBLog clear logs form was displayed');
}
// View the database log page-not-found report page.
$this->drupalGet('admin/reports/page-not-found');
$this->assertResponse($response);
......@@ -799,7 +805,7 @@ public function testOverviewLinks() {
$this->drupalGet('admin/reports/dblog');
$this->assertResponse(200);
// Make sure HTML tags are filtered out.
$this->assertRaw('title="alert(&#039;foo&#039;);Lorem ipsum dolor sit amet, consectetur adipiscing &amp; elit. Entry #0">&lt;script&gt;alert(&#039;foo&#039;);&lt;/script&gt;Lorem ipsum dolor sit…</a>');
$this->assertRaw('title="alert(&#039;foo&#039;);Lorem');
$this->assertNoRaw("<script>alert('foo');</script>");
// Make sure HTML tags are filtered out in admin/reports/dblog/event/ too.
......@@ -810,4 +816,22 @@ public function testOverviewLinks() {
$this->assertRaw("alert('foo'); <strong>Lorem ipsum</strong>");
}
/**
* Test sorting for entries with the same timestamp.
*/
public function testSameTimestampEntries() {
$this->drupalLogin($this->adminUser);
$this->generateLogEntries(1, ['timestamp' => 1498062000, 'type' => 'same_time', 'message' => 'First']);
$this->generateLogEntries(1, ['timestamp' => 1498062000, 'type' => 'same_time', 'message' => 'Second']);
$this->generateLogEntries(1, ['timestamp' => 1498062000, 'type' => 'same_time', 'message' => 'Third']);
$this->drupalGet('admin/reports/dblog');
$entries = $this->getLogEntries();
$this->assertEquals($entries[0]['message'], 'Third Entry #0');
$this->assertEquals($entries[1]['message'], 'Second Entry #0');
$this->assertEquals($entries[2]['message'], 'First Entry #0');
}
}
<?php
namespace Drupal\Tests\dblog\Functional;
use Drupal\filter\Entity\FilterFormat;
/**
* Generate events and verify dblog entries; verify user access to log reports
* based on permissions. Using the dblog UI generated by a View.
*
* @see Drupal\dblog\Tests\DbLogTest
*
* @group dblog
*/
class DbLogViewsTest extends DbLogTest {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['dblog', 'node', 'forum', 'help', 'block', 'views'];
/**
* {@inheritdoc}
*/
protected function getLogsEntriesTable() {
return $this->xpath('.//table[contains(@class, "views-view-table")]/tbody/tr');
}
/**
* {@inheritdoc}
*/
protected function filterLogsEntries($type = NULL, $severity = NULL) {
$query = [];
if (isset($type)) {
$query['type[]'] = $type;
}
if (isset($severity)) {
$query['severity[]'] = $severity;
}
$this->drupalGet('admin/reports/dblog', ['query' => $query]);
}
/**
* {@inheritdoc}
*/
public function testDBLogAddAndClear() {
// Is necesary to create the basic_html format because if absent after
// delete the logs, a new log entry is created indicating that basic_html
// format do not exists.
$basic_html_format = FilterFormat::create([
'format' => 'basic_html',
'name' => 'Basic HTML',
'filters' => [
'filter_html' => [
'status' => 1,
'settings' => [
'allowed_html' => '<p> <br> <strong> <a> <em>',
],
],
],
]);
$basic_html_format->save();
parent::testDBLogAddAndClear();
}
}
......@@ -65,7 +65,7 @@ protected function getEntityCounts() {
'user' => 7,
'user_role' => 6,
'menu_link_content' => 4,
'view' => 14,
'view' => 15,
'date_format' => 11,
'entity_form_display' => 19,
'entity_form_mode' => 1,
......
......@@ -66,7 +66,7 @@ protected function getEntityCounts() {
'user' => 4,
'user_role' => 3,
'menu_link_content' => 7,
'view' => 14,
'view' => 15,
'date_format' => 11,
'entity_form_display' => 18,
'entity_form_mode' => 1,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment