dolibarr  9.0.0
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 <http://www.gnu.org/licenses/>.
17  */
18 
24 require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
25 
26 
31 {
32  public $family = 'mailmanspip';
33  public $description = "Triggers of this module allows to synchronize Mailman an Spip.";
34 
39  public $version = self::VERSION_DOLIBARR;
40 
44  public $picto = 'technic';
45 
57  public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
58  {
59  if (empty($conf->mailmanspip->enabled)) return 0; // Module not active, we do nothing
60 
61  require_once DOL_DOCUMENT_ROOT."/mailmanspip/class/mailmanspip.class.php";
62  require_once DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php";
63 
64  if ($action == 'CATEGORY_LINK')
65  {
66  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
67 
68  // We add subscription if we change category (new category may means more mailing-list to subscribe)
69  if (is_object($object->context['linkto']) && method_exists($object->context['linkto'], 'add_to_abo') && $object->context['linkto']->add_to_abo() < 0)
70  {
71  $this->error=$object->context['linkto']->error;
72  $this->errors=$object->context['linkto']->errors;
73  $return=-1;
74  }
75  else
76  {
77  $return=1;
78  }
79 
80  return $return;
81  }
82  elseif ($action == 'CATEGORY_UNLINK')
83  {
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  {
89  $this->error=$object->context['unlinkoff']->error;
90  $this->errors=$object->context['unlinkoff']->errors;
91  $return=-1;
92  }
93  else
94  {
95  $return=1;
96  }
97 
98  return $return;
99  }
100 
101  // Members
102  elseif ($action == 'MEMBER_VALIDATE' || $action == 'MEMBER_MODIFY')
103  {
104  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
105 
106  $return=0;
107  // Add user into some linked tools (mailman, spip, etc...)
108  if (($object->oldcopy->email != $object->email) || ($object->oldcopy->typeid != $object->typeid)) // TODO Do del/add also if type change
109  {
110  if (is_object($object->oldcopy) && ($object->oldcopy->email != $object->email)) // If email has changed we delete mailman subscription for old email
111  {
112  if ($object->oldcopy->del_to_abo() < 0)
113  {
114  if (! empty($object->oldcopy->error)) $this->error=$object->oldcopy->error;
115  $this->errors=$object->oldcopy->errors;
116  $return=-1;
117  }
118  else
119  {
120  $return=1;
121  }
122  }
123  // We add subscription if new email or new type (new type may means more mailing-list to subscribe)
124  if ($object->add_to_abo() < 0)
125  {
126  if (! empty($object->error)) $this->error=$object->error;
127  $this->errors=$object->errors;
128  $return=-1;
129  }
130  else
131  {
132  $return=1;
133  }
134  }
135 
136  return $return;
137  }
138  elseif ($action == 'MEMBER_RESILIATE' || $action == 'MEMBER_DELETE')
139  {
140  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
141 
142  $return=0;
143  // Remove from external tools (mailman, spip, etc...)
144  if ($object->del_to_abo() < 0)
145  {
146  if (! empty($object->error)) $this->error=$object->error;
147  $this->errors=$object->errors;
148  $return=-1;
149  }
150  else
151  {
152  $return=1;
153  }
154 
155  return $return;
156  }
157 
158  return 0;
159  }
160 }
Class to stock current configuration.
Definition: conf.class.php:33
Class to manage Dolibarr users.
Definition: user.class.php:41
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarrr business event is done.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage translations.
Class that all the triggers must extend.