Commit 4e7f9f03 authored by catch's avatar catch

Issue #2506449 by dagmar, willzyx, mikeohara, yoroy, catch: Transform "Clear...

Issue #2506449 by dagmar, willzyx, mikeohara, yoroy, catch: Transform "Clear log messages" submit button into a link in admin/reports/dblog
parent 105b8563
dblog.view_logs:
title: 'View'
route_name: dblog.overview
base_route: dblog.overview
dblog.clear_logs:
title: 'Delete'
route_name: dblog.confirm
base_route: dblog.overview
......@@ -128,7 +128,6 @@ public function overview() {
$this->moduleHandler->loadInclude('dblog', 'admin.inc');
$build['dblog_filter_form'] = $this->formBuilder->getForm('Drupal\dblog\Form\DblogFilterForm');
$build['dblog_clear_log_form'] = $this->formBuilder->getForm('Drupal\dblog\Form\DblogClearLogForm');
$header = array(
// Icon column.
......
<?php
namespace Drupal\dblog\Form;
use Drupal\Core\Database\Connection;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides the form that clears out the log.
*/
class DblogClearLogForm extends FormBase {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* Constructs a new DblogClearLogForm.
*
* @param \Drupal\Core\Database\Connection $connection
* The database connection.
*/
public function __construct(Connection $connection) {
$this->connection = $connection;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('database')
);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'dblog_clear_log_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['dblog_clear'] = array(
'#type' => 'details',
'#title' => $this->t('Clear log messages'),
'#description' => $this->t('This will permanently remove the log messages from the database.'),
);
$form['dblog_clear']['clear'] = array(
'#type' => 'submit',
'#value' => $this->t('Clear log messages'),
);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state->setRedirect('dblog.confirm');
}
}
......@@ -26,7 +26,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$form['filters'] = array(
'#type' => 'details',
'#title' => $this->t('Filter log messages'),
'#open' => !empty($_SESSION['dblog_overview_filter']),
'#open' => TRUE,
);
foreach ($filters as $key => $filter) {
$form['filters']['status'][$key] = array(
......
......@@ -220,6 +220,32 @@ private function generateLogEntries($count, $options = array()) {
}
}
/**
* Clear the entry logs by clicking on 'Clear log messages' button.
*/
protected function clearLogsEntries() {
$this->drupalGet(Url::fromRoute('dblog.confirm'));
}
/**
* Filters the logs according to the specific severity and log entry type.
*
* @param string $type
* (optional) The log entry type.
* @param string $severity
* (optional) The log entry severity.
*/
protected function filterLogsEntries($type = NULL, $severity = NULL) {
$edit = array();
if (!is_null($type)) {
$edit['type[]'] = $type;
}
if (!is_null($severity)) {
$edit['severity[]'] = $severity;
}
$this->drupalPostForm(NULL, $edit, t('Filter'));
}
/**
* Confirms that database log reports are displayed at the correct paths.
*
......@@ -547,7 +573,7 @@ public function testDBLogAddAndClear() {
// Log in the admin user.
$this->drupalLogin($this->adminUser);
// Post in order to clear the database table.
$this->drupalPostForm('admin/reports/dblog', array(), t('Clear log messages'));
$this->clearLogsEntries();
// Confirm that the logs should be cleared.
$this->drupalPostForm(NULL, array(), 'Confirm');
// Count the rows in watchdog that previously related to the deleted user.
......@@ -595,10 +621,7 @@ public function testFilter() {
// Filter by each type and confirm that entries with various severities are
// displayed.
foreach ($type_names as $type_name) {
$edit = array(
'type[]' => array($type_name),
);
$this->drupalPostForm(NULL, $edit, t('Filter'));
$this->filterLogsEntries($type_name);
// Count the number of entries of this type.
$type_count = 0;
......@@ -615,11 +638,7 @@ public function testFilter() {
// Set the filter to match each of the two filter-type attributes and
// confirm the correct number of entries are displayed.
foreach ($types as $type) {
$edit = array(
'type[]' => array($type['type']),
'severity[]' => array($type['severity']),
);
$this->drupalPostForm(NULL, $edit, t('Filter'));
$this->filterLogsEntries($type['type'], $type['severity']);
$count = $this->getTypeCount($types);
$this->assertEqual(array_sum($count), $type['count'], 'Count matched');
......@@ -630,7 +649,7 @@ public function testFilter() {
$this->assertText(t('Operations'), 'Operations text found');
// Clear all logs and make sure the confirmation message is found.
$this->drupalPostForm('admin/reports/dblog', array(), t('Clear log messages'));
$this->clearLogsEntries();
// Confirm that the logs should be cleared.
$this->drupalPostForm(NULL, array(), 'Confirm');
$this->assertText(t('Database log cleared.'), 'Confirmation message found');
......@@ -648,7 +667,7 @@ public function testFilter() {
*/
protected function getLogEntries() {
$entries = array();
if ($table = $this->xpath('.//table[@id="admin-dblog"]')) {
if ($table = $this->getLogsEntriesTable()) {
$table = array_shift($table);
foreach ($table->tbody->tr as $row) {
$entries[] = array(
......@@ -662,6 +681,16 @@ protected function getLogEntries() {
return $entries;
}
/**
* Find the Logs table in the DOM.
*
* @return \SimpleXMLElement[]
* The return value of a xpath search.
*/
protected function getLogsEntriesTable() {
return $this->xpath('.//table[@id="admin-dblog"]');
}
/**
* Gets the count of database log entries by database log event type.
*
......
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