Skip to content

Commit b5d84bf

Browse files
committed
HOTFIX Watchdog configuration name changes
1 parent cc022f7 commit b5d84bf

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

os2web_logging.install

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,19 @@ function os2web_logging_update_8803() {
4040
// Updating view.
4141
os2web_logging_read_in_new_config('views.view.os2web_logging_access_logs');
4242
}
43+
44+
/**
45+
* Updating watchdog config.
46+
*/
47+
function os2web_logging_update_8804() {
48+
$configName = 'os2web_logging_watchdog.settings';
49+
$watchdogConfig = \Drupal::config('os2web_logging_watchdog.settings');
50+
$store_period = $watchdogConfig->get('files_store_period');
51+
$files_log_path = $watchdogConfig->get('files_log_path');
52+
$dblog_enabled = $watchdogConfig->get('dblog_enabled');
53+
$config_factory = \Drupal::configFactory();
54+
$config_factory->getEditable('os2web_logging.settings')->set('watchdog_dblog_enabled', $dblog_enabled)->save();
55+
$config_factory->getEditable('os2web_logging.settings')->set('watchdog_files_store_period', $store_period)->save();
56+
$config_factory->getEditable('os2web_logging.settings')->set('watchdog_files_log_path', $files_log_path)->save();
57+
Drupal::configFactory()->getEditable('os2web_logging_watchdog.settings')->delete();
58+
}

src/Form/WatchdogSettingsForm.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ public function buildForm(array $form, FormStateInterface $form_state) {
5050
'#open' => TRUE,
5151
];
5252

53-
$form['watchdog_db_details']['dblog_enabled'] = [
53+
$form['watchdog_db_details']['watchdog_dblog_enabled'] = [
5454
'#type' => 'checkbox',
5555
'#title' => $this->t('DB Log enabled'),
5656
'#description' => $this->t('If logs are to be stored in the database as dblog entries.'),
57-
'#default_value' => $config->get('dblog_enabled') ?? TRUE,
57+
'#default_value' => $config->get('watchdog_dblog_enabled') ?? TRUE,
5858
];
5959

6060
// Set up the link.
@@ -71,29 +71,29 @@ public function buildForm(array $form, FormStateInterface $form_state) {
7171
->t('Watchdog File logs'),
7272
];
7373

74-
$form['watchdog_files_details']['files_store_period'] = [
74+
$form['watchdog_files_details']['watchdog_files_store_period'] = [
7575
'#type' => 'number',
7676
'#title' => $this->t('Store log files for this period'),
7777
'#field_suffix' => $this->t('days'),
7878
'#size' => 5,
7979
'#min' => 180,
8080
'#description' => $this->t('Log file will be stored for the selected number of days, after that they will be automatically deleted'),
81-
'#default_value' => $config->get('files_store_period') ?? 180,
81+
'#default_value' => $config->get('watchdog_files_store_period') ?? 180,
8282
];
8383

84-
$form['watchdog_files_details']['files_log_path'] = [
84+
$form['watchdog_files_details']['watchdog_files_log_path'] = [
8585
'#type' => 'textfield',
8686
'#title' => $this->t('Store log files directory'),
8787
'#description' => $this->t('Log file will be stored for the selected number of days, after that they will be automatically deleted'),
88-
'#default_value' => $config->get('files_log_path') ?? '../logs',
88+
'#default_value' => $config->get('watchdog_files_log_path') ?? '../logs',
8989
'#field_suffix' => '<em>/os2web_logging_watchdog-YYYY-MM-DD.log</em>',
9090
];
9191

9292
$options = [];
93-
if ($config->get('files_log_path')) {
93+
if ($config->get('watchdog_files_log_path')) {
9494
/** @var FileSystemInterface $fileSystem */
9595
$fileSystem = \Drupal::service('file_system');
96-
$storedLogFiles = $fileSystem->scanDirectory($config->get('files_log_path'), '/os2web_logging_watchdog-\d{4}-\d{2}-\d{2}\.(log|gz)/');
96+
$storedLogFiles = $fileSystem->scanDirectory($config->get('watchdog_files_log_path'), '/os2web_logging_watchdog-\d{4}-\d{2}-\d{2}\.(log|gz)/');
9797

9898
foreach ($storedLogFiles as $file) {
9999
$url = Url::fromRoute('os2web_logging.logfile.download', ['filename' => $file->filename]);
@@ -123,7 +123,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
123123
public function validateForm(array &$form, FormStateInterface $form_state) {
124124
parent::validateForm($form, $form_state);
125125

126-
$files_log_path = $form_state->getValue('files_log_path');
126+
$files_log_path = $form_state->getValue('watchdog_files_log_path');
127127

128128
$exists = \Drupal::service('file_system')->prepareDirectory($files_log_path, FileSystemInterface::MODIFY_PERMISSIONS);
129129
if (!$exists) {
@@ -137,9 +137,9 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
137137
public function submitForm(array &$form, FormStateInterface $form_state) {
138138
// Saving values.
139139
$config = $this->config(WatchdogSettingsForm::$configName);
140-
$old_files_store_period = $config->get('files_store_period');
141-
$old_files_store_path = $config->get('files_log_path');
142-
$old_dblog_enabled = $config->get('dblog_enabled');
140+
$old_files_store_period = $config->get('watchdog_files_store_period');
141+
$old_files_store_path = $config->get('watchdog_files_log_path');
142+
$old_dblog_enabled = $config->get('watchdog_dblog_enabled');
143143

144144
$values = $form_state->getValues();
145145
foreach ($values as $key => $value) {
@@ -149,9 +149,9 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
149149

150150
// Rebuilding cache only if 'files_store_period' or 'files_log_path'
151151
// changed. New setting requires cache to be rebuilt.
152-
if ($old_files_store_period != $config->get('files_store_period') ||
153-
$old_files_store_path != $config->get('files_log_path') ||
154-
$old_dblog_enabled != $config->get('dblog_enabled')) {
152+
if ($old_files_store_period != $config->get('watchdog_files_store_period') ||
153+
$old_files_store_path != $config->get('watchdog_files_log_path') ||
154+
$old_dblog_enabled != $config->get('watchdog_dblog_enabled')) {
155155

156156
// Rebuild module and theme data.
157157
$module_data = \Drupal::service('extension.list.module')->getList();

src/Os2webLoggingServiceProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ public function alter(ContainerBuilder $container) {
4545
$watchdogLogger = $container->getDefinition('monolog.handler.os2web_logging_watchdog');
4646

4747
// Updating store path for watchdog logger.
48-
$logs_path = $watchdogConfig->get('files_log_path');
48+
$logs_path = $watchdogConfig->get('watchdog_files_log_path');
4949
if (!empty($logs_path)) {
5050
$logs_path .= '/os2web_logging_watchdog.log';
5151
$watchdogLogger->replaceArgument(0, $logs_path);
5252
}
5353

5454
// Updating store period for logger.
55-
$store_period = $watchdogConfig->get('files_store_period');
55+
$store_period = $watchdogConfig->get('watchdog_files_store_period');
5656
if ($store_period) {
5757
$watchdogLogger->replaceArgument(1, $store_period);
5858
}
@@ -63,7 +63,7 @@ public function alter(ContainerBuilder $container) {
6363
'os2web_logging_watchdog',
6464
];
6565
// Only add if DB Log enabled.
66-
if ($watchdogConfig->get('dblog_enabled')) {
66+
if ($watchdogConfig->get('watchdog_dblog_enabled')) {
6767
$channel_handlers['default'][] = 'drupal.dblog';
6868
}
6969
$container->setParameter('monolog.channel_handlers', $channel_handlers);

0 commit comments

Comments
 (0)