|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\mongodb_watchdog\Form; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Core\Form\FormStateInterface; |
|
6
|
|
|
use Drupal\Core\Url; |
|
7
|
|
|
use Drupal\Core\Form\ConfirmFormBase; |
|
8
|
|
|
use Drupal\mongodb_watchdog\Logger; |
|
9
|
|
|
use MongoDB\Database; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Provides a confirmation form before clearing out the logs. |
|
14
|
|
|
*/ |
|
15
|
|
|
class ClearConfirmForm extends ConfirmFormBase { |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* The logger database. |
|
19
|
|
|
* |
|
20
|
|
|
* @var \MongoDB\Database |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $database; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* The MongoDB watchdog "logger" service. |
|
26
|
|
|
* |
|
27
|
|
|
* @var \Drupal\mongodb_watchdog\Logger |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $logger; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* ClearConfirmForm constructor. |
|
33
|
|
|
* |
|
34
|
|
|
* @param \MongoDB\Database $database |
|
35
|
|
|
* The MongoDB logger database. |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(Database $database, Logger $logger) { |
|
38
|
|
|
$this->database = $database; |
|
39
|
|
|
$this->logger = $logger; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* {@inheritdoc} |
|
44
|
|
|
*/ |
|
45
|
|
|
public static function create(ContainerInterface $container) { |
|
46
|
|
|
return new static( |
|
47
|
|
|
$container->get('mongodb.watchdog_storage'), |
|
48
|
|
|
$container->get('mongodb.logger') |
|
49
|
|
|
); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* {@inheritdoc} |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getFormId() { |
|
56
|
|
|
return 'mongodb_watchdog_clear_confirm'; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* {@inheritdoc} |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getQuestion() { |
|
|
|
|
|
|
63
|
|
|
return $this->t('Are you sure you want to delete the recent logs?'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* {@inheritdoc} |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getCancelUrl() { |
|
70
|
|
|
return new Url('mongodb_watchdog.reports.overview'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* {@inheritdoc} |
|
75
|
|
|
*/ |
|
76
|
|
|
public function submitForm(array &$form, FormStateInterface $form_state) { |
|
77
|
|
|
$_SESSION['mongodb_watchdog_overview_filter'] = []; |
|
78
|
|
|
$this->database->drop(); |
|
79
|
|
|
$this->logger->ensureIndexes(); |
|
80
|
|
|
drupal_set_message($this->t('Database log cleared.')); |
|
81
|
|
|
$form_state->setRedirectUrl($this->getCancelUrl()); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
} |
|
|
|
|
|
|
85
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.