61 global $conf, $langs, $user;
63 $langs->load(
'datapolicy@datapolicy');
67 $nbupdated = $nbdeleted = 0;
70 $arrayofparameters = array(
71 'DATAPOLICY_TIERS_CLIENT' => array(
73 SELECT s.rowid FROM ".MAIN_DB_PREFIX.
"societe as s
77 AND s.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
79 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_soc = s.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
82 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
86 "file" => DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php',
87 'fields_anonym' => array(
88 'name' =>
'MAKEANONYMOUS',
101 'socialnetworks' => [],
105 'DATAPOLICY_TIERS_PROSPECT' => array(
107 SELECT s.rowid FROM ".MAIN_DB_PREFIX.
"societe as s
110 AND s.fournisseur = 0
111 AND s.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
113 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_soc = s.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
116 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
119 "class" =>
"Societe",
120 "file" => DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php',
121 'fields_anonym' => array(
122 'name' =>
'MAKEANONYMOUS',
135 'socialnetworks' => [],
139 'DATAPOLICY_TIERS_PROSPECT_CLIENT' => array(
141 SELECT s.rowid FROM ".MAIN_DB_PREFIX.
"societe as s
144 AND s.fournisseur = 0
145 AND s.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
147 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_soc = s.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
150 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
153 "class" =>
"Societe",
154 "file" => DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php',
155 'fields_anonym' => array(
156 'name' =>
'MAKEANONYMOUS',
169 'socialnetworks' => [],
173 'DATAPOLICY_TIERS_NIPROSPECT_NICLIENT' => array(
175 SELECT s.rowid FROM ".MAIN_DB_PREFIX.
"societe as s
178 AND s.fournisseur = 0
179 AND s.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
181 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_soc = s.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
184 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
187 "class" =>
"Societe",
188 "file" => DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php',
189 'fields_anonym' => array(
190 'name' =>
'MAKEANONYMOUS',
203 'socialnetworks' => [],
207 'DATAPOLICY_TIERS_FOURNISSEUR' => array(
209 SELECT s.rowid FROM ".MAIN_DB_PREFIX.
"societe as s
211 AND s.fournisseur = 1
212 AND s.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
214 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_soc = s.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
217 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
220 "class" =>
"Societe",
221 "file" => DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php',
222 'fields_anonym' => array(
223 'name' =>
'MAKEANONYMOUS',
236 'socialnetworks' => [],
240 'DATAPOLICY_CONTACT_CLIENT' => array(
242 SELECT c.rowid FROM ".MAIN_DB_PREFIX.
"socpeople as c
243 INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = c.fk_soc
245 AND c.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
247 AND s.fournisseur = 0
249 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_contact = c.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
252 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
255 "class" =>
"Contact",
256 "file" => DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php',
257 'fields_anonym' => array(
258 'lastname' =>
'MAKEANONYMOUS',
267 'phone_mobile' =>
'',
274 'socialnetworks' => [],
278 'DATAPOLICY_CONTACT_PROSPECT' => array(
280 SELECT c.rowid FROM ".MAIN_DB_PREFIX.
"socpeople as c
281 INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = c.fk_soc
283 AND c.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
285 AND s.fournisseur = 0
287 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_contact = c.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
290 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
293 "class" =>
"Contact",
294 "file" => DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php',
295 'fields_anonym' => array(
296 'lastname' =>
'MAKEANONYMOUS',
305 'phone_mobile' =>
'',
312 'socialnetworks' => [],
316 'DATAPOLICY_CONTACT_PROSPECT_CLIENT' => array(
318 SELECT c.rowid FROM ".MAIN_DB_PREFIX.
"socpeople as c
319 INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = c.fk_soc
321 AND c.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
323 AND s.fournisseur = 0
325 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_contact = c.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
328 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
331 "class" =>
"Contact",
332 "file" => DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php',
333 'fields_anonym' => array(
334 'lastname' =>
'MAKEANONYMOUS',
343 'phone_mobile' =>
'',
350 'socialnetworks' => [],
354 'DATAPOLICY_CONTACT_NIPROSPECT_NICLIENT' => array(
356 SELECT c.rowid FROM ".MAIN_DB_PREFIX.
"socpeople as c
357 INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = c.fk_soc
359 AND c.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
361 AND s.fournisseur = 0
363 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_contact = c.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
366 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
369 "class" =>
"Contact",
370 "file" => DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php',
371 'fields_anonym' => array(
372 'lastname' =>
'MAKEANONYMOUS',
381 'phone_mobile' =>
'',
388 'socialnetworks' => [],
392 'DATAPOLICY_CONTACT_FOURNISSEUR' => array(
394 SELECT c.rowid FROM ".MAIN_DB_PREFIX.
"socpeople as c
395 INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = c.fk_soc
397 AND c.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
398 AND s.fournisseur = 1
400 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_contact = c.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
403 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
406 "class" =>
"Contact",
407 "file" => DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php',
408 'fields_anonym' => array(
409 'lastname' =>
'MAKEANONYMOUS',
418 'phone_mobile' =>
'',
425 'socialnetworks' => [],
429 'DATAPOLICY_ADHERENT' => array(
431 SELECT a.rowid FROM ".MAIN_DB_PREFIX.
"adherent as a
433 AND a.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
435 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_element = a.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH) AND a.elementtype LIKE 'member'
438 "class" =>
"Adherent",
439 "file" => DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php',
440 'fields_anonym' => array(
441 'lastname' =>
'MAKEANONYMOUS',
442 'firstname' =>
'MAKEANONYMOUS',
450 'phone_mobile' =>
'',
457 'socialnetworks' => [],
465 foreach ($arrayofparameters as $key => $params) {
470 $resql = $this->db->query($sql);
472 if ($resql && $this->db->num_rows($resql) > 0) {
473 $num = $this->db->num_rows($resql);
476 require_once $params[
'file'];
477 $object =
new $params[
'class']($this->db);
479 while ($i < $num && !$error) {
480 $obj = $this->db->fetch_object($resql);
485 $action =
'anonymize';
487 if ($action ==
'anonymize') {
488 if (
$object->isObjectUsed($obj->rowid) == 0) {
489 foreach ($params[
'fields_anonym'] as $field => $val) {
490 if ($val ==
'MAKEANONYMOUS') {
491 $object->$field = $field.
'-anonymous-'.$obj->rowid;
496 $result =
$object->update($obj->rowid, $user);
505 if ($action ==
'delete') {
506 $result =
$object->delete($user);
524 $this->output = $nbupdated.
' record updated, '.$nbdeleted.
' record deleted';
526 $this->error = $errormsg;