diff --git a/core/modules/dblog/dblog.routing.yml b/core/modules/dblog/dblog.routing.yml index 76e2402..6298489 100644 --- a/core/modules/dblog/dblog.routing.yml +++ b/core/modules/dblog/dblog.routing.yml @@ -5,7 +5,15 @@ dblog.overview: _title: 'Recent log messages' requirements: _permission: 'access site reports' - + +dblog.confirm: + path: '/admin/reports/dblog/confirm' + defaults: + _content: '\Drupal\dblog\Controller\DbLogController::confirm' + _title: 'Confirm Delete Recent log messages' + requirements: + _permission: 'access site reports' + dblog.event: path: '/admin/reports/event/{event_id}' defaults: diff --git a/core/modules/dblog/lib/Drupal/dblog/Controller/DbLogController.php b/core/modules/dblog/lib/Drupal/dblog/Controller/DbLogController.php index 72ddf22..ac2a232 100644 --- a/core/modules/dblog/lib/Drupal/dblog/Controller/DbLogController.php +++ b/core/modules/dblog/lib/Drupal/dblog/Controller/DbLogController.php @@ -216,6 +216,15 @@ public function overview() { return $build; } + + /** + * Outputs a delete confirmation form. + */ + public function confirm() { + $build = array(); + $build['dblog_clear_log_form'] = $this->formBuilder->getForm('Drupal\dblog\Form\DblogClearLogConfirmForm'); + return $build; + } /** * Displays details about a specific database log message. diff --git a/core/modules/dblog/lib/Drupal/dblog/Form/DblogClearLogConfirmForm.php b/core/modules/dblog/lib/Drupal/dblog/Form/DblogClearLogConfirmForm.php new file mode 100644 index 0000000..9ed5bed --- /dev/null +++ b/core/modules/dblog/lib/Drupal/dblog/Form/DblogClearLogConfirmForm.php @@ -0,0 +1,74 @@ +connection = $connection; + } + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('database') + ); + } + + public function getQuestion() { + return t('Are you sure you want to delete the recent logs?'); + } +public function getDescription() { + return t('This will permanently remove the log messages from the database.'); + } + public function getConfirmText(){ + return t('OK'); + } + public function getCancelText(){ + return t('Cancel'); + } + public function getFormId(){ + return 'dblog_confirm'; + } + public function getCancelRoute() { + return array( + 'route_name' => 'dblog.overview', + ); + } + public function getFormName() { + return 'dblog_confirm'; + } + 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'] = 'admin/reports/dblog'; + } +} diff --git a/core/modules/dblog/lib/Drupal/dblog/Form/DblogClearLogForm.php b/core/modules/dblog/lib/Drupal/dblog/Form/DblogClearLogForm.php index 439148a..4afa08a 100644 --- a/core/modules/dblog/lib/Drupal/dblog/Form/DblogClearLogForm.php +++ b/core/modules/dblog/lib/Drupal/dblog/Form/DblogClearLogForm.php @@ -10,6 +10,7 @@ use Drupal\Core\Database\Connection; use Drupal\Core\Form\FormBase; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\RedirectResponse; /** * Provides the form that clears out the log. @@ -68,10 +69,11 @@ 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'] = 'admin/reports/dblog/confirm'; + return \Drupal::formBuilder()->redirectForm($form_state); } + } diff --git a/core/modules/dblog/lib/Drupal/dblog/Tests/DbLogTest.php b/core/modules/dblog/lib/Drupal/dblog/Tests/DbLogTest.php index 850b6e1..62c6aab 100644 --- a/core/modules/dblog/lib/Drupal/dblog/Tests/DbLogTest.php +++ b/core/modules/dblog/lib/Drupal/dblog/Tests/DbLogTest.php @@ -433,6 +433,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('admin/reports/dblog/confirm', array(), t('OK')); // 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))); @@ -511,6 +513,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('admin/reports/dblog/confirm', array(), t('OK')); $this->assertText(t('Database log cleared.'), 'Confirmation message found'); }