-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathos2web_logging.install
More file actions
executable file
·112 lines (94 loc) · 4.18 KB
/
os2web_logging.install
File metadata and controls
executable file
·112 lines (94 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
use Drupal\os2web_logging\Form\WatchdogSettingsForm;
use Drupal\os2web_logging\Form\SettingsForm;
use Symfony\Component\Yaml\Yaml;
/**
* Helper function to update configuration.
*
* @param $config_name
* String.
*/
function os2web_logging_read_in_new_config($config_name) {
$path = \Drupal::service('extension.list.module')->getPath('os2web_logging');
/** @var \Drupal\Core\Config\StorageInterface $active_storage */
$active_storage = \Drupal::service('config.storage');
$active_storage->write($config_name, Yaml::parse(file_get_contents($path . '/config/install/' . $config_name . '.yml')));
}
/**
* Increase requiest_uri field length.
*/
function os2web_logging_update_8801() {
$field_spec = [
'type' => 'varchar',
'length' => '500',
];
\Drupal::database()->schema()->changeField('os2web_logging_access_log','request_uri', 'request_uri', $field_spec);
}
/**
* Disable date_popup module.
*/
function os2web_logging_update_8802() {
\Drupal::service('module_installer')->uninstall(['date_popup']);
}
/**
* Updating logs search view.
*/
function os2web_logging_update_8803() {
// Updating view.
os2web_logging_read_in_new_config('views.view.os2web_logging_access_logs');
}
/**
* Updating watchdog config.
*/
function os2web_logging_update_8804() {
$configName = 'os2web_logging_watchdog.settings';
$watchdogConfig = \Drupal::config('os2web_logging_watchdog.settings');
$store_period = $watchdogConfig->get('files_store_period');
$files_log_path = $watchdogConfig->get('files_log_path');
$dblog_enabled = $watchdogConfig->get('dblog_enabled');
$config_factory = \Drupal::configFactory();
$config_factory->getEditable('os2web_logging.settings')->set('watchdog_dblog_enabled', $dblog_enabled)->save();
$config_factory->getEditable('os2web_logging.settings')->set('watchdog_files_store_period', $store_period)->save();
$config_factory->getEditable('os2web_logging.settings')->set('watchdog_files_log_path', $files_log_path)->save();
Drupal::configFactory()->getEditable('os2web_logging_watchdog.settings')->delete();
}
/**
* Writing config into files.
*/
function os2web_logging_update_8805() {
// Writting settigns.
$config = \Drupal::config(SettingsForm::$configName);
$site_path = \Drupal::getContainer()->getParameter('site.path');
$settings_file = DRUPAL_ROOT . '/' . $site_path . '/os2web_logging.settings.php';
$content = "<?php\n\n";
$content .= "/**\n";
$content .= " * Auto-generated by OS2Web Logging settings form.\n";
$content .= " * Do not edit manually.\n";
$content .= " */\n\n";
$content .= "\$settings['os2web_logging.files_log_path'] = " . var_export($config->get('files_log_path'), TRUE) . ";\n";
$content .= "\$settings['os2web_logging.files_store_period'] = " . var_export($config->get('files_store_period'), TRUE) . ";\n";
file_put_contents($settings_file, $content, LOCK_EX);
// Writting watchdog settigns.
$config = \Drupal::config(WatchdogSettingsForm::$configName);
$site_path = \Drupal::getContainer()->getParameter('site.path');
$settings_file = DRUPAL_ROOT . '/' . $site_path . '/os2web_logging.watchdog_settings.php';
$content = "<?php\n\n";
$content .= "/**\n";
$content .= " * Auto-generated by OS2Web Logging settings form.\n";
$content .= " * Do not edit manually.\n";
$content .= " */\n\n";
$content .= "\$settings['os2web_logging.watchdog_dblog_enabled'] = " . var_export($config->get('watchdog_dblog_enabled'), TRUE) . ";\n";
$content .= "\$settings['os2web_logging.watchdog_files_log_path'] = " . var_export($config->get('watchdog_files_log_path'), TRUE) . ";\n";
$content .= "\$settings['os2web_logging.watchdog_files_store_period'] = " . var_export($config->get('watchdog_files_store_period'), TRUE) . ";\n";
file_put_contents($settings_file, $content, LOCK_EX);
$code = <<<'CODE'
// Add this to your settings.php or settings.local.php
if (file_exists($app_root . '/' . $site_path . '/os2web_logging.settings.php')) {
include $app_root . '/' . $site_path . '/os2web_logging.settings.php';
}
if (file_exists($app_root . '/' . $site_path . '/os2web_logging.watchdog_settings.php')) {
include $app_root . '/' . $site_path . '/os2web_logging.watchdog_settings.php';
}
CODE;
return $code;
}