Some debug into cron module:

- Because cron is a module, constant must start with CRON_.
- Miscellanous fixes.
- For external link to run jobs from url, we must forge url using conf
file and not autodetect url.
This commit is contained in:
Laurent Destailleur 2013-03-23 19:23:17 +01:00
parent 9fe0d2cdd2
commit c3589e9785
10 changed files with 297 additions and 261 deletions

View File

@ -41,7 +41,7 @@ class FormCron extends Form
return 1; return 1;
} }
/** /**
* Display On Off selector * Display On Off selector
* *
@ -53,7 +53,7 @@ class FormCron extends Form
function select_typejob($htmlname,$selected=0,$readonly=0) function select_typejob($htmlname,$selected=0,$readonly=0)
{ {
global $langs; global $langs;
$langs->load('cron@cron'); $langs->load('cron@cron');
if (!empty($readonly)) { if (!empty($readonly)) {
if ($selected=='command') { if ($selected=='command') {
@ -68,26 +68,26 @@ class FormCron extends Form
$out.='</SELECT>'; $out.='</SELECT>';
} }
}else { }else {
$out='<SELECT name="'.$htmlname.'" id="'.$htmlname.'" />'; $out='<SELECT class="flat" name="'.$htmlname.'" id="'.$htmlname.'" />';
if ($selected=='command') { if ($selected=='command') {
$selected_attr=' selected=\"selected\" '; $selected_attr=' selected=\"selected\" ';
} else { } else {
$selected_attr=''; $selected_attr='';
} }
$out.= '<OPTION value="command" '.$selected_attr.'>'.$langs->trans('CronType_command').'</OPTION>'; $out.= '<OPTION value="command" '.$selected_attr.'>'.$langs->trans('CronType_command').'</OPTION>';
if ($selected=='method') { if ($selected=='method') {
$selected_attr=' selected=\"selected\" '; $selected_attr=' selected=\"selected\" ';
} else { } else {
$selected_attr=''; $selected_attr='';
} }
$out.= '<OPTION value="method" '.$selected_attr.'>'.$langs->trans('CronType_method').'</OPTION>'; $out.= '<OPTION value="method" '.$selected_attr.'>'.$langs->trans('CronType_method').'</OPTION>';
$out.='</SELECT>'; $out.='</SELECT>';
} }
return $out; return $out;
} }
} }

View File

@ -15,19 +15,18 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** /**
* \file cron/lib/cron.lib.php * \file cron/lib/cron.lib.php
* \brief Ensemble de fonctions de base pour le module jobs * \brief Function for module cron
* \ingroup jobs * \ingroup cron
*/ */
/** /**
* Return array of tabs to used on pages for third parties cards. * Return array of tabs to used on pages to setup cron module.
* *
* @param Object $object Object company shown
* @return array Array of tabs * @return array Array of tabs
*/ */
function cronadmin_prepare_head() function cronadmin_prepare_head()
{ {
global $langs, $conf, $user; global $langs, $conf, $user;
@ -35,18 +34,24 @@ function cronadmin_prepare_head()
$head = array(); $head = array();
$head[$h][0] = dol_buildpath('/cron/admin/cron.php', 1); $head[$h][0] = dol_buildpath('/cron/admin/cron.php', 1);
$head[$h][1] = $langs->trans("CronSetup"); $head[$h][1] = $langs->trans("Miscellanous");
$head[$h][2] = 'setup'; $head[$h][2] = 'setup';
$h++; $h++;
complete_head_from_modules($conf, $langs, $object, $head, $h, 'cronadmin'); complete_head_from_modules($conf, $langs, $object, $head, $h, 'cronadmin');
complete_head_from_modules($conf, $langs, $object, $head, $h, 'cronadmin', 'remove'); complete_head_from_modules($conf, $langs, $object, $head, $h, 'cronadmin', 'remove');
return $head; return $head;
} }
/**
* Return array of tabs to used on a cron job
*
* @param Object $object Object cron
* @return array Array of tabs
*/
function cron_prepare_head($object) function cron_prepare_head($object)
{ {
global $langs, $conf, $user; global $langs, $conf, $user;
@ -59,7 +64,7 @@ function cron_prepare_head($object)
$h++; $h++;
$head[$h][0] = dol_buildpath('/cron/info.php', 1).'?id='.$object->id; $head[$h][0] = dol_buildpath('/cron/info.php', 1).'?id='.$object->id;
$head[$h][1] = $langs->trans("CronInfoPage"); $head[$h][1] = $langs->trans("Info");
$head[$h][2] = 'info'; $head[$h][2] = 'info';
$h++; $h++;

View File

@ -43,7 +43,7 @@ class modCron extends DolibarrModules
// Family can be 'crm','financial','hr','projects','products','ecm','technic','other' // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
// It is used to group modules in module setup page // It is used to group modules in module setup page
$this->family = "technic"; $this->family = "base";
// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
$this->name = preg_replace('/^mod/i','',get_class($this)); $this->name = preg_replace('/^mod/i','',get_class($this));
$this->description = "Enable the Dolibarr cron service"; $this->description = "Enable the Dolibarr cron service";
@ -70,9 +70,9 @@ class modCron extends DolibarrModules
// Constantes // Constantes
//----------- //-----------
$this->const = array( $this->const = array(
0=>array( 0=>array(
'MAIN_CRON_KEY', 'CRON_KEY',
'chaine', 'chaine',
'', '',
'CRON KEY', 'CRON KEY',
@ -93,25 +93,25 @@ class modCron extends DolibarrModules
$this->rights = array(); // Permission array used by this module $this->rights = array(); // Permission array used by this module
$this->rights_class = 'cron'; $this->rights_class = 'cron';
$r=0; $r=0;
$this->rights[$r][0] = 23001; $this->rights[$r][0] = 23001;
$this->rights[$r][1] = 'Read cron jobs'; $this->rights[$r][1] = 'Read cron jobs';
$this->rights[$r][3] = 1; $this->rights[$r][3] = 1;
$this->rights[$r][4] = 'read'; $this->rights[$r][4] = 'read';
$r++; $r++;
$this->rights[$r][0] = 23002; $this->rights[$r][0] = 23002;
$this->rights[$r][1] = 'Create cron Jobs'; $this->rights[$r][1] = 'Create cron Jobs';
$this->rights[$r][3] = 0; $this->rights[$r][3] = 0;
$this->rights[$r][4] = 'create'; $this->rights[$r][4] = 'create';
$r++; $r++;
$this->rights[$r][0] = 23003; $this->rights[$r][0] = 23003;
$this->rights[$r][1] = 'Delete cron Jobs'; $this->rights[$r][1] = 'Delete cron Jobs';
$this->rights[$r][3] = 0; $this->rights[$r][3] = 0;
$this->rights[$r][4] = 'delete'; $this->rights[$r][4] = 'delete';
$r++; $r++;
$this->rights[$r][0] = 23004; $this->rights[$r][0] = 23004;
$this->rights[$r][1] = 'Execute cron Jobs'; $this->rights[$r][1] = 'Execute cron Jobs';
$this->rights[$r][3] = 0; $this->rights[$r][3] = 0;
@ -131,7 +131,7 @@ class modCron extends DolibarrModules
'target'=>'', 'target'=>'',
'user'=>2); // 0=Menu for internal users, 1=external users, 2=both 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
$r++; $r++;
$this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=modulesadmintools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=modulesadmintools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
'type'=>'left', // This is a Left menu entry 'type'=>'left', // This is a Left menu entry
'titre'=>'CronListInactive', 'titre'=>'CronListInactive',

View File

@ -1,28 +1,28 @@
<?php <?php
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.org> * Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.org>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** /**
* \file cron/admin/cron.php * \file cron/admin/cron.php
* \ingroup cron * \ingroup cron
*/ */
// Dolibarr environment // Dolibarr environment
$res = @include("../../main.inc.php"); // From htdocs directory $res = @include("../../main.inc.php"); // From htdocs directory
@ -44,7 +44,7 @@ if (!empty($actionsave))
$db->begin(); $db->begin();
$i+=dolibarr_set_const($db,'MAIN_CRON_KEY',trim(GETPOST("MAIN_CRON_KEY")),'chaine',0,'',0); $i+=dolibarr_set_const($db,'CRON_KEY',trim(GETPOST("CRON_KEY")),'chaine',0,'',0);
if ($i >= 1) if ($i >= 1)
{ {
@ -61,7 +61,7 @@ if (!empty($actionsave))
/* /*
* View * View
*/ */
llxHeader(); llxHeader();
@ -70,6 +70,7 @@ print_fiche_titre($langs->trans("CronSetup"),$linkback,'setup');
// Configuration header // Configuration header
$head = cronadmin_prepare_head(); $head = cronadmin_prepare_head();
dol_fiche_head($head,'setup',$langs->trans("Module2300Name"),0,'cron'); dol_fiche_head($head,'setup',$langs->trans("Module2300Name"),0,'cron');
print "<br>\n"; print "<br>\n";
@ -86,7 +87,7 @@ print "</tr>";
print '<tr class="impair">'; print '<tr class="impair">';
print '<td class="fieldrequired">'.$langs->trans("KeyForCronAccess").'</td>'; print '<td class="fieldrequired">'.$langs->trans("KeyForCronAccess").'</td>';
print '<td><input type="text" class="flat" id="MAIN_CRON_KEY" name="MAIN_CRON_KEY" value="'. (GETPOST('MAIN_CRON_KEY')?GETPOST('MAIN_CRON_KEY'):(! empty($conf->global->MAIN_CRON_KEY)?$conf->global->MAIN_CRON_KEY:'')) . '" size="40">'; print '<td><input type="text" class="flat" id="CRON_KEY" name="CRON_KEY" value="'. (GETPOST('CRON_KEY')?GETPOST('CRON_KEY'):(! empty($conf->global->CRON_KEY)?$conf->global->CRON_KEY:'')) . '" size="40">';
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"'); print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
print '</td>'; print '</td>';
@ -101,38 +102,42 @@ print '</center>';
print '</form>'; print '</form>';
dol_fiche_end();
print '<br><br>'; print '<br><br>';
// Define $urlwithroot
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
// Cron launch // Cron launch
print '<u>'.$langs->trans("URLToLaunchCronJobs").':</u><br>'; print '<u>'.$langs->trans("URLToLaunchCronJobs").':</u><br>';
$url=dol_buildpath('/public/cron/cron_run_jobs.php',1).(empty($conf->global->MAIN_CRON_KEY)?'':'?securitykey='.$conf->global->MAIN_CRON_KEY.'&').'userlogin='.$user->login; $url=$urlwithroot.'/public/cron/cron_run_jobs.php'.(empty($conf->global->CRON_KEY)?'':'?securitykey='.$conf->global->CRON_KEY.'&').'userlogin='.$user->login;
print img_picto('','object_globe.png').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n"; print img_picto('','object_globe.png').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
print ' '.$langs->trans("OrToLaunchASpecificJob").'<br>'; print ' '.$langs->trans("OrToLaunchASpecificJob").'<br>';
$url=dol_buildpath('/public/cron/cron_run_jobs.php',1).(empty($conf->global->MAIN_CRON_KEY)?'':'?securitykey='.$conf->global->MAIN_CRON_KEY.'&').'userlogin='.$user->login.'&id=cronjobid'; $url=$urlwithroot.'/public/cron/cron_run_jobs.php'.(empty($conf->global->CRON_KEY)?'':'?securitykey='.$conf->global->CRON_KEY.'&').'userlogin='.$user->login.'&id=cronjobid';
print img_picto('','object_globe.png').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n"; print img_picto('','object_globe.png').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
print '<br>'; print '<br>';
print '<br>';
$linuxlike=1; $linuxlike=1;
if (preg_match('/^win/i',PHP_OS)) $linuxlike=0; if (preg_match('/^win/i',PHP_OS)) $linuxlike=0;
if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0; if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0;
if ($linuxlike) {
print $langs->trans("CronExplainHowToRunUnix");
} else {
print $langs->trans("CronExplainHowToRunWin");
}
print '<br>'; print '<br>';
print '<u>'.$langs->trans("FileToLaunchCronJobs").':</u><br>'; print '<u>'.$langs->trans("FileToLaunchCronJobs").':</u><br>';
$file='/scripts/cron/cron_run_jobs.php'.' '.(empty($conf->global->MAIN_CRON_KEY)?'securitykey':''.$conf->global->MAIN_CRON_KEY.'').' '.$user->login.' cronjobid(optionnal)';
if ($linuxlike) { $file='/scripts/cron/cron_run_jobs.php'.' '.(empty($conf->global->CRON_KEY)?'securitykey':''.$conf->global->CRON_KEY.'').' '.$user->login.' [cronjobid]';
print 'user@host:'.DOL_DOCUMENT_ROOT.'$ php ..'.$file."<br>\n"; print '<textarea rows="'.ROWS_2.'" cols="120">..'.$file."</textarea><br>\n";
} else {
print DOL_DOCUMENT_ROOT.'> php ..'.$file."<br>\n";
}
print '<br>'; print '<br>';
print $langs->trans("Note").': ';
if ($linuxlike) {
print $langs->trans("CronExplainHowToRunUnix");
} else {
print $langs->trans("CronExplainHowToRunWin");
}
@ -149,7 +154,7 @@ if (! empty($conf->use_javascript_ajax))
generic: true generic: true
}, },
function(token) { function(token) {
$("#MAIN_CRON_KEY").val(token); $("#CRON_KEY").val(token);
}); });
}); });
});'; });';

View File

@ -42,6 +42,11 @@ $action=GETPOST('action','alpha');
$confirm=GETPOST('confirm','alpha'); $confirm=GETPOST('confirm','alpha');
$cancel=GETPOST('cancel'); $cancel=GETPOST('cancel');
/*
* Actions
*/
$object = new Cronjob($db); $object = new Cronjob($db);
if (!empty($id)) { if (!empty($id)) {
$result=$object->fetch($id); $result=$object->fetch($id);
@ -56,13 +61,13 @@ if(!empty($cancel)) {
}else { }else {
Header ( "Location: ".dol_buildpath('/cron/cron/list.php',1).'?status=1'); Header ( "Location: ".dol_buildpath('/cron/cron/list.php',1).'?status=1');
} }
} }
// Delete jobs // 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); $result = $object->delete($user);
if ($result < 0) { if ($result < 0) {
@ -105,7 +110,7 @@ if ($action=='add') {
$object->dateend=dol_mktime(GETPOST('dateendhour','int'), GETPOST('dateendmin','int'), 0, GETPOST('dateendmonth','int'), GETPOST('dateendday','int'), GETPOST('dateendyear','int')); $object->dateend=dol_mktime(GETPOST('dateendhour','int'), GETPOST('dateendmin','int'), 0, GETPOST('dateendmonth','int'), GETPOST('dateendday','int'), GETPOST('dateendyear','int'));
$object->unitfrequency=GETPOST('unitfrequency','int'); $object->unitfrequency=GETPOST('unitfrequency','int');
$object->frequency=$object->unitfrequency * GETPOST('nbfrequency','int'); $object->frequency=$object->unitfrequency * GETPOST('nbfrequency','int');
//Ajout de la tache cron //Ajout de la tache cron
$result = $object->create($user); $result = $object->create($user);
@ -138,7 +143,7 @@ if ($action=='update') {
$object->dateend=dol_mktime(GETPOST('dateendhour','int'), GETPOST('dateendmin','int'), 0, GETPOST('dateendmonth','int'), GETPOST('dateendday','int'), GETPOST('dateendyear','int')); $object->dateend=dol_mktime(GETPOST('dateendhour','int'), GETPOST('dateendmin','int'), 0, GETPOST('dateendmonth','int'), GETPOST('dateendday','int'), GETPOST('dateendyear','int'));
$object->unitfrequency=GETPOST('unitfrequency','int'); $object->unitfrequency=GETPOST('unitfrequency','int');
$object->frequency=$object->unitfrequency * GETPOST('nbfrequency','int'); $object->frequency=$object->unitfrequency * GETPOST('nbfrequency','int');
//Ajout de la tache cron //Ajout de la tache cron
$result = $object->update($user); $result = $object->update($user);
@ -187,16 +192,23 @@ if ($action=='inactive') {
} }
/*
* View
*/
/*
* View
*/
$form = new Form($db);
$formCron = new FormCron($db);
llxHeader('',$langs->trans("CronAdd")); llxHeader('',$langs->trans("CronAdd"));
if ($action=='edit' || empty($action) || $action=='delete' || $action=='execute') { if ($action=='edit' || empty($action) || $action=='delete' || $action=='execute')
{
$head=cron_prepare_head($object); $head=cron_prepare_head($object);
dol_fiche_head($head, 'card', $langs->trans("CronTask"), 0, 'bill'); dol_fiche_head($head, 'card', $langs->trans("CronTask"), 0, 'bill');
} elseif ($action=='create') { }
elseif ($action=='create')
{
print_fiche_titre($langs->trans("CronTask"),'','setup'); print_fiche_titre($langs->trans("CronTask"),'','setup');
} }
@ -223,9 +235,6 @@ if ($conf->use_javascript_ajax)
print '</script>'."\n"; print '</script>'."\n";
} }
$form = new Form($db);
$formCron = new FormCron($db);
if ($action == 'delete') if ($action == 'delete')
{ {
$ret=$form->form_confirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("CronDelete"),$langs->trans("CronConfirmDelete"),"confirm_delete",'','',1); $ret=$form->form_confirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("CronDelete"),$langs->trans("CronConfirmDelete"),"confirm_delete",'','',1);
@ -243,33 +252,37 @@ if ($action == 'execute'){
/* /*
* Create Template * Create Template
*/ */
if (empty($object->status)) { if (empty($object->status) && $action != 'create')
{
dol_htmloutput_mesg($langs->trans("CronTaskInactive"),'','warning',1); dol_htmloutput_mesg($langs->trans("CronTaskInactive"),'','warning',1);
} }
if (($action=="create") || ($action=="edit")) { if (($action=="create") || ($action=="edit")) {
print '<form name="cronform" action="'.$_SERVER["PHP_SELF"].'" method="post">'; print '<form name="cronform" action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'."\n"; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'."\n";
if (!empty($object->id)) { if (!empty($object->id))
{
print '<input type="hidden" name="action" value="update">'."\n"; print '<input type="hidden" name="action" value="update">'."\n";
print '<input type="hidden" name="id" value="'.$object->id.'">'."\n"; print '<input type="hidden" name="id" value="'.$object->id.'">'."\n";
} else { }
else
{
print '<input type="hidden" name="action" value="add">'."\n"; print '<input type="hidden" name="action" value="add">'."\n";
} }
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tr><td width="30%">'; print '<tr><td width="30%">';
print $langs->trans('CronLabel')."</td>"; print $langs->trans('CronLabel')."</td>";
print "<td><input type=\"text\" size=\"20\" name=\"label\" value=\"".$object->label."\" /> "; print "<td><input type=\"text\" class=\"flat\" size=\"20\" name=\"label\" value=\"".$object->label."\" /> ";
print "</td>"; print "</td>";
print "<td>"; print "<td>";
print "</td>"; print "</td>";
print "</tr>\n"; print "</tr>\n";
print "<tr><td>"; print "<tr><td>";
print $langs->trans('CronType')."</td><td>"; print $langs->trans('CronType')."</td><td>";
print $formCron->select_typejob('jobtype',$object->jobtype); print $formCron->select_typejob('jobtype',$object->jobtype);
@ -290,7 +303,7 @@ if (($action=="create") || ($action=="edit")) {
print "<td>"; print "<td>";
print "</td>"; print "</td>";
print "</tr>\n"; print "</tr>\n";
print "<tr><td>"; print "<tr><td>";
print $langs->trans('CronDtEnd')."</td><td>"; print $langs->trans('CronDtEnd')."</td><td>";
if(!empty($object->dateend)){ if(!empty($object->dateend)){
@ -303,7 +316,7 @@ if (($action=="create") || ($action=="edit")) {
print "<td>"; print "<td>";
print "</td>"; print "</td>";
print "</tr>\n"; print "</tr>\n";
print "<tr><td>"; print "<tr><td>";
print $langs->trans('CronPriority')."</td>"; print $langs->trans('CronPriority')."</td>";
$priority=0; $priority=0;
@ -315,10 +328,10 @@ if (($action=="create") || ($action=="edit")) {
print "<td>"; print "<td>";
print "</td>"; print "</td>";
print "</tr>\n"; print "</tr>\n";
print "<tr><td>"; print "<tr><td>";
print $langs->trans('CronEvery')."</td>"; print $langs->trans('CronEvery')."</td>";
print "<td><select name=\"nbfrequency\">"; print "<td><select class=\"flat\" name=\"nbfrequency\">";
for($i=1; $i<=60; $i++){ for($i=1; $i<=60; $i++){
if(($object->frequency/$object->unitfrequency) == $i){ if(($object->frequency/$object->unitfrequency) == $i){
print "<option value='".$i."' selected='selected'>".$i."</option>"; print "<option value='".$i."' selected='selected'>".$i."</option>";
@ -327,7 +340,7 @@ if (($action=="create") || ($action=="edit")) {
print "<option value='".$i."'>".$i."</option>"; print "<option value='".$i."'>".$i."</option>";
} }
} }
$input = "<input type=\"radio\" name=\"unitfrequency\" value=\"60\" id=\"frequency_minute\" "; $input = "<input class=\"flat\" type=\"radio\" name=\"unitfrequency\" value=\"60\" id=\"frequency_minute\" ";
if($object->unitfrequency=="60"){ if($object->unitfrequency=="60"){
$input .= ' checked="checked" />'; $input .= ' checked="checked" />';
} }
@ -337,7 +350,7 @@ if (($action=="create") || ($action=="edit")) {
$input .= "<label for=\"frequency_minute\">".$langs->trans('Minutes')."</label>"; $input .= "<label for=\"frequency_minute\">".$langs->trans('Minutes')."</label>";
print $input; print $input;
$input = "<input type=\"radio\" name=\"unitfrequency\" value=\"3600\" id=\"frequency_heures\" "; $input = "<input class=\"flat\" type=\"radio\" name=\"unitfrequency\" value=\"3600\" id=\"frequency_heures\" ";
if($object->unitfrequency=="3600"){ if($object->unitfrequency=="3600"){
$input .= ' checked="checked" />'; $input .= ' checked="checked" />';
} }
@ -347,7 +360,7 @@ if (($action=="create") || ($action=="edit")) {
$input .= "<label for=\"frequency_heures\">".$langs->trans('Hours')."</label>"; $input .= "<label for=\"frequency_heures\">".$langs->trans('Hours')."</label>";
print $input; print $input;
$input = "<input type=\"radio\" name=\"unitfrequency\" value=\"86400\" id=\"frequency_jours\" "; $input = "<input class=\"flat\" type=\"radio\" name=\"unitfrequency\" value=\"86400\" id=\"frequency_jours\" ";
if($object->unitfrequency=="86400"){ if($object->unitfrequency=="86400"){
$input .= ' checked="checked" />'; $input .= ' checked="checked" />';
} }
@ -370,11 +383,10 @@ if (($action=="create") || ($action=="edit")) {
print "<td>"; print "<td>";
print "</td>"; print "</td>";
print "</tr>\n"; print "</tr>\n";
print '<tr class="blockmethod"><td>'; print '<tr class="blockmethod"><td>';
print $langs->trans('CronModule')."</td><td>"; print $langs->trans('CronModule')."</td><td>";
print "<input type=\"text\" size=\"20\" name=\"module_name\" value=\"".$object->module_name."\" /> "; print "<input class=\"flat\" type=\"text\" size=\"20\" name=\"module_name\" value=\"".$object->module_name."\" /> ";
print "</td>"; print "</td>";
print "<td>"; print "<td>";
print $form->textwithpicto('',$langs->trans("CronModuleHelp"),1,'help'); print $form->textwithpicto('',$langs->trans("CronModuleHelp"),1,'help');
@ -383,7 +395,7 @@ if (($action=="create") || ($action=="edit")) {
print '<tr class="blockmethod"><td>'; print '<tr class="blockmethod"><td>';
print $langs->trans('CronClassFile')."</td><td>"; print $langs->trans('CronClassFile')."</td><td>";
print "<input type=\"text\" size=\"20\" name=\"classesname\" value=\"".$object->classesname."\" /> "; print "<input class=\"flat\" type=\"text\" size=\"20\" name=\"classesname\" value=\"".$object->classesname."\" /> ";
print "</td>"; print "</td>";
print "<td>"; print "<td>";
print $form->textwithpicto('',$langs->trans("CronClassFileHelp"),1,'help'); print $form->textwithpicto('',$langs->trans("CronClassFileHelp"),1,'help');
@ -392,7 +404,7 @@ if (($action=="create") || ($action=="edit")) {
print '<tr class="blockmethod"><td>'; print '<tr class="blockmethod"><td>';
print $langs->trans('CronObject')."</td><td>"; print $langs->trans('CronObject')."</td><td>";
print "<input type=\"text\" size=\"20\" name=\"objectname\" value=\"".$object->objectname."\" /> "; print "<input class=\"flat\" type=\"text\" size=\"20\" name=\"objectname\" value=\"".$object->objectname."\" /> ";
print "</td>"; print "</td>";
print "<td>"; print "<td>";
print $form->textwithpicto('',$langs->trans("CronObjectHelp"),1,'help'); print $form->textwithpicto('',$langs->trans("CronObjectHelp"),1,'help');
@ -401,7 +413,7 @@ if (($action=="create") || ($action=="edit")) {
print '<tr class="blockmethod"><td>'; print '<tr class="blockmethod"><td>';
print $langs->trans('CronMethod')."</td><td>"; print $langs->trans('CronMethod')."</td><td>";
print "<input type=\"text\" size=\"20\" name=\"methodename\" value=\"".$object->methodename."\" /> "; print "<input class=\"flat\" type=\"text\" size=\"20\" name=\"methodename\" value=\"".$object->methodename."\" /> ";
print "</td>"; print "</td>";
print "<td>"; print "<td>";
print $form->textwithpicto('',$langs->trans("CronMethodHelp"),1,'help'); print $form->textwithpicto('',$langs->trans("CronMethodHelp"),1,'help');
@ -410,22 +422,22 @@ if (($action=="create") || ($action=="edit")) {
print '<tr class="blockmethod"><td>'; print '<tr class="blockmethod"><td>';
print $langs->trans('CronArgs')."</td><td>"; print $langs->trans('CronArgs')."</td><td>";
print "<input type=\"text\" size=\"20\" name=\"params\" value=\"".$object->params."\" /> "; print "<input class=\"flat\" type=\"text\" size=\"20\" name=\"params\" value=\"".$object->params."\" /> ";
print "</td>"; print "</td>";
print "<td>"; print "<td>";
print $form->textwithpicto('',$langs->trans("CronArgsHelp"),1,'help'); print $form->textwithpicto('',$langs->trans("CronArgsHelp"),1,'help');
print "</td>"; print "</td>";
print "</tr>\n"; print "</tr>\n";
print '<tr class="blockcommand"><td>'; print '<tr class="blockcommand"><td>';
print $langs->trans('CronCommand')."</td><td>"; print $langs->trans('CronCommand')."</td><td>";
print "<input type=\"text\" size=\"50\" name=\"command\" value=\"".$object->command."\" /> "; print "<input class=\"flat\" type=\"text\" size=\"50\" name=\"command\" value=\"".$object->command."\" /> ";
print "</td>"; print "</td>";
print "<td>"; print "<td>";
print $form->textwithpicto('',$langs->trans("CronCommandHelp"),1,'help'); print $form->textwithpicto('',$langs->trans("CronCommandHelp"),1,'help');
print "</td>"; print "</td>";
print "</tr>\n"; print "</tr>\n";
print '<tr><td>'; print '<tr><td>';
print $langs->trans('CronNote')."</td><td>"; print $langs->trans('CronNote')."</td><td>";
$doleditor = new DolEditor('note', $object->note, '', 160, 'dolibarr_notes', 'In', true, false, 0, 4, 90); $doleditor = new DolEditor('note', $object->note, '', 160, 'dolibarr_notes', 'In', true, false, 0, 4, 90);
@ -435,7 +447,7 @@ if (($action=="create") || ($action=="edit")) {
print "</td>"; print "</td>";
print "</tr>\n"; print "</tr>\n";
print '<tr><td colspan="2" align="center">'; print '<tr><td colspan="2" align="center">';
print "<input type=\"submit\" name=\"save\" class=\"button\" value=\"".$langs->trans("Save")."\">"; print "<input type=\"submit\" name=\"save\" class=\"button\" value=\"".$langs->trans("Save")."\">";
print "<input type=\"submit\" name=\"cancel\" class=\"button\" value=\"".$langs->trans("Cancel")."\">"; print "<input type=\"submit\" name=\"cancel\" class=\"button\" value=\"".$langs->trans("Cancel")."\">";
@ -443,20 +455,22 @@ if (($action=="create") || ($action=="edit")) {
print "<td>"; print "<td>";
print "</td>"; print "</td>";
print "</tr>\n"; print "</tr>\n";
print '</table>'; print '</table>';
print "</form>\n"; print "</form>\n";
}else { }
else
{
/* /*
* view Template * view Template
*/ */
// box add_jobs_box // box add_jobs_box
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tr><td width="30%">'; print '<tr><td width="30%">';
print $langs->trans('CronId')."</td>"; print $langs->trans('CronId')."</td>";
print "<td>".$form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'id'); print "<td>".$form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'id');
@ -466,7 +480,7 @@ if (($action=="create") || ($action=="edit")) {
print $langs->trans('CronLabel')."</td>"; print $langs->trans('CronLabel')."</td>";
print "<td>".$object->label; print "<td>".$object->label;
print "</td></tr>"; print "</td></tr>";
print "<tr><td>"; print "<tr><td>";
print $langs->trans('CronType')."</td><td>"; print $langs->trans('CronType')."</td><td>";
print $formCron->select_typejob('jobtype',$object->jobtype,1); print $formCron->select_typejob('jobtype',$object->jobtype,1);
@ -476,32 +490,32 @@ if (($action=="create") || ($action=="edit")) {
print $langs->trans('CronHourStart')."</td><td>"; print $langs->trans('CronHourStart')."</td><td>";
if(!empty($object->datestart)) {print dol_print_date($object->datestart,'dayhourtext');} else {print $langs->trans('CronNone');} if(!empty($object->datestart)) {print dol_print_date($object->datestart,'dayhourtext');} else {print $langs->trans('CronNone');}
print "</td></tr>"; print "</td></tr>";
print "<tr><td>"; print "<tr><td>";
print $langs->trans('CronDtEnd')."</td><td>"; print $langs->trans('CronDtEnd')."</td><td>";
if(!empty($object->dateend)) {print dol_print_date($object->dateend,'dayhourtext');} else {print $langs->trans('CronNone');} if(!empty($object->dateend)) {print dol_print_date($object->dateend,'dayhourtext');} else {print $langs->trans('CronNone');}
print "</td></tr>"; print "</td></tr>";
print "<tr><td>"; print "<tr><td>";
print $langs->trans('CronPriority')."</td>"; print $langs->trans('CronPriority')."</td>";
print "<td>".$object->priority; print "<td>".$object->priority;
print "</td></tr>"; print "</td></tr>";
print "<tr><td>"; print "<tr><td>";
print $langs->trans('CronNbRun')."</td>"; print $langs->trans('CronNbRun')."</td>";
print "<td>".$object->nbrun; print "<td>".$object->nbrun;
print "</td></tr>"; print "</td></tr>";
print "<tr><td>"; print "<tr><td>";
print $langs->trans('CronEvery')."</td>"; print $langs->trans('CronEvery')."</td>";
print "<td>"; print "<td>";
if($object->unitfrequency == "60") print $langs->trans('CronEach')." ".($object->frequency/$object->unitfrequency)." ".$langs->trans('Minutes'); if($object->unitfrequency == "60") print $langs->trans('CronEach')." ".($object->frequency/$object->unitfrequency)." ".$langs->trans('Minutes');
if($object->unitfrequency == "3600") print $langs->trans('CronEach')." ".($object->frequency/$object->unitfrequency)." ".$langs->trans('Hours'); if($object->unitfrequency == "3600") print $langs->trans('CronEach')." ".($object->frequency/$object->unitfrequency)." ".$langs->trans('Hours');
if($object->unitfrequency == "86400") print $langs->trans('CronEach')." ".($object->frequency/$object->unitfrequency)." ".$langs->trans('Days'); if($object->unitfrequency == "86400") print $langs->trans('CronEach')." ".($object->frequency/$object->unitfrequency)." ".$langs->trans('Days');
if($object->unitfrequency == "604800") print $langs->trans('CronEach')." ".($object->frequency/$object->unitfrequency)." ".$langs->trans('Weeks'); if($object->unitfrequency == "604800") print $langs->trans('CronEach')." ".($object->frequency/$object->unitfrequency)." ".$langs->trans('Weeks');
print "</td></tr>"; print "</td></tr>";
print '<tr class="blockmethod"><td>'; print '<tr class="blockmethod"><td>';
print $langs->trans('CronModule')."</td><td>"; print $langs->trans('CronModule')."</td><td>";
print $object->module_name; print $object->module_name;
@ -526,44 +540,48 @@ if (($action=="create") || ($action=="edit")) {
print $langs->trans('CronArgs')."</td><td>"; print $langs->trans('CronArgs')."</td><td>";
print $object->params; print $object->params;
print "</td></tr>"; print "</td></tr>";
print '<tr class="blockcommand"><td>'; print '<tr class="blockcommand"><td>';
print $langs->trans('CronCommand')."</td><td>"; print $langs->trans('CronCommand')."</td><td>";
print $object->command; print $object->command;
print "</td></tr>"; print "</td></tr>";
print '<tr><td>'; print '<tr><td>';
print $langs->trans('CronNote')."</td><td>"; print $langs->trans('CronNote')."</td><td>";
print $object->note; print $object->note;
print "</td></tr>"; print "</td></tr>";
print '<tr><td>'; print '<tr><td>';
print $langs->trans('CronDtLastLaunch')."</td><td>"; print $langs->trans('CronDtLastLaunch')."</td><td>";
if(!empty($object->datelastrun)) {print dol_print_date($object->datelastrun,'dayhourtext');} else {print $langs->trans('CronNone');} if(!empty($object->datelastrun)) {print dol_print_date($object->datelastrun,'dayhourtext');} else {print $langs->trans('CronNone');}
print "</td></tr>"; print "</td></tr>";
print '<tr><td>'; print '<tr><td>';
print $langs->trans('CronDtNextLaunch')."</td><td>"; print $langs->trans('CronDtNextLaunch')."</td><td>";
if(!empty($object->datenextrun)) {print dol_print_date($object->datenextrun,'dayhourtext');} else {print $langs->trans('CronNone');} if(!empty($object->datenextrun)) {print dol_print_date($object->datenextrun,'dayhourtext');} else {print $langs->trans('CronNone');}
print "</td></tr>"; print "</td></tr>";
print '<tr><td>'; print '<tr><td>';
print $langs->trans('CronDtLastResult')."</td><td>"; print $langs->trans('CronDtLastResult')."</td><td>";
if(!empty($object->datelastresult)) {print dol_print_date($object->datelastresult,'dayhourtext');} else {print $langs->trans('CronNone');} if(!empty($object->datelastresult)) {print dol_print_date($object->datelastresult,'dayhourtext');} else {print $langs->trans('CronNone');}
print "</td></tr>"; print "</td></tr>";
print '<tr><td>'; print '<tr><td>';
print $langs->trans('CronLastResult')."</td><td>"; print $langs->trans('CronLastResult')."</td><td>";
print $object->lastresult; print $object->lastresult;
print "</td></tr>"; print "</td></tr>";
print '<tr><td>'; print '<tr><td>';
print $langs->trans('CronLastOutput')."</td><td>"; print $langs->trans('CronLastOutput')."</td><td>";
print nl2br($object->lastoutput); print nl2br($object->lastoutput);
print "</td></tr>"; print "</td></tr>";
print '</table>'; print '</table>';
print dol_fiche_end();
print "\n\n<div class=\"tabsAction\">\n"; print "\n\n<div class=\"tabsAction\">\n";
if (! $user->rights->cron->create) { if (! $user->rights->cron->create) {
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("Edit").'</a>'; print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("Edit").'</a>';

View File

@ -37,7 +37,7 @@ class Cronjob extends CommonObject
var $table_element='cronjob'; //!< Name of table without prefix where object is stored var $table_element='cronjob'; //!< Name of table without prefix where object is stored
var $id; var $id;
var $ref; //Use for prevnext_ref var $ref; //Use for prevnext_ref
var $jobtype; var $jobtype;
var $tms=''; var $tms='';
@ -65,10 +65,10 @@ class Cronjob extends CommonObject
var $fk_user_mod; var $fk_user_mod;
var $note; var $note;
var $nbrun; var $nbrun;
var $lines; var $lines;
/** /**
@ -96,7 +96,7 @@ class Cronjob extends CommonObject
$error=0; $error=0;
// Clean parameters // Clean parameters
if (isset($this->label)) $this->label=trim($this->label); if (isset($this->label)) $this->label=trim($this->label);
if (isset($this->jobtype)) $this->jobtype=trim($this->jobtype); if (isset($this->jobtype)) $this->jobtype=trim($this->jobtype);
if (isset($this->command)) $this->command=trim($this->command); if (isset($this->command)) $this->command=trim($this->command);
@ -152,7 +152,7 @@ class Cronjob extends CommonObject
// Insert request // Insert request
$sql = "INSERT INTO ".MAIN_DB_PREFIX."cronjob("; $sql = "INSERT INTO ".MAIN_DB_PREFIX."cronjob(";
$sql.= "datec,"; $sql.= "datec,";
$sql.= "jobtype,"; $sql.= "jobtype,";
$sql.= "label,"; $sql.= "label,";
@ -179,9 +179,9 @@ class Cronjob extends CommonObject
$sql.= "note,"; $sql.= "note,";
$sql.= "nbrun"; $sql.= "nbrun";
$sql.= ") VALUES ("; $sql.= ") VALUES (";
$sql.= " ".$this->db->idate(dol_now()).","; $sql.= " ".$this->db->idate(dol_now()).",";
$sql.= " ".(! isset($this->jobtype)?'NULL':"'".$this->db->escape($this->jobtype)."'").","; $sql.= " ".(! isset($this->jobtype)?'NULL':"'".$this->db->escape($this->jobtype)."'").",";
$sql.= " ".(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").","; $sql.= " ".(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").",";
@ -208,16 +208,16 @@ class Cronjob extends CommonObject
$sql.= " ".(! isset($this->note)?'NULL':"'".$this->db->escape($this->note)."'").","; $sql.= " ".(! isset($this->note)?'NULL':"'".$this->db->escape($this->note)."'").",";
$sql.= " ".(! isset($this->nbrun)?'0':"'".$this->db->escape($this->nbrun)."'").""; $sql.= " ".(! isset($this->nbrun)?'0':"'".$this->db->escape($this->nbrun)."'")."";
$sql.= ")"; $sql.= ")";
$this->db->begin(); $this->db->begin();
dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
$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)
{ {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."cronjob"); $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."cronjob");
@ -266,7 +266,7 @@ class Cronjob extends CommonObject
global $langs; global $langs;
$sql = "SELECT"; $sql = "SELECT";
$sql.= " t.rowid,"; $sql.= " t.rowid,";
$sql.= " t.tms,"; $sql.= " t.tms,";
$sql.= " t.datec,"; $sql.= " t.datec,";
$sql.= " t.jobtype,"; $sql.= " t.jobtype,";
@ -294,7 +294,7 @@ class Cronjob extends CommonObject
$sql.= " t.note,"; $sql.= " t.note,";
$sql.= " t.nbrun"; $sql.= " t.nbrun";
$sql.= " FROM ".MAIN_DB_PREFIX."cronjob as t"; $sql.= " FROM ".MAIN_DB_PREFIX."cronjob as t";
$sql.= " WHERE t.rowid = ".$id; $sql.= " WHERE t.rowid = ".$id;
@ -308,7 +308,7 @@ class Cronjob extends CommonObject
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->ref = $obj->rowid; $this->ref = $obj->rowid;
$this->tms = $this->db->jdate($obj->tms); $this->tms = $this->db->jdate($obj->tms);
$this->datec = $this->db->jdate($obj->datec); $this->datec = $this->db->jdate($obj->datec);
$this->label = $obj->label; $this->label = $obj->label;
@ -336,7 +336,7 @@ class Cronjob extends CommonObject
$this->note = $obj->note; $this->note = $obj->note;
$this->nbrun = $obj->nbrun; $this->nbrun = $obj->nbrun;
} }
$this->db->free($resql); $this->db->free($resql);
@ -349,7 +349,7 @@ class Cronjob extends CommonObject
return -1; return -1;
} }
} }
/** /**
* Load object in memory from the database * Load object in memory from the database
* *
@ -392,8 +392,8 @@ class Cronjob extends CommonObject
$sql.= " t.fk_user_mod,"; $sql.= " t.fk_user_mod,";
$sql.= " t.note,"; $sql.= " t.note,";
$sql.= " t.nbrun"; $sql.= " t.nbrun";
$sql.= " FROM ".MAIN_DB_PREFIX."cronjob as t"; $sql.= " FROM ".MAIN_DB_PREFIX."cronjob as t";
$status = (empty($status))?'0':'1'; $status = (empty($status))?'0':'1';
$sql.= " WHERE t.status=".$status; $sql.= " WHERE t.status=".$status;
@ -403,43 +403,43 @@ class Cronjob extends CommonObject
$sql.= ' AND '.$key.' LIKE \'%'.$value.'%\''; $sql.= ' AND '.$key.' LIKE \'%'.$value.'%\'';
} }
} }
$sql.= " ORDER BY $sortfield $sortorder "; $sql.= " ORDER BY $sortfield $sortorder ";
if (!empty($limit) && !empty($offset)) { if (!empty($limit) && !empty($offset)) {
$sql.= $this->db->plimit( $limit + 1 ,$offset); $sql.= $this->db->plimit( $limit + 1 ,$offset);
} }
$sqlwhere = array(); $sqlwhere = array();
if (!empty($module_name)) { if (!empty($module_name)) {
$sqlwhere[]='(t.module_name='.$module_name.')'; $sqlwhere[]='(t.module_name='.$module_name.')';
} }
if (count($sqlwhere)>0) { if (count($sqlwhere)>0) {
$sql.= " WHERE ".implode(' AND ',$sqlwhere); $sql.= " WHERE ".implode(' AND ',$sqlwhere);
} }
dol_syslog(get_class($this)."::fetch_all sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::fetch_all sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
$num=$this->db->num_rows($resql); $num=$this->db->num_rows($resql);
$i=0; $i=0;
if ($num) if ($num)
{ {
$this->lines=array(); $this->lines=array();
while ($i < $num) while ($i < $num)
{ {
$line = new Cronjobline(); $line = new Cronjobline();
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$line->id = $obj->rowid; $line->id = $obj->rowid;
$line->ref = $obj->rowid; $line->ref = $obj->rowid;
$line->tms = $this->db->jdate($obj->tms); $line->tms = $this->db->jdate($obj->tms);
$line->datec = $this->db->jdate($obj->datec); $line->datec = $this->db->jdate($obj->datec);
$line->label = $obj->label; $line->label = $obj->label;
@ -466,15 +466,15 @@ class Cronjob extends CommonObject
$line->fk_user_mod = $obj->fk_user_mod; $line->fk_user_mod = $obj->fk_user_mod;
$line->note = $obj->note; $line->note = $obj->note;
$line->nbrun = $obj->nbrun; $line->nbrun = $obj->nbrun;
$this->lines[]=$line; $this->lines[]=$line;
$i++; $i++;
} }
} }
$this->db->free($resql); $this->db->free($resql);
return 1; return 1;
} }
else else
@ -496,13 +496,13 @@ class Cronjob extends CommonObject
function update($user=0, $notrigger=0) function update($user=0, $notrigger=0)
{ {
global $conf, $langs; global $conf, $langs;
$langs->load('cron'); $langs->load('cron');
$error=0; $error=0;
// Clean parameters // Clean parameters
if (isset($this->label)) $this->label=trim($this->label); if (isset($this->label)) $this->label=trim($this->label);
if (isset($this->jobtype)) $this->jobtype=trim($this->jobtype); if (isset($this->jobtype)) $this->jobtype=trim($this->jobtype);
if (isset($this->command)) $this->command=trim($this->command); if (isset($this->command)) $this->command=trim($this->command);
@ -558,11 +558,11 @@ class Cronjob extends CommonObject
$this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronObject')); $this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronObject'));
$error++; $error++;
} }
// Update request // Update request
$sql = "UPDATE ".MAIN_DB_PREFIX."cronjob SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."cronjob SET";
$sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").","; $sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").",";
$sql.= " jobtype=".(isset($this->jobtype)?"'".$this->db->escape($this->jobtype)."'":"null").","; $sql.= " jobtype=".(isset($this->jobtype)?"'".$this->db->escape($this->jobtype)."'":"null").",";
$sql.= " command=".(isset($this->command)?"'".$this->db->escape($this->command)."'":"null").","; $sql.= " command=".(isset($this->command)?"'".$this->db->escape($this->command)."'":"null").",";
@ -587,7 +587,7 @@ class Cronjob extends CommonObject
$sql.= " note=".(isset($this->note)?"'".$this->db->escape($this->note)."'":"null").","; $sql.= " note=".(isset($this->note)?"'".$this->db->escape($this->note)."'":"null").",";
$sql.= " nbrun=".(isset($this->nbrun)?$this->nbrun:"null"); $sql.= " nbrun=".(isset($this->nbrun)?$this->nbrun:"null");
$sql.= " WHERE rowid=".$this->id; $sql.= " WHERE rowid=".$this->id;
$this->db->begin(); $this->db->begin();
@ -595,7 +595,7 @@ class Cronjob extends CommonObject
dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
$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)
{ {
if (! $notrigger) if (! $notrigger)
@ -755,7 +755,7 @@ class Cronjob extends CommonObject
{ {
$this->id=0; $this->id=0;
$this->ref=0; $this->ref=0;
$this->tms=''; $this->tms='';
$this->datec=''; $this->datec='';
$this->label=''; $this->label='';
@ -780,24 +780,24 @@ class Cronjob extends CommonObject
$this->status=''; $this->status='';
$this->fk_user_author=''; $this->fk_user_author='';
$this->fk_user_mod=''; $this->fk_user_mod='';
$this->note=''; $this->note='';
$this->nbrun=''; $this->nbrun='';
} }
/** /**
* Load object information * Load object information
* *
* @return void * @return void
*/ */
function info() function info()
{ {
global $langs; global $langs;
$sql = "SELECT"; $sql = "SELECT";
$sql.= " f.rowid, f.datec, f.tms, f.fk_user_mod, f.fk_user_author"; $sql.= " f.rowid, f.datec, f.tms, f.fk_user_mod, f.fk_user_author";
$sql.= " FROM ".MAIN_DB_PREFIX."cronjob as f"; $sql.= " FROM ".MAIN_DB_PREFIX."cronjob as f";
$sql.= " WHERE f.rowid = ".$this->id; $sql.= " WHERE f.rowid = ".$this->id;
dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
@ -812,7 +812,7 @@ class Cronjob extends CommonObject
$this->user_creation = $obj->fk_user_author; $this->user_creation = $obj->fk_user_author;
} }
$this->db->free($resql); $this->db->free($resql);
return 1; return 1;
} }
else else
@ -822,26 +822,26 @@ class Cronjob extends CommonObject
return -1; return -1;
} }
} }
/** /**
* Run a job * Run a job
* *
* @param string $userlogin User login * @param string $userlogin User login
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function run_jobs($userlogin) function run_jobs($userlogin)
{ {
global $langs, $conf; global $langs, $conf;
$langs->load('cron'); $langs->load('cron');
if (empty($userlogin)) { if (empty($userlogin)) {
$this->error="User login is mandatory"; $this->error="User login is mandatory";
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR); dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
return -1; return -1;
} }
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
$user=new User($this->db); $user=new User($this->db);
$result=$user->fetch('',$userlogin); $result=$user->fetch('',$userlogin);
@ -856,14 +856,14 @@ class Cronjob extends CommonObject
return -1; return -1;
} }
} }
dol_syslog(get_class($this)."::run_jobs userlogin:$userlogin", LOG_DEBUG); dol_syslog(get_class($this)."::run_jobs userlogin:$userlogin", LOG_DEBUG);
$error=0; $error=0;
$now=dol_now(); $now=dol_now();
$this->db->begin(); $this->db->begin();
if ($this->jobtype=='method') { if ($this->jobtype=='method') {
// load classes // load classes
$ret=dol_include_once("/".$this->module_name."/class/".$this->classesname,$this->objectname); $ret=dol_include_once("/".$this->module_name."/class/".$this->classesname,$this->objectname);
@ -872,19 +872,19 @@ class Cronjob extends CommonObject
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR); dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
return -1; return -1;
} }
// Load langs // Load langs
$result=$langs->load($this->module_name.'@'.$this->module_name); $result=$langs->load($this->module_name.'@'.$this->module_name);
if ($result<0) { if ($result<0) {
dol_syslog(get_class($this)."::run_jobs Cannot load module langs".$langs->error, LOG_ERR); dol_syslog(get_class($this)."::run_jobs Cannot load module langs".$langs->error, LOG_ERR);
return -1; return -1;
} }
dol_syslog(get_class($this)."::run_jobs ".$this->objectname."->".$this->methodename."(".$this->params.");", LOG_DEBUG); dol_syslog(get_class($this)."::run_jobs ".$this->objectname."->".$this->methodename."(".$this->params.");", LOG_DEBUG);
// Create Object for the call module // Create Object for the call module
$object = new $this->objectname($this->db); $object = new $this->objectname($this->db);
$params_arr = array(); $params_arr = array();
$params_arr=explode(", ",$this->params); $params_arr=explode(", ",$this->params);
if (!is_array($params_arr)) { if (!is_array($params_arr)) {
@ -892,7 +892,7 @@ class Cronjob extends CommonObject
}else { }else {
$result = call_user_func_array(array($object, $this->methodename), $params_arr); $result = call_user_func_array(array($object, $this->methodename), $params_arr);
} }
if ($result===false) { if ($result===false) {
dol_syslog(get_class($this)."::run_jobs ".$object->error, LOG_ERR); dol_syslog(get_class($this)."::run_jobs ".$object->error, LOG_ERR);
return -1; return -1;
@ -900,15 +900,15 @@ class Cronjob extends CommonObject
$this->lastoutput=var_export($result,true); $this->lastoutput=var_export($result,true);
$this->lastresult=var_export($result,true); $this->lastresult=var_export($result,true);
} }
} elseif ($this->jobtype=='command') { } elseif ($this->jobtype=='command') {
dol_syslog(get_class($this)."::run_jobs system:".$this->command, LOG_DEBUG); dol_syslog(get_class($this)."::run_jobs system:".$this->command, LOG_DEBUG);
$output_arr=array(); $output_arr=array();
exec($this->command, $output_arr,$retval); exec($this->command, $output_arr,$retval);
dol_syslog(get_class($this)."::run_jobs output_arr:".var_export($output_arr,true), LOG_DEBUG); dol_syslog(get_class($this)."::run_jobs output_arr:".var_export($output_arr,true), LOG_DEBUG);
$this->lastoutput=''; $this->lastoutput='';
if (is_array($output_arr) && count($output_arr)>0) { if (is_array($output_arr) && count($output_arr)>0) {
foreach($output_arr as $val) { foreach($output_arr as $val) {
@ -917,7 +917,7 @@ class Cronjob extends CommonObject
} }
$this->lastresult=$retval; $this->lastresult=$retval;
} }
$this->datelastresult=$now; $this->datelastresult=$now;
$this->datelastrun=$now; $this->datelastrun=$now;
$this->nbrun=$this->nbrun+1; $this->nbrun=$this->nbrun+1;
@ -930,23 +930,23 @@ class Cronjob extends CommonObject
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
} }
/** /**
* Reprogram a job * Reprogram a job
* *
* @param string $userlogin User login * @param string $userlogin User login
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
* *
*/ */
function reprogram_jobs($userlogin) function reprogram_jobs($userlogin)
{ {
global $langs, $conf; global $langs, $conf;
dol_syslog(get_class($this)."::reprogram_jobs userlogin:$userlogin", LOG_DEBUG); dol_syslog(get_class($this)."::reprogram_jobs userlogin:$userlogin", LOG_DEBUG);
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
$user=new User($this->db); $user=new User($this->db);
$result=$user->fetch('',$userlogin); $result=$user->fetch('',$userlogin);
@ -961,9 +961,9 @@ class Cronjob extends CommonObject
return -1; return -1;
} }
} }
dol_syslog(get_class($this)."::reprogram_jobs ", LOG_DEBUG); dol_syslog(get_class($this)."::reprogram_jobs ", LOG_DEBUG);
if (empty($this->datenextrun)) { if (empty($this->datenextrun)) {
$this->datenextrun=dol_now()+$this->frequency; $this->datenextrun=dol_now()+$this->frequency;
} else { } else {
@ -972,15 +972,15 @@ class Cronjob extends CommonObject
} else { } else {
$this->datenextrun=$this->datenextrun+$this->frequency; $this->datenextrun=$this->datenextrun+$this->frequency;
} }
} }
$result = $this->update($user); $result = $this->update($user);
if ($result<0) { if ($result<0) {
dol_syslog(get_class($this)."::reprogram_jobs ".$this->error, LOG_ERR); dol_syslog(get_class($this)."::reprogram_jobs ".$this->error, LOG_ERR);
return -1; return -1;
} }
return 1; return 1;
} }
} }
@ -989,10 +989,10 @@ class Cronjob extends CommonObject
* Crob Job line class * Crob Job line class
*/ */
class Cronjobline{ class Cronjobline{
var $id; var $id;
var $ref; var $ref;
var $tms=''; var $tms='';
var $datec=''; var $datec='';
var $label; var $label;
@ -1018,7 +1018,7 @@ class Cronjobline{
var $fk_user_mod; var $fk_user_mod;
var $note; var $note;
var $nbrun; var $nbrun;
/** /**
* Constructor * Constructor
* *

View File

@ -9,8 +9,8 @@ URLToLaunchCronJobs=URL pour lancer les taches automatiques
OrToLaunchASpecificJob=Ou pour lancer une tache spécifique OrToLaunchASpecificJob=Ou pour lancer une tache spécifique
KeyForCronAccess=Clé de sécurité pour l'URL de lancement des taches automatiques KeyForCronAccess=Clé de sécurité pour l'URL de lancement des taches automatiques
FileToLaunchCronJobs=Commande pour lancer les taches automatiques FileToLaunchCronJobs=Commande pour lancer les taches automatiques
CronExplainHowToRunUnix=Sur un environement Unix vous pouvez paramétré CronTab pour executer cette commande toute les minutes CronExplainHowToRunUnix=Sur un environement Unix vous pouvez paramétrer CronTab pour executer cette commande toute les minutes.
CronExplainHowToRunWin=Sur un environement Microsoft(tm) Windows vous pouvez utilisr le planificateur de tache pour lancer cette commande toute les minutes CronExplainHowToRunWin=Sur un environement Microsoft(tm) Windows vous pouvez utiliser le planificateur de tache pour lancer cette commande toute les minutes.
# #
# Menu # Menu

View File

@ -49,7 +49,7 @@ if (empty($key)) {
echo 'securitykey is require'; echo 'securitykey is require';
exit; exit;
} }
if($key != $conf->global->MAIN_CRON_KEY) if($key != $conf->global->CRON_KEY)
{ {
echo 'securitykey is wrong'; echo 'securitykey is wrong';
exit; exit;
@ -104,13 +104,13 @@ if(is_array($object->lines) && (count($object->lines)>0)){
foreach($object->lines as $line){ foreach($object->lines as $line){
dol_syslog("cron_run_jobs.php:: fetch cronjobid:".$line->id, LOG_ERR); dol_syslog("cron_run_jobs.php:: fetch cronjobid:".$line->id, LOG_ERR);
//If date_next_jobs is less of current dat, execute the program, and store the execution time of the next execution in database //If date_next_jobs is less of current dat, execute the program, and store the execution time of the next execution in database
if ((($line->datenextrun <= $now) && $line->dateend < $now) if ((($line->datenextrun <= $now) && $line->dateend < $now)
|| ((empty($line->datenextrun)) && (empty($line->dateend)))){ || ((empty($line->datenextrun)) && (empty($line->dateend)))){
dol_syslog("cron_run_jobs.php:: torun line->datenextrun:".dol_print_date($line->datenextrun,'dayhourtext')." line->dateend:".dol_print_date($line->dateend,'dayhourtext')." now:".dol_print_date($now,'dayhourtext'), LOG_ERR); dol_syslog("cron_run_jobs.php:: torun line->datenextrun:".dol_print_date($line->datenextrun,'dayhourtext')." line->dateend:".dol_print_date($line->dateend,'dayhourtext')." now:".dol_print_date($now,'dayhourtext'), LOG_ERR);
$cronjob=new Cronjob($db); $cronjob=new Cronjob($db);
$result=$cronjob->fetch($line->id); $result=$cronjob->fetch($line->id);
if ($result<0) { if ($result<0) {
@ -125,7 +125,7 @@ if(is_array($object->lines) && (count($object->lines)>0)){
dol_syslog("cron_run_jobs.php:: run_jobs Error".$cronjob->error, LOG_ERR); dol_syslog("cron_run_jobs.php:: run_jobs Error".$cronjob->error, LOG_ERR);
exit; exit;
} }
// we re-program the next execution and stores the last execution time for this job // we re-program the next execution and stores the last execution time for this job
$result=$cronjob->reprogram_jobs($userlogin); $result=$cronjob->reprogram_jobs($userlogin);
if ($result<0) { if ($result<0) {
@ -133,7 +133,7 @@ if(is_array($object->lines) && (count($object->lines)>0)){
dol_syslog("cron_run_jobs.php:: reprogram_jobs Error".$cronjob->error, LOG_ERR); dol_syslog("cron_run_jobs.php:: reprogram_jobs Error".$cronjob->error, LOG_ERR);
exit; exit;
} }
} }
} }
echo "OK"; echo "OK";

View File

Before

Width:  |  Height:  |  Size: 655 B

After

Width:  |  Height:  |  Size: 655 B

102
scripts/cron/cron_run_jobs.php Normal file → Executable file
View File

@ -27,72 +27,74 @@ if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
if (! defined('NOLOGIN')) define('NOLOGIN','1'); if (! defined('NOLOGIN')) define('NOLOGIN','1');
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
$sapi_type = php_sapi_name();
$script_file = basename(__FILE__);
$path=dirname(__FILE__).'/';
// Test if batch mode
if (substr($sapi_type, 0, 3) == 'cgi') {
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
exit;
}
$sapi_type = php_sapi_name();
$script_file = basename(__FILE__);
$path=dirname(__FILE__).'/';
// Test if batch mode
if (substr($sapi_type, 0, 3) == 'cgi') {
echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
exit;
}
if (! isset($argv[1]) || ! $argv[1]) { if (! isset($argv[1]) || ! $argv[1]) {
print "Usage: ".$script_file." securitykey userlogin cronjobid(optional)\n"; print "Usage: ".$script_file." securitykey userlogin cronjobid(optional)\n";
exit; exit;
} }
$key=$argv[1]; $key=$argv[1];
if (! isset($argv[2]) || ! $argv[2]) { if (! isset($argv[2]) || ! $argv[2]) {
print "Usage: ".$script_file." securitykey userlogin cronjobid(optional)\n"; print "Usage: ".$script_file." securitykey userlogin cronjobid(optional)\n";
exit; exit;
} else { } else {
$userlogin=$argv[2]; $userlogin=$argv[2];
} }
require_once ($path."../../htdocs/master.inc.php");
require_once (DOL_DOCUMENT_ROOT."/cron/class/cronjob.class.php");
require_once (DOL_DOCUMENT_ROOT.'/user/class/user.class.php');
require_once (DOL_DOCUMENT_ROOT."/cron/class/cronjob.class.php");
$res=@include("../../master.inc.php"); // For root directory /*
if (! $res) $res=@include("../../../master.inc.php"); // For "custom" directory * Main
if (! $res) die("Include of master.inc.php fails"); */
// Check security key
// librarie jobs if ($key != $conf->global->CRON_KEY)
require_once (DOL_DOCUMENT_ROOT_ALT."/cron/class/cronjob.class.php");
//Check security key
if($key != $conf->global->MAIN_CRON_KEY)
{ {
echo 'securitykey is wrong'; print "Error: securitykey is wrong\n";
exit; exit;
} }
//Check user login // Check user login
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
$user=new User($db); $user=new User($db);
$result=$user->fetch('',$userlogin); $result=$user->fetch('',$userlogin);
if ($result<0) { if ($result < 0)
echo "User Error:".$user->error; {
echo "User Error: ".$user->error;
dol_syslog("cron_run_jobs.php:: User Error:".$user->error, LOG_ERR); dol_syslog("cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
exit; exit;
}else { }
if (empty($user->id)) { else
echo " User user login:".$userlogin." do not exists"; {
if (empty($user->id))
{
echo " User user login: ".$userlogin." do not exists";
dol_syslog(" User user login:".$userlogin." do not exists", LOG_ERR); dol_syslog(" User user login:".$userlogin." do not exists", LOG_ERR);
exit; exit;
} }
} }
if (isset($argv[3]) || $argv[3]) { if (isset($argv[3]) || $argv[3])
{
$id = $argv[3]; $id = $argv[3];
} }
// librarie jobs
require_once (DOL_DOCUMENT_ROOT_ALT."/cron/class/cronjob.class.php");
// create a jobs object // create a jobs object
$object = new Cronjob($db); $object = new Cronjob($db);
@ -103,18 +105,21 @@ if (empty($id)) {
} }
$result = $object->fetch_all('DESC','t.rowid', 0, 0, 1, $filter); $result = $object->fetch_all('DESC','t.rowid', 0, 0, 1, $filter);
if ($result<0) { if ($result<0)
echo "Error:".$cronjob->error; {
dol_syslog("cron_run_jobs.php:: fetch Error".$cronjob->error, LOG_ERR); echo "Error: ".$object->error;
dol_syslog("cron_run_jobs.php:: fetch Error ".$object->error, LOG_ERR);
exit; exit;
} }
// current date // current date
$now=dol_now(); $now=dol_now();
if(is_array($object->lines) && (count($object->lines)>0)){ if(is_array($object->lines) && (count($object->lines)>0))
{
// Loop over job // Loop over job
foreach($object->lines as $line){ foreach($object->lines as $line)
{
//If date_next_jobs is less of current dat, execute the program, and store the execution time of the next execution in database //If date_next_jobs is less of current dat, execute the program, and store the execution time of the next execution in database
if (($line->datenextrun < $now) && $line->dateend < $now){ if (($line->datenextrun < $now) && $line->dateend < $now){
@ -132,7 +137,7 @@ if(is_array($object->lines) && (count($object->lines)>0)){
dol_syslog("cron_run_jobs.php:: run_jobs Error".$cronjob->error, LOG_ERR); dol_syslog("cron_run_jobs.php:: run_jobs Error".$cronjob->error, LOG_ERR);
exit; exit;
} }
// we re-program the next execution and stores the last execution time for this job // we re-program the next execution and stores the last execution time for this job
$result=$cronjob->reprogram_jobs($userlogin); $result=$cronjob->reprogram_jobs($userlogin);
if ($result<0) { if ($result<0) {
@ -140,7 +145,10 @@ if(is_array($object->lines) && (count($object->lines)>0)){
dol_syslog("cron_run_jobs.php:: reprogram_jobs Error".$cronjob->error, LOG_ERR); dol_syslog("cron_run_jobs.php:: reprogram_jobs Error".$cronjob->error, LOG_ERR);
exit; exit;
} }
} }
} }
} }
$db->close();
?>