Merge pull request #9541 from frederic34/patch-23

reduce complexity of cronjob class
This commit is contained in:
Laurent Destailleur 2018-09-18 15:18:28 +02:00 committed by GitHub
commit 2918d4dc9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -244,8 +244,8 @@ class Cronjob extends CommonObject
{ {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."cronjob"); $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."cronjob");
if (! $notrigger) //if (! $notrigger)
{ //{
// Uncomment this and change MYOBJECT to your own tag if you // Uncomment this and change MYOBJECT to your own tag if you
// want this action calls a trigger. // want this action calls a trigger.
@ -255,7 +255,7 @@ class Cronjob extends CommonObject
//$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf); //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf);
//if ($result < 0) { $error++; $this->errors=$interface->errors; } //if ($result < 0) { $error++; $this->errors=$interface->errors; }
//// End call triggers //// End call triggers
} //}
} }
// Commit or rollback // Commit or rollback
@ -430,7 +430,7 @@ class Cronjob extends CommonObject
$sql.= " WHERE 1 = 1"; $sql.= " WHERE 1 = 1";
if ($processing >= 0) $sql.= " AND t.processing = ".(empty($processing)?'0':'1'); if ($processing >= 0) $sql.= " AND t.processing = ".(empty($processing)?'0':'1');
if ($status >= 0 && $status < 2) $sql.= " AND t.status = ".(empty($status)?'0':'1'); if ($status >= 0 && $status < 2) $sql.= " AND t.status = ".(empty($status)?'0':'1');
if ($status == 2) $sql.= " AND t.status = 2"; elseif ($status == 2) $sql.= " AND t.status = 2";
//Manage filter //Manage filter
if (is_array($filter) && count($filter)>0) { if (is_array($filter) && count($filter)>0) {
foreach($filter as $key => $value) foreach($filter as $key => $value)
@ -633,10 +633,8 @@ class Cronjob extends CommonObject
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
if (! $error) //if (! $error && ! $notrigger)
{ //{
if (! $notrigger)
{
// Uncomment this and change MYOBJECT to your own tag if you // Uncomment this and change MYOBJECT to your own tag if you
// want this action calls a trigger. // want this action calls a trigger.
@ -646,8 +644,7 @@ class Cronjob extends CommonObject
//$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf);
//if ($result < 0) { $error++; $this->errors=$interface->errors; } //if ($result < 0) { $error++; $this->errors=$interface->errors; }
//// End call triggers //// End call triggers
} //}
}
// Commit or rollback // Commit or rollback
if ($error) if ($error)
@ -763,11 +760,11 @@ class Cronjob extends CommonObject
$error++; $error++;
} }
if (! $error) //if (! $error)
{ //{
} //}
unset($this->context['createfromclone']); unset($this->context['createfromclone']);
@ -1304,34 +1301,33 @@ class Cronjob extends CommonObject
if ($mode == 0) if ($mode == 0)
{ {
$prefix='';
if ($status == 1) return $langs->trans('Enabled'); if ($status == 1) return $langs->trans('Enabled');
if ($status == 0) return $langs->trans('Disabled'); elseif ($status == 0) return $langs->trans('Disabled');
} }
if ($mode == 1) elseif ($mode == 1)
{ {
if ($status == 1) return $langs->trans('Enabled'); if ($status == 1) return $langs->trans('Enabled');
if ($status == 0) return $langs->trans('Disabled'); elseif ($status == 0) return $langs->trans('Disabled');
} }
if ($mode == 2) elseif ($mode == 2)
{ {
if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4','class="pictostatus"').' '.$langs->trans('Enabled'); if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4','class="pictostatus"').' '.$langs->trans('Enabled');
if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5','class="pictostatus"').' '.$langs->trans('Disabled'); elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5','class="pictostatus"').' '.$langs->trans('Disabled');
} }
if ($mode == 3) elseif ($mode == 3)
{ {
if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4','class="pictostatus"'); if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4','class="pictostatus"');
if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5','class="pictostatus"'); elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5','class="pictostatus"');
} }
if ($mode == 4) elseif ($mode == 4)
{ {
if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4','class="pictostatus"').' '.$langs->trans('Enabled'); if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4','class="pictostatus"').' '.$langs->trans('Enabled');
if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5','class="pictostatus"').' '.$langs->trans('Disabled'); elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5','class="pictostatus"').' '.$langs->trans('Disabled');
} }
if ($mode == 5) elseif ($mode == 5)
{ {
if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4','class="pictostatus"'); if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4','class="pictostatus"');
if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5','class="pictostatus"'); elseif ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5','class="pictostatus"');
} }
} }
} }