dolibarr  7.0.0-beta
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 require_once DOL_DOCUMENT_ROOT."/mailmanspip/class/mailmanspip.class.php";
26 require_once DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php";
27 
28 
33 {
34  public $family = 'mailmanspip';
35  public $description = "Triggers of this module allows to synchronize Mailman an Spip.";
36  public $version = self::VERSION_DOLIBARR;
37  public $picto = 'technic';
38 
50  public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
51  {
52  if (empty($conf->mailmanspip->enabled)) return 0; // Module not active, we do nothing
53 
54  if ($action == 'CATEGORY_LINK')
55  {
56  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
57 
58  // We add subscription if we change category (new category may means more mailing-list to subscribe)
59  if (is_object($object->linkto) && method_exists($object->linkto, 'add_to_abo') && $object->linkto->add_to_abo() < 0)
60  {
61  $this->error=$object->linkto->error;
62  $this->errors=$object->linkto->errors;
63  $return=-1;
64  }
65  else
66  {
67  $return=1;
68  }
69 
70  return $return;
71  }
72  elseif ($action == 'CATEGORY_UNLINK')
73  {
74  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
75 
76  // We remove subscription if we change category (lessw category may means less mailing-list to subscribe)
77  if (is_object($object->unlinkoff) && method_exists($object->unlinkoff, 'del_to_abo') && $object->unlinkoff->del_to_abo() < 0)
78  {
79  $this->error=$object->unlinkoff->error;
80  $this->errors=$object->unlinkoff->errors;
81  $return=-1;
82  }
83  else
84  {
85  $return=1;
86  }
87 
88  return $return;
89  }
90 
91  // Members
92  elseif ($action == 'MEMBER_VALIDATE' || $action == 'MEMBER_MODIFY')
93  {
94  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
95 
96  $return=0;
97  // Add user into some linked tools (mailman, spip, etc...)
98  if (($object->oldcopy->email != $object->email) || ($object->oldcopy->typeid != $object->typeid)) // TODO Do del/add also if type change
99  {
100  if (is_object($object->oldcopy) && ($object->oldcopy->email != $object->email)) // If email has changed we delete mailman subscription for old email
101  {
102  if ($object->oldcopy->del_to_abo() < 0)
103  {
104  if (! empty($object->oldcopy->error)) $this->error=$object->oldcopy->error;
105  $this->errors=$object->oldcopy->errors;
106  $return=-1;
107  }
108  else
109  {
110  $return=1;
111  }
112  }
113  // We add subscription if new email or new type (new type may means more mailing-list to subscribe)
114  if ($object->add_to_abo() < 0)
115  {
116  if (! empty($object->error)) $this->error=$object->error;
117  $this->errors=$object->errors;
118  $return=-1;
119  }
120  else
121  {
122  $return=1;
123  }
124  }
125 
126  return $return;
127  }
128  elseif ($action == 'MEMBER_RESILIATE' || $action == 'MEMBER_DELETE')
129  {
130  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
131 
132  $return=0;
133  // Remove from external tools (mailman, spip, etc...)
134  if ($object->del_to_abo() < 0)
135  {
136  if (! empty($object->error)) $this->error=$object->error;
137  $this->errors=$object->errors;
138  $return=-1;
139  }
140  else
141  {
142  $return=1;
143  }
144 
145  return $return;
146  }
147 
148  return 0;
149  }
150 
151 }
Class to stock current configuration.
Definition: conf.class.php:33
Class to manage Dolibarr users.
Definition: user.class.php:39
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarrr business event is done.
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.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104