Enhance module datapolicy

This commit is contained in:
ldestailleur
2025-07-24 12:35:41 +02:00
parent 6b0f6f4b3a
commit ab8b4feca0
3 changed files with 15 additions and 4 deletions

View File

@@ -430,9 +430,10 @@ class Cronjob extends CommonObject
* @param int $id Id object
* @param string $objectname Object name
* @param string $methodname Method name
* @param string $label Label
* @return int if KO: <0 || if OK: >0
*/
public function fetch(int $id, string $objectname = '', string $methodname = '')
public function fetch(int $id, string $objectname = '', string $methodname = '', string $label = '')
{
$sql = "SELECT";
$sql .= " t.rowid,";
@@ -472,13 +473,15 @@ class Cronjob extends CommonObject
$sql .= " FROM ".MAIN_DB_PREFIX."cronjob as t";
if ($id > 0) {
$sql .= " WHERE t.rowid = ".((int) $id);
} elseif ($label) {
$sql .= " WHERE t.entity IN(0, ".getEntity('cron').")";
$sql .= " AND t.label = '".$this->db->escape($label)."'";
} else {
$sql .= " WHERE t.entity IN(0, ".getEntity('cron').")";
$sql .= " AND t.objectname = '".$this->db->escape($objectname)."'";
$sql .= " AND t.methodename = '".$this->db->escape($methodname)."'";
}
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
if ($this->db->num_rows($resql)) {
@@ -488,6 +491,7 @@ class Cronjob extends CommonObject
$this->ref = $obj->rowid;
$this->entity = $obj->entity;
$this->tms = $this->db->jdate($obj->tms);
$this->date_modification = $this->db->jdate($obj->tms);
$this->datec = $this->db->jdate($obj->datec);
$this->label = $obj->label;
$this->jobtype = $obj->jobtype;

View File

@@ -29,6 +29,7 @@
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
require_once DOL_DOCUMENT_ROOT.'/datapolicy/lib/datapolicy.lib.php';
require_once DOL_DOCUMENT_ROOT.'/cron/class/cronjob.class.php';
/**
* @var Conf $conf
@@ -256,8 +257,13 @@ print dol_get_fiche_head($head, 'settings', '', -1, '');
print '<span class="opacitymedium">'.$langs->trans("datapolicySetupPage").'</span>';
print $form->textwithpicto('', $langs->trans('DATAPOLICY_Tooltip_SETUP', $langs->transnoentitiesnoconv("DATAPOLICYJob"), $langs->transnoentitiesnoconv("CronList")));
if (!isModEnabled('cron')) {
print info_admin($langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentities("CronList")), 0, 0, 'warning');
print info_admin($langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("CronList")), 0, 0, 'warning');
} else {
$tmpjob = new Cronjob($db);
$tmpjob->fetch(0, '', '', 'DATAPOLICYJob');
if ($tmpjob->status != $tmpjob::STATUS_ENABLED) {
print info_admin($langs->trans("JobMustBeEnabledFirst", $langs->transnoentitiesnoconv("DATAPOLICYJob"), $langs->transnoentitiesnoconv("CronList")), 0, 0, 'warning');
}
}
print '<br><br>';

View File

@@ -415,7 +415,8 @@ ThemeDir=Skins directory
ConnectionTimeout=Connection timeout
ResponseTimeout=Response timeout
SmsTestMessage=Test message from __PHONEFROM__ to __PHONETO__
ModuleMustBeEnabledFirst=Module <b>%s</b> must be enabled first if you need this feature.
ModuleMustBeEnabledFirst=The module <b>%s</b> must be enabled first if you need this feature.
JobMustBeEnabledFirst=The scheduled job <b>%s</b> is not enabled. It must be enabled first if you need this feature (see the setup of module <b>%s</b>).
SecurityToken=Key to secure URLs
NoSmsEngine=No SMS sender manager available. A SMS sender manager is not installed with the default distribution because they depend on an external vendor, but you can find some on %s
PDF=PDF