Merge pull request #768 from FHenry/develop_cron
[ task #122 ] Create a scheduled cron module
93
htdocs/core/class/html.formcron.class.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file cron/class/html.formcron.class.php
|
||||
* \brief Fichier de la classe des fonctions predefinie de composants html cron
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Class to manage building of HTML components
|
||||
*/
|
||||
class FormCron extends Form
|
||||
{
|
||||
var $db;
|
||||
var $error;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
*/
|
||||
function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display On Off selector
|
||||
*
|
||||
* @param string $htmlname Html control name
|
||||
* @param string $selected selected value
|
||||
* @param string $readonly Select is read only or not
|
||||
* @return string HTML select field
|
||||
*/
|
||||
function select_typejob($htmlname,$selected=0,$readonly=0)
|
||||
{
|
||||
global $langs;
|
||||
|
||||
$langs->load('cron@cron');
|
||||
if (!empty($readonly)) {
|
||||
if ($selected=='command') {
|
||||
$out= $langs->trans('CronType_command');
|
||||
$out.='<SELECT name="'.$htmlname.'" id="'.$htmlname.'" style="display:none"/>';
|
||||
$out.= '<OPTION value="command" selected=\"selected\">'.$langs->trans('CronType_command').'</OPTION>';
|
||||
$out.='</SELECT>';
|
||||
} elseif ($selected=='method') {
|
||||
$out= $langs->trans('CronType_method');
|
||||
$out.='<SELECT name="'.$htmlname.'" id="'.$htmlname.'" style="display:none"/>';
|
||||
$out.= '<OPTION value="method" selected=\"selected\">'.$langs->trans('CronType_method').'</OPTION>';
|
||||
$out.='</SELECT>';
|
||||
}
|
||||
}else {
|
||||
|
||||
$out='<SELECT name="'.$htmlname.'" id="'.$htmlname.'" />';
|
||||
|
||||
if ($selected=='command') {
|
||||
$selected_attr=' selected=\"selected\" ';
|
||||
} else {
|
||||
$selected_attr='';
|
||||
}
|
||||
$out.= '<OPTION value="command" '.$selected_attr.'>'.$langs->trans('CronType_command').'</OPTION>';
|
||||
|
||||
if ($selected=='method') {
|
||||
$selected_attr=' selected=\"selected\" ';
|
||||
} else {
|
||||
$selected_attr='';
|
||||
}
|
||||
$out.= '<OPTION value="method" '.$selected_attr.'>'.$langs->trans('CronType_method').'</OPTION>';
|
||||
|
||||
$out.='</SELECT>';
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
71
htdocs/core/lib/cron.lib.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
|
||||
* Copyright (C) 2013 Florian Henry <florian.henry@opn-concept.pro>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/**
|
||||
* \file cron/lib/cron.lib.php
|
||||
* \brief Ensemble de fonctions de base pour le module jobs
|
||||
* \ingroup jobs
|
||||
*/
|
||||
|
||||
/**
|
||||
* Return array of tabs to used on pages for third parties cards.
|
||||
*
|
||||
* @param Object $object Object company shown
|
||||
* @return array Array of tabs
|
||||
*/
|
||||
|
||||
function cronadmin_prepare_head()
|
||||
{
|
||||
global $langs, $conf, $user;
|
||||
$h = 0;
|
||||
$head = array();
|
||||
|
||||
$head[$h][0] = dol_buildpath('/cron/admin/cron.php', 1);
|
||||
$head[$h][1] = $langs->trans("CronSetup");
|
||||
$head[$h][2] = 'setup';
|
||||
$h++;
|
||||
|
||||
complete_head_from_modules($conf, $langs, $object, $head, $h, 'cronadmin');
|
||||
|
||||
complete_head_from_modules($conf, $langs, $object, $head, $h, 'cronadmin', 'remove');
|
||||
|
||||
|
||||
return $head;
|
||||
}
|
||||
|
||||
function cron_prepare_head($object)
|
||||
{
|
||||
global $langs, $conf, $user;
|
||||
$h = 0;
|
||||
$head = array();
|
||||
|
||||
$head[$h][0] = dol_buildpath('/cron/card.php', 1).'?id='.$object->id;
|
||||
$head[$h][1] = $langs->trans("CronTask");
|
||||
$head[$h][2] = 'card';
|
||||
$h++;
|
||||
|
||||
$head[$h][0] = dol_buildpath('/cron/info.php', 1).'?id='.$object->id;
|
||||
$head[$h][1] = $langs->trans("CronInfoPage");
|
||||
$head[$h][2] = 'info';
|
||||
$h++;
|
||||
|
||||
complete_head_from_modules($conf, $langs, $object, $head, $h, 'cron');
|
||||
|
||||
complete_head_from_modules($conf, $langs, $object, $head, $h, 'cron', 'remove');
|
||||
|
||||
return $head;
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
/* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
|
||||
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
|
||||
*
|
||||
* 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
|
||||
@ -16,11 +17,11 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \defgroup webservices Module webservices
|
||||
* \brief Module to enable the Dolibarr server of web services
|
||||
* \file htdocs/core/modules/modCron.class.php
|
||||
* \ingroup cron
|
||||
* \brief File to describe cron module
|
||||
* \defgroup cron Module cron
|
||||
* \brief cron module descriptor.
|
||||
* \file cron/core/modules/modCron.class.php
|
||||
* \ingroup cron
|
||||
* \brief Description and activation file for module Jobs
|
||||
*/
|
||||
include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
|
||||
|
||||
@ -65,11 +66,20 @@ class modCron extends DolibarrModules
|
||||
//-------------
|
||||
$this->depends = array();
|
||||
$this->requiredby = array();
|
||||
$this->langfiles = array("cron");
|
||||
$this->langfiles = array("cron@cron");
|
||||
|
||||
// Constantes
|
||||
//-----------
|
||||
$this->const = array();
|
||||
$this->const = array(
|
||||
0=>array(
|
||||
'MAIN_CRON_KEY',
|
||||
'chaine',
|
||||
'',
|
||||
'CRON KEY',
|
||||
0,
|
||||
'main',
|
||||
0
|
||||
),);
|
||||
|
||||
// New pages on tabs
|
||||
// -----------------
|
||||
@ -79,25 +89,60 @@ class modCron extends DolibarrModules
|
||||
//------
|
||||
$this->boxes = array();
|
||||
|
||||
// Permissions
|
||||
//------------
|
||||
$this->rights = array();
|
||||
$this->rights_class = 'cron';
|
||||
$r=0;
|
||||
// Permissions
|
||||
$this->rights = array(); // Permission array used by this module
|
||||
$this->rights_class = 'cron';
|
||||
$r=0;
|
||||
|
||||
$this->rights[$r][0] = 23001;
|
||||
$this->rights[$r][1] = 'Read cron jobs';
|
||||
$this->rights[$r][3] = 1;
|
||||
$this->rights[$r][4] = 'read';
|
||||
$r++;
|
||||
|
||||
$this->rights[$r][0] = 23002;
|
||||
$this->rights[$r][1] = 'Create cron Jobs';
|
||||
$this->rights[$r][3] = 0;
|
||||
$this->rights[$r][4] = 'create';
|
||||
$r++;
|
||||
|
||||
$this->rights[$r][0] = 23003;
|
||||
$this->rights[$r][1] = 'Delete cron Jobs';
|
||||
$this->rights[$r][3] = 0;
|
||||
$this->rights[$r][4] = 'delete';
|
||||
$r++;
|
||||
|
||||
$this->rights[$r][0] = 23004;
|
||||
$this->rights[$r][1] = 'Execute cron Jobs';
|
||||
$this->rights[$r][3] = 0;
|
||||
$this->rights[$r][4] = 'execute';
|
||||
$r++;
|
||||
|
||||
// Main menu entries
|
||||
$r=0;
|
||||
$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
|
||||
'titre'=>'CronJobs',
|
||||
'url'=>'/cron/index.php',
|
||||
'langs'=>'cron@cron', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
|
||||
'position'=>100,
|
||||
'titre'=>'CronListActive',
|
||||
'url'=>'/cron/list.php?status=1',
|
||||
'langs'=>'cron', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
|
||||
'position'=>200,
|
||||
'enabled'=>'$leftmenu==\'modulesadmintools\'', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
|
||||
'perms'=>'$user->admin', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
|
||||
'perms'=>'$user->rights->cron->read', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
|
||||
'target'=>'',
|
||||
'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
|
||||
$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
|
||||
'type'=>'left', // This is a Left menu entry
|
||||
'titre'=>'CronListInactive',
|
||||
'url'=>'/cron/list.php?status=0',
|
||||
'langs'=>'cron', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
|
||||
'position'=>201,
|
||||
'enabled'=>'$leftmenu==\'modulesadmintools\'', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
|
||||
'perms'=>'$user->rights->cron->read', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
|
||||
'target'=>'',
|
||||
'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
|
||||
$r++;
|
||||
}
|
||||
|
||||
|
||||
@ -114,8 +159,6 @@ class modCron extends DolibarrModules
|
||||
// Prevent pb of modules not correctly disabled
|
||||
//$this->remove($options);
|
||||
|
||||
$sql = array();
|
||||
|
||||
return $this->_init($sql,$options);
|
||||
}
|
||||
|
||||
|
||||
@ -1,34 +1,36 @@
|
||||
<?php
|
||||
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.org>
|
||||
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
|
||||
* Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
|
||||
* Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/cron/admin/cron.php
|
||||
* \ingroup cron
|
||||
* \brief Page to setup cron module
|
||||
*/
|
||||
* \file cron/admin/cron.php
|
||||
* \ingroup cron
|
||||
*/
|
||||
|
||||
require '../../main.inc.php';
|
||||
// Dolibarr environment
|
||||
$res = @include("../../main.inc.php"); // From htdocs directory
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/cron.lib.php';
|
||||
|
||||
$langs->load("admin");
|
||||
$langs->load("cron");
|
||||
$langs->load("admin");
|
||||
$langs->load("cron");
|
||||
|
||||
if (! $user->admin)
|
||||
accessforbidden();
|
||||
@ -36,37 +38,40 @@ if (! $user->admin)
|
||||
$actionsave=GETPOST("save");
|
||||
|
||||
// Sauvegardes parametres
|
||||
if ($actionsave)
|
||||
if (!empty($actionsave))
|
||||
{
|
||||
$i=0;
|
||||
$i=0;
|
||||
|
||||
$db->begin();
|
||||
$db->begin();
|
||||
|
||||
$i+=dolibarr_set_const($db,'CRON_KEY',trim(GETPOST("CRON_KEY")),'chaine',0,'',$conf->entity);
|
||||
$i+=dolibarr_set_const($db,'MAIN_CRON_KEY',trim(GETPOST("MAIN_CRON_KEY")),'chaine',0,'',0);
|
||||
|
||||
if ($i >= 1)
|
||||
{
|
||||
$db->commit();
|
||||
setEventMessage($langs->trans("SetupSaved"));
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
setEventMessage($langs->trans("Error"), 'errors');
|
||||
}
|
||||
if ($i >= 1)
|
||||
{
|
||||
$db->commit();
|
||||
setEventMessage($langs->trans("SetupSaved"));
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
setEventMessage($langs->trans("Error"), 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
*/
|
||||
|
||||
llxHeader();
|
||||
|
||||
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
|
||||
print_fiche_titre($langs->trans("CronSetup"),$linkback,'setup');
|
||||
|
||||
print $langs->trans("CronDesc")."<br>\n";
|
||||
// Configuration header
|
||||
$head = cronadmin_prepare_head();
|
||||
dol_fiche_head($head,'setup',$langs->trans("Module2300Name"),0,'cron');
|
||||
|
||||
print "<br>\n";
|
||||
|
||||
print '<form name="agendasetupform" action="'.$_SERVER["PHP_SELF"].'" method="post">';
|
||||
@ -76,13 +81,12 @@ print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print "<td>".$langs->trans("Parameter")."</td>";
|
||||
print "<td>".$langs->trans("Value")."</td>";
|
||||
//print "<td>".$langs->trans("Examples")."</td>";
|
||||
print "<td> </td>";
|
||||
print "</tr>";
|
||||
|
||||
print '<tr class="impair">';
|
||||
print '<td class="fieldrequired">'.$langs->trans("KeyForCronAccess").'</td>';
|
||||
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">';
|
||||
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">';
|
||||
if (! empty($conf->use_javascript_ajax))
|
||||
print ' '.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
|
||||
print '</td>';
|
||||
@ -102,12 +106,35 @@ print '<br><br>';
|
||||
|
||||
// Cron launch
|
||||
print '<u>'.$langs->trans("URLToLaunchCronJobs").':</u><br>';
|
||||
$url=DOL_MAIN_URL_ROOT.'/public/cron/cron_run_jobs.php'.(empty($conf->global->CRON_KEY)?'':'?securitykey='.$conf->global->CRON_KEY);
|
||||
$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;
|
||||
print img_picto('','object_globe.png').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
|
||||
print ' '.$langs->trans("OrToLaunchASpecificJob").'<br>';
|
||||
$url=DOL_MAIN_URL_ROOT.'/public/cron/cron_run_jobs.php?'.(empty($conf->global->CRON_KEY)?'':'securitykey='.$conf->global->CRON_KEY.'&').'id=cronjobid';
|
||||
print img_picto('','object_globe.png').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
|
||||
$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';
|
||||
print img_picto('','object_globe.png').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
|
||||
print '<br>';
|
||||
print '<br>';
|
||||
|
||||
|
||||
$linuxlike=1;
|
||||
if (preg_match('/^win/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 '<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) {
|
||||
print 'user@host:'.DOL_DOCUMENT_ROOT.'$ php ..'.$file."<br>\n";
|
||||
} else {
|
||||
print DOL_DOCUMENT_ROOT.'> php ..'.$file."<br>\n";
|
||||
}
|
||||
print '<br>';
|
||||
|
||||
|
||||
|
||||
|
||||
print '<br>';
|
||||
@ -116,20 +143,18 @@ if (! empty($conf->use_javascript_ajax))
|
||||
{
|
||||
print "\n".'<script type="text/javascript">';
|
||||
print '$(document).ready(function () {
|
||||
$("#generate_token").click(function() {
|
||||
$.get( "'.DOL_URL_ROOT.'/core/ajax/security.php", {
|
||||
action: \'getrandompassword\',
|
||||
generic: true
|
||||
},
|
||||
function(token) {
|
||||
$("#CRON_KEY").val(token);
|
||||
});
|
||||
});
|
||||
});';
|
||||
$("#generate_token").click(function() {
|
||||
$.get( "'.DOL_URL_ROOT.'/core/ajax/security.php", {
|
||||
action: \'getrandompassword\',
|
||||
generic: true
|
||||
},
|
||||
function(token) {
|
||||
$("#MAIN_CRON_KEY").val(token);
|
||||
});
|
||||
});
|
||||
});';
|
||||
print '</script>';
|
||||
}
|
||||
|
||||
|
||||
llxFooter();
|
||||
$db->close();
|
||||
?>
|
||||
$db->close();
|
||||
596
htdocs/cron/card.php
Normal file
@ -0,0 +1,596 @@
|
||||
<?php
|
||||
/* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
|
||||
* Copyright (C) 2013 Florian Henry <florian.henry@open-concpt.pro>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file cron/card.php
|
||||
* \ingroup cron
|
||||
* \brief Cron Jobs Card
|
||||
*/
|
||||
|
||||
require '../main.inc.php';
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
|
||||
|
||||
// librairie jobs
|
||||
require_once DOL_DOCUMENT_ROOT."/cron/class/cronjob.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT."/core/class/html.formcron.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/cron.lib.php';
|
||||
|
||||
|
||||
$langs->load("admin");
|
||||
$langs->load("cron");
|
||||
|
||||
if (!$user->rights->cron->create) accessforbidden();
|
||||
|
||||
$id=GETPOST('id','int');
|
||||
$action=GETPOST('action','alpha');
|
||||
$confirm=GETPOST('confirm','alpha');
|
||||
$cancel=GETPOST('cancel');
|
||||
|
||||
$object = new Cronjob($db);
|
||||
if (!empty($id)) {
|
||||
$result=$object->fetch($id);
|
||||
if ($result < 0) {
|
||||
setEventMessage($object->error,'errors');
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($cancel)) {
|
||||
if (!empty($id)) {
|
||||
$action='';
|
||||
}else {
|
||||
Header ( "Location: ".dol_buildpath('/cron/cron/list.php',1).'?status=1');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Delete jobs
|
||||
if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->cron->delete){
|
||||
|
||||
|
||||
$result = $object->delete($user);
|
||||
|
||||
if ($result < 0) {
|
||||
setEventMessage($object->error,'errors');
|
||||
$action='edit';
|
||||
}else {
|
||||
Header ( "Location: ".dol_buildpath('/cron/cron/list.php',1).'?status=1');
|
||||
}
|
||||
}
|
||||
|
||||
// Execute jobs
|
||||
if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->execute){
|
||||
|
||||
$result=$object->run_jobs($user->login);
|
||||
|
||||
if ($result < 0) {
|
||||
setEventMessage($object->error,'errors');
|
||||
$action='';
|
||||
}else {
|
||||
$action='';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ($action=='add') {
|
||||
|
||||
$object->jobtype=GETPOST('jobtype','alpha');
|
||||
$object->label=GETPOST('label','alpha');
|
||||
$object->command=GETPOST('command','alpha');
|
||||
$object->priority=GETPOST('priority','int');
|
||||
$object->classesname=GETPOST('classesname','alpha');
|
||||
$object->objectname=GETPOST('objectname','alpha');
|
||||
$object->methodename=GETPOST('methodename','alpha');
|
||||
$object->params=GETPOST('params');
|
||||
$object->md5params=GETPOST('md5params');
|
||||
$object->module_name=GETPOST('module_name','alpha');
|
||||
$object->note=GETPOST('note');
|
||||
$object->datestart=dol_mktime(GETPOST('datestarthour','int'), GETPOST('datestartmin','int'), 0, GETPOST('datestartmonth','int'), GETPOST('datestartday','int'), GETPOST('datestartyear','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->frequency=$object->unitfrequency * GETPOST('nbfrequency','int');
|
||||
|
||||
//Ajout de la tache cron
|
||||
$result = $object->create($user);
|
||||
|
||||
// test du Resultat de la requete
|
||||
if ($result < 0) {
|
||||
setEventMessage($object->error,'errors');
|
||||
$action='create';
|
||||
}
|
||||
else {
|
||||
setEventMessage($langs->trans('CronSaveSucess'),'mesgs');
|
||||
$action='';
|
||||
}
|
||||
}
|
||||
|
||||
// Save parameters
|
||||
if ($action=='update') {
|
||||
$object->id=$id;
|
||||
$object->jobtype=GETPOST('jobtype','alpha');
|
||||
$object->label=GETPOST('label','alpha');
|
||||
$object->command=GETPOST('command','alpha');
|
||||
$object->classesname=GETPOST('classesname','alpha');
|
||||
$object->priority=GETPOST('priority','int');
|
||||
$object->objectname=GETPOST('objectname','alpha');
|
||||
$object->methodename=GETPOST('methodename','alpha');
|
||||
$object->params=GETPOST('params');
|
||||
$object->md5params=GETPOST('md5params');
|
||||
$object->module_name=GETPOST('module_name','alpha');
|
||||
$object->note=GETPOST('note');
|
||||
$object->datestart=dol_mktime(GETPOST('datestarthour','int'), GETPOST('datestartmin','int'), 0, GETPOST('datestartmonth','int'), GETPOST('datestartday','int'), GETPOST('datestartyear','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->frequency=$object->unitfrequency * GETPOST('nbfrequency','int');
|
||||
|
||||
//Ajout de la tache cron
|
||||
$result = $object->update($user);
|
||||
|
||||
// test du Resultat de la requete
|
||||
if ($result < 0) {
|
||||
setEventMessage($object->error,'errors');
|
||||
$action='edit';
|
||||
}
|
||||
else {
|
||||
setEventMessage($langs->trans('CronSaveSucess'),'mesgs');
|
||||
$action='';
|
||||
}
|
||||
}
|
||||
|
||||
if ($action=='activate') {
|
||||
$object->status=1;
|
||||
|
||||
//Ajout de la tache cron
|
||||
$result = $object->update($user);
|
||||
|
||||
// test du Resultat de la requete
|
||||
if ($result < 0) {
|
||||
setEventMessage($object->error,'errors');
|
||||
$action='edit';
|
||||
}
|
||||
else {
|
||||
setEventMessage($langs->trans('CronSaveSucess'),'mesgs');
|
||||
$action='';
|
||||
}
|
||||
}
|
||||
|
||||
if ($action=='inactive') {
|
||||
$object->status=0;
|
||||
//Ajout de la tache cron
|
||||
$result = $object->update($user);
|
||||
|
||||
// test du Resultat de la requete
|
||||
if ($result < 0) {
|
||||
setEventMessage($object->error,'errors');
|
||||
$action='edit';
|
||||
}
|
||||
else {
|
||||
setEventMessage($langs->trans('CronSaveSucess'),'mesgs');
|
||||
$action='';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
llxHeader('',$langs->trans("CronAdd"));
|
||||
|
||||
if ($action=='edit' || empty($action) || $action=='delete' || $action=='execute') {
|
||||
$head=cron_prepare_head($object);
|
||||
dol_fiche_head($head, 'card', $langs->trans("CronTask"), 0, 'bill');
|
||||
} elseif ($action=='create') {
|
||||
print_fiche_titre($langs->trans("CronTask"),'','setup');
|
||||
}
|
||||
|
||||
if ($conf->use_javascript_ajax)
|
||||
{
|
||||
print "\n".'<script type="text/javascript" language="javascript">';
|
||||
print 'jQuery(document).ready(function () {
|
||||
function initfields()
|
||||
{
|
||||
if ($("#jobtype option:selected").val()==\'method\') {
|
||||
$(".blockmethod").show();
|
||||
$(".blockcommand").hide();
|
||||
}
|
||||
if ($("#jobtype option:selected").val()==\'command\') {
|
||||
$(".blockmethod").hide();
|
||||
$(".blockcommand").show();
|
||||
}
|
||||
}
|
||||
initfields();
|
||||
jQuery("#jobtype").change(function() {
|
||||
initfields();
|
||||
});
|
||||
})';
|
||||
print '</script>'."\n";
|
||||
}
|
||||
|
||||
$form = new Form($db);
|
||||
$formCron = new FormCron($db);
|
||||
|
||||
if ($action == 'delete')
|
||||
{
|
||||
$ret=$form->form_confirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("CronDelete"),$langs->trans("CronConfirmDelete"),"confirm_delete",'','',1);
|
||||
if ($ret == 'html') print '<br>';
|
||||
$action='';
|
||||
}
|
||||
|
||||
if ($action == 'execute'){
|
||||
$ret=$form->form_confirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("CronExecute"),$langs->trans("CronConfirmExecute"),"confirm_execute",'','',1);
|
||||
if ($ret == 'html') print '<br>';
|
||||
$action='';
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Create Template
|
||||
*/
|
||||
|
||||
if (empty($object->status)) {
|
||||
dol_htmloutput_mesg($langs->trans("CronTaskInactive"),'','warning',1);
|
||||
}
|
||||
|
||||
if (($action=="create") || ($action=="edit")) {
|
||||
|
||||
print '<form name="cronform" action="'.$_SERVER["PHP_SELF"].'" method="post">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'."\n";
|
||||
if (!empty($object->id)) {
|
||||
print '<input type="hidden" name="action" value="update">'."\n";
|
||||
print '<input type="hidden" name="id" value="'.$object->id.'">'."\n";
|
||||
} else {
|
||||
print '<input type="hidden" name="action" value="add">'."\n";
|
||||
}
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
print '<tr><td width="30%">';
|
||||
print $langs->trans('CronLabel')."</td>";
|
||||
print "<td><input type=\"text\" size=\"20\" name=\"label\" value=\"".$object->label."\" /> ";
|
||||
print "</td>";
|
||||
print "<td>";
|
||||
print "</td>";
|
||||
print "</tr>\n";
|
||||
|
||||
print "<tr><td>";
|
||||
print $langs->trans('CronType')."</td><td>";
|
||||
print $formCron->select_typejob('jobtype',$object->jobtype);
|
||||
print "</td>";
|
||||
print "<td>";
|
||||
print "</td>";
|
||||
print "</tr>\n";
|
||||
|
||||
print "<tr><td>";
|
||||
print $langs->trans('CronHourStart')."</td><td>";
|
||||
if(!empty($object->datestart)){
|
||||
$form->select_date($object->datestart,'datestart',1,1,'',"cronform");
|
||||
}
|
||||
else{
|
||||
$form->select_date(dol_now(),'datestart',1,1,'',"cronform");
|
||||
}
|
||||
print "</td>";
|
||||
print "<td>";
|
||||
print "</td>";
|
||||
print "</tr>\n";
|
||||
|
||||
print "<tr><td>";
|
||||
print $langs->trans('CronDtEnd')."</td><td>";
|
||||
if(!empty($object->dateend)){
|
||||
$form->select_date($object->dateend,'dateend',1,1,'',"cronform");
|
||||
}
|
||||
else{
|
||||
$form->select_date('','dateend',1,1,1,"cronform");
|
||||
}
|
||||
print "</td>";
|
||||
print "<td>";
|
||||
print "</td>";
|
||||
print "</tr>\n";
|
||||
|
||||
print "<tr><td>";
|
||||
print $langs->trans('CronPriority')."</td>";
|
||||
$priority=0;
|
||||
if (!empty($object->priority)) {
|
||||
$priority=$object->priority;
|
||||
}
|
||||
print "<td><input type=\"text\" size=\"2\" name=\"priority\" value=\"".$priority."\" /> ";
|
||||
print "</td>";
|
||||
print "<td>";
|
||||
print "</td>";
|
||||
print "</tr>\n";
|
||||
|
||||
print "<tr><td>";
|
||||
print $langs->trans('CronEvery')."</td>";
|
||||
print "<td><select name=\"nbfrequency\">";
|
||||
for($i=1; $i<=60; $i++){
|
||||
if(($object->frequency/$object->unitfrequency) == $i){
|
||||
print "<option value='".$i."' selected='selected'>".$i."</option>";
|
||||
}
|
||||
else{
|
||||
print "<option value='".$i."'>".$i."</option>";
|
||||
}
|
||||
}
|
||||
$input = "<input type=\"radio\" name=\"unitfrequency\" value=\"60\" id=\"frequency_minute\" ";
|
||||
if($object->unitfrequency=="60"){
|
||||
$input .= ' checked="checked" />';
|
||||
}
|
||||
else{
|
||||
$input .= ' />';
|
||||
}
|
||||
$input .= "<label for=\"frequency_minute\">".$langs->trans('Minutes')."</label>";
|
||||
print $input;
|
||||
|
||||
$input = "<input type=\"radio\" name=\"unitfrequency\" value=\"3600\" id=\"frequency_heures\" ";
|
||||
if($object->unitfrequency=="3600"){
|
||||
$input .= ' checked="checked" />';
|
||||
}
|
||||
else{
|
||||
$input .= ' />';
|
||||
}
|
||||
$input .= "<label for=\"frequency_heures\">".$langs->trans('Hours')."</label>";
|
||||
print $input;
|
||||
|
||||
$input = "<input type=\"radio\" name=\"unitfrequency\" value=\"86400\" id=\"frequency_jours\" ";
|
||||
if($object->unitfrequency=="86400"){
|
||||
$input .= ' checked="checked" />';
|
||||
}
|
||||
else{
|
||||
$input .= ' />';
|
||||
}
|
||||
$input .= "<label for=\"frequency_jours\">".$langs->trans('Days')."</label>";
|
||||
print $input;
|
||||
|
||||
$input = "<input type=\"radio\" name=\"unitfrequency\" value=\"604800\" id=\"frequency_semaine\" ";
|
||||
if($object->unitfrequency=="604800"){
|
||||
$input .= ' checked="checked" />';
|
||||
}
|
||||
else{
|
||||
$input .= ' />';
|
||||
}
|
||||
$input .= "<label for=\"frequency_semaine\">".$langs->trans('Weeks')."</label>";
|
||||
print $input;
|
||||
print "</td>";
|
||||
print "<td>";
|
||||
print "</td>";
|
||||
print "</tr>\n";
|
||||
|
||||
|
||||
print '<tr class="blockmethod"><td>';
|
||||
print $langs->trans('CronModule')."</td><td>";
|
||||
print "<input type=\"text\" size=\"20\" name=\"module_name\" value=\"".$object->module_name."\" /> ";
|
||||
print "</td>";
|
||||
print "<td>";
|
||||
print $form->textwithpicto('',$langs->trans("CronModuleHelp"),1,'help');
|
||||
print "</td>";
|
||||
print "</tr>\n";
|
||||
|
||||
print '<tr class="blockmethod"><td>';
|
||||
print $langs->trans('CronClassFile')."</td><td>";
|
||||
print "<input type=\"text\" size=\"20\" name=\"classesname\" value=\"".$object->classesname."\" /> ";
|
||||
print "</td>";
|
||||
print "<td>";
|
||||
print $form->textwithpicto('',$langs->trans("CronClassFileHelp"),1,'help');
|
||||
print "</td>";
|
||||
print "</tr>\n";
|
||||
|
||||
print '<tr class="blockmethod"><td>';
|
||||
print $langs->trans('CronObject')."</td><td>";
|
||||
print "<input type=\"text\" size=\"20\" name=\"objectname\" value=\"".$object->objectname."\" /> ";
|
||||
print "</td>";
|
||||
print "<td>";
|
||||
print $form->textwithpicto('',$langs->trans("CronObjectHelp"),1,'help');
|
||||
print "</td>";
|
||||
print "</tr>\n";
|
||||
|
||||
print '<tr class="blockmethod"><td>';
|
||||
print $langs->trans('CronMethod')."</td><td>";
|
||||
print "<input type=\"text\" size=\"20\" name=\"methodename\" value=\"".$object->methodename."\" /> ";
|
||||
print "</td>";
|
||||
print "<td>";
|
||||
print $form->textwithpicto('',$langs->trans("CronMethodHelp"),1,'help');
|
||||
print "</td>";
|
||||
print "</tr>\n";
|
||||
|
||||
print '<tr class="blockmethod"><td>';
|
||||
print $langs->trans('CronArgs')."</td><td>";
|
||||
print "<input type=\"text\" size=\"20\" name=\"params\" value=\"".$object->params."\" /> ";
|
||||
print "</td>";
|
||||
print "<td>";
|
||||
print $form->textwithpicto('',$langs->trans("CronArgsHelp"),1,'help');
|
||||
print "</td>";
|
||||
print "</tr>\n";
|
||||
|
||||
print '<tr class="blockcommand"><td>';
|
||||
print $langs->trans('CronCommand')."</td><td>";
|
||||
print "<input type=\"text\" size=\"50\" name=\"command\" value=\"".$object->command."\" /> ";
|
||||
print "</td>";
|
||||
print "<td>";
|
||||
print $form->textwithpicto('',$langs->trans("CronCommandHelp"),1,'help');
|
||||
print "</td>";
|
||||
print "</tr>\n";
|
||||
|
||||
print '<tr><td>';
|
||||
print $langs->trans('CronNote')."</td><td>";
|
||||
$doleditor = new DolEditor('note', $object->note, '', 160, 'dolibarr_notes', 'In', true, false, 0, 4, 90);
|
||||
$doleditor->Create();
|
||||
print "</td>";
|
||||
print "<td>";
|
||||
print "</td>";
|
||||
print "</tr>\n";
|
||||
|
||||
|
||||
print '<tr><td colspan="2" align="center">';
|
||||
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 "</td>";
|
||||
print "<td>";
|
||||
print "</td>";
|
||||
print "</tr>\n";
|
||||
|
||||
print '</table>';
|
||||
|
||||
print "</form>\n";
|
||||
|
||||
}else {
|
||||
|
||||
/*
|
||||
* view Template
|
||||
*/
|
||||
|
||||
// box add_jobs_box
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
print '<tr><td width="30%">';
|
||||
print $langs->trans('CronId')."</td>";
|
||||
print "<td>".$form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'id');
|
||||
print "</td></tr>\n";
|
||||
|
||||
print '<tr><td>';
|
||||
print $langs->trans('CronLabel')."</td>";
|
||||
print "<td>".$object->label;
|
||||
print "</td></tr>";
|
||||
|
||||
print "<tr><td>";
|
||||
print $langs->trans('CronType')."</td><td>";
|
||||
print $formCron->select_typejob('jobtype',$object->jobtype,1);
|
||||
print "</td></tr>";
|
||||
|
||||
print "<tr><td>";
|
||||
print $langs->trans('CronHourStart')."</td><td>";
|
||||
if(!empty($object->datestart)) {print dol_print_date($object->datestart,'dayhourtext');} else {print $langs->trans('CronNone');}
|
||||
print "</td></tr>";
|
||||
|
||||
print "<tr><td>";
|
||||
print $langs->trans('CronDtEnd')."</td><td>";
|
||||
if(!empty($object->dateend)) {print dol_print_date($object->dateend,'dayhourtext');} else {print $langs->trans('CronNone');}
|
||||
print "</td></tr>";
|
||||
|
||||
print "<tr><td>";
|
||||
print $langs->trans('CronPriority')."</td>";
|
||||
print "<td>".$object->priority;
|
||||
print "</td></tr>";
|
||||
|
||||
print "<tr><td>";
|
||||
print $langs->trans('CronNbRun')."</td>";
|
||||
print "<td>".$object->nbrun;
|
||||
print "</td></tr>";
|
||||
|
||||
print "<tr><td>";
|
||||
print $langs->trans('CronEvery')."</td>";
|
||||
print "<td>";
|
||||
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 == "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');
|
||||
print "</td></tr>";
|
||||
|
||||
|
||||
print '<tr class="blockmethod"><td>';
|
||||
print $langs->trans('CronModule')."</td><td>";
|
||||
print $object->module_name;
|
||||
print "</td></tr>";
|
||||
|
||||
print '<tr class="blockmethod"><td>';
|
||||
print $langs->trans('CronClassFile')."</td><td>";
|
||||
print $object->classesname;
|
||||
print "</td></tr>";
|
||||
|
||||
print '<tr class="blockmethod"><td>';
|
||||
print $langs->trans('CronObject')."</td><td>";
|
||||
print $object->objectname;
|
||||
print "</td></tr>";
|
||||
|
||||
print '<tr class="blockmethod"><td>';
|
||||
print $langs->trans('CronMethod')."</td><td>";
|
||||
print $object->methodename;
|
||||
print "</td></tr>";
|
||||
|
||||
print '<tr class="blockmethod"><td>';
|
||||
print $langs->trans('CronArgs')."</td><td>";
|
||||
print $object->params;
|
||||
print "</td></tr>";
|
||||
|
||||
print '<tr class="blockcommand"><td>';
|
||||
print $langs->trans('CronCommand')."</td><td>";
|
||||
print $object->command;
|
||||
print "</td></tr>";
|
||||
|
||||
print '<tr><td>';
|
||||
print $langs->trans('CronNote')."</td><td>";
|
||||
print $object->note;
|
||||
print "</td></tr>";
|
||||
|
||||
print '<tr><td>';
|
||||
print $langs->trans('CronDtLastLaunch')."</td><td>";
|
||||
if(!empty($object->datelastrun)) {print dol_print_date($object->datelastrun,'dayhourtext');} else {print $langs->trans('CronNone');}
|
||||
print "</td></tr>";
|
||||
|
||||
print '<tr><td>';
|
||||
print $langs->trans('CronDtNextLaunch')."</td><td>";
|
||||
if(!empty($object->datenextrun)) {print dol_print_date($object->datenextrun,'dayhourtext');} else {print $langs->trans('CronNone');}
|
||||
print "</td></tr>";
|
||||
|
||||
print '<tr><td>';
|
||||
print $langs->trans('CronDtLastResult')."</td><td>";
|
||||
if(!empty($object->datelastresult)) {print dol_print_date($object->datelastresult,'dayhourtext');} else {print $langs->trans('CronNone');}
|
||||
print "</td></tr>";
|
||||
|
||||
print '<tr><td>';
|
||||
print $langs->trans('CronLastResult')."</td><td>";
|
||||
print $object->lastresult;
|
||||
print "</td></tr>";
|
||||
|
||||
print '<tr><td>';
|
||||
print $langs->trans('CronLastOutput')."</td><td>";
|
||||
print nl2br($object->lastoutput);
|
||||
print "</td></tr>";
|
||||
|
||||
print '</table>';
|
||||
|
||||
print "\n\n<div class=\"tabsAction\">\n";
|
||||
if (! $user->rights->cron->create) {
|
||||
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("Edit").'</a>';
|
||||
} else {
|
||||
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&id='.$object->id.'">'.$langs->trans("Edit").'</a>';
|
||||
}
|
||||
if (! $user->rights->cron->delete) {
|
||||
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("Delete").'</a>';
|
||||
} else {
|
||||
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=delete&id='.$object->id.'">'.$langs->trans("Delete").'</a>';
|
||||
}
|
||||
if (! $user->rights->cron->create) {
|
||||
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("CronStatusActiveBtn").'/'.$langs->trans("CronStatusInactiveBtn").'</a>';
|
||||
} else {
|
||||
if (empty($object->status)) {
|
||||
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=activate&id='.$object->id.'">'.$langs->trans("CronStatusActiveBtn").'</a>';
|
||||
} else {
|
||||
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=inactive&id='.$object->id.'">'.$langs->trans("CronStatusInactiveBtn").'</a>';
|
||||
}
|
||||
}
|
||||
if ((! $user->rights->cron->execute) || (empty($object->status))) {
|
||||
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("CronExecute").'</a>';
|
||||
} else {
|
||||
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=execute&id='.$object->id.'">'.$langs->trans("CronExecute").'</a>';
|
||||
}
|
||||
print '<br><br></div>';
|
||||
}
|
||||
|
||||
$db->close();
|
||||
llxFooter();
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) ---Put here your own copyright and developer email---
|
||||
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
|
||||
*
|
||||
* 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
|
||||
@ -17,42 +17,58 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file dev/skeletons/cronjob.class.php
|
||||
* \file cron/class/cronjob.class.php
|
||||
* \ingroup cron
|
||||
* \brief CRUD class file (Create/Read/Update/Delete) for cronjob table
|
||||
* Initialy built by build_class_from_table on 2013-03-17 18:50
|
||||
*/
|
||||
|
||||
// Put here all includes required by your class file
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php");
|
||||
//require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
|
||||
//require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
|
||||
|
||||
|
||||
/**
|
||||
* Put here description of your class
|
||||
* Crob Job class
|
||||
*/
|
||||
class Cronjob extends CommonObject
|
||||
{
|
||||
var $db; //!< To store db handler
|
||||
var $error; //!< To return error code (or message)
|
||||
var $errors=array(); //!< To return several error codes (or messages)
|
||||
var $element='cronjob'; //!< Id that identify managed objects
|
||||
var $element='cronjob'; //!< Id that identify managed objects
|
||||
var $table_element='cronjob'; //!< Name of table without prefix where object is stored
|
||||
|
||||
var $id;
|
||||
|
||||
|
||||
var $ref; //Use for prevnext_ref
|
||||
var $jobtype;
|
||||
var $tms='';
|
||||
var $datec='';
|
||||
var $label;
|
||||
var $command;
|
||||
var $classesname;
|
||||
var $objectname;
|
||||
var $methodename;
|
||||
var $params;
|
||||
var $md5params;
|
||||
var $module_name;
|
||||
var $priority;
|
||||
var $datelastrun='';
|
||||
var $lastresult='';
|
||||
var $datenextrun='';
|
||||
var $dateend='';
|
||||
var $datestart='';
|
||||
var $datelastresult='';
|
||||
var $lastresult;
|
||||
var $lastoutput;
|
||||
var $fk_user;
|
||||
var $unitfrequency;
|
||||
var $frequency;
|
||||
var $status;
|
||||
var $fk_user_author;
|
||||
var $fk_user_mod;
|
||||
var $note;
|
||||
var $nbrun;
|
||||
|
||||
var $lines;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@ -80,51 +96,128 @@ 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->fk_user)) $this->fk_user=trim($this->fk_user);
|
||||
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)) $this->note=trim($this->note);
|
||||
|
||||
|
||||
if (isset($this->nbrun)) $this->nbrun=trim($this->nbrun);
|
||||
|
||||
// Check parameters
|
||||
// Put here code to add control on parameters values
|
||||
// Put here code to add a control on parameters values
|
||||
if (dol_strlen($this->datestart)==0) {
|
||||
$this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronDtStart'));
|
||||
$error++;
|
||||
}
|
||||
if (empty($this->label)) {
|
||||
$this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronLabel'));
|
||||
$error++;
|
||||
}
|
||||
if ((dol_strlen($this->datestart)!=0) && (dol_strlen($this->dateend)!=0) && ($this->dateend<$this->datestart)) {
|
||||
$this->errors[]=$langs->trans('CronErrEndDateStartDt');
|
||||
$error++;
|
||||
}
|
||||
if (empty($this->unitfrequency)) {
|
||||
$this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronFrequency'));
|
||||
$error++;
|
||||
}
|
||||
if (($this->jobtype=='command') && (empty($this->command))) {
|
||||
$this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronCommand'));
|
||||
$error++;
|
||||
}
|
||||
if (($this->jobtype=='method') && (empty($this->classesname))) {
|
||||
$this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronClass'));
|
||||
$error++;
|
||||
}
|
||||
if (($this->jobtype=='method') && (empty($this->methodename))) {
|
||||
$this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronMethod'));
|
||||
$error++;
|
||||
}
|
||||
if (($this->jobtype=='method') && (empty($this->objectname))) {
|
||||
$this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronObject'));
|
||||
$error++;
|
||||
}
|
||||
|
||||
// Insert request
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."cronjob(";
|
||||
|
||||
|
||||
$sql.= "datec,";
|
||||
$sql.= "jobtype,";
|
||||
$sql.= "label,";
|
||||
$sql.= "command,";
|
||||
$sql.= "classesname,";
|
||||
$sql.= "objectname,";
|
||||
$sql.= "methodename,";
|
||||
$sql.= "params,";
|
||||
$sql.= "md5params,";
|
||||
$sql.= "module_name,";
|
||||
$sql.= "priority,";
|
||||
$sql.= "datelastrun,";
|
||||
$sql.= "datenextrun,";
|
||||
$sql.= "dateend,";
|
||||
$sql.= "datestart,";
|
||||
$sql.= "lastresult,";
|
||||
$sql.= "datelastresult,";
|
||||
$sql.= "lastoutput,";
|
||||
$sql.= "fk_user,";
|
||||
$sql.= "note";
|
||||
|
||||
$sql.= "unitfrequency,";
|
||||
$sql.= "frequency,";
|
||||
$sql.= "status,";
|
||||
$sql.= "fk_user_author,";
|
||||
$sql.= "fk_user_mod,";
|
||||
$sql.= "note,";
|
||||
$sql.= "nbrun";
|
||||
|
||||
|
||||
$sql.= ") VALUES (";
|
||||
|
||||
$sql.= " ".(! isset($this->datec) || dol_strlen($this->datec)==0?'NULL':$this->db->idate($this->datec)).",";
|
||||
|
||||
$sql.= " ".$this->db->idate(dol_now()).",";
|
||||
$sql.= " ".(! isset($this->jobtype)?'NULL':"'".$this->db->escape($this->jobtype)."'").",";
|
||||
$sql.= " ".(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").",";
|
||||
$sql.= " ".(! isset($this->command)?'NULL':"'".$this->db->escape($this->command)."'").",";
|
||||
$sql.= " ".(! isset($this->classesname)?'NULL':"'".$this->db->escape($this->classesname)."'").",";
|
||||
$sql.= " ".(! isset($this->objectname)?'NULL':"'".$this->db->escape($this->objectname)."'").",";
|
||||
$sql.= " ".(! isset($this->methodename)?'NULL':"'".$this->db->escape($this->methodename)."'").",";
|
||||
$sql.= " ".(! isset($this->params)?'NULL':"'".$this->db->escape($this->params)."'").",";
|
||||
$sql.= " ".(! isset($this->md5params)?'NULL':"'".$this->db->escape($this->md5params)."'").",";
|
||||
$sql.= " ".(! isset($this->module_name)?'NULL':"'".$this->db->escape($this->module_name)."'").",";
|
||||
$sql.= " ".(! isset($this->priority)?'NULL':"'".$this->priority."'").",";
|
||||
$sql.= " ".(! isset($this->datelastrun) || dol_strlen($this->datelastrun)==0?'NULL':$this->db->idate($this->datelastrun)).",";
|
||||
$sql.= " ".(! isset($this->lastresult) || dol_strlen($this->lastresult)==0?'NULL':$this->db->idate($this->lastresult)).",";
|
||||
$sql.= " ".(! isset($this->datenextrun) || dol_strlen($this->datenextrun)==0?'NULL':$this->db->idate($this->datenextrun)).",";
|
||||
$sql.= " ".(! isset($this->dateend) || dol_strlen($this->dateend)==0?'NULL':$this->db->idate($this->dateend)).",";
|
||||
$sql.= " ".(! isset($this->datestart) || dol_strlen($this->datestart)==0?'NULL':$this->db->idate($this->datestart)).",";
|
||||
$sql.= " ".(! isset($this->lastresult)?'NULL':"'".$this->db->escape($this->lastresult)."'").",";
|
||||
$sql.= " ".(! isset($this->datelastresult) || dol_strlen($this->datelastresult)==0?'NULL':$this->db->idate($this->datelastresult)).",";
|
||||
$sql.= " ".(! isset($this->lastoutput)?'NULL':"'".$this->db->escape($this->lastoutput)."'").",";
|
||||
$sql.= " ".(! isset($this->fk_user)?'NULL':"'".$this->fk_user."'").",";
|
||||
$sql.= " ".(! isset($this->note)?'NULL':"'".$this->db->escape($this->note)."'")."";
|
||||
|
||||
$sql.= " ".(! isset($this->unitfrequency)?'NULL':"'".$this->unitfrequency."'").",";
|
||||
$sql.= " ".(! isset($this->frequency)?'NULL':"'".$this->frequency."'").",";
|
||||
$sql.= " ".(! isset($this->status)?'0':"'".$this->status."'").",";
|
||||
$sql.= " ".$user->id.",";
|
||||
$sql.= " ".$user->id.",";
|
||||
$sql.= " ".(! isset($this->note)?'NULL':"'".$this->db->escape($this->note)."'").",";
|
||||
$sql.= " ".(! isset($this->nbrun)?'0':"'".$this->db->escape($this->nbrun)."'")."";
|
||||
|
||||
|
||||
$sql.= ")";
|
||||
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
|
||||
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."cronjob");
|
||||
@ -173,18 +266,35 @@ class Cronjob extends CommonObject
|
||||
global $langs;
|
||||
$sql = "SELECT";
|
||||
$sql.= " t.rowid,";
|
||||
|
||||
|
||||
$sql.= " t.tms,";
|
||||
$sql.= " t.datec,";
|
||||
$sql.= " t.jobtype,";
|
||||
$sql.= " t.label,";
|
||||
$sql.= " t.command,";
|
||||
$sql.= " t.classesname,";
|
||||
$sql.= " t.objectname,";
|
||||
$sql.= " t.methodename,";
|
||||
$sql.= " t.params,";
|
||||
$sql.= " t.md5params,";
|
||||
$sql.= " t.module_name,";
|
||||
$sql.= " t.priority,";
|
||||
$sql.= " t.datelastrun,";
|
||||
$sql.= " t.datenextrun,";
|
||||
$sql.= " t.dateend,";
|
||||
$sql.= " t.datestart,";
|
||||
$sql.= " t.lastresult,";
|
||||
$sql.= " t.datelastresult,";
|
||||
$sql.= " t.lastoutput,";
|
||||
$sql.= " t.fk_user,";
|
||||
$sql.= " t.note";
|
||||
|
||||
$sql.= " t.unitfrequency,";
|
||||
$sql.= " t.frequency,";
|
||||
$sql.= " t.status,";
|
||||
$sql.= " t.fk_user_author,";
|
||||
$sql.= " t.fk_user_mod,";
|
||||
$sql.= " t.note,";
|
||||
$sql.= " t.nbrun";
|
||||
|
||||
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."cronjob as t";
|
||||
$sql.= " WHERE t.rowid = ".$id;
|
||||
|
||||
@ -197,18 +307,36 @@ class Cronjob extends CommonObject
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$this->id = $obj->rowid;
|
||||
|
||||
$this->ref = $obj->rowid;
|
||||
|
||||
$this->tms = $this->db->jdate($obj->tms);
|
||||
$this->datec = $this->db->jdate($obj->datec);
|
||||
$this->label = $obj->label;
|
||||
$this->jobtype = $obj->jobtype;
|
||||
$this->command = $obj->command;
|
||||
$this->classesname = $obj->classesname;
|
||||
$this->objectname = $obj->objectname;
|
||||
$this->methodename = $obj->methodename;
|
||||
$this->params = $obj->params;
|
||||
$this->md5params = $obj->md5params;
|
||||
$this->module_name = $obj->module_name;
|
||||
$this->priority = $obj->priority;
|
||||
$this->datelastrun = $this->db->jdate($obj->datelastrun);
|
||||
$this->lastresult = $this->db->jdate($obj->lastresult);
|
||||
$this->datenextrun = $this->db->jdate($obj->datenextrun);
|
||||
$this->dateend = $this->db->jdate($obj->dateend);
|
||||
$this->datestart = $this->db->jdate($obj->datestart);
|
||||
$this->lastresult = $obj->lastresult;
|
||||
$this->lastoutput = $obj->lastoutput;
|
||||
$this->fk_user = $obj->fk_user;
|
||||
$this->datelastresult = $this->db->jdate($obj->datelastresult);
|
||||
$this->unitfrequency = $obj->unitfrequency;
|
||||
$this->frequency = $obj->frequency;
|
||||
$this->status = $obj->status;
|
||||
$this->fk_user_author = $obj->fk_user_author;
|
||||
$this->fk_user_mod = $obj->fk_user_mod;
|
||||
$this->note = $obj->note;
|
||||
$this->nbrun = $obj->nbrun;
|
||||
|
||||
|
||||
|
||||
}
|
||||
$this->db->free($resql);
|
||||
|
||||
@ -221,6 +349,141 @@ class Cronjob extends CommonObject
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load object in memory from the database
|
||||
*
|
||||
* @param string $sortorder sort order
|
||||
* @param string $sortfield sort field
|
||||
* @param int $limit limit page
|
||||
* @param int $offset page
|
||||
* @param int $status display active or not
|
||||
* @param array $filter filter output
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function fetch_all($sortorder='DESC', $sortfield='t.rowid', $limit=0, $offset=0, $status=1, $filter='')
|
||||
{
|
||||
global $langs;
|
||||
$sql = "SELECT";
|
||||
$sql.= " t.rowid,";
|
||||
$sql.= " t.tms,";
|
||||
$sql.= " t.datec,";
|
||||
$sql.= " t.jobtype,";
|
||||
$sql.= " t.label,";
|
||||
$sql.= " t.command,";
|
||||
$sql.= " t.classesname,";
|
||||
$sql.= " t.objectname,";
|
||||
$sql.= " t.methodename,";
|
||||
$sql.= " t.params,";
|
||||
$sql.= " t.md5params,";
|
||||
$sql.= " t.module_name,";
|
||||
$sql.= " t.priority,";
|
||||
$sql.= " t.datelastrun,";
|
||||
$sql.= " t.datenextrun,";
|
||||
$sql.= " t.dateend,";
|
||||
$sql.= " t.datestart,";
|
||||
$sql.= " t.lastresult,";
|
||||
$sql.= " t.datelastresult,";
|
||||
$sql.= " t.lastoutput,";
|
||||
$sql.= " t.unitfrequency,";
|
||||
$sql.= " t.frequency,";
|
||||
$sql.= " t.status,";
|
||||
$sql.= " t.fk_user_author,";
|
||||
$sql.= " t.fk_user_mod,";
|
||||
$sql.= " t.note,";
|
||||
$sql.= " t.nbrun";
|
||||
|
||||
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."cronjob as t";
|
||||
$status = (empty($status))?'0':'1';
|
||||
$sql.= " WHERE t.status=".$status;
|
||||
//Manage filter
|
||||
if (is_array($filter) && count($filter)>0) {
|
||||
foreach($filter as $key => $value) {
|
||||
$sql.= ' AND '.$key.' LIKE \'%'.$value.'%\'';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$sql.= " ORDER BY $sortfield $sortorder ";
|
||||
if (!empty($limit) && !empty($offset)) {
|
||||
$sql.= $this->db->plimit( $limit + 1 ,$offset);
|
||||
}
|
||||
|
||||
$sqlwhere = array();
|
||||
|
||||
if (!empty($module_name)) {
|
||||
$sqlwhere[]='(t.module_name='.$module_name.')';
|
||||
}
|
||||
if (count($sqlwhere)>0) {
|
||||
$sql.= " WHERE ".implode(' AND ',$sqlwhere);
|
||||
}
|
||||
|
||||
dol_syslog(get_class($this)."::fetch_all sql=".$sql, LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num=$this->db->num_rows($resql);
|
||||
$i=0;
|
||||
|
||||
if ($num)
|
||||
{
|
||||
$this->lines=array();
|
||||
|
||||
while ($i < $num)
|
||||
{
|
||||
|
||||
$line = new Cronjobline();
|
||||
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$line->id = $obj->rowid;
|
||||
$line->ref = $obj->rowid;
|
||||
|
||||
$line->tms = $this->db->jdate($obj->tms);
|
||||
$line->datec = $this->db->jdate($obj->datec);
|
||||
$line->label = $obj->label;
|
||||
$line->jobtype = $obj->jobtype;
|
||||
$line->command = $obj->command;
|
||||
$line->classesname = $obj->classesname;
|
||||
$line->objectname = $obj->objectname;
|
||||
$line->methodename = $obj->methodename;
|
||||
$line->params = $obj->params;
|
||||
$line->md5params = $obj->md5params;
|
||||
$line->module_name = $obj->module_name;
|
||||
$line->priority = $obj->priority;
|
||||
$line->datelastrun = $this->db->jdate($obj->datelastrun);
|
||||
$line->datenextrun = $this->db->jdate($obj->datenextrun);
|
||||
$line->dateend = $this->db->jdate($obj->dateend);
|
||||
$line->datestart = $this->db->jdate($obj->datestart);
|
||||
$line->lastresult = $obj->lastresult;
|
||||
$line->datelastresult = $this->db->jdate($obj->datelastresult);
|
||||
$line->lastoutput = $obj->lastoutput;
|
||||
$line->unitfrequency = $obj->unitfrequency;
|
||||
$line->frequency = $obj->frequency;
|
||||
$line->status = $obj->status;
|
||||
$line->fk_user_author = $obj->fk_user_author;
|
||||
$line->fk_user_mod = $obj->fk_user_mod;
|
||||
$line->note = $obj->note;
|
||||
$line->nbrun = $obj->nbrun;
|
||||
|
||||
$this->lines[]=$line;
|
||||
|
||||
$i++;
|
||||
|
||||
}
|
||||
}
|
||||
$this->db->free($resql);
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error="Error ".$this->db->lasterror();
|
||||
dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -233,35 +496,98 @@ class Cronjob extends CommonObject
|
||||
function update($user=0, $notrigger=0)
|
||||
{
|
||||
global $conf, $langs;
|
||||
|
||||
$langs->load('cron');
|
||||
|
||||
$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->fk_user)) $this->fk_user=trim($this->fk_user);
|
||||
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)) $this->note=trim($this->note);
|
||||
|
||||
|
||||
if (isset($this->nbrun)) $this->nbrun=trim($this->nbrun);
|
||||
|
||||
// Check parameters
|
||||
// Put here code to add a control on parameters values
|
||||
if (empty($this->status)) {
|
||||
$this->dateend=dol_now();
|
||||
}
|
||||
if (dol_strlen($this->datestart)==0) {
|
||||
$this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronDtStart'));
|
||||
$error++;
|
||||
}
|
||||
if ((dol_strlen($this->datestart)!=0) && (dol_strlen($this->dateend)!=0) && ($this->dateend<$this->datestart)) {
|
||||
$this->errors[]=$langs->trans('CronErrEndDateStartDt');
|
||||
$error++;
|
||||
}
|
||||
if (empty($this->label)) {
|
||||
$this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronLabel'));
|
||||
$error++;
|
||||
}
|
||||
if (empty($this->unitfrequency)) {
|
||||
$this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronFrequency'));
|
||||
$error++;
|
||||
}
|
||||
if (($this->jobtype=='command') && (empty($this->command))) {
|
||||
$this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronCommand'));
|
||||
$error++;
|
||||
}
|
||||
if (($this->jobtype=='method') && (empty($this->classesname))) {
|
||||
$this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronClass'));
|
||||
$error++;
|
||||
}
|
||||
if (($this->jobtype=='method') && (empty($this->methodename))) {
|
||||
$this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronMethod'));
|
||||
$error++;
|
||||
}
|
||||
if (($this->jobtype=='method') && (empty($this->objectname))) {
|
||||
$this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronObject'));
|
||||
$error++;
|
||||
}
|
||||
|
||||
|
||||
// Update request
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."cronjob SET";
|
||||
|
||||
$sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
|
||||
$sql.= " datec=".(dol_strlen($this->datec)!=0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
|
||||
|
||||
$sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").",";
|
||||
$sql.= " jobtype=".(isset($this->jobtype)?"'".$this->db->escape($this->jobtype)."'":"null").",";
|
||||
$sql.= " command=".(isset($this->command)?"'".$this->db->escape($this->command)."'":"null").",";
|
||||
$sql.= " classesname=".(isset($this->classesname)?"'".$this->db->escape($this->classesname)."'":"null").",";
|
||||
$sql.= " objectname=".(isset($this->objectname)?"'".$this->db->escape($this->objectname)."'":"null").",";
|
||||
$sql.= " methodename=".(isset($this->methodename)?"'".$this->db->escape($this->methodename)."'":"null").",";
|
||||
$sql.= " params=".(isset($this->params)?"'".$this->db->escape($this->params)."'":"null").",";
|
||||
$sql.= " md5params=".(isset($this->md5params)?"'".$this->db->escape($this->md5params)."'":"null").",";
|
||||
$sql.= " module_name=".(isset($this->module_name)?"'".$this->db->escape($this->module_name)."'":"null").",";
|
||||
$sql.= " priority=".(isset($this->priority)?$this->priority:"null").",";
|
||||
$sql.= " datelastrun=".(dol_strlen($this->datelastrun)!=0 ? "'".$this->db->idate($this->datelastrun)."'" : 'null').",";
|
||||
$sql.= " lastresult=".(dol_strlen($this->lastresult)!=0 ? "'".$this->db->idate($this->lastresult)."'" : 'null').",";
|
||||
$sql.= " datenextrun=".(dol_strlen($this->datenextrun)!=0 ? "'".$this->db->idate($this->datenextrun)."'" : 'null').",";
|
||||
$sql.= " dateend=".(dol_strlen($this->dateend)!=0 ? "'".$this->db->idate($this->dateend)."'" : 'null').",";
|
||||
$sql.= " datestart=".(dol_strlen($this->datestart)!=0 ? "'".$this->db->idate($this->datestart)."'" : 'null').",";
|
||||
$sql.= " datelastresult=".(dol_strlen($this->datelastresult)!=0 ? "'".$this->db->idate($this->datelastresult)."'" : 'null').",";
|
||||
$sql.= " lastresult=".(isset($this->lastresult)?"'".$this->db->escape($this->lastresult)."'":"null").",";
|
||||
$sql.= " lastoutput=".(isset($this->lastoutput)?"'".$this->db->escape($this->lastoutput)."'":"null").",";
|
||||
$sql.= " fk_user=".(isset($this->fk_user)?$this->fk_user:"null").",";
|
||||
$sql.= " note=".(isset($this->note)?"'".$this->db->escape($this->note)."'":"null")."";
|
||||
|
||||
$sql.= " unitfrequency=".(isset($this->unitfrequency)?$this->unitfrequency:"null").",";
|
||||
$sql.= " frequency=".(isset($this->frequency)?$this->frequency:"null").",";
|
||||
$sql.= " status=".(isset($this->status)?$this->status:"null").",";
|
||||
$sql.= " fk_user_mod=".$user->id.",";
|
||||
$sql.= " note=".(isset($this->note)?"'".$this->db->escape($this->note)."'":"null").",";
|
||||
$sql.= " nbrun=".(isset($this->nbrun)?$this->nbrun:"null");
|
||||
|
||||
|
||||
$sql.= " WHERE rowid=".$this->id;
|
||||
|
||||
$this->db->begin();
|
||||
@ -269,7 +595,7 @@ class Cronjob extends CommonObject
|
||||
dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
|
||||
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
if (! $notrigger)
|
||||
@ -377,7 +703,7 @@ class Cronjob extends CommonObject
|
||||
|
||||
$error=0;
|
||||
|
||||
$object=new Cronjobs($this->db);
|
||||
$object=new Cronjob($this->db);
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
@ -428,19 +754,277 @@ class Cronjob extends CommonObject
|
||||
function initAsSpecimen()
|
||||
{
|
||||
$this->id=0;
|
||||
|
||||
$this->ref=0;
|
||||
|
||||
$this->tms='';
|
||||
$this->datec='';
|
||||
$this->label='';
|
||||
$this->jobtype='';
|
||||
$this->command='';
|
||||
$this->classesname='';
|
||||
$this->objectname='';
|
||||
$this->methodename='';
|
||||
$this->params='';
|
||||
$this->md5params='';
|
||||
$this->module_name='';
|
||||
$this->priority='';
|
||||
$this->datelastrun='';
|
||||
$this->lastresult='';
|
||||
$this->datenextrun='';
|
||||
$this->dateend='';
|
||||
$this->datestart='';
|
||||
$this->datelastresult='';
|
||||
$this->lastoutput='';
|
||||
$this->fk_user='';
|
||||
$this->note='';
|
||||
|
||||
|
||||
$this->lastresult='';
|
||||
$this->unitfrequency='';
|
||||
$this->frequency='';
|
||||
$this->status='';
|
||||
$this->fk_user_author='';
|
||||
$this->fk_user_mod='';
|
||||
$this->note='';
|
||||
$this->nbrun='';
|
||||
}
|
||||
|
||||
/**
|
||||
* Load object information
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function info()
|
||||
{
|
||||
global $langs;
|
||||
|
||||
$sql = "SELECT";
|
||||
$sql.= " f.rowid, f.datec, f.tms, f.fk_user_mod, f.fk_user_author";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."cronjob as f";
|
||||
$sql.= " WHERE f.rowid = ".$this->id;
|
||||
|
||||
dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
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);
|
||||
$this->date_modification = $this->db->jdate($obj->tms);
|
||||
$this->user_modification = $obj->fk_user_mod;
|
||||
$this->user_creation = $obj->fk_user_author;
|
||||
}
|
||||
$this->db->free($resql);
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error="Error ".$this->db->lasterror();
|
||||
dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run a job
|
||||
*
|
||||
* @param string $userlogin User login
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function run_jobs($userlogin)
|
||||
{
|
||||
global $langs, $conf;
|
||||
|
||||
$langs->load('cron');
|
||||
|
||||
if (empty($userlogin)) {
|
||||
$this->error="User login is mandatory";
|
||||
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
|
||||
$user=new User($this->db);
|
||||
$result=$user->fetch('',$userlogin);
|
||||
if ($result<0) {
|
||||
$this->error="User Error:".$user->error;
|
||||
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}else {
|
||||
if (empty($user->id)) {
|
||||
$this->error=" User user login:".$userlogin." do not exists";
|
||||
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
dol_syslog(get_class($this)."::run_jobs userlogin:$userlogin", LOG_DEBUG);
|
||||
|
||||
$error=0;
|
||||
$now=dol_now();
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
if ($this->jobtype=='method') {
|
||||
// load classes
|
||||
$ret=dol_include_once("/".$this->module_name."/class/".$this->classesname,$this->objectname);
|
||||
if ($ret===false) {
|
||||
$this->error=$langs->trans('CronCannotLoadClass',$file,$this->objectname);
|
||||
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Load langs
|
||||
$result=$langs->load($this->module_name.'@'.$this->module_name);
|
||||
if ($result<0) {
|
||||
dol_syslog(get_class($this)."::run_jobs Cannot load module langs".$langs->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
dol_syslog(get_class($this)."::run_jobs ".$this->objectname."->".$this->methodename."(".$this->params.");", LOG_DEBUG);
|
||||
|
||||
// Create Object for the call module
|
||||
$object = new $this->objectname($this->db);
|
||||
|
||||
$params_arr = array();
|
||||
$params_arr=explode(", ",$this->params);
|
||||
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) {
|
||||
dol_syslog(get_class($this)."::run_jobs ".$object->error, LOG_ERR);
|
||||
return -1;
|
||||
}else {
|
||||
$this->lastoutput=var_export($result,true);
|
||||
$this->lastresult=var_export($result,true);
|
||||
}
|
||||
|
||||
} elseif ($this->jobtype=='command') {
|
||||
dol_syslog(get_class($this)."::run_jobs system:".$this->command, LOG_DEBUG);
|
||||
$output_arr=array();
|
||||
|
||||
exec($this->command, $output_arr,$retval);
|
||||
|
||||
dol_syslog(get_class($this)."::run_jobs output_arr:".var_export($output_arr,true), LOG_DEBUG);
|
||||
|
||||
$this->lastoutput='';
|
||||
if (is_array($output_arr) && count($output_arr)>0) {
|
||||
foreach($output_arr as $val) {
|
||||
$this->lastoutput.=$val."\n";
|
||||
}
|
||||
}
|
||||
$this->lastresult=$retval;
|
||||
}
|
||||
|
||||
$this->datelastresult=$now;
|
||||
$this->datelastrun=$now;
|
||||
$this->nbrun=$this->nbrun+1;
|
||||
$result = $this->update($user);
|
||||
if ($result<0) {
|
||||
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}else {
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reprogram a job
|
||||
*
|
||||
* @param string $userlogin User login
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*
|
||||
*/
|
||||
function reprogram_jobs($userlogin)
|
||||
{
|
||||
global $langs, $conf;
|
||||
|
||||
dol_syslog(get_class($this)."::reprogram_jobs userlogin:$userlogin", LOG_DEBUG);
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
|
||||
$user=new User($this->db);
|
||||
$result=$user->fetch('',$userlogin);
|
||||
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)) {
|
||||
$this->error=" User user login:".$userlogin." do not exists";
|
||||
dol_syslog(get_class($this)."::reprogram_jobs ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
dol_syslog(get_class($this)."::reprogram_jobs ", LOG_DEBUG);
|
||||
|
||||
if (empty($this->datenextrun)) {
|
||||
$this->datenextrun=dol_now()+$this->frequency;
|
||||
} else {
|
||||
if ($this->datenextrun<dol_now()) {
|
||||
$this->datenextrun=dol_now()+$this->frequency;
|
||||
} else {
|
||||
$this->datenextrun=$this->datenextrun+$this->frequency;
|
||||
}
|
||||
}
|
||||
$result = $this->update($user);
|
||||
if ($result<0) {
|
||||
dol_syslog(get_class($this)."::reprogram_jobs ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
/**
|
||||
* Crob Job line class
|
||||
*/
|
||||
class Cronjobline{
|
||||
|
||||
var $id;
|
||||
var $ref;
|
||||
|
||||
var $tms='';
|
||||
var $datec='';
|
||||
var $label;
|
||||
var $jobtype;
|
||||
var $command;
|
||||
var $classesname;
|
||||
var $objectname;
|
||||
var $methodename;
|
||||
var $params;
|
||||
var $md5params;
|
||||
var $module_name;
|
||||
var $priority;
|
||||
var $datelastrun='';
|
||||
var $datenextrun='';
|
||||
var $dateend='';
|
||||
var $datestart='';
|
||||
var $lastresult='';
|
||||
var $lastoutput;
|
||||
var $unitfrequency;
|
||||
var $frequency;
|
||||
var $status;
|
||||
var $fk_user_author;
|
||||
var $fk_user_mod;
|
||||
var $note;
|
||||
var $nbrun;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
/* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2007-2009 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file cron/functions_cron.lib.php
|
||||
* \ingroup core
|
||||
* \brief Functions for miscellaneous cron tasks
|
||||
*/
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@ -1,219 +0,0 @@
|
||||
<?php
|
||||
/* Copyright (C) 2007-2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file dev/Cronjobss/Cronjobs_page.php
|
||||
* \ingroup mymodule othermodule1 othermodule2
|
||||
* \brief This file is an example of a php page
|
||||
* Initialy built by build_class_from_table on 2013-03-17 18:50
|
||||
*/
|
||||
|
||||
//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1');
|
||||
//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1');
|
||||
//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
|
||||
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
|
||||
//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
|
||||
//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');
|
||||
//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no menu to show
|
||||
//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php
|
||||
//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
|
||||
//if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session)
|
||||
|
||||
// Change this following line to use the correct relative path (../, ../../, etc)
|
||||
$res=0;
|
||||
if (! $res && file_exists("../main.inc.php")) $res=@include '../main.inc.php';
|
||||
if (! $res && file_exists("../../main.inc.php")) $res=@include '../../main.inc.php';
|
||||
if (! $res && file_exists("../../../main.inc.php")) $res=@include '../../../main.inc.php';
|
||||
if (! $res && file_exists("../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only
|
||||
if (! $res && file_exists("../../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only
|
||||
if (! $res && file_exists("../../../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only
|
||||
if (! $res) die("Include of main fails");
|
||||
// Change this following line to use the correct relative path from htdocs
|
||||
dol_include_once('/module/class/cronjob.class.php');
|
||||
|
||||
// Load traductions files requiredby by page
|
||||
$langs->load("companies");
|
||||
$langs->load("other");
|
||||
$langs->load("cron");
|
||||
|
||||
// Get parameters
|
||||
$id = GETPOST('id','int');
|
||||
$action = GETPOST('action','alpha');
|
||||
$myparam = GETPOST('myparam','alpha');
|
||||
$action='list';
|
||||
|
||||
// Protection if external user
|
||||
if ($user->societe_id > 0) accessforbidden();
|
||||
if (! $user->admin) accessforbidden();
|
||||
|
||||
|
||||
/*******************************************************************
|
||||
* ACTIONS
|
||||
*
|
||||
* Put here all code to do according to value of "action" parameter
|
||||
********************************************************************/
|
||||
|
||||
if ($action == 'add')
|
||||
{
|
||||
$object=new Cronjobs($db);
|
||||
$object->prop1=$_POST["field1"];
|
||||
$object->prop2=$_POST["field2"];
|
||||
$result=$object->create($user);
|
||||
if ($result > 0)
|
||||
{
|
||||
// Creation OK
|
||||
}
|
||||
{
|
||||
// Creation KO
|
||||
$mesg=$object->error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/***************************************************
|
||||
* VIEW
|
||||
*
|
||||
* Put here all code to build page
|
||||
****************************************************/
|
||||
|
||||
llxHeader('','MyPageName','');
|
||||
|
||||
$form=new Form($db);
|
||||
|
||||
|
||||
//print '<table border="0" width="100%" class="notopnoleftnoright">';
|
||||
//print '<tr><td valign="top" width="30%" class="notopnoleft">';
|
||||
print '<div class="fichecenter"><div class="fichethirdleft">';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//print '</td><td valign="top" width="70%" class="notopnoleftnoright">';
|
||||
print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
|
||||
|
||||
|
||||
|
||||
// Example 1 : Adding jquery code
|
||||
print '<script type="text/javascript" language="javascript">
|
||||
jQuery(document).ready(function() {
|
||||
function init_myfunc()
|
||||
{
|
||||
jQuery("#myid").removeAttr(\'disabled\');
|
||||
jQuery("#myid").attr(\'disabled\',\'disabled\');
|
||||
}
|
||||
init_myfunc();
|
||||
jQuery("#mybutton").click(function() {
|
||||
init_needroot();
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
|
||||
// Example 2 : Adding links to objects
|
||||
// The class must extends CommonObject class to have this method available
|
||||
//$somethingshown=$object->showLinkedObjectBlock();
|
||||
|
||||
|
||||
// Example 3 : List of data
|
||||
if ($action == 'list')
|
||||
{
|
||||
$sql = "SELECT";
|
||||
$sql.= " t.rowid,";
|
||||
|
||||
$sql.= " t.tms,";
|
||||
$sql.= " t.datec,";
|
||||
$sql.= " t.command,";
|
||||
$sql.= " t.params,";
|
||||
$sql.= " t.datelastrun,";
|
||||
$sql.= " t.lastresult,";
|
||||
$sql.= " t.lastoutput,";
|
||||
$sql.= " t.fk_user,";
|
||||
$sql.= " t.note";
|
||||
|
||||
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."cronjob as t";
|
||||
//$sql.= " WHERE field3 = 'xxx'";
|
||||
//$sql.= " ORDER BY field1 ASC";
|
||||
|
||||
|
||||
print_fiche_titre($langs->trans("ListOfCronJobs"),'','').'<br>';
|
||||
|
||||
|
||||
print '<table class="noborder">'."\n";
|
||||
print '<tr class="liste_titre">';
|
||||
print_liste_field_titre($langs->trans('Id'),$_SERVER['PHP_SELF'],'t.rowid','',$param,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans('Command'),$_SERVER['PHP_SELF'],'t.command','',$param,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans('DateCreation'),$_SERVER['PHP_SELF'],'t.datec','align="center"',$param,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans('LastOutput'),$_SERVER['PHP_SELF'],'','',$param,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans('DateLastRun'),$_SERVER['PHP_SELF'],'t.datelastrun','align="center"',$param,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans('LastResult'),$_SERVER['PHP_SELF'],'t.lastresult','align="right"',$param,'',$sortfield,$sortorder);
|
||||
print '</tr>';
|
||||
|
||||
dol_syslog($script_file." sql=".$sql, LOG_DEBUG);
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
if ($num)
|
||||
{
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
if ($obj)
|
||||
{
|
||||
// You can use here results
|
||||
print '<tr><td>';
|
||||
print $obj->rowid;
|
||||
print '</td><td>';
|
||||
print $obj->command;
|
||||
print '</td><td align="center">';
|
||||
print $db->jdate($obj->datec);
|
||||
print '</td><td>';
|
||||
print '';
|
||||
print '</td><td align="center">';
|
||||
print $db->jdate($obj->datelastrun);
|
||||
print '</td><td align="right">';
|
||||
print $obj->lastresult;
|
||||
print '</td></tr>';
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
print '</table>'."\n";
|
||||
}
|
||||
|
||||
|
||||
//print '</td></tr></table>';
|
||||
print '<div></div></div>';
|
||||
|
||||
|
||||
// End of page
|
||||
llxFooter();
|
||||
$db->close();
|
||||
?>
|
||||
59
htdocs/cron/info.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file /cron/cron/info.php
|
||||
* \brief Page fiche d'une operation
|
||||
*/
|
||||
|
||||
require '../main.inc.php';
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT."/cron/class/cronjob.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/cron.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
|
||||
|
||||
|
||||
// Security check
|
||||
if (!$user->rights->cron->read) accessforbidden();
|
||||
|
||||
$id=GETPOST('id','int');
|
||||
|
||||
$mesg = '';
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
llxHeader('',$langs->trans("CronInfo"));
|
||||
|
||||
$object = new Cronjob($db);
|
||||
$object->fetch($id);
|
||||
$object->info($id);
|
||||
|
||||
$head = cron_prepare_head($object);
|
||||
|
||||
dol_fiche_head($head, 'info', $langs->trans("CronTask"), 0, 'bill');
|
||||
|
||||
print '<table width="100%"><tr><td>';
|
||||
dol_print_object_info($object);
|
||||
print '</td></tr></table>';
|
||||
print '</div>';
|
||||
|
||||
|
||||
$db->close();
|
||||
llxFooter();
|
||||
295
htdocs/cron/list.php
Normal file
@ -0,0 +1,295 @@
|
||||
<?php
|
||||
/* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
|
||||
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file cron/cron/list.php
|
||||
* \ingroup cron
|
||||
* \brief Lists Jobs
|
||||
*/
|
||||
|
||||
|
||||
require '../main.inc.php';
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
|
||||
|
||||
// librairie jobs
|
||||
require_once DOL_DOCUMENT_ROOT."/cron/class/cronjob.class.php";
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/cron.lib.php';
|
||||
|
||||
$langs->load("admin");
|
||||
$langs->load("cron");
|
||||
|
||||
if (!$user->rights->cron->read) accessforbidden();
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
$action=GETPOST('action','alpha');
|
||||
$confirm=GETPOST('confirm','alpha');
|
||||
$id=GETPOST('id','int');
|
||||
|
||||
$sortorder=GETPOST('sortorder','alpha');
|
||||
$sortfield=GETPOST('sortfield','alpha');
|
||||
$page=GETPOST('page','int');
|
||||
$status=GETPOST('status','int');
|
||||
|
||||
//Search criteria
|
||||
$search_label=GETPOST("search_label",'alpha');
|
||||
|
||||
if (empty($sortorder)) $sortorder="DESC";
|
||||
if (empty($sortfield)) $sortfield="t.datenextrun";
|
||||
if (empty($arch)) $arch = 0;
|
||||
|
||||
if ($page == -1) {
|
||||
$page = 0 ;
|
||||
}
|
||||
|
||||
$limit = $conf->global->MAIN_SIZE_LISTE_LIMIT;
|
||||
$offset = $limit * $page ;
|
||||
$pageprev = $page - 1;
|
||||
$pagenext = $page + 1;
|
||||
|
||||
// Do we click on purge search criteria ?
|
||||
if (GETPOST("button_removefilter_x"))
|
||||
{
|
||||
$search_label='';
|
||||
}
|
||||
|
||||
$filter=array();
|
||||
if (!empty($search_label)) {
|
||||
$filter['t.label']=$search_label;
|
||||
}
|
||||
|
||||
// Delete jobs
|
||||
if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->cron->delete){
|
||||
|
||||
//Delete de la tache cron
|
||||
$object = new Cronjob($db);
|
||||
$object->id=$id;
|
||||
$result = $object->delete($user);
|
||||
|
||||
if ($result < 0) {
|
||||
setEventMessage($object->error,'errors');
|
||||
}
|
||||
}
|
||||
|
||||
// Execute jobs
|
||||
if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->execute){
|
||||
|
||||
//Execute jobs
|
||||
$object = new Cronjob($db);
|
||||
$job = $object->fetch($id);
|
||||
|
||||
$result = $object->run_jobs($user->login);
|
||||
if ($result < 0) {
|
||||
setEventMessage($object->error,'errors');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
if (!empty($status)) {
|
||||
$pagetitle=$langs->trans("CronListActive");
|
||||
}else {
|
||||
$pagetitle=$langs->trans("CronListInactive");
|
||||
}
|
||||
|
||||
llxHeader('',$pagetitle);
|
||||
|
||||
|
||||
// Form object for popup
|
||||
$form = new Form($db);
|
||||
|
||||
if ($action == 'delete')
|
||||
{
|
||||
$ret=$form->form_confirm($_SERVER['PHP_SELF']."?id=".$id.'&status='.$status,$langs->trans("CronDelete"),$langs->trans("CronConfirmDelete"),"confirm_delete",'','',1);
|
||||
if ($ret == 'html') print '<br>';
|
||||
}
|
||||
|
||||
if ($action == 'execute'){
|
||||
$ret=$form->form_confirm($_SERVER['PHP_SELF']."?id=".$id.'&status='.$status,$langs->trans("CronExecute"),$langs->trans("CronConfirmExecute"),"confirm_execute",'','',1);
|
||||
if ($ret == 'html') print '<br>';
|
||||
}
|
||||
|
||||
|
||||
print_fiche_titre($pagetitle,'','setup');
|
||||
|
||||
print $langs->trans('CronInfo');
|
||||
|
||||
// liste des jobs creer
|
||||
$object = new Cronjob($db);
|
||||
$result=$object->fetch_all($sortorder, $sortfield, $limit, $offset, $status, $filter);
|
||||
if ($result < 0) {
|
||||
setEventMessage($object->error,'errors');
|
||||
}
|
||||
|
||||
|
||||
print "<p><h2>";
|
||||
print $langs->trans('CronWaitingJobs');
|
||||
print "</h2></p>";
|
||||
|
||||
if (count($object->lines)>0) {
|
||||
|
||||
print '<table width="100%" cellspacing="0" cellpadding="4" class="border">';
|
||||
print '<tr class="liste_titre">';
|
||||
$arg_url='&page='.$page.'&status='.$status.'&search_label='.$search_label;
|
||||
print_liste_field_titre($langs->trans("CronLabel"),$_SERVEUR['PHP_SELF'],"t.label","",$arg_url,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronTask"),'','',"",$arg_url,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronDtStart"),$_SERVEUR['PHP_SELF'],"t.datestart","",$arg_url,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronDtEnd"),$_SERVEUR['PHP_SELF'],"t.dateend","",$arg_url,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronDtLastLaunch"),$_SERVEUR['PHP_SELF'],"t.datelastrun","",$arg_url,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronDtNextLaunch"),$_SERVEUR['PHP_SELF'],"t.datenextrun","",$arg_url,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronFrequency"),'',"","",$arg_url,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronNbRun"),$_SERVEUR['PHP_SELF'],"t.nbrun","",$arg_url,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronLastResult"),$_SERVEUR['PHP_SELF'],"t.lastresult","",$arg_url,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronLastOutput"),$_SERVEUR['PHP_SELF'],"t.lastoutput","",$arg_url,'',$sortfield,$sortorder);
|
||||
print '<td></td>';
|
||||
|
||||
print '</tr>';
|
||||
|
||||
print '<form method="get" action="'.$url_form.'" name="search_form">'."\n";
|
||||
print '<input type="hidden" name="status" value="'.$status.'" >';
|
||||
print '<tr class="liste_titre">';
|
||||
|
||||
|
||||
|
||||
print '<td class="liste_titre">';
|
||||
print '<input type="text" class="flat" name="search_label" value="'.$search_label.'" size="10">';
|
||||
print '</td>';
|
||||
print '<td> </td>';
|
||||
print '<td> </td>';
|
||||
print '<td> </td>';
|
||||
print '<td> </td>';
|
||||
print '<td> </td>';
|
||||
print '<td> </td>';
|
||||
print '<td> </td>';
|
||||
print '<td> </td>';
|
||||
print '<td> </td>';
|
||||
print '<td class="liste_titre" align="right"><input class="liste_titre" type="image" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
|
||||
print ' ';
|
||||
print '<input type="image" class="liste_titre" name="button_removefilter" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/searchclear.png" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
|
||||
print '</td>';
|
||||
|
||||
print '</tr>';
|
||||
print '</from>';
|
||||
|
||||
|
||||
|
||||
// Boucler sur chaque job
|
||||
$style='impair';
|
||||
foreach($object->lines as $line){
|
||||
// title profil
|
||||
if ($style=='pair') {$style='impair';}
|
||||
else {$style='pair';}
|
||||
|
||||
print '<tr class="'.$style.'">';
|
||||
|
||||
print '<td>';
|
||||
if(!empty($line->label)) {
|
||||
print '<a href="'.dol_buildpath('/cron/cron/card.php',1).'?id='.$line->id.'">'.$line->label.'</a>';
|
||||
}
|
||||
else {
|
||||
print $langs->trans('CronNone');
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
if ($line->jobtype=='method') {
|
||||
print $langs->trans('CronModule').':'.$line->module_name.'<BR>';
|
||||
print $langs->trans('CronClass').':'. $line->classesname.'<BR>';
|
||||
print $langs->trans('CronObject').':'. $line->objectname.'<BR>';
|
||||
print $langs->trans('CronMethod').':'. $line->methodename;
|
||||
if(!empty($line->params)) {
|
||||
print '<BR/>'.$langs->trans('CronArgs').':'. $line->params;
|
||||
}
|
||||
|
||||
}elseif ($line->jobtype=='command') {
|
||||
print $langs->trans('CronCommand').':'. dol_trunc($line->command);
|
||||
if(!empty($line->params)) {
|
||||
print '<BR/>'.$langs->trans('CronArgs').':'. $line->params;
|
||||
}
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
if(!empty($line->datestart)) {print dol_print_date($line->datestart,'dayhourtext');} else {print $langs->trans('CronNone');}
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
if(!empty($line->dateend)) {print dol_print_date($line->dateend,'dayhourtext');} else {print $langs->trans('CronNone');}
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
if(!empty($line->datelastrun)) {print dol_print_date($line->datelastrun,'dayhourtext');} else {print $langs->trans('CronNone');}
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
if(!empty($line->datenextrun)) {print dol_print_date($line->datenextrun,'dayhourtext');} else {print $langs->trans('CronNone');}
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
if($line->unitfrequency == "60") print $langs->trans('CronEach')." ".($line->frequency/$line->unitfrequency)." ".$langs->trans('Minutes');
|
||||
if($line->unitfrequency == "3600") print $langs->trans('CronEach')." ".($line->frequency/$line->unitfrequency)." ".$langs->trans('Hours');
|
||||
if($line->unitfrequency == "86400") print $langs->trans('CronEach')." ".($line->frequency/$line->unitfrequency)." ".$langs->trans('Days');
|
||||
if($line->unitfrequency == "604800") print $langs->trans('CronEach')." ".($line->frequency/$line->unitfrequency)." ".$langs->trans('Weeks');
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
if(!empty($line->nbrun)) {print $line->nbrun;} else {print '0';}
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
if(!empty($line->lastresult)) {print dol_trunc($line->lastresult);} else {print $langs->trans('CronNone');}
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
if(!empty($line->lastoutput)) {print dol_trunc(nl2br($line->lastoutput),100);} else {print $langs->trans('CronNone');}
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
if ($user->rights->cron->delete) {
|
||||
print "<a href=\"".dol_buildpath('/cron/cron/list.php',1)."?id=".$line->id."&status=".$status."&action=delete\" title=\"".$langs->trans('CronDelete')."\"><img src=\"".dol_buildpath('/cron/img/delete.png',1)."\" alt=\"".$langs->trans('CronDelete')."\" /></a>";
|
||||
} else {
|
||||
print "<a href=\"#\" title=\"".$langs->trans('NotEnoughPermissions')."\"><img src=\"".dol_buildpath('/cron/img/delete.png',1)."\" alt=\"".$langs->trans('NotEnoughPermissions')."\" /></a>";
|
||||
}
|
||||
if ($user->rights->cron->execute) {
|
||||
print "<a href=\"".dol_buildpath('/cron/cron/list.php',1)."?id=".$line->id."&status=".$status."&action=execute\" title=\"".$langs->trans('CronExecute')."\"><img src=\"".dol_buildpath('/cron/img/execute.png',1)."\" alt=\"".$langs->trans('CronExecute')."\" /></a>";
|
||||
} else {
|
||||
print "<a href=\"#\" title=\"".$langs->trans('NotEnoughPermissions')."\"><img src=\"".dol_buildpath('/cron/img/execute.png',1)."\" alt=\"".$langs->trans('NotEnoughPermissions')."\" /></a>";
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
print '</tr>';
|
||||
}
|
||||
print '</table>';
|
||||
} else {
|
||||
print $langs->trans('CronNoJobs');
|
||||
}
|
||||
|
||||
print "\n\n<div class=\"tabsAction\">\n";
|
||||
if (! $user->rights->cron->create) {
|
||||
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("New").'</a>';
|
||||
} else {
|
||||
print '<a class="butAction" href="'.dol_buildpath('/cron/card.php',1).'?action=create">'.$langs->trans("New").'</a>';
|
||||
}
|
||||
print '<br><br></div>';
|
||||
|
||||
llxFooter();
|
||||
$db->close();
|
||||
@ -159,3 +159,36 @@ ALTER TABLE llx_c_action_trigger ADD INDEX idx_action_trigger_rang (rang);
|
||||
|
||||
ALTER TABLE llx_facture_fourn_det ADD COLUMN fk_code_ventilation integer DEFAULT 0 NOT NULL;
|
||||
ALTER TABLE llx_facturedet DROP COLUMN fk_export_compta;
|
||||
|
||||
CREATE TABLE llx_cronjob
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
tms timestamp,
|
||||
datec datetime,
|
||||
jobtype varchar(10) NOT NULL,
|
||||
label text NOT NULL,
|
||||
command varchar(255),
|
||||
classesname varchar(255),
|
||||
objectname varchar(255),
|
||||
methodename varchar(255),
|
||||
params text NOT NULL,
|
||||
md5params varchar(32),
|
||||
module_name varchar(255),
|
||||
priority integer DEFAULT 0,
|
||||
datelastrun datetime,
|
||||
datenextrun datetime,
|
||||
datestart datetime,
|
||||
dateend datetime,
|
||||
datelastresult datetime,
|
||||
lastresult text,
|
||||
lastoutput text,
|
||||
unitfrequency integer NOT NULL DEFAULT 0,
|
||||
frequency integer NOT NULL DEFAULT 0,
|
||||
nbrun integer,
|
||||
status integer NOT NULL DEFAULT 1,
|
||||
fk_user_author integer DEFAULT NULL,
|
||||
fk_user_mod integer DEFAULT NULL,
|
||||
note text
|
||||
)ENGINE=innodb;
|
||||
|
||||
|
||||
|
||||
@ -1,32 +1,52 @@
|
||||
-- ===================================================================
|
||||
-- Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
--
|
||||
-- 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
|
||||
-- the Free Software Foundation; either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
--
|
||||
-- ===================================================================
|
||||
|
||||
create table llx_cronjob
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
tms timestamp,
|
||||
datec datetime,
|
||||
command varchar(256),
|
||||
params text,
|
||||
frequency varchar(24),
|
||||
datelastrun datetime,
|
||||
lastresult date,
|
||||
lastoutput text,
|
||||
fk_user integer DEFAULT NULL,
|
||||
note text
|
||||
)ENGINE=innodb;
|
||||
-- ===================================================================
|
||||
-- Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
-- Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
|
||||
--
|
||||
-- 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
|
||||
-- the Free Software Foundation; either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
--
|
||||
-- ===================================================================
|
||||
|
||||
|
||||
CREATE TABLE llx_cronjob
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
tms timestamp,
|
||||
datec datetime,
|
||||
jobtype varchar(10) NOT NULL,
|
||||
label text NOT NULL,
|
||||
command varchar(255),
|
||||
classesname varchar(255),
|
||||
objectname varchar(255),
|
||||
methodename varchar(255),
|
||||
params text NOT NULL,
|
||||
md5params varchar(32),
|
||||
module_name varchar(255),
|
||||
priority integer DEFAULT 0,
|
||||
datelastrun datetime,
|
||||
datenextrun datetime,
|
||||
datestart datetime,
|
||||
dateend datetime,
|
||||
datelastresult datetime,
|
||||
lastresult text,
|
||||
lastoutput text,
|
||||
unitfrequency integer NOT NULL DEFAULT 0,
|
||||
frequency integer NOT NULL DEFAULT 0,
|
||||
nbrun integer,
|
||||
status integer NOT NULL DEFAULT 1,
|
||||
fk_user_author integer DEFAULT NULL,
|
||||
fk_user_mod integer DEFAULT NULL,
|
||||
note text
|
||||
)ENGINE=innodb;
|
||||
|
||||
|
||||
|
||||
@ -116,3 +116,4 @@ CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_tva FOR EACH ROW EXE
|
||||
CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_user FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms();
|
||||
CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_user_extrafields FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms();
|
||||
CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_usergroup FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms();
|
||||
CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_cronjob FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms();
|
||||
|
||||
@ -672,6 +672,10 @@ Permission1237=Export supplier orders and their details
|
||||
Permission1251=Run mass imports of external data into database (data load)
|
||||
Permission1321=Export customer invoices, attributes and payments
|
||||
Permission1421=Export customer orders and attributes
|
||||
Permission23001 = Read Scheduled task
|
||||
Permission23002 = Create/update Scheduled task
|
||||
Permission23003 = Delete Scheduled task
|
||||
Permission23004 = Execute Scheduled task
|
||||
Permission2401=Read actions (events or tasks) linked to his account
|
||||
Permission2402=Create/modify actions (events or tasks) linked to his account
|
||||
Permission2403=Delete actions (events or tasks) linked to his account
|
||||
|
||||
@ -1,11 +1,87 @@
|
||||
# Dolibarr language file - en_US - cron
|
||||
CHARSET=UTF-8
|
||||
CronSetup=Cron scheduler setup
|
||||
CronDesc=This page can be used to setup options of the scheduler manager
|
||||
|
||||
#
|
||||
# Admin
|
||||
#
|
||||
CronSetup= Configuration Scheduled task management
|
||||
URLToLaunchCronJobs=URL to launch cron jobs
|
||||
OrToLaunchASpecificJob=Or to launch a specific job
|
||||
KeyForCronAccess=Security key for URL to launch cron jobs
|
||||
DateLastRun=Last run
|
||||
LastOutput=Last run output
|
||||
LastResult=Last result code
|
||||
ListOfCronJobs=List of scheduled jobs
|
||||
Command=Command
|
||||
FileToLaunchCronJobs=Command to launch cron jobs
|
||||
CronExplainHowToRunUnix=On Unix environement you should use crontab to run Command line each minutes
|
||||
CronExplainHowToRunWin=On Microsoft(tm) Windows environement you can use Scheduled task tools to run Command line each minutes
|
||||
|
||||
#
|
||||
# Page list
|
||||
#
|
||||
CronDateLastRun=Last run
|
||||
CronLastOutput=Last run output
|
||||
CronLastResult=Last result code
|
||||
CronListOfCronJobs=List of scheduled jobs
|
||||
CronCommand=Command
|
||||
CronList= Job list
|
||||
CronDelete= Delete cron jobs
|
||||
CronConfirmDelete= Are you sure to delete this cron jobs ?
|
||||
CronExecute=Launch task
|
||||
CronConfirmExecute= Are you sure to execute this job now
|
||||
CronInfo= Jobs allow to execute task that have been planned
|
||||
CronWaitingJobs=Wainting jobs
|
||||
CronTask=Task
|
||||
CronNone= None
|
||||
CronDtStart=Start date
|
||||
CronDtEnd=End fin
|
||||
CronDtNextLaunch=Next execution
|
||||
CronDtLastLaunch=Last execution
|
||||
CronFrequency=Frequancy
|
||||
CronClass=Classe
|
||||
CronMethod=Method
|
||||
CronModule=Module
|
||||
CronAction=Action
|
||||
CronStatus=Status
|
||||
CronStatusActive=Active
|
||||
CronStatusInactive=Inactive
|
||||
CronNoJobs=No jobs registered
|
||||
CronPriority=Priority
|
||||
CronLabel=Description
|
||||
CronNbRun=Nb. launch
|
||||
|
||||
#
|
||||
#Page card
|
||||
#
|
||||
CronAdd= Add jobs
|
||||
CronHourStart= Start Hour and date of task
|
||||
CronEvery= And execute task each
|
||||
CronObject= Instance/Object to create
|
||||
CronArgs=Parameters
|
||||
CronSaveSucess=Save succefully
|
||||
CronNote=Comment
|
||||
CronFieldMandatory=Fields %s is mandatory
|
||||
CronErrEndDateStartDt=End date cannot be before start date
|
||||
CronStatusActiveBtn=Active
|
||||
CronStatusInactiveBtn=Inactive
|
||||
CronTaskInactive=This task is inactive
|
||||
CronDtLastResult=Last result date
|
||||
CronId=Id
|
||||
CronClassFile=Classes (file name)
|
||||
CronModuleHelp=Name of Dolibarr module directory (also work with external Dolibarr module). <BR> For exemple to fetch method of Dolibarr Product object /htdocs/<u>product</u>/class/product.class.php, the value of module is <i>product</i>
|
||||
CronClassFileHelp=The file name to load. <BR> For exemple to fetch method of Dolibarr Product object /htdocs/product/class/<u>product.class.php</u>, the value of class file name is <i>product.class.php</i>
|
||||
CronObjectHelp=The object name to load. <BR> For exemple to fetch method of Dolibarr Product object /htdocs/product/class/product.class.php, the value of class file name is <i>Product</i>
|
||||
CronMethodHelp=The object method to launch. <BR> For exemple to fetch method of Dolibarr Product object /htdocs/product/class/product.class.php, the value of method is is <i>fecth</i>
|
||||
CronArgsHelp=The method arguments. <BR> For exemple to fetch method of Dolibarr Product object /htdocs/product/class/product.class.php, the value of paramters can be <i>0, ProductRef</i>
|
||||
CronCommandHelp=The system command line to execute.
|
||||
|
||||
#
|
||||
# Info
|
||||
#
|
||||
CronInfoPage=Information
|
||||
|
||||
|
||||
#
|
||||
# Common
|
||||
#
|
||||
CronType=Task type
|
||||
CronType_method=Call method of a Dolibarr Class
|
||||
CronType_command=Shell command
|
||||
CronMenu=Cron
|
||||
CronCannotLoadClass=Cannot load class %s or object %s
|
||||
@ -678,6 +678,10 @@ Permission1411= Lire les mouvements comptables
|
||||
Permission1412= Créer/modifier/annuler les mouvements comptables
|
||||
Permission1415= Lire CA, bilans, résultats, journaux, grands livres
|
||||
Permission1421= Exporter les commandes clients et attributs
|
||||
Permission23001 = Voir les taches planifiée
|
||||
Permission23002 = Créer/Modifier les taches planifiée
|
||||
Permission23003 = Supprimer les taches planifiée
|
||||
Permission23004 = Executer les taches planifiée
|
||||
Permission2401= Lire les actions (événements ou tâches) liées à son compte
|
||||
Permission2402= Créer/modifier les actions (événements ou tâches) liées à son compte
|
||||
Permission2403= Supprimer les actions (événements ou tâches) liées à son compte
|
||||
|
||||
@ -1,11 +1,93 @@
|
||||
# Dolibarr language file - fr_FR - cron
|
||||
CHARSET=UTF-8
|
||||
CronSetup=Configuration du séquenceur de taches
|
||||
CronDesc=Cette page permet de configurer certaines options du séquenceur de taches
|
||||
|
||||
#
|
||||
# Admin
|
||||
#
|
||||
CronSetup = Page de configuration du module - Gestion de tâches planifiées
|
||||
URLToLaunchCronJobs=URL pour lancer les taches automatiques
|
||||
OrToLaunchASpecificJob=Ou pour lancer une tache spécifique
|
||||
KeyForCronAccess=Clé de sécurité pour l'URL de lancement des taches automatiques
|
||||
DateLastRun=Dernier lancement
|
||||
LastOutput=Dernière sortie
|
||||
LastResult=Dernière code retour
|
||||
ListOfCronJobs=Liste des taches programmées
|
||||
Command=Commande
|
||||
FileToLaunchCronJobs=Commande pour lancer les taches automatiques
|
||||
CronExplainHowToRunUnix=Sur un environement Unix vous pouvez paramétré 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
|
||||
|
||||
#
|
||||
# Menu
|
||||
#
|
||||
CronListActive= Liste des tâches planifiées active
|
||||
CronListInactive= Liste des tâches planifiées inactive
|
||||
|
||||
|
||||
#
|
||||
# Page list
|
||||
#
|
||||
CronDateLastRun=Dernier lancement
|
||||
CronLastOutput=Dernière sortie
|
||||
CronLastResult=Dernier code retour
|
||||
CronCommand=Commande
|
||||
CronList= Liste des tâches planifiées
|
||||
CronDelete= Supprimer la tâche planifiée
|
||||
CronConfirmDelete= Êtes-vous sûr de vouloir supprimer cette tâche planifiée ?
|
||||
CronExecute=Exécuter cette tâche
|
||||
CronConfirmExecute= Êtes-vous sûr de vouloir exécuter cette tâche maintenant?
|
||||
CronInfo= Les jobs permettent d'exécuter des tâches à intervales réguliers
|
||||
CronWaitingJobs= Vos jobs en attente:
|
||||
CronTask= Tâche
|
||||
CronNone=Aucun(e)
|
||||
CronDtStart=Date début
|
||||
CronDtEnd=Date fin
|
||||
CronDtNextLaunch=Prochaine éxécution
|
||||
CronDtLastLaunch=Dernière éxécution
|
||||
CronFrequency=Fréquence
|
||||
CronClass=Classes
|
||||
CronMethod=Méthode
|
||||
CronModule=Module
|
||||
CronAction=Action
|
||||
CronStatus=Status
|
||||
CronStatusActive=Active
|
||||
CronStatusInactive=Inactive
|
||||
CronEach=Tou(te)s
|
||||
CronNoJobs= Aucun jobs actuellement
|
||||
CronPriority=Priorité
|
||||
CronLabel=Description
|
||||
CronNbRun=Nb. exec.
|
||||
CronDtLastResult=Date du derniétre resulat de la dernière éxécution
|
||||
|
||||
#
|
||||
#Page card
|
||||
#
|
||||
CronAdd= Ajoutez une tâche
|
||||
CronHourStart= Jour et Heure de début de la tâche
|
||||
CronEvery= Puis execution toutes les
|
||||
CronObject= Instance/Objet à créer
|
||||
CronArgs= Argument
|
||||
CronSaveSucess=Enregistrement effectué
|
||||
CronNote=Note
|
||||
CronFieldMandatory=Le champ %s est obligatoire
|
||||
CronErrEndDateStartDt=La date de fin ne peux être avant la date de début
|
||||
CronStatusActiveBtn=Activer
|
||||
CronStatusInactiveBtn=Désactiver
|
||||
CronTaskInactive=Cette tâche est désactivée
|
||||
CronId=Id
|
||||
CronClassFile=Classes (fichier)
|
||||
CronModuleHelp=Nom du repertoire du module dolibarr (fonctionne automatiquement avec les modules externe Dolibarr). <BR> Par exemple pour appeler la mèthode fetch de l'object Product de Dolibarr /htdocs/<u>product</u>/class/product.class.php, la valeur de module est <i>product</i>
|
||||
CronClassFileHelp=Le fichier qui contient l'objet . <BR> Par exemple pour appeler la mèthode fetch de l'object Product de Dolibarr /htdocs/product/class/<u>product.class.php</u>, la valeur de classe est <i>product.class.php</i>
|
||||
CronObjectHelp=Le nom de l'object a crée. <BR> Par exemple pour appeler la mèthode fetch de l'object Product de Dolibarr /htdocs/product/class/product.class.php, la valeur de objet est <i>Product</i>
|
||||
CronMethodHelp=La mèthode a lancer. <BR> Par exemple pour appeler la mèthode fetch de l'object Product de Dolibarr /htdocs/product/class/product.class.php, la valeur de mèthode est <i>fecth</i>
|
||||
CronArgsHelp=Les arguments de la mèthode. <BR> For exemple to fetch method of Dolibarr Product object /htdocs/product/class/product.class.php, la valeur de paramétre pourrait être <i>0, RefProduit</i>
|
||||
CronCommandHelp=La commande système a éxecuter
|
||||
|
||||
#
|
||||
# Info
|
||||
#
|
||||
CronInfoPage=Suivie
|
||||
|
||||
#
|
||||
# Common
|
||||
#
|
||||
CronType=Type d'action a executer
|
||||
CronType_method=Méthode d'une classe d'un module Dolibarr
|
||||
CronType_command=Commande Shell
|
||||
CronMenu=Cron
|
||||
CronCannotLoadClass=impossible de charger la classe %s ou l'object %s
|
||||
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2007-2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
/* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
|
||||
* Copyright (C) 2013 Florian Henry <forian.henry@open-cocnept.pro
|
||||
*
|
||||
* 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
|
||||
@ -16,158 +17,126 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file cron/cron_run_jobs.php
|
||||
* \ingroup cron
|
||||
* \brief This file is the page to call to run jobs
|
||||
* Initialy built by build_class_from_table on 2013-03-17 18:50
|
||||
* \file cron/public/cron/cron_run_jobs.php
|
||||
* \ingroup cron
|
||||
* \brief Execute pendings jobs
|
||||
*/
|
||||
|
||||
//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1');
|
||||
//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1');
|
||||
//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
|
||||
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
|
||||
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
|
||||
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
|
||||
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
|
||||
if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
|
||||
if (! defined('NOLOGIN')) define('NOLOGIN','1');
|
||||
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
|
||||
//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
|
||||
//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');
|
||||
//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no menu to show
|
||||
//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php
|
||||
//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
|
||||
//if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session)
|
||||
|
||||
// Change this following line to use the correct relative path (../, ../../, etc)
|
||||
$res=0;
|
||||
if (! $res && file_exists("../main.inc.php")) $res=@include '../main.inc.php';
|
||||
if (! $res && file_exists("../../main.inc.php")) $res=@include '../../main.inc.php';
|
||||
if (! $res && file_exists("../../../main.inc.php")) $res=@include '../../../main.inc.php';
|
||||
if (! $res && file_exists("../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only
|
||||
if (! $res && file_exists("../../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only
|
||||
if (! $res && file_exists("../../../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only
|
||||
if (! $res) die("Include of main fails");
|
||||
// Change this following line to use the correct relative path from htdocs
|
||||
include_once(DOL_DOCUMENT_ROOT.'/cron/class/cronjob.class.php');
|
||||
|
||||
|
||||
// C'est un wrapper, donc header vierge
|
||||
/**
|
||||
* Header function
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function llxHeaderVierge() {
|
||||
print '<html><title>Export agenda cal</title><body>';
|
||||
}
|
||||
/**
|
||||
* Footer function
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function llxFooterVierge() {
|
||||
print '</body></html>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Load traductions files requiredby by page
|
||||
$langs->load("companies");
|
||||
$langs->load("other");
|
||||
$langs->load("cron@cron");
|
||||
|
||||
// Get parameters
|
||||
$id = GETPOST('id','int');
|
||||
$action = GETPOST('action','alpha');
|
||||
|
||||
// Protection if external user
|
||||
if ($user->societe_id > 0)
|
||||
{
|
||||
//accessforbidden();
|
||||
// librarie core
|
||||
// Dolibarr environment
|
||||
$res = @include("../../main.inc.php"); // From htdocs directory
|
||||
if (! $res) {
|
||||
$res = @include("../../../main.inc.php"); // From "custom" directory
|
||||
}
|
||||
if (! $res) die("Include of master.inc.php fails");
|
||||
|
||||
// Security check
|
||||
if (empty($conf->cron->enabled)) accessforbidden('',1,1,1);
|
||||
// librarie jobs
|
||||
dol_include_once("/cron/class/cronjob.class.php");
|
||||
|
||||
// Check also security key
|
||||
if (empty($_GET["securitykey"]) || $conf->global->CRON_KEY != $_GET["securitykey"])
|
||||
{
|
||||
$user->getrights();
|
||||
|
||||
llxHeaderVierge();
|
||||
print '<div class="error">Bad value for key.</div>';
|
||||
llxFooterVierge();
|
||||
exit;
|
||||
|
||||
global $langs, $conf;
|
||||
|
||||
// Check the key, avoid that a stranger starts cron
|
||||
$key = $_GET['securitykey'];
|
||||
if (empty($key)) {
|
||||
echo 'securitykey is require';
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************
|
||||
* ACTIONS
|
||||
*
|
||||
* Put here all code to do according to value of "action" parameter
|
||||
********************************************************************/
|
||||
|
||||
if ($action == 'add')
|
||||
if($key != $conf->global->MAIN_CRON_KEY)
|
||||
{
|
||||
$object=new Cronjobs($db);
|
||||
$object->prop1=$_POST["field1"];
|
||||
$object->prop2=$_POST["field2"];
|
||||
$result=$object->create($user);
|
||||
if ($result > 0)
|
||||
{
|
||||
// Creation OK
|
||||
}
|
||||
{
|
||||
// Creation KO
|
||||
$mesg=$object->error;
|
||||
echo 'securitykey is wrong';
|
||||
exit;
|
||||
}
|
||||
// Check the key, avoid that a stranger starts cron
|
||||
$userlogin = $_GET['userlogin'];
|
||||
if (empty($userlogin)) {
|
||||
echo 'userlogin is require';
|
||||
exit;
|
||||
}
|
||||
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
|
||||
$user=new User($db);
|
||||
$result=$user->fetch('',$userlogin);
|
||||
if ($result<0) {
|
||||
echo "User Error:".$user->error;
|
||||
dol_syslog("cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
|
||||
exit;
|
||||
}else {
|
||||
if (empty($user->id)) {
|
||||
echo " User user login:".$userlogin." do not exists";
|
||||
dol_syslog(" User user login:".$userlogin." do not exists", LOG_ERR);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$id = $_GET['id'];
|
||||
|
||||
// Language Management
|
||||
$langs->load("admin");
|
||||
$langs->load("cron@cron");
|
||||
|
||||
// create a jobs object
|
||||
$object = new Cronjob($db);
|
||||
|
||||
$filter=array();
|
||||
if (empty($id)) {
|
||||
$filter=array();
|
||||
$filter['t.rowid']=$id;
|
||||
}
|
||||
|
||||
$result = $object->fetch_all('DESC','t.rowid', 0, 0, 1, $filter);
|
||||
if ($result<0) {
|
||||
echo "Error:".$cronjob->error;
|
||||
dol_syslog("cron_run_jobs.php:: fetch Error".$cronjob->error, LOG_ERR);
|
||||
exit;
|
||||
}
|
||||
|
||||
/***************************************************
|
||||
* VIEW
|
||||
*
|
||||
* Put here all code to build page
|
||||
****************************************************/
|
||||
// current date
|
||||
$now=dol_now();
|
||||
|
||||
llxHeader('',$langs->trans('CronList'),'');
|
||||
if(is_array($object->lines) && (count($object->lines)>0)){
|
||||
// Loop over job
|
||||
foreach($object->lines as $line){
|
||||
|
||||
$form=new Form($db);
|
||||
|
||||
|
||||
// Put here content of your page
|
||||
|
||||
// Example 1 : Adding jquery code
|
||||
print '<script type="text/javascript" language="javascript">
|
||||
jQuery(document).ready(function() {
|
||||
function init_myfunc()
|
||||
{
|
||||
jQuery("#myid").removeAttr(\'disabled\');
|
||||
jQuery("#myid").attr(\'disabled\',\'disabled\');
|
||||
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 ((($line->datenextrun <= $now) && $line->dateend < $now)
|
||||
|| ((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);
|
||||
|
||||
$cronjob=new Cronjob($db);
|
||||
$result=$cronjob->fetch($line->id);
|
||||
if ($result<0) {
|
||||
echo "Error:".$cronjob->error;
|
||||
dol_syslog("cron_run_jobs.php:: fetch Error".$cronjob->error, LOG_ERR);
|
||||
exit;
|
||||
}
|
||||
// execute methode
|
||||
$result=$cronjob->run_jobs($userlogin);
|
||||
if ($result<0) {
|
||||
echo "Error:".$cronjob->error;
|
||||
dol_syslog("cron_run_jobs.php:: run_jobs Error".$cronjob->error, LOG_ERR);
|
||||
exit;
|
||||
}
|
||||
|
||||
// we re-program the next execution and stores the last execution time for this job
|
||||
$result=$cronjob->reprogram_jobs($userlogin);
|
||||
if ($result<0) {
|
||||
echo "Error:".$cronjob->error;
|
||||
dol_syslog("cron_run_jobs.php:: reprogram_jobs Error".$cronjob->error, LOG_ERR);
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
init_myfunc();
|
||||
jQuery("#mybutton").click(function() {
|
||||
init_needroot();
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
|
||||
$cronjob=new CronJob($db);
|
||||
$result=$cronjob->fetch($id);
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
|
||||
|
||||
echo "OK";
|
||||
} else {
|
||||
echo "No Jobs to run";
|
||||
}
|
||||
else
|
||||
{
|
||||
$langs->load("errors");
|
||||
print $langs->trans("ErrorRecordNotFound");
|
||||
}
|
||||
|
||||
|
||||
// End of page
|
||||
llxFooter();
|
||||
|
||||
$db->close();
|
||||
?>
|
||||
|
||||
BIN
htdocs/theme/amarok/img/cron.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
htdocs/theme/amarok/img/object_cron.png
Normal file
|
After Width: | Height: | Size: 655 B |
BIN
htdocs/theme/auguria/img/cron.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
htdocs/theme/auguria/img/object_cron.png
Normal file
|
After Width: | Height: | Size: 655 B |
BIN
htdocs/theme/bureau2crea/img/cron.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
htdocs/theme/bureau2crea/img/object_cron.png
Normal file
|
After Width: | Height: | Size: 655 B |
BIN
htdocs/theme/cameleo/img/cron.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
htdocs/theme/cameleo/img/object_cron.png
Normal file
|
After Width: | Height: | Size: 655 B |
BIN
htdocs/theme/eldy/img/menus/cron.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
htdocs/theme/eldy/img/menus/object_cron.png
Normal file
|
After Width: | Height: | Size: 655 B |
146
scripts/cron/cron_run_jobs.php
Normal file
@ -0,0 +1,146 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
/* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
|
||||
* Copyright (C) 2013 Florian Henry <forian.henry@open-cocnept.pro
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file cron/script/cron/cron_run_jobs.php
|
||||
* \ingroup cron
|
||||
* \brief Execute pendings jobs
|
||||
*/
|
||||
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
|
||||
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
|
||||
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
|
||||
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
|
||||
if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
|
||||
if (! defined('NOLOGIN')) define('NOLOGIN','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;
|
||||
}
|
||||
|
||||
if (! isset($argv[1]) || ! $argv[1]) {
|
||||
print "Usage: ".$script_file." securitykey userlogin cronjobid(optional)\n";
|
||||
exit;
|
||||
}
|
||||
$key=$argv[1];
|
||||
|
||||
if (! isset($argv[2]) || ! $argv[2]) {
|
||||
print "Usage: ".$script_file." securitykey userlogin cronjobid(optional)\n";
|
||||
exit;
|
||||
} else {
|
||||
$userlogin=$argv[2];
|
||||
}
|
||||
|
||||
|
||||
$res=@include("../../master.inc.php"); // For root directory
|
||||
if (! $res) $res=@include("../../../master.inc.php"); // For "custom" directory
|
||||
if (! $res) die("Include of master.inc.php fails");
|
||||
|
||||
|
||||
// librarie jobs
|
||||
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';
|
||||
exit;
|
||||
}
|
||||
|
||||
//Check user login
|
||||
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
|
||||
$user=new User($db);
|
||||
$result=$user->fetch('',$userlogin);
|
||||
if ($result<0) {
|
||||
echo "User Error:".$user->error;
|
||||
dol_syslog("cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
|
||||
exit;
|
||||
}else {
|
||||
if (empty($user->id)) {
|
||||
echo " User user login:".$userlogin." do not exists";
|
||||
dol_syslog(" User user login:".$userlogin." do not exists", LOG_ERR);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($argv[3]) || $argv[3]) {
|
||||
$id = $argv[3];
|
||||
}
|
||||
|
||||
// librarie jobs
|
||||
require_once (DOL_DOCUMENT_ROOT_ALT."/cron/class/cronjob.class.php");
|
||||
|
||||
// create a jobs object
|
||||
$object = new Cronjob($db);
|
||||
|
||||
$filter=array();
|
||||
if (empty($id)) {
|
||||
$filter=array();
|
||||
$filter['t.rowid']=$id;
|
||||
}
|
||||
|
||||
$result = $object->fetch_all('DESC','t.rowid', 0, 0, 1, $filter);
|
||||
if ($result<0) {
|
||||
echo "Error:".$cronjob->error;
|
||||
dol_syslog("cron_run_jobs.php:: fetch Error".$cronjob->error, LOG_ERR);
|
||||
exit;
|
||||
}
|
||||
|
||||
// current date
|
||||
$now=dol_now();
|
||||
|
||||
if(is_array($object->lines) && (count($object->lines)>0)){
|
||||
// Loop over job
|
||||
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 (($line->datenextrun < $now) && $line->dateend < $now){
|
||||
$cronjob=new Cronjob($db);
|
||||
$result=$cronjob->fetch($line->id);
|
||||
if ($result<0) {
|
||||
echo "Error:".$cronjob->error;
|
||||
dol_syslog("cron_run_jobs.php:: fetch Error".$cronjob->error, LOG_ERR);
|
||||
exit;
|
||||
}
|
||||
// execute methode
|
||||
$result=$cronjob->run_jobs($userlogin);
|
||||
if ($result<0) {
|
||||
echo "Error:".$cronjob->error;
|
||||
dol_syslog("cron_run_jobs.php:: run_jobs Error".$cronjob->error, LOG_ERR);
|
||||
exit;
|
||||
}
|
||||
|
||||
// we re-program the next execution and stores the last execution time for this job
|
||||
$result=$cronjob->reprogram_jobs($userlogin);
|
||||
if ($result<0) {
|
||||
echo "Error:".$cronjob->error;
|
||||
dol_syslog("cron_run_jobs.php:: reprogram_jobs Error".$cronjob->error, LOG_ERR);
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||