code syntax cron directory

This commit is contained in:
Frédéric FRANCE 2021-02-28 23:47:30 +01:00
parent f7933a6884
commit 0a6f307716
No known key found for this signature in database
GPG Key ID: 06809324E4B2ABC1
5 changed files with 527 additions and 371 deletions

View File

@ -32,22 +32,21 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/cron.lib.php';
// Load translation files required by the page
$langs->loadLangs(array('admin', 'cron'));
if (!$user->admin)
if (!$user->admin) {
accessforbidden();
}
$actionsave = GETPOST("save", 'alphanohtml');
// Save parameters
if (!empty($actionsave))
{
if (!empty($actionsave)) {
$i = 0;
$db->begin();
$i += dolibarr_set_const($db, 'CRON_KEY', GETPOST("CRON_KEY"), 'chaine', 0, '', 0);
if ($i >= 1)
{
if ($i >= 1) {
$db->commit();
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
} else {
@ -90,13 +89,15 @@ print "</tr>";
print '<tr class="oddeven">';
print '<td class="fieldrequired">'.$langs->trans("KeyForCronAccess").'</td>';
$disabled = '';
if (!empty($conf->global->CRON_DISABLE_KEY_CHANGE)) $disabled = ' disabled="disabled"';
if (!empty($conf->global->CRON_DISABLE_KEY_CHANGE)) {
$disabled = ' disabled="disabled"';
}
print '<td>';
if (empty($conf->global->CRON_DISABLE_KEY_CHANGE))
{
if (empty($conf->global->CRON_DISABLE_KEY_CHANGE)) {
print '<input type="text" class="flat minwidth300"'.$disabled.' id="CRON_KEY" name="CRON_KEY" value="'.(GETPOST('CRON_KEY') ?GETPOST('CRON_KEY') : (!empty($conf->global->CRON_KEY) ? $conf->global->CRON_KEY : '')).'">';
if (!empty($conf->use_javascript_ajax))
if (!empty($conf->use_javascript_ajax)) {
print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
}
} else {
print (!empty($conf->global->CRON_KEY) ? $conf->global->CRON_KEY : '');
print '<input type="hidden" id="CRON_KEY" name="CRON_KEY" value="'.(GETPOST('CRON_KEY') ?GETPOST('CRON_KEY') : (!empty($conf->global->CRON_KEY) ? $conf->global->CRON_KEY : '')).'">';
@ -119,7 +120,9 @@ print '</form>';
print '<br><br><br>';
//print $langs->trans("UseMenuModuleToolsToAddCronJobs", dol_buildpath('/cron/list.php?leftmenu=admintools', 1)).'<br>';
if (!empty($conf->global->CRON_WARNING_DELAY_HOURS)) print info_admin($langs->trans("WarningCronDelayed", $conf->global->CRON_WARNING_DELAY_HOURS)).'<br>';
if (!empty($conf->global->CRON_WARNING_DELAY_HOURS)) {
print info_admin($langs->trans("WarningCronDelayed", $conf->global->CRON_WARNING_DELAY_HOURS)).'<br>';
}
print '<br>';
@ -128,8 +131,7 @@ dol_print_cron_urls();
print '<br>';
if (!empty($conf->use_javascript_ajax))
{
if (!empty($conf->use_javascript_ajax)) {
print "\n".'<script type="text/javascript">';
print '$(document).ready(function () {
$("#generate_token").click(function() {

View File

@ -36,7 +36,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/cron.lib.php';
// Load translation files required by the page
$langs->loadLangs(array('admin', 'cron', 'members'));
if (!$user->rights->cron->create) accessforbidden();
if (!$user->rights->cron->create) {
accessforbidden();
}
$id = GETPOST('id', 'int');
$action = GETPOST('action', 'aZ09');
@ -53,23 +55,18 @@ $securitykey = GETPOST('securitykey', 'alpha');
*/
$object = new Cronjob($db);
if (!empty($id))
{
if (!empty($id)) {
$result = $object->fetch($id);
if ($result < 0)
{
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
}
if (!empty($cancel))
{
if (!empty($id) && empty($backtopage))
{
if (!empty($cancel)) {
if (!empty($id) && empty($backtopage)) {
$action = '';
} else {
if ($backtopage)
{
if ($backtopage) {
header("Location: ".$backtopage);
exit;
} else {
@ -80,12 +77,10 @@ if (!empty($cancel))
}
// Delete jobs
if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->cron->delete)
{
if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->cron->delete) {
$result = $object->delete($user);
if ($result < 0)
{
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
$action = 'edit';
} else {
@ -95,10 +90,8 @@ if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->cron->del
}
// Execute jobs
if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->execute)
{
if (!empty($conf->global->CRON_KEY) && $conf->global->CRON_KEY != $securitykey)
{
if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->execute) {
if (!empty($conf->global->CRON_KEY) && $conf->global->CRON_KEY != $securitykey) {
setEventMessages('Security key '.$securitykey.' is wrong', null, 'errors');
$action = '';
} else {
@ -106,16 +99,17 @@ if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->ex
$result = $object->run_jobs($user->login);
if ($result < 0)
{
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
$action = '';
} else {
$res = $object->reprogram_jobs($user->login, $now);
if ($res > 0)
{
if ($object->lastresult > 0) setEventMessages($langs->trans("JobFinished"), null, 'warnings');
else setEventMessages($langs->trans("JobFinished"), null, 'mesgs');
if ($res > 0) {
if ($object->lastresult > 0) {
setEventMessages($langs->trans("JobFinished"), null, 'warnings');
} else {
setEventMessages($langs->trans("JobFinished"), null, 'mesgs');
}
$action = '';
} else {
setEventMessages($object->error, $object->errors, 'errors');
@ -126,8 +120,7 @@ if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->ex
}
if ($action == 'add')
{
if ($action == 'add') {
$object->jobtype = GETPOST('jobtype');
$object->label = GETPOST('label');
$object->command = GETPOST('command');
@ -160,8 +153,7 @@ if ($action == 'add')
}
// Save parameters
if ($action == 'update')
{
if ($action == 'update') {
$object->id = $id;
$object->jobtype = GETPOST('jobtype');
$object->label = GETPOST('label');
@ -194,8 +186,7 @@ if ($action == 'update')
}
}
if ($action == 'activate')
{
if ($action == 'activate') {
$object->status = 1;
// Add cron task
@ -211,8 +202,7 @@ if ($action == 'activate')
}
}
if ($action == 'inactive')
{
if ($action == 'inactive') {
$object->status = 0;
$object->processing = 0;
@ -240,16 +230,13 @@ $formCron = new FormCron($db);
llxHeader('', $langs->trans("CronTask"));
if ($action == 'edit' || empty($action) || $action == 'delete' || $action == 'execute')
{
if ($action == 'edit' || empty($action) || $action == 'delete' || $action == 'execute') {
$head = cron_prepare_head($object);
} elseif ($action == 'create')
{
} elseif ($action == 'create') {
print load_fiche_titre($langs->trans("CronTask"), '', 'title_setup');
}
if ($conf->use_javascript_ajax)
{
if ($conf->use_javascript_ajax) {
print "\n".'<script type="text/javascript" language="javascript">';
print 'jQuery(document).ready(function () {
function initfields()
@ -271,8 +258,7 @@ if ($conf->use_javascript_ajax)
print '</script>'."\n";
}
if ($action == 'delete')
{
if ($action == 'delete') {
print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id, $langs->trans("CronDelete"), $langs->trans("CronConfirmDelete"), "confirm_delete", '', '', 1);
$action = '';
@ -290,13 +276,11 @@ if ($action == 'execute') {
* Create Template
*/
if (empty($object->status) && $action != 'create')
{
if (empty($object->status) && $action != 'create') {
setEventMessages($langs->trans("CronTaskInactive"), null, 'warnings');
}
if (($action == "create") || ($action == "edit"))
{
if (($action == "create") || ($action == "edit")) {
print '<form name="cronform" action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
print '<input type="hidden" name="backtopage" value="'.GETPOST('backtopage').'">'."\n";
@ -307,8 +291,11 @@ if (($action == "create") || ($action == "edit"))
print '<input type="hidden" name="action" value="add">'."\n";
}
if ($action == "edit") print dol_get_fiche_head($head, 'card', $langs->trans("CronTask"), 0, 'cron');
else print dol_get_fiche_head('');
if ($action == "edit") {
print dol_get_fiche_head($head, 'card', $langs->trans("CronTask"), 0, 'cron');
} else {
print dol_get_fiche_head('');
}
print '<table class="border centpercent">';
@ -395,10 +382,8 @@ if (($action == "create") || ($action == "edit"))
print $langs->trans('CronEvery')."</td>";
print "<td>";
print '<select name="nbfrequency">';
for ($i = 1; $i <= 60; $i++)
{
if ($object->frequency == $i)
{
for ($i = 1; $i <= 60; $i++) {
if ($object->frequency == $i) {
print "<option value='".$i."' selected>".$i."</option>";
} else {
print "<option value='".$i."'>".$i."</option>";
@ -406,8 +391,7 @@ if (($action == "create") || ($action == "edit"))
}
print "</select>";
$input = " <input type=\"radio\" name=\"unitfrequency\" value=\"60\" id=\"frequency_minute\" ";
if ($object->unitfrequency == "60")
{
if ($object->unitfrequency == "60") {
$input .= ' checked />';
} else {
$input .= ' />';
@ -448,8 +432,7 @@ if (($action == "create") || ($action == "edit"))
print "<tr><td>";
print $langs->trans('CronDtStart')."</td><td>";
if (!empty($object->datestart))
{
if (!empty($object->datestart)) {
print $form->selectDate($object->datestart, 'datestart', 1, 1, '', "cronform");
} else {
print $form->selectDate('', 'datestart', 1, 1, '', "cronform");
@ -499,8 +482,7 @@ if (($action == "create") || ($action == "edit"))
print $langs->trans('CronDtNextLaunch');
print ' ('.$langs->trans('CronFrom').')';
print "</td><td>";
if (!empty($object->datenextrun))
{
if (!empty($object->datenextrun)) {
print $form->selectDate($object->datenextrun, 'datenextrun', 1, 1, '', "cronform");
} else {
print $form->selectDate(-1, 'datenextrun', 1, 1, '', "cronform");
@ -588,12 +570,10 @@ if (($action == "create") || ($action == "edit"))
}
print "</td></tr>";
if (!empty($conf->multicompany->enabled))
{
if (!empty($conf->multicompany->enabled)) {
print '<tr><td>';
print $langs->trans('Entity')."</td><td>";
if (!$object->entity)
{
if (!$object->entity) {
print $langs->trans("AllEntities");
} else {
$mc->getInfo($object->entity);
@ -615,20 +595,32 @@ if (($action == "create") || ($action == "edit"))
print '<tr><td class="titlefield">';
print $langs->trans('CronEvery')."</td>";
print "<td>";
if ($object->unitfrequency == "60") print $langs->trans('CronEach')." ".($object->frequency)." ".$langs->trans('Minutes');
if ($object->unitfrequency == "3600") print $langs->trans('CronEach')." ".($object->frequency)." ".$langs->trans('Hours');
if ($object->unitfrequency == "86400") print $langs->trans('CronEach')." ".($object->frequency)." ".$langs->trans('Days');
if ($object->unitfrequency == "604800") print $langs->trans('CronEach')." ".($object->frequency)." ".$langs->trans('Weeks');
if ($object->unitfrequency == "60") {
print $langs->trans('CronEach')." ".($object->frequency)." ".$langs->trans('Minutes');
}
if ($object->unitfrequency == "3600") {
print $langs->trans('CronEach')." ".($object->frequency)." ".$langs->trans('Hours');
}
if ($object->unitfrequency == "86400") {
print $langs->trans('CronEach')." ".($object->frequency)." ".$langs->trans('Days');
}
if ($object->unitfrequency == "604800") {
print $langs->trans('CronEach')." ".($object->frequency)." ".$langs->trans('Weeks');
}
print "</td></tr>";
print '<tr><td>';
print $langs->trans('CronDtStart')."</td><td>";
if (!empty($object->datestart)) {print $form->textwithpicto(dol_print_date($object->datestart, 'dayhoursec'), $langs->trans("CurrentTimeZone")); }
if (!empty($object->datestart)) {
print $form->textwithpicto(dol_print_date($object->datestart, 'dayhoursec'), $langs->trans("CurrentTimeZone"));
}
print "</td></tr>";
print "<tr><td>";
print $langs->trans('CronDtEnd')."</td><td>";
if (!empty($object->dateend)) {print $form->textwithpicto(dol_print_date($object->dateend, 'dayhoursec'), $langs->trans("CurrentTimeZone")); }
if (!empty($object->dateend)) {
print $form->textwithpicto(dol_print_date($object->dateend, 'dayhoursec'), $langs->trans("CurrentTimeZone"));
}
print "</td></tr>";
print "<tr><td>";
@ -652,12 +644,19 @@ if (($action == "create") || ($action == "edit"))
print $langs->trans('CronDtNextLaunch');
print ' ('.$langs->trans('CronFrom').')';
print "</td><td>";
if (!$object->status) print $langs->trans("Disabled");
elseif (!empty($object->datenextrun)) { print img_picto('', 'object_calendarday').' '.$form->textwithpicto(dol_print_date($object->datenextrun, 'dayhoursec'), $langs->trans("CurrentTimeZone")); } else { print $langs->trans('CronNone'); }
if ($object->status == Cronjob::STATUS_ENABLED)
{
if ($object->maxrun && $object->nbrun >= $object->maxrun) print img_warning($langs->trans("MaxRunReached"));
elseif ($object->datenextrun && $object->datenextrun < $now) print img_warning($langs->trans("Late"));
if (!$object->status) {
print $langs->trans("Disabled");
} elseif (!empty($object->datenextrun)) {
print img_picto('', 'object_calendarday').' '.$form->textwithpicto(dol_print_date($object->datenextrun, 'dayhoursec'), $langs->trans("CurrentTimeZone"));
} else {
print $langs->trans('CronNone');
}
if ($object->status == Cronjob::STATUS_ENABLED) {
if ($object->maxrun && $object->nbrun >= $object->maxrun) {
print img_warning($langs->trans("MaxRunReached"));
} elseif ($object->datenextrun && $object->datenextrun < $now) {
print img_warning($langs->trans("Late"));
}
}
print "</td></tr>";
@ -672,19 +671,31 @@ if (($action == "create") || ($action == "edit"))
print '<tr><td class="titlefield">';
print $langs->trans('CronDtLastLaunch')."</td><td>";
if (!empty($object->datelastrun)) {print $form->textwithpicto(dol_print_date($object->datelastrun, 'dayhoursec'), $langs->trans("CurrentTimeZone")); } else {print $langs->trans('CronNone'); }
if (!empty($object->datelastrun)) {
print $form->textwithpicto(dol_print_date($object->datelastrun, 'dayhoursec'), $langs->trans("CurrentTimeZone"));
} else {
print $langs->trans('CronNone');
}
print "</td></tr>";
print '<tr><td>';
print $langs->trans('CronDtLastResult')."</td><td>";
if (!empty($object->datelastresult)) {print $form->textwithpicto(dol_print_date($object->datelastresult, 'dayhoursec'), $langs->trans("CurrentTimeZone")); } else {print $langs->trans('CronNone'); }
if (!empty($object->datelastresult)) {
print $form->textwithpicto(dol_print_date($object->datelastresult, 'dayhoursec'), $langs->trans("CurrentTimeZone"));
} else {
print $langs->trans('CronNone');
}
print "</td></tr>";
print '<tr><td>';
print $langs->trans('CronLastResult')."</td><td>";
if ($object->lastresult) print '<span class="error">';
if ($object->lastresult) {
print '<span class="error">';
}
print $object->lastresult;
if ($object->lastresult) print '</span>';
if ($object->lastresult) {
print '</span>';
}
print "</td></tr>";
print '<tr><td>';
@ -705,11 +716,9 @@ if (($action == "create") || ($action == "edit"))
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&id='.$object->id.'">'.$langs->trans("Edit").'</a>';
}
if ((empty($user->rights->cron->execute)))
{
if ((empty($user->rights->cron->execute))) {
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("CronExecute").'</a>';
} elseif (empty($object->status))
{
} elseif (empty($object->status)) {
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("JobDisabled")).'">'.$langs->trans("CronExecute").'</a>';
} else {
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=execute&id='.$object->id.(empty($conf->global->CRON_KEY) ? '' : '&securitykey='.$conf->global->CRON_KEY).'">'.$langs->trans("CronExecute").'</a>';

View File

@ -199,30 +199,66 @@ class Cronjob extends CommonObject
// Clean parameters
if (isset($this->label)) $this->label = trim($this->label);
if (isset($this->jobtype)) $this->jobtype = trim($this->jobtype);
if (isset($this->command)) $this->command = trim($this->command);
if (isset($this->classesname)) $this->classesname = trim($this->classesname);
if (isset($this->objectname)) $this->objectname = trim($this->objectname);
if (isset($this->methodename)) $this->methodename = trim($this->methodename);
if (isset($this->params)) $this->params = trim($this->params);
if (isset($this->md5params)) $this->md5params = trim($this->md5params);
if (isset($this->module_name)) $this->module_name = trim($this->module_name);
if (isset($this->priority)) $this->priority = trim($this->priority);
if (isset($this->lastoutput)) $this->lastoutput = trim($this->lastoutput);
if (isset($this->lastresult)) $this->lastresult = trim($this->lastresult);
if (isset($this->unitfrequency)) $this->unitfrequency = trim($this->unitfrequency);
if (isset($this->frequency)) $this->frequency = trim($this->frequency);
if (isset($this->status)) $this->status = trim($this->status);
if (isset($this->note_private)) $this->note_private = trim($this->note_private);
if (isset($this->label)) {
$this->label = trim($this->label);
}
if (isset($this->jobtype)) {
$this->jobtype = trim($this->jobtype);
}
if (isset($this->command)) {
$this->command = trim($this->command);
}
if (isset($this->classesname)) {
$this->classesname = trim($this->classesname);
}
if (isset($this->objectname)) {
$this->objectname = trim($this->objectname);
}
if (isset($this->methodename)) {
$this->methodename = trim($this->methodename);
}
if (isset($this->params)) {
$this->params = trim($this->params);
}
if (isset($this->md5params)) {
$this->md5params = trim($this->md5params);
}
if (isset($this->module_name)) {
$this->module_name = trim($this->module_name);
}
if (isset($this->priority)) {
$this->priority = trim($this->priority);
}
if (isset($this->lastoutput)) {
$this->lastoutput = trim($this->lastoutput);
}
if (isset($this->lastresult)) {
$this->lastresult = trim($this->lastresult);
}
if (isset($this->unitfrequency)) {
$this->unitfrequency = trim($this->unitfrequency);
}
if (isset($this->frequency)) {
$this->frequency = trim($this->frequency);
}
if (isset($this->status)) {
$this->status = trim($this->status);
}
if (isset($this->note_private)) {
$this->note_private = trim($this->note_private);
}
if (isset($this->nbrun)) {
$this->nbrun = (int) $this->nbrun;
}
if (isset($this->maxrun)) {
$this->maxrun = (int) $this->maxrun;
}
if (isset($this->libname)) $this->libname = trim($this->libname);
if (isset($this->test)) $this->test = trim($this->test);
if (isset($this->libname)) {
$this->libname = trim($this->libname);
}
if (isset($this->test)) {
$this->test = trim($this->test);
}
// Check parameters
// Put here code to add a control on parameters values
@ -328,23 +364,20 @@ class Cronjob extends CommonObject
$this->db->begin();
dol_syslog(get_class($this)."::create", LOG_DEBUG);
dol_syslog(get_class($this)."::create", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) {
$error++;
$this->errors[] = "Error ".$this->db->lasterror();
}
if (!$error)
{
if (!$error) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."cronjob");
}
// Commit or rollback
if ($error)
{
foreach ($this->errors as $errmsg)
{
if ($error) {
foreach ($this->errors as $errmsg) {
dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@ -411,10 +444,8 @@ class Cronjob extends CommonObject
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows($resql))
{
if ($resql) {
if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
@ -455,7 +486,7 @@ class Cronjob extends CommonObject
return 1;
} else {
$this->error = "Error ".$this->db->lasterror();
$this->error = "Error ".$this->db->lasterror();
return -1;
}
}
@ -514,15 +545,22 @@ class Cronjob extends CommonObject
$sql .= " t.test";
$sql .= " FROM ".MAIN_DB_PREFIX."cronjob as t";
$sql .= " WHERE 1 = 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');
elseif ($status == 2) $sql .= " AND t.status = 2";
if ($processing >= 0) {
$sql .= " AND t.processing = ".(empty($processing) ? '0' : '1');
}
if ($status >= 0 && $status < 2) {
$sql .= " AND t.status = ".(empty($status) ? '0' : '1');
} elseif ($status == 2) {
$sql .= " AND t.status = 2";
}
//Manage filter
if (is_array($filter) && count($filter) > 0) {
foreach ($filter as $key => $value)
{
if ($key == 't.rowid') $sql .= ' AND '.$key.' = '.$this->db->escape($value);
else $sql .= ' AND '.$key.' LIKE \'%'.$this->db->escape($value).'%\'';
foreach ($filter as $key => $value) {
if ($key == 't.rowid') {
$sql .= ' AND '.$key.' = '.$this->db->escape($value);
} else {
$sql .= ' AND '.$key.' LIKE \'%'.$this->db->escape($value).'%\'';
}
}
}
@ -539,15 +577,12 @@ class Cronjob extends CommonObject
dol_syslog(get_class($this)."::fetch_all", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$num = $this->db->num_rows($resql);
$i = 0;
if ($num)
{
while ($i < $num)
{
if ($num) {
while ($i < $num) {
$line = new Cronjobline();
$obj = $this->db->fetch_object($resql);
@ -615,28 +650,70 @@ class Cronjob extends CommonObject
$error = 0;
// Clean parameters
if (isset($this->label)) $this->label = trim($this->label);
if (isset($this->jobtype)) $this->jobtype = trim($this->jobtype);
if (isset($this->command)) $this->command = trim($this->command);
if (isset($this->classesname)) $this->classesname = trim($this->classesname);
if (isset($this->objectname)) $this->objectname = trim($this->objectname);
if (isset($this->methodename)) $this->methodename = trim($this->methodename);
if (isset($this->params)) $this->params = trim($this->params);
if (isset($this->md5params)) $this->md5params = trim($this->md5params);
if (isset($this->module_name)) $this->module_name = trim($this->module_name);
if (isset($this->priority)) $this->priority = trim($this->priority);
if (isset($this->lastoutput)) $this->lastoutput = trim($this->lastoutput);
if (isset($this->lastresult)) $this->lastresult = trim($this->lastresult);
if (isset($this->unitfrequency)) $this->unitfrequency = trim($this->unitfrequency);
if (isset($this->frequency)) $this->frequency = trim($this->frequency);
if (isset($this->status)) $this->status = trim($this->status);
if (isset($this->note_private)) $this->note_private = trim($this->note_private);
if (isset($this->nbrun)) $this->nbrun = trim($this->nbrun);
if (isset($this->libname)) $this->libname = trim($this->libname);
if (isset($this->test)) $this->test = trim($this->test);
if (isset($this->label)) {
$this->label = trim($this->label);
}
if (isset($this->jobtype)) {
$this->jobtype = trim($this->jobtype);
}
if (isset($this->command)) {
$this->command = trim($this->command);
}
if (isset($this->classesname)) {
$this->classesname = trim($this->classesname);
}
if (isset($this->objectname)) {
$this->objectname = trim($this->objectname);
}
if (isset($this->methodename)) {
$this->methodename = trim($this->methodename);
}
if (isset($this->params)) {
$this->params = trim($this->params);
}
if (isset($this->md5params)) {
$this->md5params = trim($this->md5params);
}
if (isset($this->module_name)) {
$this->module_name = trim($this->module_name);
}
if (isset($this->priority)) {
$this->priority = trim($this->priority);
}
if (isset($this->lastoutput)) {
$this->lastoutput = trim($this->lastoutput);
}
if (isset($this->lastresult)) {
$this->lastresult = trim($this->lastresult);
}
if (isset($this->unitfrequency)) {
$this->unitfrequency = trim($this->unitfrequency);
}
if (isset($this->frequency)) {
$this->frequency = trim($this->frequency);
}
if (isset($this->status)) {
$this->status = trim($this->status);
}
if (isset($this->note_private)) {
$this->note_private = trim($this->note_private);
}
if (isset($this->nbrun)) {
$this->nbrun = trim($this->nbrun);
}
if (isset($this->libname)) {
$this->libname = trim($this->libname);
}
if (isset($this->test)) {
$this->test = trim($this->test);
}
if (empty($this->maxrun)) $this->maxrun = 0;
if (empty($this->processing)) $this->processing = 0;
if (empty($this->maxrun)) {
$this->maxrun = 0;
}
if (empty($this->processing)) {
$this->processing = 0;
}
// Check parameters
// Put here code to add a control on parameters values
@ -715,13 +792,13 @@ class Cronjob extends CommonObject
dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
if (!$resql) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
}
// Commit or rollback
if ($error)
{
foreach ($this->errors as $errmsg)
{
if ($error) {
foreach ($this->errors as $errmsg) {
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@ -734,13 +811,13 @@ class Cronjob extends CommonObject
}
/**
* Delete object in database
*
* @param User $user User that deletes
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, >0 if OK
*/
/**
* Delete object in database
*
* @param User $user User that deletes
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, >0 if OK
*/
public function delete($user, $notrigger = 0)
{
$error = 0;
@ -758,10 +835,8 @@ class Cronjob extends CommonObject
}
// Commit or rollback
if ($error)
{
foreach ($this->errors as $errmsg)
{
if ($error) {
foreach ($this->errors as $errmsg) {
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@ -803,8 +878,7 @@ class Cronjob extends CommonObject
$result = $object->create($user);
// Other options
if ($result < 0)
{
if ($result < 0) {
$this->error = $object->error;
$error++;
}
@ -817,8 +891,7 @@ class Cronjob extends CommonObject
unset($object->context['createfromclone']);
// End
if (!$error)
{
if (!$error) {
$this->db->commit();
return $object->id;
} else {
@ -887,7 +960,9 @@ class Cronjob extends CommonObject
global $dolibarr_main_authentication, $dolibarr_main_demo;
global $menumanager;
if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
if (!empty($conf->dol_no_mouse_hover)) {
$notooltip = 1; // Force disable tooltips
}
$result = '';
@ -900,33 +975,40 @@ class Cronjob extends CommonObject
$url = DOL_URL_ROOT.'/cron/card.php?id='.$this->id;
if ($option != 'nolink')
{
if ($option != 'nolink') {
// Add param to save lastsearch_values or not
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
$add_save_lastsearch_values = 1;
}
if ($add_save_lastsearch_values) {
$url .= '&save_lastsearch_values=1';
}
}
$linkclose = '';
if (empty($notooltip))
{
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
{
if (empty($notooltip)) {
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
$label = $langs->trans("ShowCronJob");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
}
$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
} else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
} else {
$linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
}
$linkstart = '<a href="'.$url.'"';
$linkstart .= $linkclose.'>';
$linkend = '</a>';
$result .= $linkstart;
if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
if ($withpicto != 2) $result .= $this->ref;
if ($withpicto) {
$result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
}
if ($withpicto != 2) {
$result .= $this->ref;
}
$result .= $linkend;
//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
@ -949,10 +1031,8 @@ class Cronjob extends CommonObject
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows($resql))
{
if ($resql) {
if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
$this->date_creation = $this->db->jdate($obj->datec);
@ -992,8 +1072,7 @@ class Cronjob extends CommonObject
$langs->load('cron');
if (empty($userlogin))
{
if (empty($userlogin)) {
$this->error = "User login is mandatory";
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
return -1;
@ -1001,8 +1080,7 @@ class Cronjob extends CommonObject
// Force the environment of running to the environment declared for job, so jobs launched from command line will run into correct environment
// When job is ran from GUI, the environment should already be same, except if job has entity 0 (visible into all environments)
if ($conf->entity != $this->entity && $this->entity > 0)
{
if ($conf->entity != $this->entity && $this->entity > 0) {
dol_syslog("We try to run a job in entity ".$this->entity." when we are in entity ".$conf->entity, LOG_WARNING);
}
$savcurrententity = $conf->entity;
@ -1012,15 +1090,13 @@ class Cronjob extends CommonObject
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
$user = new User($this->db);
$result = $user->fetch('', $userlogin);
if ($result < 0)
{
if ($result < 0) {
$this->error = "User Error:".$user->error;
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
$conf->entity = $savcurrententity;
return -1;
} else {
if (empty($user->id))
{
if (empty($user->id)) {
$this->error = " User user login:".$userlogin." do not exists";
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
$conf->entity = $savcurrententity;
@ -1032,16 +1108,14 @@ class Cronjob extends CommonObject
// Increase limit of time. Works only if we are not in safe mode
$ExecTimeLimit = 600;
if (!empty($ExecTimeLimit))
{
if (!empty($ExecTimeLimit)) {
$err = error_reporting();
error_reporting(0); // Disable all errors
//error_reporting(E_ALL);
@set_time_limit($ExecTimeLimit); // Need more than 240 on Windows 7/64
error_reporting($err);
}
if (!empty($MemoryLimit))
{
if (!empty($MemoryLimit)) {
@ini_set('memory_limit', $MemoryLimit);
}
@ -1060,16 +1134,16 @@ class Cronjob extends CommonObject
}
// Run a method
if ($this->jobtype == 'method')
{
if ($this->jobtype == 'method') {
// load classes
if (!$error)
{
if (!$error) {
$ret = dol_include_once($this->classesname);
if ($ret === false || (!class_exists($this->objectname)))
{
if ($ret === false) $this->error = $langs->trans('CronCannotLoadClass', $this->classesname, $this->objectname);
else $this->error = $langs->trans('CronCannotLoadObject', $this->classesname, $this->objectname);
if ($ret === false || (!class_exists($this->objectname))) {
if ($ret === false) {
$this->error = $langs->trans('CronCannotLoadClass', $this->classesname, $this->objectname);
} else {
$this->error = $langs->trans('CronCannotLoadObject', $this->classesname, $this->objectname);
}
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
$this->lastoutput = $this->error;
$this->lastresult = -1;
@ -1079,10 +1153,8 @@ class Cronjob extends CommonObject
}
// test if method exists
if (!$error)
{
if (!method_exists($this->objectname, $this->methodename))
{
if (!$error) {
if (!method_exists($this->objectname, $this->methodename)) {
$this->error = $langs->trans('CronMethodDoesNotExists', $this->objectname, $this->methodename);
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
$this->lastoutput = $this->error;
@ -1090,8 +1162,7 @@ class Cronjob extends CommonObject
$retval = $this->lastresult;
$error++;
}
if (in_array(strtolower(trim($this->methodename)), array('executecli')))
{
if (in_array(strtolower(trim($this->methodename)), array('executecli'))) {
$this->error = $langs->trans('CronMethodNotAllowed', $this->methodename, $this->objectname);
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
$this->lastoutput = $this->error;
@ -1102,13 +1173,11 @@ class Cronjob extends CommonObject
}
// Load langs
if (!$error)
{
if (!$error) {
$result = $langs->load($this->module_name);
$result = $langs->load($this->module_name.'@'.$this->module_name, 0, 0, '', 0, 1);
if ($result < 0) // If technical error
{
if ($result < 0) { // If technical error
dol_syslog(get_class($this)."::run_jobs Cannot load module lang file - ".$langs->error, LOG_ERR);
$this->error = $langs->error;
$this->lastoutput = $this->error;
@ -1118,34 +1187,39 @@ class Cronjob extends CommonObject
}
}
if (!$error)
{
if (!$error) {
dol_syslog(get_class($this)."::run_jobs START ".$this->objectname."->".$this->methodename."(".$this->params.");", LOG_DEBUG);
// Create Object for the called module
$object = new $this->objectname($this->db);
if ($this->entity > 0) $object->entity = $this->entity; // We work on a dedicated entity
if ($this->entity > 0) {
$object->entity = $this->entity; // We work on a dedicated entity
}
$params_arr = array();
if (!empty($this->params) || $this->params === '0') {
$params_arr = array_map('trim', explode(",", $this->params));
}
if (!is_array($params_arr))
{
if (!is_array($params_arr)) {
$result = call_user_func(array($object, $this->methodename), $this->params);
} else {
$result = call_user_func_array(array($object, $this->methodename), $params_arr);
}
if ($result === false || (!is_bool($result) && $result != 0))
{
if ($result === false || (!is_bool($result) && $result != 0)) {
$langs->load("errors");
$errmsg = '';
if (!is_array($object->errors) || !in_array($object->error, $object->errors)) $errmsg .= $object->error;
if (is_array($object->errors) && count($object->errors)) $errmsg .= (($errmsg ? ', ' : '').join(', ', $object->errors));
if (empty($errmsg)) $errmsg = $langs->trans('ErrorUnknown');
if (!is_array($object->errors) || !in_array($object->error, $object->errors)) {
$errmsg .= $object->error;
}
if (is_array($object->errors) && count($object->errors)) {
$errmsg .= (($errmsg ? ', ' : '').join(', ', $object->errors));
}
if (empty($errmsg)) {
$errmsg = $langs->trans('ErrorUnknown');
}
dol_syslog(get_class($this)."::run_jobs END result=".$result." error=".$errmsg, LOG_ERR);
@ -1167,8 +1241,7 @@ class Cronjob extends CommonObject
//load lib
$libpath = '/'.strtolower($this->module_name).'/lib/'.$this->libname;
$ret = dol_include_once($libpath);
if ($ret === false)
{
if ($ret === false) {
$this->error = $langs->trans('CronCannotLoadLib').': '.$libpath;
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
$conf->entity = $savcurrententity;
@ -1178,8 +1251,7 @@ class Cronjob extends CommonObject
// Load langs
$result = $langs->load($this->module_name);
$result = $langs->load($this->module_name.'@'.$this->module_name); // If this->module_name was an existing language file, this will make nothing
if ($result < 0) // If technical error
{
if ($result < 0) { // If technical error
dol_syslog(get_class($this)."::run_jobs Cannot load module langs".$langs->error, LOG_ERR);
$conf->entity = $savcurrententity;
return -1;
@ -1187,15 +1259,13 @@ class Cronjob extends CommonObject
dol_syslog(get_class($this)."::run_jobs ".$this->libname."::".$this->methodename."(".$this->params.");", LOG_DEBUG);
$params_arr = explode(", ", $this->params);
if (!is_array($params_arr))
{
if (!is_array($params_arr)) {
$result = call_user_func($this->methodename, $this->params);
} else {
$result = call_user_func_array($this->methodename, $params_arr);
}
if ($result === false || (!is_bool($result) && $result != 0))
{
if ($result === false || (!is_bool($result) && $result != 0)) {
$langs->load("errors");
dol_syslog(get_class($this)."::run_jobs result=".$result, LOG_ERR);
$this->error = $langs->trans('ErrorUnknown');
@ -1211,8 +1281,7 @@ class Cronjob extends CommonObject
}
// Run a command line
if ($this->jobtype == 'command')
{
if ($this->jobtype == 'command') {
global $dolibarr_cron_allow_cli;
if (empty($dolibarr_cron_allow_cli)) {
@ -1222,10 +1291,11 @@ class Cronjob extends CommonObject
$this->lastresult = $langs->trans("ErrorParameterMustBeEnabledToAllwoThisFeature", 'dolibarr_cron_allow_cli');
} else {
$outputdir = $conf->cron->dir_temp;
if (empty($outputdir)) $outputdir = $conf->cronjob->dir_temp;
if (empty($outputdir)) {
$outputdir = $conf->cronjob->dir_temp;
}
if (!empty($outputdir))
{
if (!empty($outputdir)) {
dol_mkdir($outputdir);
$outputfile = $outputdir.'/cronjob.'.$userlogin.'.out'; // File used with popen method
@ -1247,8 +1317,7 @@ class Cronjob extends CommonObject
$this->datelastresult = dol_now();
$this->processing = 0;
$result = $this->update($user); // This include begin/commit
if ($result < 0)
{
if ($result < 0) {
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
$conf->entity = $savcurrententity;
return -1;
@ -1275,14 +1344,12 @@ class Cronjob extends CommonObject
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
$user = new User($this->db);
$result = $user->fetch('', $userlogin);
if ($result < 0)
{
if ($result < 0) {
$this->error = "User Error : ".$user->error;
dol_syslog(get_class($this)."::reprogram_jobs ".$this->error, LOG_ERR);
return -1;
} else {
if (empty($user->id))
{
if (empty($user->id)) {
$this->error = " User user login:".$userlogin." do not exists";
dol_syslog(get_class($this)."::reprogram_jobs ".$this->error, LOG_ERR);
return -1;
@ -1291,17 +1358,17 @@ class Cronjob extends CommonObject
dol_syslog(get_class($this)."::reprogram_jobs datenextrun=".$this->datenextrun." ".dol_print_date($this->datenextrun, 'dayhourrfc')." frequency=".$this->frequency." unitfrequency=".$this->unitfrequency, LOG_DEBUG);
if (empty($this->datenextrun))
{
if (empty($this->datestart)) $this->datenextrun = $now + ($this->frequency * $this->unitfrequency);
else $this->datenextrun = $this->datestart + ($this->frequency * $this->unitfrequency);
if (empty($this->datenextrun)) {
if (empty($this->datestart)) {
$this->datenextrun = $now + ($this->frequency * $this->unitfrequency);
} else {
$this->datenextrun = $this->datestart + ($this->frequency * $this->unitfrequency);
}
}
if ($this->datenextrun < $now && $this->frequency > 0 && $this->unitfrequency > 0)
{
if ($this->datenextrun < $now && $this->frequency > 0 && $this->unitfrequency > 0) {
// Loop until date is after future
while ($this->datenextrun < $now)
{
while ($this->datenextrun < $now) {
$this->datenextrun += ($this->frequency * $this->unitfrequency);
// TODO For exact frequency (every month, every year, ...), use instead a dol_time_plus_duree($time, $duration_value, $duration_unit)
@ -1313,11 +1380,9 @@ class Cronjob extends CommonObject
// Archive job
if ($this->autodelete == 2)
{
if ($this->autodelete == 2) {
if (($this->maxrun > 0 && ($this->nbrun >= $this->maxrun))
|| ($this->dateend && ($this->datenextrun > $this->dateend)))
{
|| ($this->dateend && ($this->datenextrun > $this->dateend))) {
$this->status = self::STATUS_ARCHIVED;
dol_syslog(get_class($this)."::reprogram_jobs Job will be set to archived", LOG_ERR);
}
@ -1377,9 +1442,15 @@ class Cronjob extends CommonObject
}
$statusType = 'status4';
if ($status == 1 && $processing) $statusType = 'status1';
if ($status == 0) $statusType = 'status5';
if ($this->lastresult) $statusType = 'status8';
if ($status == 1 && $processing) {
$statusType = 'status1';
}
if ($status == 0) {
$statusType = 'status5';
}
if ($this->lastresult) {
$statusType = 'status8';
}
return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
}

View File

@ -30,7 +30,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
$langs->loadLangs(array('admin', 'cron'));
// Security check
if (!$user->rights->cron->read) accessforbidden();
if (!$user->rights->cron->read) {
accessforbidden();
}
$id = GETPOST('id', 'int');

View File

@ -34,7 +34,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
// Load translation files required by the page
$langs->loadLangs(array("admin", "cron", "bills", "members"));
if (!$user->rights->cron->read) accessforbidden();
if (!$user->rights->cron->read) {
accessforbidden();
}
$action = GETPOST('action', 'aZ09');
$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
@ -48,12 +50,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortfield) $sortfield = 't.status,t.priority';
if (!$sortorder) $sortorder = 'DESC,ASC';
if (!$sortfield) {
$sortfield = 't.status,t.priority';
}
if (!$sortorder) {
$sortorder = 'DESC,ASC';
}
$mode = GETPOST('mode', 'aZ09');
//Search criteria
@ -82,21 +90,25 @@ $search_array_options = $extrafields->getOptionalsFromPost($object->table_elemen
* Actions
*/
if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
if (GETPOST('cancel', 'alpha')) {
$action = 'list'; $massaction = '';
}
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
$massaction = '';
}
$parameters = array();
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook))
{
if (empty($reshook)) {
// Selection of new fields
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
// Purge search criteria
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers
{
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
$search_label = '';
$search_status = -1;
$search_lastresult = '';
@ -104,20 +116,17 @@ if (empty($reshook))
$search_array_options = array();
}
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
|| GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha'))
{
|| GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
$massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
}
$filter = array();
if (!empty($search_label))
{
if (!empty($search_label)) {
$filter['t.label'] = $search_label;
}
// Delete jobs
if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->cron->delete)
{
if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->cron->delete) {
//Delete cron task
$object = new Cronjob($db);
$object->id = $id;
@ -129,10 +138,8 @@ if (empty($reshook))
}
// Execute jobs
if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->execute)
{
if (!empty($conf->global->CRON_KEY) && $conf->global->CRON_KEY != $securitykey)
{
if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->execute) {
if (!empty($conf->global->CRON_KEY) && $conf->global->CRON_KEY != $securitykey) {
setEventMessages('Security key '.$securitykey.' is wrong', null, 'errors');
$action = '';
} else {
@ -148,12 +155,13 @@ if (empty($reshook))
// Programm next run
$res = $object->reprogram_jobs($user->login, $now);
if ($res > 0)
{
if ($resrunjob >= 0) // We show the result of reprogram only if no error message already reported
{
if ($object->lastresult >= 0) setEventMessages($langs->trans("JobFinished"), null, 'mesgs');
else setEventMessages($langs->trans("JobFinished"), null, 'errors');
if ($res > 0) {
if ($resrunjob >= 0) { // We show the result of reprogram only if no error message already reported
if ($object->lastresult >= 0) {
setEventMessages($langs->trans("JobFinished"), null, 'mesgs');
} else {
setEventMessages($langs->trans("JobFinished"), null, 'errors');
}
}
$action = '';
} else {
@ -162,10 +170,18 @@ if (empty($reshook))
}
$param = '&search_status='.urlencode($search_status);
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
if ($search_label) $param .= '&search_label='.urlencode($search_label);
if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
$param .= '&contextpage='.urlencode($contextpage);
}
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.urlencode($limit);
}
if ($search_label) {
$param .= '&search_label='.urlencode($search_label);
}
if ($optioncss != '') {
$param .= '&optioncss='.urlencode($optioncss);
}
// Add $param from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
@ -182,19 +198,21 @@ if (empty($reshook))
$permissiontodelete = $user->rights->cron->delete;
$uploaddir = $conf->cron->dir_output;
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
if ($permissiontoadd)
{
if ($permissiontoadd) {
$tmpcron = new Cronjob($db);
foreach ($toselect as $id)
{
foreach ($toselect as $id) {
$result = $tmpcron->fetch($id);
if ($result)
{
if ($result) {
$result = 0;
if ($massaction == 'disable') $result = $tmpcron->setStatut(Cronjob::STATUS_DISABLED);
elseif ($massaction == 'enable') $result = $tmpcron->setStatut(Cronjob::STATUS_ENABLED);
if ($massaction == 'disable') {
$result = $tmpcron->setStatut(Cronjob::STATUS_DISABLED);
} elseif ($massaction == 'enable') {
$result = $tmpcron->setStatut(Cronjob::STATUS_ENABLED);
}
//else dol_print_error($db, 'Bad value for massaction');
if ($result < 0) setEventMessages($tmpcron->error, $tmpcron->errors, 'errors');
if ($result < 0) {
setEventMessages($tmpcron->error, $tmpcron->errors, 'errors');
}
} else {
$error++;
}
@ -248,8 +266,12 @@ $sql .= " t.libname,";
$sql .= " t.test";
$sql .= " FROM ".MAIN_DB_PREFIX."cronjob as t";
$sql .= " WHERE entity IN (0,".$conf->entity.")";
if ($search_status >= 0 && $search_status < 2 && $search_status != '') $sql .= " AND t.status = ".(empty($search_status) ? '0' : '1');
if ($search_lastresult != '') $sql .= natural_search("t.lastresult", $search_lastresult, 1);
if ($search_status >= 0 && $search_status < 2 && $search_status != '') {
$sql .= " AND t.status = ".(empty($search_status) ? '0' : '1');
}
if ($search_lastresult != '') {
$sql .= natural_search("t.lastresult", $search_lastresult, 1);
}
//Manage filter
if (is_array($filter) && count($filter) > 0) {
foreach ($filter as $key => $value) {
@ -274,12 +296,10 @@ $sql .= $db->order($sortfield, $sortorder);
// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result);
if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
{
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
$page = 0;
$offset = 0;
}
@ -288,32 +308,48 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
$sql .= $db->plimit($limit + 1, $offset);
$result = $db->query($sql);
if (!$result) dol_print_error($db);
if (!$result) {
dol_print_error($db);
}
$num = $db->num_rows($result);
$arrayofselected = is_array($toselect) ? $toselect : array();
$param = '';
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
if ($search_status) $param .= '&search_status='.urlencode($search_status);
if ($search_label) $param .= '&search_label='.urlencode($search_label);
if ($search_module_name) $param .= '&search_module_name='.urlencode($search_module_name);
if ($search_lastresult) $param .= '&search_lastresult='.urlencode($search_lastresult);
if ($mode) $param .= '&mode='.urlencode($mode);
if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
$param .= '&contextpage='.urlencode($contextpage);
}
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.urlencode($limit);
}
if ($search_status) {
$param .= '&search_status='.urlencode($search_status);
}
if ($search_label) {
$param .= '&search_label='.urlencode($search_label);
}
if ($search_module_name) {
$param .= '&search_module_name='.urlencode($search_module_name);
}
if ($search_lastresult) {
$param .= '&search_lastresult='.urlencode($search_lastresult);
}
if ($mode) {
$param .= '&mode='.urlencode($mode);
}
if ($optioncss != '') {
$param .= '&optioncss='.urlencode($optioncss);
}
// Add $param from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
$stringcurrentdate = $langs->trans("CurrentHour").': '.dol_print_date(dol_now(), 'dayhour');
if ($action == 'delete')
{
if ($action == 'delete') {
print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$id.$param, $langs->trans("CronDelete"), $langs->trans("CronConfirmDelete"), "confirm_delete", '', '', 1);
}
if ($action == 'execute')
{
if ($action == 'execute') {
print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$id.'&securitykey='.$securitykey.$param, $langs->trans("CronExecute"), $langs->trans("CronConfirmExecute"), "confirm_execute", '', '', 1);
}
@ -324,8 +360,12 @@ $arrayofmassactions = array(
'enable'=>$langs->trans("CronStatusActiveBtn"),
'disable'=>$langs->trans("CronStatusInactiveBtn"),
);
if ($user->rights->mymodule->delete) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
if ($user->rights->mymodule->delete) {
$arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
}
if (in_array($massaction, array('presend', 'predelete'))) {
$arrayofmassactions = array();
}
$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
if ($mode == 'modulesetup') {
@ -337,7 +377,9 @@ if ($mode == 'modulesetup') {
}
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" name="search_form">'."\n";
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">';
@ -362,7 +404,9 @@ print_barre_liste($pagetitle, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $
$text = $langs->trans("HoursOnThisPageAreOnServerTZ").' '.$stringcurrentdate.'<br>';
if (!empty($conf->global->CRON_WARNING_DELAY_HOURS)) $text .= $langs->trans("WarningCronDelayed", $conf->global->CRON_WARNING_DELAY_HOURS);
if (!empty($conf->global->CRON_WARNING_DELAY_HOURS)) {
$text .= $langs->trans("WarningCronDelayed", $conf->global->CRON_WARNING_DELAY_HOURS);
}
print info_admin($text);
print '<br>';
@ -417,18 +461,20 @@ print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", "", $param, '
print "</tr>\n";
if ($num > 0)
{
if ($num > 0) {
// Loop on each job
$now = dol_now();
$i = 0;
while ($i < min($num, $limit))
{
while ($i < min($num, $limit)) {
$obj = $db->fetch_object($result);
if (empty($obj)) break;
if (!verifCond($obj->test)) continue; // Discard line with test = false
if (empty($obj)) {
break;
}
if (!verifCond($obj->test)) {
continue; // Discard line with test = false
}
$object->id = $obj->rowid;
$object->ref = $obj->rowid;
@ -450,8 +496,7 @@ if ($num > 0)
// Label
print '<td class="tdoverflowmax300">';
if (!empty($obj->label))
{
if (!empty($obj->label)) {
$object->ref = $langs->trans($obj->label);
print '<span title="'.dol_escape_htmltag($langs->trans($obj->label)).'">'.$object->getNomUrl(0, '', 1).'</span>';
$object->ref = $obj->rowid;
@ -466,8 +511,7 @@ if ($num > 0)
print '</td>';
print '<td>';
if ($obj->jobtype == 'method')
{
if ($obj->jobtype == 'method') {
$text = $langs->trans("CronClass");
$texttoshow = $langs->trans('CronModule').': '.$obj->module_name.'<br>';
$texttoshow .= $langs->trans('CronClass').': '.$obj->classesname.'<br>';
@ -475,8 +519,7 @@ if ($num > 0)
$texttoshow .= $langs->trans('CronMethod').': '.$obj->methodename;
$texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$obj->params;
$texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($obj->note);
} elseif ($obj->jobtype == 'command')
{
} elseif ($obj->jobtype == 'command') {
$text = $langs->trans('CronCommand');
$texttoshow = $langs->trans('CronCommand').': '.dol_trunc($obj->command);
$texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$obj->params;
@ -486,28 +529,48 @@ if ($num > 0)
print '</td>';
print '<td>';
if ($obj->unitfrequency == "60") print $langs->trans('CronEach')." ".($obj->frequency)." ".$langs->trans('Minutes');
if ($obj->unitfrequency == "3600") print $langs->trans('CronEach')." ".($obj->frequency)." ".$langs->trans('Hours');
if ($obj->unitfrequency == "86400") print $langs->trans('CronEach')." ".($obj->frequency)." ".$langs->trans('Days');
if ($obj->unitfrequency == "604800") print $langs->trans('CronEach')." ".($obj->frequency)." ".$langs->trans('Weeks');
if ($obj->unitfrequency == "60") {
print $langs->trans('CronEach')." ".($obj->frequency)." ".$langs->trans('Minutes');
}
if ($obj->unitfrequency == "3600") {
print $langs->trans('CronEach')." ".($obj->frequency)." ".$langs->trans('Hours');
}
if ($obj->unitfrequency == "86400") {
print $langs->trans('CronEach')." ".($obj->frequency)." ".$langs->trans('Days');
}
if ($obj->unitfrequency == "604800") {
print $langs->trans('CronEach')." ".($obj->frequency)." ".$langs->trans('Weeks');
}
print '</td>';
print '<td class="center">';
if (!empty($obj->datestart)) { print dol_print_date($db->jdate($obj->datestart), 'dayhour'); }
if (!empty($obj->datestart)) {
print dol_print_date($db->jdate($obj->datestart), 'dayhour');
}
print '</td>';
print '<td class="center">';
if (!empty($obj->dateend)) { print dol_print_date($db->jdate($obj->dateend), 'dayhour'); }
if (!empty($obj->dateend)) {
print dol_print_date($db->jdate($obj->dateend), 'dayhour');
}
print '</td>';
print '<td class="right">';
if (!empty($obj->nbrun)) { print $obj->nbrun; } else {print '0'; }
if (!empty($obj->maxrun)) { print ' <span class="'.$langs->trans("Max").'">/ '.$obj->maxrun.'</span>'; }
if (!empty($obj->nbrun)) {
print $obj->nbrun;
} else {
print '0';
}
if (!empty($obj->maxrun)) {
print ' <span class="'.$langs->trans("Max").'">/ '.$obj->maxrun.'</span>';
}
print '</td>';
// Date start last run
print '<td class="center">';
if (!empty($datelastrun)) { print dol_print_date($datelastrun, 'dayhoursec'); }
if (!empty($datelastrun)) {
print dol_print_date($datelastrun, 'dayhoursec');
}
print '</td>';
// Duration
@ -521,27 +584,38 @@ if ($num > 0)
// Return code of last run
print '<td class="center">';
if ($obj->lastresult != '') {
if (empty($obj->lastresult)) print $obj->lastresult;
else print '<span class="error">'.dol_trunc($obj->lastresult).'</div>';
if (empty($obj->lastresult)) {
print $obj->lastresult;
} else {
print '<span class="error">'.dol_trunc($obj->lastresult).'</div>';
}
}
print '</td>';
// Output of last run
print '<td>';
if (!empty($obj->lastoutput)) {print dol_trunc(nl2br($obj->lastoutput), 50); }
if (!empty($obj->lastoutput)) {
print dol_trunc(nl2br($obj->lastoutput), 50);
}
print '</td>';
print '<td class="center">';
if (!empty($obj->datenextrun)) {
$datenextrun = $db->jdate($obj->datenextrun);
if (empty($obj->status)) print '<span class="opacitymedium">';
print dol_print_date($datenextrun, 'dayhoursec');
if ($obj->status == Cronjob::STATUS_ENABLED)
{
if ($obj->maxrun && $obj->nbrun >= $obj->maxrun) print img_warning($langs->trans("MaxRunReached"));
elseif ($datenextrun && $datenextrun < $now) print img_warning($langs->trans("Late"));
if (empty($obj->status)) {
print '<span class="opacitymedium">';
}
print dol_print_date($datenextrun, 'dayhoursec');
if ($obj->status == Cronjob::STATUS_ENABLED) {
if ($obj->maxrun && $obj->nbrun >= $obj->maxrun) {
print img_warning($langs->trans("MaxRunReached"));
} elseif ($datenextrun && $datenextrun < $now) {
print img_warning($langs->trans("Late"));
}
}
if (empty($obj->status)) {
print '</span>';
}
if (empty($obj->status)) print '</span>';
}
print '</td>';
@ -553,20 +627,17 @@ if ($num > 0)
print '<td class="nowraponall right">';
$backtopage = urlencode($_SERVER["PHP_SELF"].'?'.$param.($sortfield ? '&sortfield='.$sortfield : '').($sortorder ? '&sortorder='.$sortorder : ''));
if ($user->rights->cron->create)
{
if ($user->rights->cron->create) {
print '<a class="editfielda" href="'.DOL_URL_ROOT."/cron/card.php?id=".$obj->rowid.'&action=edit&token='.newToken().($sortfield ? '&sortfield='.$sortfield : '').($sortorder ? '&sortorder='.$sortorder : '').$param;
print "&backtopage=".$backtopage."\" title=\"".dol_escape_htmltag($langs->trans('Edit'))."\">".img_picto($langs->trans('Edit'), 'edit')."</a> &nbsp;";
}
if ($user->rights->cron->delete)
{
if ($user->rights->cron->delete) {
print '<a class="reposition" href="'.$_SERVER["PHP_SELF"]."?id=".$obj->rowid.'&action=delete&token='.newToken().($page ? '&page='.$page : '').($sortfield ? '&sortfield='.$sortfield : '').($sortorder ? '&sortorder='.$sortorder : '').$param;
print "\" title=\"".dol_escape_htmltag($langs->trans('CronDelete'))."\">".img_picto($langs->trans('CronDelete'), 'delete', '', false, 0, 0, '', 'marginleftonly')."</a> &nbsp; ";
} else {
print "<a href=\"#\" title=\"".dol_escape_htmltag($langs->trans('NotEnoughPermissions'))."\">".img_picto($langs->trans('NotEnoughPermissions'), 'delete', '', false, 0, 0, '', 'marginleftonly')."</a> &nbsp; ";
}
if ($user->rights->cron->execute)
{
if ($user->rights->cron->execute) {
if (!empty($obj->status)) {
print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=execute';
print (empty($conf->global->CRON_KEY) ? '' : '&securitykey='.$conf->global->CRON_KEY);
@ -579,10 +650,11 @@ if ($num > 0)
} else {
print '<a href="#" class="cursornotallowed" title="'.dol_escape_htmltag($langs->trans('NotEnoughPermissions')).'">'.img_picto($langs->trans('NotEnoughPermissions'), "playdisabled", '', false, 0, 0, '', 'marginleftonly').'</a>';
}
if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
{
if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
$selected = 0;
if (in_array($obj->rowid, $arrayofselected)) $selected = 1;
if (in_array($obj->rowid, $arrayofselected)) {
$selected = 1;
}
print ' &nbsp; <input id="cb'.$obj->rowid.'" class="flat checkforselect valignmiddle" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
}
print '</td>';