summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2014-07-04 17:37:44 (GMT)
committerAlex Pott2014-07-04 17:37:44 (GMT)
commitf0cb85ac25e1c224aff7844c593ec36dd3d84888 (patch)
tree444c9e99d2adbfc9838dd93801318cc4f324e85d
parentfb01ce4ecccd2bb21b1a8a78974c225bd1440204 (diff)
Issue #936704 by Matt V., swentel, tim.plunkett, Jalandhar, jimi-o: Added Use confirm form before clearing log messages.
-rw-r--r--core/modules/dblog/dblog.routing.yml8
-rw-r--r--core/modules/dblog/src/Form/DblogClearLogConfirmForm.php77
-rw-r--r--core/modules/dblog/src/Form/DblogClearLogForm.php5
-rw-r--r--core/modules/dblog/src/Tests/DbLogTest.php4
4 files changed, 91 insertions, 3 deletions
diff --git a/core/modules/dblog/dblog.routing.yml b/core/modules/dblog/dblog.routing.yml
index 287f7af..aed0edc 100644
--- a/core/modules/dblog/dblog.routing.yml
+++ b/core/modules/dblog/dblog.routing.yml
@@ -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:
diff --git a/core/modules/dblog/src/Form/DblogClearLogConfirmForm.php b/core/modules/dblog/src/Form/DblogClearLogConfirmForm.php
new file mode 100644
index 0000000..3c668a8
--- /dev/null
+++ b/core/modules/dblog/src/Form/DblogClearLogConfirmForm.php
@@ -0,0 +1,77 @@
+<?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();
+ }
+
+}
diff --git a/core/modules/dblog/src/Form/DblogClearLogForm.php b/core/modules/dblog/src/Form/DblogClearLogForm.php
index 439148a..133ab43 100644
--- a/core/modules/dblog/src/Form/DblogClearLogForm.php
+++ b/core/modules/dblog/src/Form/DblogClearLogForm.php
@@ -9,6 +9,7 @@ namespace Drupal\dblog\Form;
use Drupal\Core\Database\Connection;
use Drupal\Core\Form\FormBase;
+use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@@ -69,9 +70,7 @@ class DblogClearLogForm extends FormBase {
* {@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');
}
}
diff --git a/core/modules/dblog/src/Tests/DbLogTest.php b/core/modules/dblog/src/Tests/DbLogTest.php
index 790924d..55659f3 100644
--- a/core/modules/dblog/src/Tests/DbLogTest.php
+++ b/core/modules/dblog/src/Tests/DbLogTest.php
@@ -445,6 +445,8 @@ class DbLogTest extends WebTestBase {
$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 @@ class DbLogTest extends WebTestBase {
// 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');
}