NEW Clean and enhance code for cron engine
This commit is contained in:
parent
426e9297ea
commit
928336c835
@ -107,6 +107,10 @@ $dump_buffer_len = 0;
|
||||
$time_start = time();
|
||||
|
||||
|
||||
$outputdir = $conf->admin->dir_output.'/backup';
|
||||
$result=dol_mkdir($outputdir);
|
||||
|
||||
|
||||
// MYSQL
|
||||
if ($what == 'mysql')
|
||||
{
|
||||
@ -116,7 +120,6 @@ if ($what == 'mysql')
|
||||
dolibarr_set_const($db, 'SYSTEMTOOLS_MYSQLDUMP', $cmddump,'chaine',0,'',$conf->entity);
|
||||
}
|
||||
|
||||
$outputdir = $conf->admin->dir_output.'/backup';
|
||||
$outputfile = $outputdir.'/'.$file;
|
||||
// for compression format, we add extension
|
||||
$compression=GETPOST('compression') ? GETPOST('compression','alpha') : 'none';
|
||||
@ -185,8 +188,6 @@ if ($what == 'mysql')
|
||||
|
||||
$errormsg='';
|
||||
|
||||
$result=dol_mkdir($outputdir);
|
||||
|
||||
// Debut appel methode execution
|
||||
$fullcommandcrypted=$command." ".$paramcrypted." 2>&1";
|
||||
$fullcommandclear=$command." ".$paramclear." 2>&1";
|
||||
@ -254,7 +255,6 @@ if ($what == 'mysql')
|
||||
|
||||
if ($what == 'mysqlnobin')
|
||||
{
|
||||
$outputdir = $conf->admin->dir_output.'/backup';
|
||||
$outputfile = $outputdir.'/'.$file;
|
||||
$outputfiletemp = $outputfile.'-TMP.sql';
|
||||
// for compression format, we add extension
|
||||
@ -288,7 +288,6 @@ if ($what == 'postgresql')
|
||||
dolibarr_set_const($db, 'SYSTEMTOOLS_POSTGRESQLDUMP', $cmddump,'chaine',0,'',$conf->entity);
|
||||
}
|
||||
|
||||
$outputdir = $conf->admin->dir_output.'/backup';
|
||||
$outputfile = $outputdir.'/'.$file;
|
||||
// for compression format, we add extension
|
||||
$compression=GETPOST('compression') ? GETPOST('compression','alpha') : 'none';
|
||||
@ -299,7 +298,7 @@ if ($what == 'postgresql')
|
||||
|
||||
// Parameteres execution
|
||||
$command=$cmddump;
|
||||
if (preg_match("/\s/",$command)) $command=$command=escapeshellarg($command); // Use quotes on command
|
||||
if (preg_match("/\s/",$command)) $command=escapeshellarg($command); // Use quotes on command
|
||||
|
||||
//$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass);
|
||||
//$param="-F c";
|
||||
@ -352,38 +351,34 @@ if ($what == 'postgresql')
|
||||
|
||||
|
||||
|
||||
if ($errormsg)
|
||||
{
|
||||
setEventMessages($langs->trans("Error")." : ".$errormsg, null, 'errors');
|
||||
|
||||
// Si on a demande une generation
|
||||
//if ($what)
|
||||
//{
|
||||
if ($errormsg)
|
||||
{
|
||||
setEventMessages($langs->trans("Error")." : ".$errormsg, null, 'errors');
|
||||
$resultstring='';
|
||||
$resultstring.='<div class="error">'.$langs->trans("Error")." : ".$errormsg.'</div>';
|
||||
|
||||
$resultstring='';
|
||||
$resultstring.='<div class="error">'.$langs->trans("Error")." : ".$errormsg.'</div>';
|
||||
$_SESSION["commandbackupresult"]=$resultstring;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($what)
|
||||
{
|
||||
setEventMessages($langs->trans("BackupFileSuccessfullyCreated").'.<br>'.$langs->trans("YouCanDownloadBackupFile"), null, 'mesgs');
|
||||
|
||||
$resultstring='<div class="ok">';
|
||||
$resultstring.=$langs->trans("BackupFileSuccessfullyCreated").'.<br>';
|
||||
$resultstring.=$langs->trans("YouCanDownloadBackupFile");
|
||||
$resultstring.='<div>';
|
||||
|
||||
$_SESSION["commandbackupresult"]=$resultstring;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($what)
|
||||
{
|
||||
setEventMessages($langs->trans("BackupFileSuccessfullyCreated").'.<br>'.$langs->trans("YouCanDownloadBackupFile"), null, 'mesgs');
|
||||
setEventMessages($langs->trans("YouMustRunCommandFromCommandLineAfterLoginToUser",$dolibarr_main_db_user,$dolibarr_main_db_user), null, 'mesgs');
|
||||
}
|
||||
}
|
||||
|
||||
$resultstring='<div class="ok">';
|
||||
$resultstring.=$langs->trans("BackupFileSuccessfullyCreated").'.<br>';
|
||||
$resultstring.=$langs->trans("YouCanDownloadBackupFile");
|
||||
$resultstring.='<div>';
|
||||
|
||||
$_SESSION["commandbackupresult"]=$resultstring;
|
||||
}
|
||||
else
|
||||
{
|
||||
setEventMessages($langs->trans("YouMustRunCommandFromCommandLineAfterLoginToUser",$dolibarr_main_db_user,$dolibarr_main_db_user), null, 'mesgs');
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
/*
|
||||
$filearray=dol_dir_list($conf->admin->dir_output.'/backup','files',0,'','',$sortfield,(strtolower($sortorder)=='asc'?SORT_ASC:SORT_DESC),1);
|
||||
|
||||
@ -306,7 +306,7 @@ function dol_getprefix()
|
||||
* To link to a module file from a core file, then this function can be used (call by hook / trigger / speciales pages)
|
||||
*
|
||||
* @param string $relpath Relative path to file (Ie: mydir/myfile, ../myfile, ...)
|
||||
* @param string $classname Class name
|
||||
* @param string $classname Class name (deprecated)
|
||||
* @return bool True if load is a success, False if it fails
|
||||
*/
|
||||
function dol_include_once($relpath, $classname='')
|
||||
|
||||
@ -913,7 +913,10 @@ class DolibarrModules // Can not be abstract, because we need to insta
|
||||
$comment = isset($this->cronjobs[$key]['comment'])?$this->cronjobs[$key]['comment']:'';
|
||||
$frequency = isset($this->cronjobs[$key]['frequency'])?$this->cronjobs[$key]['frequency']:'';
|
||||
$unitfrequency = isset($this->cronjobs[$key]['unitfrequency'])?$this->cronjobs[$key]['unitfrequency']:'';
|
||||
|
||||
$status = isset($this->cronjobs[$key]['status'])?$this->cronjobs[$key]['status']:'';
|
||||
$priority = isset($this->cronjobs[$key]['priority'])?$this->cronjobs[$key]['priority']:'';
|
||||
$test = isset($this->cronjobs[$key]['test'])?$this->cronjobs[$key]['test']:'';
|
||||
|
||||
// Search if boxes def already present
|
||||
$sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."cronjob";
|
||||
$sql.= " WHERE module_name = '".$this->db->escape($this->rights_class)."'";
|
||||
@ -936,7 +939,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
|
||||
|
||||
if (! $err)
|
||||
{
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."cronjob (module_name, datec, datestart, label, jobtype, classesname, objectname, methodename, command, params, note, frequency, unitfrequency, entity)";
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."cronjob (module_name, datec, datestart, label, jobtype, classesname, objectname, methodename, command, params, note, frequency, unitfrequency, priority, status, entity, test)";
|
||||
$sql.= " VALUES (";
|
||||
$sql.= "'".$this->db->escape($this->rights_class)."', ";
|
||||
$sql.= "'".$this->db->idate($now)."', ";
|
||||
@ -951,7 +954,10 @@ class DolibarrModules // Can not be abstract, because we need to insta
|
||||
$sql.= ($comment?"'".$this->db->escape($comment)."'":"null").",";
|
||||
$sql.= "'".$this->db->escape($frequency)."', ";
|
||||
$sql.= "'".$this->db->escape($unitfrequency)."', ";
|
||||
$sql.= $conf->entity;
|
||||
$sql.= "'".$this->db->escape($priority)."', ";
|
||||
$sql.= "'".$this->db->escape($status)."', ";
|
||||
$sql.= $conf->entity.",";
|
||||
$sql.= "'".$this->db->escape($test)."'";
|
||||
$sql.= ")";
|
||||
|
||||
dol_syslog(get_class($this)."::insert_cronjobs", LOG_DEBUG);
|
||||
|
||||
@ -101,8 +101,9 @@ class modCron extends DolibarrModules
|
||||
|
||||
// Cronjobs
|
||||
$this->cronjobs = array(
|
||||
0=>array('label'=>'PurgeDeleteTemporaryFilesShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'purgeFiles', 'parameters'=>'', 'comment'=>'PurgeDeleteTemporaryFiles', 'frequency'=>1, 'unitfrequency'=>3600 * 24 * 7),
|
||||
// 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24)
|
||||
0=>array('label'=>'PurgeDeleteTemporaryFilesShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'purgeFiles', 'parameters'=>'', 'comment'=>'PurgeDeleteTemporaryFiles', 'frequency'=>1, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>10, 'status'=>1, 'test'=>'1'),
|
||||
1=>array('label'=>'MakeLocalDatabaseDumpShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'dumpDatabase', 'parameters'=>'', 'comment'=>'MakeLocalDatabaseDump', 'frequency'=>1, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>20, 'status'=>0, 'test'=>'0'),
|
||||
// 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24)
|
||||
);
|
||||
|
||||
$this->rights[$r][0] = 23001;
|
||||
|
||||
@ -107,7 +107,7 @@ class modFacture extends DolibarrModules
|
||||
|
||||
// Cronjobs
|
||||
$this->cronjobs = array(
|
||||
0=>array('label'=>'RecurringInvoices', 'jobtype'=>'method', 'class'=>'compta/facture/class/facture-rec.class.php', 'objectname'=>'Facture', 'method'=>'generateRecurringInvoices', 'parameters'=>'', 'comment'=>'Generate recurring invoices', 'frequency'=>1, 'unitfrequency'=>3600*24),
|
||||
0=>array('label'=>'RecurringInvoices', 'jobtype'=>'method', 'class'=>'compta/facture/class/facture-rec.class.php', 'objectname'=>'FactureRec', 'method'=>'generateRecurringInvoices', 'parameters'=>'', 'comment'=>'Generate recurring invoices', 'frequency'=>1, 'unitfrequency'=>3600*24),
|
||||
// 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>3600, 'unitfrequency'=>3600)
|
||||
);
|
||||
// List of cron jobs entries to add
|
||||
|
||||
@ -391,9 +391,10 @@ class Cronjob extends CommonObject
|
||||
$sql.= " t.fk_user_author,";
|
||||
$sql.= " t.fk_user_mod,";
|
||||
$sql.= " t.note,";
|
||||
$sql.= " t.nbrun";
|
||||
$sql .= ", t.libname";
|
||||
|
||||
$sql.= " t.nbrun,";
|
||||
$sql.= " t.libname,";
|
||||
$sql.= " t.test";
|
||||
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."cronjob as t";
|
||||
$sql.= " WHERE 1 = 1";
|
||||
if ($status >= 0) $sql.= " AND t.status = ".(empty($status)?'0':'1');
|
||||
@ -465,7 +466,8 @@ class Cronjob extends CommonObject
|
||||
$line->fk_user_mod = $obj->fk_user_mod;
|
||||
$line->note = $obj->note;
|
||||
$line->nbrun = $obj->nbrun;
|
||||
$line->libname = $obj->libname;
|
||||
$line->libname = $obj->libname;
|
||||
$line->test = $obj->test;
|
||||
$this->lines[]=$line;
|
||||
|
||||
$i++;
|
||||
@ -905,25 +907,43 @@ class Cronjob extends CommonObject
|
||||
if ($this->jobtype=='method')
|
||||
{
|
||||
// load classes
|
||||
$ret=dol_include_once($this->classesname,$this->objectname);
|
||||
if (! $error && $ret===false)
|
||||
if (! $error)
|
||||
{
|
||||
$this->error=$langs->trans('CronCannotLoadClass',$this->classesname,$this->objectname);
|
||||
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
|
||||
$this->lastoutput = $this->error;
|
||||
$this->lastresult = -1;
|
||||
$retval = $this->lastresult;
|
||||
$error++;
|
||||
$ret=dol_include_once($this->classesname);
|
||||
if ($ret===false || (! class_exists($this->objectname)))
|
||||
{
|
||||
$this->error=$langs->trans('CronCannotLoadClass',$this->classesname,$this->objectname);
|
||||
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
|
||||
$this->lastoutput = $this->error;
|
||||
$this->lastresult = -1;
|
||||
$retval = $this->lastresult;
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
// test if method exists
|
||||
if (! $error)
|
||||
{
|
||||
if (! method_exists($this->objectname, $this->methodename))
|
||||
{
|
||||
$this->error=$langs->trans('CronMethodDoesNotExists',$this->objectname,$this->methodename);
|
||||
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
|
||||
$this->lastoutput = $this->error;
|
||||
$this->lastresult = -1;
|
||||
$retval = $this->lastresult;
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
// Load langs
|
||||
if (! $error)
|
||||
{
|
||||
$result=$langs->load($this->module_name.'@'.$this->module_name);
|
||||
if ($result<0)
|
||||
if ($result < 0)
|
||||
{
|
||||
dol_syslog(get_class($this)."::run_jobs Cannot load module lang file - ".$langs->error, LOG_ERR);
|
||||
$this->lastoutput = $langs->error;
|
||||
$this->error = $langs->error;
|
||||
$this->lastoutput = $this->error;
|
||||
$this->lastresult = -1;
|
||||
$retval = $this->lastresult;
|
||||
$error++;
|
||||
|
||||
@ -220,6 +220,8 @@ if ($num > 0)
|
||||
$style='pair';
|
||||
foreach($object->lines as $line)
|
||||
{
|
||||
if (! verifCond($line->test)) continue; // Discard line with test = false
|
||||
|
||||
// title profil
|
||||
if ($style=='pair') {$style='impair';}
|
||||
else {$style='pair';}
|
||||
|
||||
@ -35,6 +35,7 @@ UPDATE llx_projet as p set opp_percent = (SELECT percent from llx_c_lead_status
|
||||
ALTER TABLE llx_overwrite_trans ADD UNIQUE INDEX uk_overwrite_trans(lang, transkey);
|
||||
|
||||
ALTER TABLE llx_cronjob MODIFY COLUMN unitfrequency varchar(255) NOT NULL DEFAULT '3600';
|
||||
ALTER TABLE llx_cronjob ADD COLUMN test varchar(255) DEFAULT '1';
|
||||
|
||||
ALTER TABLE llx_facture ADD INDEX idx_facture_fk_statut (fk_statut);
|
||||
|
||||
|
||||
@ -46,6 +46,7 @@ CREATE TABLE llx_cronjob
|
||||
nbrun integer, -- nb of run complete (failed or not)
|
||||
autodelete integer DEFAULT 0, -- 0=Job is kept unchanged once nbrun > maxrun or date > dateend, 2=Job must be archived (archive = status 2) once nbrun > maxrun or date > dateend
|
||||
status integer NOT NULL DEFAULT 1, -- 0=disabled, 1=enabled, 2=archived
|
||||
test varchar(255) DEFAULT '1',
|
||||
fk_user_author integer DEFAULT NULL,
|
||||
fk_user_mod integer DEFAULT NULL,
|
||||
fk_mailing integer DEFAULT NULL, -- id of emailing if job was queued to send mass emailing
|
||||
|
||||
@ -89,3 +89,5 @@ CronMenu=Cron
|
||||
CronCannotLoadClass=Cannot load class %s or object %s
|
||||
UseMenuModuleToolsToAddCronJobs=Go into menu "Home - Modules tools - Job list" to see and edit scheduled jobs.
|
||||
TaskDisabled=Job disabled
|
||||
MakeLocalDatabaseDumpShort=Local database backup
|
||||
MakeLocalDatabaseDump=Create a local database dump
|
||||
|
||||
Loading…
Reference in New Issue
Block a user