diff --git a/core/modules/dblog/dblog.routing.yml b/core/modules/dblog/dblog.routing.yml index 287f7afac20dc66e652398038603f40e37a1f069..aed0edc9e32f5e85c212b2b48472c20f4dec18c4 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 0000000000000000000000000000000000000000..3c668a8430e901d3e8f88fb783ff319c36d6e4ff --- /dev/null +++ b/core/modules/dblog/src/Form/DblogClearLogConfirmForm.php @@ -0,0 +1,77 @@ +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 439148a0830295973213256242d50c77c2e88873..133ab439d2125a8cef91e01083493d511da92a72 100644 --- a/core/modules/dblog/src/Form/DblogClearLogForm.php +++ b/core/modules/dblog/src/Form/DblogClearLogForm.php @@ -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'); } } diff --git a/core/modules/dblog/src/Tests/DbLogTest.php b/core/modules/dblog/src/Tests/DbLogTest.php index 790924d5f753f0e9ce6eafd9638347f6282fa4a0..55659f37449d75f32652df63689d69f381def90c 100644 --- a/core/modules/dblog/src/Tests/DbLogTest.php +++ b/core/modules/dblog/src/Tests/DbLogTest.php @@ -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'); }