-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaillog.install
260 lines (234 loc) · 7.85 KB
/
maillog.install
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<?php
/**
* @file
* Provides the installation routines for the maillog module.
*/
/**
* Implements hook_enable().
*/
function maillog_enable() {
// The system default class.
$default_class = 'DefaultMailSystem';
// Load the current mail configuration.
$mail_system['default-system'] = config_get('system.mail', 'default-system');
$mail_system['maillog'] = 'MaillogMailSystem';
// Only take over if the settings are still default.
if ($mail_system['default-system'] == $default_class) {
$mail_system['default-system'] = $mail_system['maillog'];
}
else {
backdrop_set_message(t('The Maillog module was not set as the default email system because another module is already handling email.'));
}
// Update the settings.
config_set('system.mail', 'default-system', $mail_system['default-system']);
// The maillog reports page is provided by a view, but it needs a menu cache
// clear after the default views are loaded in order for the menu item to
// become active.
global $language;
cache_clear_all('views:plugin_data:' . $language->langcode, 'cache');
state_set('menu_rebuild_needed', TRUE);
}
/**
* Implements hook_disable().
*/
function maillog_disable() {
// Get the current mail system config.
$config = config('system.mail');
$mail_system = $config->get();
// Delete any overrides that might be set for Maillog.
unset($mail_system['maillog']);
// Revert the default config mail config if it is currently set to use
// Maillog, and any others that are set to Maillog can be just deleted so they
// revert to the default.
$default_class = 'DefaultMailSystem';
$maillog_class = 'MaillogMailSystem';
foreach ($mail_system as $system => $class) {
// Look for the default mail handler.
if ($system == 'default-system') {
// If this is currently using Maillog, revert it to the default class.
if ($class == $maillog_class) {
$mail_system[$system] = $default_class;
}
}
// For all other mail handlers, just delete them if they're set to Maillog
// so that the system default handler is used instead.
elseif ($class == $maillog_class) {
unset($mail_system[$system]);
}
}
// Update the mail config.
$config->setData($mail_system);
$config->save();
}
/**
* Implements hook_schema().
*/
function maillog_schema() {
$schema['maillog'] = array(
'description' => "Stores outgoing emails that are captured using the Maillog module.",
'fields' => array(
'id' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => "The primary key of this table.",
),
'header_message_id' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => "The 'message-id' field of the e-mail.",
),
'header_from' => array(
'type' => 'text',
'not null' => TRUE,
'description' => "The 'From' field of the e-mail.",
),
'header_to' => array(
'type' => 'text',
'not null' => TRUE,
'description' => "The 'To' field of the e-mail.",
),
'header_reply_to' => array(
'type' => 'text',
'not null' => TRUE,
'description' => "The 'Reply-To' field of the e-mail.",
),
'header_all' => array(
'type' => 'text',
'not null' => TRUE,
'description' => "The 'Header' field of the e-mail.",
),
'subject' => array(
'description' => "The 'Subject' field of the e-mail.",
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'body' => array(
'description' => 'The body of this message.',
'type' => 'text',
'not null' => TRUE,
'size' => 'big',
),
'sent_date' => array(
'description' => 'The Unix timestamp when the mail was sent.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('id'),
);
return $schema;
}
/**
* Implements hook_uninstall().
*/
function maillog_uninstall() {
if (db_table_exists('maillog')) {
db_drop_table('maillog');
}
}
/**
* Update variables from Drupal to config in Backdrop.
*/
function maillog_update_1000() {
$config = config('maillog.settings');
// Migrate variables.
$config->set('maillog_send', update_variable_get('maillog_send', TRUE));
$config->set('maillog_log', update_variable_get('maillog_log', TRUE));
$config->set('maillog_devel', update_variable_get('maillog_devel', TRUE));
$config->set('maillog_engine', update_variable_get('maillog_engine', 'DefaultMailSystem'));
$config->set('maillog_row_limit', update_variable_get('maillog_row_limit', 1000));
$config->set('maillog_delete_time', update_variable_get('maillog_delete_time', 0));
$config->set('maillog_body', update_variable_get('maillog_body', 'all'));
$config->save();
// Delete variables.
update_variable_del('maillog_send');
update_variable_del('maillog_log');
update_variable_del('maillog_devel');
update_variable_del('maillog_engine');
update_variable_del('maillog_row_limit');
update_variable_del('maillog_delete_time');
update_variable_del('maillog_body');
}
/**
* Ensure a default row limit is set.
*/
function maillog_update_1100() {
$config = config('maillog.settings');
$row_limit = $config->get('maillog_row_limit');
if (empty($row_limit) || !is_int($row_limit)) {
$config->set('maillog_row_limit', 1000);
$config->save();
}
}
/**
* Ensure values for new config settings; Clear Menu and Views cache so the new
* paths will be picked up.
*/
function maillog_update_1101() {
$config = config('maillog.settings');
if (empty($config->get('maillog_body'))) {
$config->set('maillog_body', 'all');
}
if (empty($config->get('maillog_delete_time'))) {
$config->set('maillog_delete_time', 0);
}
$config->save();
state_set('menu_rebuild_needed', TRUE);
cache_clear_all('*', 'cache_views', TRUE);
cache_clear_all('*', 'cache_views_data', TRUE);
}
/**
* Rename the 'idmaillog' field to just 'id'.
*/
function maillog_update_1102() {
if (!db_field_exists('maillog', 'id')) {
// Add the new 'id' field.
$spec = array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => "The primary key of this table.",
);
db_add_field('maillog', 'id', $spec);
// Fill in all of the 'id' fields.
db_query("UPDATE {maillog} SET id=idmaillog");
// Drop the 'idmaillog' field.
db_drop_field('maillog', 'idmaillog');
// Change the 'id' field to a serial.
$spec = array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => "The primary key of this table.",
);
$keys = array(
'primary key' => array('id'),
);
db_change_field('maillog', 'id', 'id', $spec, $keys);
}
}
/**
* Ensure the Maillog view has been updated so links function.
*/
function maillog_update_1103() {
// We're just going to do a targeted check on a few particulars rather than
// reload the entire view.
$view_config = config('views.view.maillog');
if ($view_config->get('description') == "Displays the list of e-mails logged by the 'Mail Log' module.") {
$view_config->set('description', 'Displays the list of email logged by the Maillog module.');
}
if ($view_config->get('display.default.display_options.fields.subject.alter.path') == 'maillog/details/[idmaillog]') {
$view_config->set('display.default.display_options.fields.subject.alter.path', 'admin/reports/maillog/view/[id]');
}
if ($view_config->get('display.default.display_options.fields.nothing.alter.path') == 'maillog/details/[idmaillog]') {
$view_config->set('display.default.display_options.fields.nothing.alter.path', 'admin/reports/maillog/view/[id]');
}
$view_config->save();
}