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