Commit f0cb85ac authored by alexpott's avatar alexpott

Issue #936704 by Matt V., swentel, tim.plunkett, Jalandhar, jimi-o: Added Use...

Issue #936704 by Matt V., swentel, tim.plunkett, Jalandhar, jimi-o: Added Use confirm form before clearing log messages.
parent fb01ce4e
......@@ -6,6 +6,14 @@ dblog.overview:
requirements:
_permission: 'access site reports'
dblog.confirm:
path: '/admin/reports/dblog/confirm'
defaults:
_form: '\Drupal\dblog\Form\DblogClearLogConfirmForm'
_title: 'Confirm delete recent log messages'
requirements:
_permission: 'access site reports'
dblog.event:
path: '/admin/reports/dblog/event/{event_id}'
defaults:
......
<?php
/**
* @file
* Contains \Drupal\dblog\Form\DblogClearLogConfirmForm.
*/
namespace Drupal\dblog\Form;
use Drupal\Core\Url;
use Drupal\Core\Database\Connection;
use Drupal\Core\Form\ConfirmFormBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a confirmation form before clearing out the logs.
*/
class DblogClearLogConfirmForm extends ConfirmFormBase {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* Constructs a new DblogClearLogConfirmForm.
*
* @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_confirm';
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete the recent logs?');
}
/**
* {@inheritdoc}
*/
public function getCancelRoute() {
return new Url('dblog.overview');
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$_SESSION['dblog_overview_filter'] = array();
$this->connection->delete('watchdog')->execute();
drupal_set_message($this->t('Database log cleared.'));
$form_state['redirect_route'] = $this->getCancelRoute();
}
}
......@@ -9,6 +9,7 @@
use Drupal\Core\Database\Connection;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -69,9 +70,7 @@ public function buildForm(array $form, array &$form_state) {
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$_SESSION['dblog_overview_filter'] = array();
$this->connection->delete('watchdog')->execute();
drupal_set_message($this->t('Database log cleared.'));
$form_state['redirect_route'] = new Url('dblog.confirm');
}
}
......@@ -445,6 +445,8 @@ protected function testDBLogAddAndClear() {
$this->drupalLogin($this->big_user);
// Post in order to clear the database table.
$this->drupalPostForm('admin/reports/dblog', array(), t('Clear log messages'));
// Confirm that the logs should be cleared.
$this->drupalPostForm(NULL, array(), 'Confirm');
// Count the rows in watchdog that previously related to the deleted user.
$count = db_query('SELECT COUNT(*) FROM {watchdog}')->fetchField();
$this->assertEqual($count, 0, format_string('DBLog contains :count records after a clear.', array(':count' => $count)));
......@@ -523,6 +525,8 @@ protected function testFilter() {
// Clear all logs and make sure the confirmation message is found.
$this->drupalPostForm('admin/reports/dblog', array(), t('Clear log messages'));
// Confirm that the logs should be cleared.
$this->drupalPostForm(NULL, array(), 'Confirm');
$this->assertText(t('Database log cleared.'), 'Confirmation message found');
}
......
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