Skip to content

Commit efca279

Browse files
author
Marius Burkard
committed
- added method onAfterDatalogSave
- move update of spamfilter users to after datalog update
1 parent edf105a commit efca279

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

interface/lib/classes/tform_actions.inc.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ function onUpdate() {
141141
$app->tform->datalogSave('UPDATE', $this->id, $this->oldDataRecord, $new_data_record);
142142
unset($new_data_record);
143143
unset($old_data_record);
144+
145+
$this->onAfterDatalogSave();
144146
}
145147

146148
if($_REQUEST["next_tab"] == '') {
@@ -222,6 +224,7 @@ function onInsert() {
222224
$new_data_record = $app->tform->getDataRecord($this->id);
223225
$app->tform->datalogSave('INSERT', $this->id, array(), $new_data_record);
224226
unset($new_data_record);
227+
$this->onAfterDatalogSave(true);
225228
}
226229

227230

@@ -264,21 +267,19 @@ function onInsertSave($sql) {
264267
}
265268

266269
function onBeforeUpdate() {
267-
global $app, $conf;
268270
}
269271

270272
function onBeforeInsert() {
271-
global $app, $conf;
272273
}
273274

274275
function onAfterUpdate() {
275-
global $app, $conf;
276276
}
277277

278278
function onAfterInsert() {
279-
global $app, $conf;
280279
}
281280

281+
function onAfterDatalogSave($insert = false) {
282+
}
282283

283284
/**
284285
* Function called on data insert or update error
@@ -297,7 +298,7 @@ function onError() {
297298
*/
298299
function onDelete() {
299300
global $app, $conf, $list_def_file, $tform_def_file;
300-
301+
301302
// Check CSRF Token
302303
$app->auth->csrf_token_check('GET');
303304

interface/web/mail/spamfilter_policy_edit.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@
4949
$app->load('tform_actions');
5050

5151
class page_action extends tform_actions {
52-
52+
53+
private $record_has_changed = false;
54+
5355
function onShowNew() {
5456
global $app;
5557

@@ -87,38 +89,40 @@ function onSubmit() {
8789

8890
parent::onSubmit();
8991
}
90-
92+
9193
function onAfterUpdate() {
92-
global $app;
93-
94-
$record_has_changed = false;
94+
$this->record_has_changed = false;
9595
foreach($this->dataRecord as $key => $val) {
9696
if(isset($this->oldDataRecord[$key]) && @$this->oldDataRecord[$key] != $val) {
9797
// Record has changed
98-
$record_has_changed = true;
98+
$this->record_has_changed = true;
9999
}
100100
}
101+
}
101102

102-
if($record_has_changed){
103+
function onAfterDatalogSave($insert = false) {
104+
global $app;
105+
106+
if(!$insert && $this->record_has_changed){
103107
$spamfilter_users = $app->db->queryAllRecords("SELECT * FROM spamfilter_users WHERE policy_id = ?", intval($this->id));
104108

105109
if(is_array($spamfilter_users) && !empty($spamfilter_users)){
106110
foreach($spamfilter_users as $spamfilter_user){
107111
$app->db->datalogUpdate('spamfilter_users', $spamfilter_user, 'id', $spamfilter_user["id"], true);
108-
112+
109113
// check if this is an email domain
110114
if(substr($spamfilter_user['email'],0,1) == '@') {
111115
$domain = substr($spamfilter_user['email'],1);
112116
$forwardings = $app->db->queryAllRecords("SELECT * FROM mail_forwarding WHERE source LIKE ? OR destination LIKE ?", "%@" . $domain, "%@" . $domain);
113-
117+
114118
// Force-update aliases and forwards
115119
if(is_array($forwardings)) {
116120
foreach($forwardings as $rec) {
117121
$app->db->datalogUpdate('mail_forwarding', array("source" => $rec['source']), 'forwarding_id', $rec['forwarding_id'],true);
118122
}
119123
}
120124
}
121-
125+
122126
}
123127
}
124128
}

0 commit comments

Comments
 (0)