dolibarr 19.0.4
interface_50_modMailmanspip_Mailmanspipsynchro.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Rafael San José <rsanjose@alxarafe.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
26require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
27
28
33{
39 public function __construct($db)
40 {
41 $this->db = $db;
42
43 $this->name = preg_replace('/^Interface/i', '', get_class($this));
44 $this->family = "mailmanspip";
45 $this->description = "Triggers of this module allows to synchronize Mailman an Spip.";
46 // 'development', 'experimental', 'dolibarr' or version
47 $this->version = self::VERSION_DOLIBARR;
48 $this->picto = 'technic';
49 }
50
62 public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
63 {
64 if (empty($conf->mailmanspip) || empty($conf->mailmanspip->enabled)) {
65 return 0; // Module not active, we do nothing
66 }
67
68 require_once DOL_DOCUMENT_ROOT."/mailmanspip/class/mailmanspip.class.php";
69 require_once DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php";
70
71 if ($action == 'CATEGORY_LINK') {
72 dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
73
74 // We add subscription if we change category (new category may means more mailing-list to subscribe)
75 if (is_object($object->context['linkto']) && method_exists($object->context['linkto'], 'add_to_abo') && $object->context['linkto']->add_to_abo() < 0) {
76 $this->error = $object->context['linkto']->error;
77 $this->errors = $object->context['linkto']->errors;
78 $return = -1;
79 } else {
80 $return = 1;
81 }
82
83 return $return;
84 } elseif ($action == 'CATEGORY_UNLINK') {
85 dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
86
87 // We remove subscription if we change category (lessw category may means less mailing-list to subscribe)
88 if (is_object($object->context['unlinkoff']) && method_exists($object->context['unlinkoff'], 'del_to_abo') && $object->context['unlinkoff']->del_to_abo() < 0) {
89 $this->error = $object->context['unlinkoff']->error;
90 $this->errors = $object->context['unlinkoff']->errors;
91 $return = -1;
92 } else {
93 $return = 1;
94 }
95
96 return $return;
97 } elseif ($action == 'MEMBER_VALIDATE') {
98 // Members
99 dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
100
101 $return = 0;
102 if ($object->add_to_abo() < 0) {
103 $this->errors = $object->errors;
104 if (!empty($object->error)) {
105 $this->errors[] = $object->error;
106 }
107 $return = -1;
108 } else {
109 $return = 1;
110 }
111
112 return $return;
113 } elseif ($action == 'MEMBER_MODIFY') {
114 dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
115
116 $return = 0;
117 // Add user into some linked tools (mailman, spip, etc...)
118 if (($object->oldcopy->email != $object->email) || ($object->oldcopy->typeid != $object->typeid)) {
119 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
120 // $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()
121 $tmpmember = new Adherent($this->db);
122 $tmpmember->fetch($object->oldcopy->id);
123 if ($tmpmember->del_to_abo() < 0) {
124 $this->errors = $tmpmember->errors;
125 if (!empty($tmpmember->error)) {
126 $this->errors[] = $tmpmember->error;
127 }
128 $return = -1;
129 } else {
130 $return = 1;
131 }
132 }
133 // We add subscription if new email or new type (new type may means more mailing-list to subscribe)
134 if ($object->add_to_abo() < 0) {
135 $this->errors = $object->errors;
136 if (!empty($object->error)) {
137 $this->errors[] = $object->error;
138 }
139 $return = -1;
140 } else {
141 $return = 1;
142 }
143 }
144
145 return $return;
146 } elseif ($action == 'MEMBER_RESILIATE' || $action == 'MEMBER_DELETE') {
147 dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
148
149 $return = 0;
150 // Remove from external tools (mailman, spip, etc...)
151 if ($object->del_to_abo() < 0) {
152 $this->errors = $object->errors;
153 if (!empty($object->error)) {
154 $this->errors[] = $object->error;
155 }
156 $return = -1;
157 } else {
158 $return = 1;
159 }
160
161 return $return;
162 }
163
164 return 0;
165 }
166}
Class to manage members of a foundation.
Class to stock current configuration.
Class that all the triggers must extend.
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarrr business event is done.
Class to manage translations.
Class to manage Dolibarr users.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:124