diff --git a/htdocs/admin/tools/export.php b/htdocs/admin/tools/export.php index c89fafbe052..3cfb3baf496 100644 --- a/htdocs/admin/tools/export.php +++ b/htdocs/admin/tools/export.php @@ -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.='
'.$langs->trans("Error")." : ".$errormsg.'
'; - $resultstring=''; - $resultstring.='
'.$langs->trans("Error")." : ".$errormsg.'
'; + $_SESSION["commandbackupresult"]=$resultstring; +} +else +{ + if ($what) + { + setEventMessages($langs->trans("BackupFileSuccessfullyCreated").'.
'.$langs->trans("YouCanDownloadBackupFile"), null, 'mesgs'); + + $resultstring='
'; + $resultstring.=$langs->trans("BackupFileSuccessfullyCreated").'.
'; + $resultstring.=$langs->trans("YouCanDownloadBackupFile"); + $resultstring.='
'; $_SESSION["commandbackupresult"]=$resultstring; - } - else + } + else { - if ($what) - { - setEventMessages($langs->trans("BackupFileSuccessfullyCreated").'.
'.$langs->trans("YouCanDownloadBackupFile"), null, 'mesgs'); + setEventMessages($langs->trans("YouMustRunCommandFromCommandLineAfterLoginToUser",$dolibarr_main_db_user,$dolibarr_main_db_user), null, 'mesgs'); + } +} - $resultstring='
'; - $resultstring.=$langs->trans("BackupFileSuccessfullyCreated").'.
'; - $resultstring.=$langs->trans("YouCanDownloadBackupFile"); - $resultstring.='
'; - - $_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); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 7a0d8d5ec5a..acdf123e4ce 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -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='') diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index 06b3bc89860..8f0d161bb5b 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -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); diff --git a/htdocs/core/modules/modCron.class.php b/htdocs/core/modules/modCron.class.php index 4981eeb0089..33491ea9a5a 100644 --- a/htdocs/core/modules/modCron.class.php +++ b/htdocs/core/modules/modCron.class.php @@ -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; diff --git a/htdocs/core/modules/modFacture.class.php b/htdocs/core/modules/modFacture.class.php index eaba97d093b..b642873c82d 100644 --- a/htdocs/core/modules/modFacture.class.php +++ b/htdocs/core/modules/modFacture.class.php @@ -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 diff --git a/htdocs/cron/class/cronjob.class.php b/htdocs/cron/class/cronjob.class.php index 18713622476..31b4fc39c7c 100644 --- a/htdocs/cron/class/cronjob.class.php +++ b/htdocs/cron/class/cronjob.class.php @@ -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++; diff --git a/htdocs/cron/list.php b/htdocs/cron/list.php index 41b08acbdd5..b6d830dd201 100644 --- a/htdocs/cron/list.php +++ b/htdocs/cron/list.php @@ -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';} diff --git a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql index f2b3ff181cc..3ffb260f415 100644 --- a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql +++ b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql @@ -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); diff --git a/htdocs/install/mysql/tables/llx_cronjob.sql b/htdocs/install/mysql/tables/llx_cronjob.sql index a70051d4c11..f9d2ac1ab7a 100644 --- a/htdocs/install/mysql/tables/llx_cronjob.sql +++ b/htdocs/install/mysql/tables/llx_cronjob.sql @@ -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 diff --git a/htdocs/langs/en_US/cron.lang b/htdocs/langs/en_US/cron.lang index b7cdb069346..f2184b50b08 100644 --- a/htdocs/langs/en_US/cron.lang +++ b/htdocs/langs/en_US/cron.lang @@ -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