1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Drupal\mongodb_watchdog\Form; |
6
|
|
|
|
7
|
|
|
use Drupal\Core\Form\ConfirmFormBase; |
|
|
|
|
8
|
|
|
use Drupal\Core\Form\FormStateInterface; |
|
|
|
|
9
|
|
|
use Drupal\Core\StringTranslation\TranslatableMarkup; |
|
|
|
|
10
|
|
|
use Drupal\Core\Url; |
|
|
|
|
11
|
|
|
use Drupal\mongodb_watchdog\Logger; |
12
|
|
|
use MongoDB\Database; |
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Provides a confirmation form before clearing out the logs. |
17
|
|
|
* |
18
|
|
|
* D8 has no session API, so use of $_SESSION is required, so ignore warnings. |
19
|
|
|
* |
20
|
|
|
* @SuppressWarnings("PHPMD.Superglobals") |
21
|
|
|
*/ |
22
|
|
|
class ClearConfirmForm extends ConfirmFormBase { |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The logger database. |
26
|
|
|
* |
27
|
|
|
* @var \MongoDB\Database |
28
|
|
|
*/ |
29
|
|
|
protected $database; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The MongoDB watchdog "logger" service. |
33
|
|
|
* |
34
|
|
|
* @var \Drupal\mongodb_watchdog\Logger |
35
|
|
|
*/ |
36
|
|
|
protected $logger; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* ClearConfirmForm constructor. |
40
|
|
|
* |
41
|
|
|
* @param \MongoDB\Database $database |
42
|
|
|
* The MongoDB logger database. |
43
|
|
|
* @param \Drupal\mongodb_watchdog\Logger $logger |
44
|
|
|
* The mongodb.logger service. |
45
|
|
|
*/ |
46
|
|
|
public function __construct(Database $database, Logger $logger) { |
47
|
|
|
$this->database = $database; |
48
|
|
|
$this->logger = $logger; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public static function create(ContainerInterface $container): self { |
55
|
|
|
return new static( |
56
|
|
|
$container->get('mongodb.watchdog_storage'), |
57
|
|
|
$container->get(Logger::SERVICE_LOGGER) |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
|
|
public function getFormId(): string { |
65
|
|
|
return 'mongodb_watchdog_clear_confirm'; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
*/ |
71
|
|
|
public function getQuestion(): TranslatableMarkup { |
72
|
|
|
return $this->t('Are you sure you want to delete the recent logs?'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
|
|
public function getCancelUrl(): Url { |
79
|
|
|
return new Url('mongodb_watchdog.reports.overview'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritdoc} |
84
|
|
|
*/ |
85
|
|
|
public function submitForm(array &$form, FormStateInterface $formState): void { |
86
|
|
|
$_SESSION['mongodb_watchdog_overview_filter'] = []; |
87
|
|
|
$this->database->drop(); |
88
|
|
|
$this->logger->ensureSchema(); |
89
|
|
|
$this->messenger()->addMessage($this->t('Database log cleared.')); |
90
|
|
|
$formState->setRedirectUrl($this->getCancelUrl()); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths