dolibarr 21.0.0-alpha
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 $this->version = self::VERSIONS['prod'];
47 $this->picto = 'technic';
48 }
49
61 public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
62 {
63 if (empty($conf->mailmanspip) || empty($conf->mailmanspip->enabled)) {
64 return 0; // Module not active, we do nothing
65 }
66
67 require_once DOL_DOCUMENT_ROOT."/mailmanspip/class/mailmanspip.class.php";
68 require_once DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php";
69
70 if ($action == 'CATEGORY_LINK') {
71 dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
72
73 // We add subscription if we change category (new category may means more mailing-list to subscribe)
74 if (is_object($object->context['linkto']) && method_exists($object->context['linkto'], 'add_to_abo') && $object->context['linkto']->add_to_abo() < 0) {
75 $this->error = $object->context['linkto']->error;
76 $this->errors = $object->context['linkto']->errors;
77 $return = -1;
78 } else {
79 $return = 1;
80 }
81
82 return $return;
83 } elseif ($action == 'CATEGORY_UNLINK') {
84 dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
85
86 // We remove subscription if we change category (lessw category may means less mailing-list to subscribe)
87 if (is_object($object->context['unlinkoff']) && method_exists($object->context['unlinkoff'], 'del_to_abo') && $object->context['unlinkoff']->del_to_abo() < 0) {
88 $this->error = $object->context['unlinkoff']->error;
89 $this->errors = $object->context['unlinkoff']->errors;
90 $return = -1;
91 } else {
92 $return = 1;
93 }
94
95 return $return;
96 } elseif ($action == 'MEMBER_VALIDATE') {
97 // Members
98 dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
99
100 $return = 0;
101 if ($object->add_to_abo() < 0) {
102 $this->errors = $object->errors;
103 if (!empty($object->error)) {
104 $this->errors[] = $object->error;
105 }
106 $return = -1;
107 } else {
108 $return = 1;
109 }
110
111 return $return;
112 } elseif ($action == 'MEMBER_MODIFY') {
113 dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
114
115 $return = 0;
116 // Add user into some linked tools (mailman, spip, etc...)
117 if (($object->oldcopy->email != $object->email) || ($object->oldcopy->typeid != $object->typeid)) {
118 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
119 // $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()
120 $tmpmember = new Adherent($this->db);
121 $tmpmember->fetch($object->oldcopy->id);
122 if ($tmpmember->del_to_abo() < 0) {
123 $this->errors = $tmpmember->errors;
124 if (!empty($tmpmember->error)) {
125 $this->errors[] = $tmpmember->error;
126 }
127 $return = -1;
128 } else {
129 $return = 1;
130 }
131 }
132 // We add subscription if new email or new type (new type may means more mailing-list to subscribe)
133 if ($object->add_to_abo() < 0) {
134 $this->errors = $object->errors;
135 if (!empty($object->error)) {
136 $this->errors[] = $object->error;
137 }
138 $return = -1;
139 } else {
140 $return = 1;
141 }
142 }
143
144 return $return;
145 } elseif ($action == 'MEMBER_RESILIATE' || $action == 'MEMBER_DELETE') {
146 dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
147
148 $return = 0;
149 // Remove from external tools (mailman, spip, etc...)
150 if ($object->del_to_abo() < 0) {
151 $this->errors = $object->errors;
152 if (!empty($object->error)) {
153 $this->errors[] = $object->error;
154 }
155 $return = -1;
156 } else {
157 $return = 1;
158 }
159
160 return $return;
161 }
162
163 return 0;
164 }
165}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class to manage members of a foundation.
Class to stock current configuration.
Class that all triggers must inherit.
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarr 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:140