/
interface_50_modMailmanspip_Mailmanspipsynchro.class.php
165 lines (147 loc) · 5.93 KB
/
interface_50_modMailmanspip_Mailmanspipsynchro.class.php
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
<?php
/* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 Rafael San José <rsanjose@alxarafe.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/core/triggers/interface_50_modMailmanspip_Mailmanspipsynchro.class.php
* \ingroup core
* \brief File to manage triggers Mailman and Spip
*/
require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
/**
* Class of triggers for MailmanSpip module
*/
class InterfaceMailmanSpipsynchro extends DolibarrTriggers
{
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
public function __construct($db)
{
$this->db = $db;
$this->name = preg_replace('/^Interface/i', '', get_class($this));
$this->family = "mailmanspip";
$this->description = "Triggers of this module allows to synchronize Mailman an Spip.";
$this->version = self::VERSIONS['prod'];
$this->picto = 'technic';
}
/**
* Function called when a Dolibarr business event is done.
* All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared)
*
* @param string $action Event action code
* @param Object $object Object
* @param User $user Object user
* @param Translate $langs Object langs
* @param conf $conf Object conf
* @return int Return integer <0 if KO, 0 if no triggered ran, >0 if OK
*/
public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
{
if (empty($conf->mailmanspip) || empty($conf->mailmanspip->enabled)) {
return 0; // Module not active, we do nothing
}
require_once DOL_DOCUMENT_ROOT."/mailmanspip/class/mailmanspip.class.php";
require_once DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php";
if ($action == 'CATEGORY_LINK') {
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
// We add subscription if we change category (new category may means more mailing-list to subscribe)
if (is_object($object->context['linkto']) && method_exists($object->context['linkto'], 'add_to_abo') && $object->context['linkto']->add_to_abo() < 0) {
$this->error = $object->context['linkto']->error;
$this->errors = $object->context['linkto']->errors;
$return = -1;
} else {
$return = 1;
}
return $return;
} elseif ($action == 'CATEGORY_UNLINK') {
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
// We remove subscription if we change category (lessw category may means less mailing-list to subscribe)
if (is_object($object->context['unlinkoff']) && method_exists($object->context['unlinkoff'], 'del_to_abo') && $object->context['unlinkoff']->del_to_abo() < 0) {
$this->error = $object->context['unlinkoff']->error;
$this->errors = $object->context['unlinkoff']->errors;
$return = -1;
} else {
$return = 1;
}
return $return;
} elseif ($action == 'MEMBER_VALIDATE') {
// Members
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$return = 0;
if ($object->add_to_abo() < 0) {
$this->errors = $object->errors;
if (!empty($object->error)) {
$this->errors[] = $object->error;
}
$return = -1;
} else {
$return = 1;
}
return $return;
} elseif ($action == 'MEMBER_MODIFY') {
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$return = 0;
// Add user into some linked tools (mailman, spip, etc...)
if (($object->oldcopy->email != $object->email) || ($object->oldcopy->typeid != $object->typeid)) {
if (is_object($object->oldcopy) && (($object->oldcopy->email != $object->email) || ($object->oldcopy->typeid != $object->typeid))) { // If email has changed or if list has changed we delete mailman subscription for old email
// $object->oldcopy may be a stdClass and not original object depending on copy type, so we realod a new object to run the del_to_abo()
$tmpmember = new Adherent($this->db);
$tmpmember->fetch($object->oldcopy->id);
if ($tmpmember->del_to_abo() < 0) {
$this->errors = $tmpmember->errors;
if (!empty($tmpmember->error)) {
$this->errors[] = $tmpmember->error;
}
$return = -1;
} else {
$return = 1;
}
}
// We add subscription if new email or new type (new type may means more mailing-list to subscribe)
if ($object->add_to_abo() < 0) {
$this->errors = $object->errors;
if (!empty($object->error)) {
$this->errors[] = $object->error;
}
$return = -1;
} else {
$return = 1;
}
}
return $return;
} elseif ($action == 'MEMBER_RESILIATE' || $action == 'MEMBER_DELETE') {
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$return = 0;
// Remove from external tools (mailman, spip, etc...)
if ($object->del_to_abo() < 0) {
$this->errors = $object->errors;
if (!empty($object->error)) {
$this->errors[] = $object->error;
}
$return = -1;
} else {
$return = 1;
}
return $return;
}
return 0;
}
}