From 89e1cdff61556c6fd453794b2753b4dd21f97329 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 6 Sep 2019 19:41:15 +0200 Subject: [PATCH] Debug module datapolicy --- htdocs/core/modules/modDataPolicy.class.php | 2 +- htdocs/datapolicy/class/datapolicy.class.php | 15 ++++++++++- .../datapolicy/class/datapolicycron.class.php | 27 ++++++++++++------- htdocs/langs/en_US/cron.lang | 1 + 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/htdocs/core/modules/modDataPolicy.class.php b/htdocs/core/modules/modDataPolicy.class.php index a08ce2f7873..2c6d749d1ee 100644 --- a/htdocs/core/modules/modDataPolicy.class.php +++ b/htdocs/core/modules/modDataPolicy.class.php @@ -187,7 +187,7 @@ class modDataPolicy extends DolibarrModules { // Cronjobs (List of cron jobs entries to add when module is enabled) // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week $this->cronjobs = array( - 0 => array('label' => 'DATAPOLICY Cron', 'jobtype' => 'method', 'class' => '/datapolicy/class/datapolicyCron.class.php', 'objectname' => 'DataPolicyCron', 'method' => 'exec', 'parameters' => '', 'comment' => 'Clean data', 'frequency' => 1, 'unitfrequency' => 86400, 'status' => 1, 'test' => '$conf->datapolicy->enabled'), + 0 => array('label' => 'DATAPOLICYJob', 'jobtype' => 'method', 'class' => 'datapolicy/class/datapolicycron.class.php', 'objectname' => 'DataPolicyCron', 'method' => 'cleanDataForDataPolicy', 'parameters' => '', 'comment' => 'Clean data', 'frequency' => 1, 'unitfrequency' => 86400, 'status' => 1, 'test' => '$conf->datapolicy->enabled'), //1 => array('label' => 'DATAPOLICY Mailing', 'jobtype' => 'method', 'class' => '/datapolicy/class/datapolicyCron.class.php', 'objectname' => 'RgpdCron', 'method' => 'sendMailing', 'parameters' => '', 'comment' => 'Comment', 'frequency' => 1, 'unitfrequency' => 86400, 'status' => 0, 'test' => true) ); // Example: $this->cronjobs=array(0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'/dir/class/file.class.php', 'objectname'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600, 'status'=>0, 'test'=>true), diff --git a/htdocs/datapolicy/class/datapolicy.class.php b/htdocs/datapolicy/class/datapolicy.class.php index bf1033084d5..c4b3cd2458d 100644 --- a/htdocs/datapolicy/class/datapolicy.class.php +++ b/htdocs/datapolicy/class/datapolicy.class.php @@ -30,6 +30,16 @@ include_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php'; */ class DataPolicy { + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; + } + /** * getAllContactNotInformed * @@ -200,7 +210,6 @@ class DataPolicy } else { $result4 = $mailfile->sendfile(); if (!$error) { - $resultmasssend .= $langs->trans("MailSent") . ': ' . $sendto . "
"; $contact->array_options['options_datapolicy_send'] = date('Y-m-d', time()); $contact->update($contact->id); @@ -301,6 +310,10 @@ class DataPolicy $sendto = $adherent->email; + // TODO Use a dolibarr email template + $s = 'TXTLINKDATAPOLICIESSUBJECT_' . $l; + $ma = 'TXTLINKDATAPOLICIESMESSAGE_' . $l; + $code= md5($adherent->email); if (!empty($adherent->default_lang)) { $l = $adherent->default_lang; diff --git a/htdocs/datapolicy/class/datapolicycron.class.php b/htdocs/datapolicy/class/datapolicycron.class.php index 656831eed2f..a938724ad73 100644 --- a/htdocs/datapolicy/class/datapolicycron.class.php +++ b/htdocs/datapolicy/class/datapolicycron.class.php @@ -27,12 +27,24 @@ */ class DataPolicyCron { + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; + } + + /** * Function exec + * CAN BE A CRON TASK * - * @return boolean + * @return int 0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK) */ - public function exec() + public function cleanDataForDataPolicy() { global $conf, $db, $langs, $user; @@ -479,14 +491,10 @@ class DataPolicyCron $db->query($sql); } } else { - if (DOL_VERSION < 8) { + if ($object->element == 'adherent') { $ret = $object->delete($obj->rowid, $user); } else { - if ($object->element == 'adherent') { - $ret = $object->delete($obj->rowid); - } else { - $ret = $object->delete(); - } + $ret = $object->delete($user); } } @@ -495,7 +503,8 @@ class DataPolicyCron } } } - return true; + + return 0; } diff --git a/htdocs/langs/en_US/cron.lang b/htdocs/langs/en_US/cron.lang index aee4d7bb988..1de1251831a 100644 --- a/htdocs/langs/en_US/cron.lang +++ b/htdocs/langs/en_US/cron.lang @@ -81,3 +81,4 @@ JobDisabled=Job disabled MakeLocalDatabaseDumpShort=Local database backup MakeLocalDatabaseDump=Create a local database dump. Parameters are: compression ('gz' or 'bz' or 'none'), backup type ('mysql', 'pgsql', 'auto'), 1, 'auto' or filename to build, number of backup files to keep WarningCronDelayed=Attention, for performance purpose, whatever is next date of execution of enabled jobs, your jobs may be delayed to a maximum of %s hours, before being run. +DATAPOLICYJob=Data cleaner and anonymizer