62 public function purgeFiles($choices =
'tempfilesold+logfiles', $nbsecondsold = 86400)
64 global $conf, $langs, $user;
65 global $dolibarr_main_data_root;
67 $langs->load(
"admin");
69 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
71 if (empty($choices)) {
72 $choices =
'tempfilesold+logfiles';
74 if ($choices ==
'allfiles' && $nbsecondsold > 0) {
75 $choices =
'allfilesold';
78 dol_syslog(
"Utils::purgeFiles choice=".$choices, LOG_DEBUG);
81 if (in_array($choices, array(
'allfiles',
'allfilesold'))) {
82 if (empty($user->admin)) {
83 $this->output =
'Error: to erase data files, user running the batch (currently '.$user->login.
') must be an admin user';
93 $choicesarray = preg_split(
'/[\+,]/', $choices);
94 foreach ($choicesarray as $choice) {
96 $filesarray = array();
98 if ($choice ==
'tempfiles' || $choice ==
'tempfilesold') {
100 if ($dolibarr_main_data_root) {
101 $filesarray =
dol_dir_list($dolibarr_main_data_root,
"directories", 1,
'^temp$',
'',
'name', SORT_ASC, 2, 0,
'', 1);
103 if ($choice ==
'tempfilesold') {
104 foreach ($filesarray as $key => $val) {
105 if ($val[
'date'] > ($now - ($nbsecondsold))) {
106 unset($filesarray[$key]);
113 if ($choice ==
'allfiles') {
115 if ($dolibarr_main_data_root) {
116 $filesarray =
dol_dir_list($dolibarr_main_data_root,
"all", 0,
'',
'(\.lock|\.unlock)$',
'name', SORT_ASC, 0, 0,
'', 1);
120 if ($choice ==
'allfilesold') {
122 if ($dolibarr_main_data_root) {
123 $filesarray =
dol_dir_list($dolibarr_main_data_root,
"files", 1,
'',
'(\.lock|\.unlock)$',
'name', SORT_ASC, 0, 0,
'', 1, $nbsecondsold);
127 if ($choice ==
'logfile' || $choice ==
'logfiles') {
129 if ($dolibarr_main_data_root) {
130 $filesarray =
dol_dir_list($dolibarr_main_data_root,
"files", 0,
'.*\.log[\.0-9]*(\.gz)?$',
'(\.lock|\.unlock)$',
'name', SORT_ASC, 0, 0,
'', 1);
133 if (isModEnabled(
'syslog')) {
134 $filelog = $conf->global->SYSLOG_FILE;
135 $filelog = preg_replace(
'/DOL_DATA_ROOT/i', DOL_DATA_ROOT, $filelog);
137 $alreadyincluded =
false;
138 foreach ($filesarray as $tmpcursor) {
139 if ($tmpcursor[
'fullname'] == $filelog) {
140 $alreadyincluded =
true;
143 if (!$alreadyincluded) {
144 $filesarray[] = array(
'fullname'=>$filelog,
'type'=>
'file');
149 if (is_array($filesarray) && count($filesarray)) {
150 foreach ($filesarray as $key => $value) {
152 if ($filesarray[$key][
'type'] ==
'dir') {
154 $tmpcountdeleted = 0;
158 if (!in_array($filesarray[$key][
'fullname'], array($conf->api->dir_temp, $conf->user->dir_temp))) {
160 $countdeleted += $tmpcountdeleted;
162 } elseif ($filesarray[$key][
'type'] ==
'file') {
163 if ($choice !=
'allfilesold' || $filesarray[$key][
'date'] < ($now - $nbsecondsold)) {
165 if ($filesarray[$key][
'fullname'] != $filelog || $choice ==
'logfile' || $choice ==
'logfiles') {
179 if (isModEnabled(
'ecm') && $choice ==
'allfiles') {
180 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
182 $result = $ecmdirstatic->refreshcachenboffile(1);
188 $langs->load(
"admin");
189 $this->output = $langs->trans(
"PurgeNDirectoriesDeleted", $countdeleted);
190 if ($count > $countdeleted) {
191 $this->output .=
'<br>'.$langs->trans(
"PurgeNDirectoriesFailed", ($count - $countdeleted));
194 $this->output = $langs->trans(
"PurgeNothingToDelete").(in_array(
'tempfilesold', $choicesarray) ?
' (older than 24h for temp files)' :
'');
198 if (isModEnabled(
'api')) {
221 public function dumpDatabase($compression =
'none', $type =
'auto', $usedefault = 1, $file =
'auto', $keeplastnfiles = 0, $execmethod = 0, $lowmemorydump = 0)
223 global
$db, $conf, $langs, $dolibarr_main_data_root;
224 global $dolibarr_main_db_name, $dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_port, $dolibarr_main_db_pass;
225 global $dolibarr_main_db_character_set;
227 $langs->load(
"admin");
229 dol_syslog(
"Utils::dumpDatabase type=".$type.
" compression=".$compression.
" file=".$file, LOG_DEBUG);
230 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
236 if (!in_array($compression, array(
'none',
'gz',
'bz',
'zip',
'zstd'))) {
237 $langs->load(
"errors");
238 $this->error = $langs->transnoentitiesnoconv(
"ErrorBadValueForParameter", $compression,
"Compression");
243 if ($type ==
'auto') {
244 $type = $this->db->type;
246 if (!in_array($type, array(
'postgresql',
'pgsql',
'mysql',
'mysqli',
'mysqlnobin'))) {
247 $langs->load(
"errors");
248 $this->error = $langs->transnoentitiesnoconv(
"ErrorBadValueForParameter", $type,
"Basetype");
253 if ($file ==
'auto') {
256 if (in_array($type, array(
'mysql',
'mysqli'))) {
257 $prefix =
'mysqldump';
261 if (in_array($type, array(
'pgsql'))) {
268 $outputdir = $conf->admin->dir_output.
'/backup';
273 if ($type ==
'mysql' || $type ==
'mysqli') {
275 $cmddump =
$db->getPathOfDump();
277 $cmddump = $conf->global->SYSTEMTOOLS_MYSQLDUMP;
279 if (empty($cmddump)) {
280 $this->error =
"Failed to detect command to use for mysqldump. Try a manual backup before to set path of command.";
284 $outputfile = $outputdir.
'/'.$file;
286 $compression = $compression ? $compression :
'none';
287 if ($compression ==
'gz') {
288 $outputfile .=
'.gz';
289 } elseif ($compression ==
'bz') {
290 $outputfile .=
'.bz2';
291 } elseif ($compression ==
'zstd') {
292 $outputfile .=
'.zst';
294 $outputerror = $outputfile.
'.err';
295 dol_mkdir($conf->admin->dir_output.
'/backup');
299 $command = preg_replace(
'/(\$|%)/',
'', $command);
300 if (preg_match(
"/\s/", $command)) {
301 $command = escapeshellarg($command);
305 $param = $dolibarr_main_db_name.
" -h ".$dolibarr_main_db_host;
306 $param .=
" -u ".$dolibarr_main_db_user;
307 if (!empty($dolibarr_main_db_port)) {
308 $param .=
" -P ".$dolibarr_main_db_port.
" --protocol=tcp";
310 if (
GETPOST(
"use_transaction",
"alpha")) {
311 $param .=
" --single-transaction";
313 if (
GETPOST(
"disable_fk",
"alpha") || $usedefault) {
316 if (
GETPOST(
"sql_compat",
"alpha") &&
GETPOST(
"sql_compat",
"alpha") !=
'NONE') {
317 $param .=
" --compatible=".escapeshellarg(
GETPOST(
"sql_compat",
"alpha"));
319 if (
GETPOST(
"drop_database",
"alpha")) {
320 $param .=
" --add-drop-database";
322 if (
GETPOST(
"use_mysql_quick_param",
"alpha")) {
323 $param .=
" --quick";
325 if (
GETPOST(
"use_force",
"alpha")) {
328 if (
GETPOST(
"sql_structure",
"alpha") || $usedefault) {
329 if (
GETPOST(
"drop",
"alpha") || $usedefault) {
330 $param .=
" --add-drop-table=TRUE";
332 $param .=
" --add-drop-table=FALSE";
337 if (
GETPOST(
"disable-add-locks",
"alpha")) {
338 $param .=
" --add-locks=FALSE";
340 if (
GETPOST(
"sql_data",
"alpha") || $usedefault) {
341 $param .=
" --tables";
342 if (
GETPOST(
"showcolumns",
"alpha") || $usedefault) {
345 if (
GETPOST(
"extended_ins",
"alpha") || $usedefault) {
348 $param .=
" --skip-extended-insert";
350 if (
GETPOST(
"delayed",
"alpha")) {
351 $param .=
" --delayed-insert";
353 if (
GETPOST(
"sql_ignore",
"alpha")) {
354 $param .=
" --insert-ignore";
356 if (
GETPOST(
"hexforbinary",
"alpha") || $usedefault) {
357 $param .=
" --hex-blob";
362 if ($dolibarr_main_db_character_set ==
'utf8mb4') {
364 $param .=
" --default-character-set=utf8mb4 --no-tablespaces";
366 $param .=
" --default-character-set=utf8 --no-tablespaces";
368 $paramcrypted = $param;
369 $paramclear = $param;
370 if (!empty($dolibarr_main_db_pass)) {
371 $paramcrypted .=
' -p"'.preg_replace(
'/./i',
'*', $dolibarr_main_db_pass).
'"';
372 $paramclear .=
' -p"'.str_replace(array(
'"',
'`',
'$'), array(
'\"',
'\`',
'\$'), $dolibarr_main_db_pass).
'"';
378 $fullcommandcrypted = $command.
" ".$paramcrypted.
" 2>&1";
379 $fullcommandclear = $command.
" ".$paramclear.
" 2>&1";
380 if (!$lowmemorydump) {
381 if ($compression ==
'none') {
382 $handle = fopen($outputfile,
'w');
383 } elseif ($compression ==
'gz') {
384 $handle = gzopen($outputfile,
'w');
385 } elseif ($compression ==
'bz') {
386 $handle = bzopen($outputfile,
'w');
387 } elseif ($compression ==
'zstd') {
388 $handle = fopen($outputfile,
'w');
391 if ($compression ==
'none') {
392 $fullcommandclear .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." > "'.dol_sanitizePathName($outputfile).
'"';
393 $fullcommandcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." > "'.dol_sanitizePathName($outputfile).
'"';
395 } elseif ($compression ==
'gz') {
396 $fullcommandclear .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | gzip > "'.dol_sanitizePathName($outputfile).
'"';
397 $fullcommandcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | gzip > "'.dol_sanitizePathName($outputfile).
'"';
398 $paramcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | gzip';
400 } elseif ($compression ==
'bz') {
401 $fullcommandclear .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | bzip2 > "'.dol_sanitizePathName($outputfile).
'"';
402 $fullcommandcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | bzip2 > "'.dol_sanitizePathName($outputfile).
'"';
403 $paramcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | bzip2';
405 } elseif ($compression ==
'zstd') {
406 $fullcommandclear .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | zstd > "'.dol_sanitizePathName($outputfile).
'"';
407 $fullcommandcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | zstd > "'.dol_sanitizePathName($outputfile).
'"';
408 $paramcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | zstd';
416 $execmethod = $conf->global->MAIN_EXEC_USE_POPEN;
418 if (empty($execmethod)) {
422 dol_syslog(
"Utils::dumpDatabase execmethod=".$execmethod.
" command:".$fullcommandcrypted, LOG_INFO);
427 if (!empty($MemoryLimit)) {
428 @ini_set(
'memory_limit', $MemoryLimit);
432 if ($execmethod == 1) {
433 $output_arr = array();
436 exec($fullcommandclear, $output_arr, $retval);
444 $langs->load(
"errors");
445 dol_syslog(
"Datadump retval after exec=".$retval, LOG_ERR);
446 $errormsg =
'Error '.$retval;
450 if (!empty($output_arr)) {
451 foreach ($output_arr as $key => $read) {
453 if ($i == 1 && preg_match(
'/Warning.*Using a password/i', $read)) {
458 if (!$lowmemorydump) {
459 fwrite($handle, $read.($execmethod == 2 ?
'' :
"\n"));
460 if (preg_match(
'/'.preg_quote(
'-- Dump completed',
'/').
'/i', $read)) {
462 } elseif (preg_match(
'/'.preg_quote(
'SET SQL_NOTES=@OLD_SQL_NOTES',
'/').
'/i', $read)) {
469 } elseif ($lowmemorydump) {
475 if ($execmethod == 2) {
476 $handlein = popen($fullcommandclear,
'r');
479 while (!feof($handlein)) {
481 $read = fgets($handlein);
483 if ($i == 1 && preg_match(
'/Warning.*Using a password/i', $read)) {
486 fwrite($handle, $read);
487 if (preg_match(
'/'.preg_quote(
'-- Dump completed').
'/i', $read)) {
489 } elseif (preg_match(
'/'.preg_quote(
'SET SQL_NOTES=@OLD_SQL_NOTES').
'/i', $read)) {
497 if (!$lowmemorydump) {
498 if ($compression ==
'none') {
500 } elseif ($compression ==
'gz') {
502 } elseif ($compression ==
'bz') {
504 } elseif ($compression ==
'zstd') {
511 $langs->load(
"errors");
512 dol_syslog(
"Failed to open file ".$outputfile, LOG_ERR);
513 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir");
517 if ($compression ==
'none') {
518 $handle = fopen($outputfile,
'r');
519 } elseif ($compression ==
'gz') {
520 $handle = gzopen($outputfile,
'r');
521 } elseif ($compression ==
'bz') {
522 $handle = bzopen($outputfile,
'r');
523 } elseif ($compression ==
'zstd') {
524 $handle = fopen($outputfile,
'r');
528 $errormsg = fgets($handle, 2048);
532 if ($compression ==
'none') {
534 } elseif ($compression ==
'gz') {
536 } elseif ($compression ==
'bz') {
538 } elseif ($compression ==
'zstd') {
541 if ($ok && preg_match(
'/^-- (MySql|MariaDB)/i', $errormsg)) {
547 @rename($outputfile, $outputerror);
550 $langs->load(
"errors");
551 $errormsg = $langs->trans(
"ErrorFailedToRunExternalCommand");
557 $this->output = $errormsg;
558 $this->error = $errormsg;
559 $this->result = array(
"commandbackuplastdone" => $command.
" ".$paramcrypted,
"commandbackuptorun" =>
"");
564 if ($type ==
'mysqlnobin') {
565 $outputfile = $outputdir.
'/'.$file;
566 $outputfiletemp = $outputfile.
'-TMP.sql';
568 $compression = $compression ? $compression :
'none';
569 if ($compression ==
'gz') {
570 $outputfile .=
'.gz';
572 if ($compression ==
'bz') {
573 $outputfile .=
'.bz2';
575 $outputerror = $outputfile.
'.err';
576 dol_mkdir($conf->admin->dir_output.
'/backup');
578 if ($compression ==
'gz' or $compression ==
'bz') {
579 $this->backupTables($outputfiletemp);
580 dol_compress_file($outputfiletemp, $outputfile, $compression);
581 unlink($outputfiletemp);
583 $this->backupTables($outputfile);
587 $this->result = array(
"commandbackuplastdone" =>
"",
"commandbackuptorun" =>
"");
591 if ($type ==
'postgresql' || $type ==
'pgsql') {
592 $cmddump = $conf->global->SYSTEMTOOLS_POSTGRESQLDUMP;
594 $outputfile = $outputdir.
'/'.$file;
596 $compression = $compression ? $compression :
'none';
597 if ($compression ==
'gz') {
598 $outputfile .=
'.gz';
600 if ($compression ==
'bz') {
601 $outputfile .=
'.bz2';
603 $outputerror = $outputfile.
'.err';
604 dol_mkdir($conf->admin->dir_output.
'/backup');
608 $command = preg_replace(
'/(\$|%)/',
'', $command);
609 if (preg_match(
"/\s/", $command)) {
610 $command = escapeshellarg($command);
616 $param .=
" --no-tablespaces --inserts -h ".$dolibarr_main_db_host;
617 $param .=
" -U ".$dolibarr_main_db_user;
618 if (!empty($dolibarr_main_db_port)) {
619 $param .=
" -p ".$dolibarr_main_db_port;
622 $param .=
" --disable-dollar-quoting";
624 if (
GETPOST(
"drop_database")) {
627 if (
GETPOST(
"sql_structure")) {
629 $param .=
" --add-drop-table";
636 if (!
GETPOST(
"sql_structure")) {
643 $param .=
' -f "'.$outputfile.
'"';
645 if ($compression ==
'gz') {
649 $paramcrypted = $param;
650 $paramclear = $param;
656 $paramcrypted .=
" -w ".$dolibarr_main_db_name;
657 $paramclear .=
" -w ".$dolibarr_main_db_name;
660 $this->result = array(
"commandbackuplastdone" =>
"",
"commandbackuptorun" => $command.
" ".$paramcrypted);
664 if (!$errormsg && $keeplastnfiles > 0) {
665 $tmpfiles =
dol_dir_list($conf->admin->dir_output.
'/backup',
'files', 0,
'',
'(\.err|\.old|\.sav)$',
'date', SORT_DESC);
667 if (is_array($tmpfiles)) {
668 foreach ($tmpfiles as $key => $val) {
670 if ($i <= $keeplastnfiles) {
678 return ($errormsg ? -1 : 0);
696 public function executeCLI($command, $outputfile, $execmethod = 0, $redirectionfile =
null, $noescapecommand = 0, $redirectionfileerr =
null)
698 global $conf, $langs;
704 if (empty($noescapecommand)) {
705 $command = escapeshellcmd($command);
708 if ($redirectionfile) {
709 $command .=
" > ".dol_sanitizePathName($redirectionfile);
712 if ($redirectionfileerr && ($redirectionfileerr != $redirectionfile)) {
714 $command .=
" 2> ".dol_sanitizePathName($redirectionfileerr);
720 $execmethod = $conf->global->MAIN_EXEC_USE_POPEN;
722 if (empty($execmethod)) {
726 dol_syslog(
"Utils::executeCLI execmethod=".$execmethod.
" command=".$command, LOG_DEBUG);
727 $output_arr = array();
729 if ($execmethod == 1) {
731 exec($command, $output_arr, $retval);
734 $langs->load(
"errors");
735 dol_syslog(
"Utils::executeCLI retval after exec=".$retval, LOG_ERR);
736 $error =
'Error '.$retval;
739 if ($execmethod == 2) {
740 $handle = fopen($outputfile,
'w+b');
742 dol_syslog(
"Utils::executeCLI run command ".$command);
743 $handlein = popen($command,
'r');
744 while (!feof($handlein)) {
745 $read = fgets($handlein);
746 fwrite($handle, $read);
747 $output_arr[] = $read;
756 if (is_array($output_arr) && count($output_arr) > 0) {
757 foreach ($output_arr as $val) {
758 $output .= $val.($execmethod == 2 ?
'' :
"\n");
762 dol_syslog(
"Utils::executeCLI result=".$result.
" output=".$output.
" error=".$error, LOG_DEBUG);
764 return array(
'result'=>$result,
'output'=>$output,
'error'=>$error);
775 global $conf, $langs, $user, $mysoc;
780 $modulelowercase = strtolower($module);
784 $dir = $dirins.
'/'.$modulelowercase;
789 dol_include_once($modulelowercase.
'/core/modules/mod'.$module.
'.class.php');
790 $class =
'mod'.$module;
792 if (class_exists($class)) {
794 $moduleobj =
new $class($this->db);
801 $langs->load(
"errors");
802 dol_print_error($langs->trans(
"ErrorFailedToLoadModuleDescriptorForXXX", $module));
806 $arrayversion = explode(
'.', $moduleobj->version, 3);
807 if (count($arrayversion)) {
808 $FILENAMEASCII = strtolower($module).
'.asciidoc';
809 $FILENAMEDOC = strtolower($module).
'.html';
810 $FILENAMEDOCPDF = strtolower($module).
'.pdf';
813 $dirofmoduledoc =
dol_buildpath(strtolower($module), 0).
'/doc';
814 $dirofmoduletmp =
dol_buildpath(strtolower($module), 0).
'/doc/temp';
815 $outputfiledoc = $dirofmoduledoc.
'/'.$FILENAMEDOC;
816 if ($dirofmoduledoc) {
823 if (!is_writable($dirofmoduletmp)) {
824 $this->error =
'Dir '.$dirofmoduletmp.
' does not exists or is not writable';
829 $this->error =
'Setup of module ModuleBuilder not complete';
834 dol_copy($dirofmodule.
'/README.md', $dirofmoduletmp.
'/README.md', 0, 1);
835 dol_copy($dirofmodule.
'/ChangeLog.md', $dirofmoduletmp.
'/ChangeLog.md', 0, 1);
838 $arrayreplacement = array();
839 $arrayreplacement[
'/^#\s.*/m'] =
'';
840 $arrayreplacement[
'/^#/m'] =
'##';
842 dolReplaceInFile($dirofmoduletmp.
'/README.md', $arrayreplacement,
'', 0, 0, 1);
843 dolReplaceInFile($dirofmoduletmp.
'/ChangeLog.md', $arrayreplacement,
'', 0, 0, 1);
846 $destfile = $dirofmoduletmp.
'/'.$FILENAMEASCII;
848 $fhandle = fopen($destfile,
'w+');
850 $specs =
dol_dir_list(
dol_buildpath(strtolower($module).
'/doc', 0),
'files', 1,
'(\.md|\.asciidoc)$', array(
'\/temp\/'));
853 foreach ($specs as $spec) {
854 if (preg_match(
'/notindoc/', $spec[
'relativename'])) {
857 if (preg_match(
'/example/', $spec[
'relativename'])) {
860 if (preg_match(
'/disabled/', $spec[
'relativename'])) {
864 $pathtofile = strtolower($module).
'/doc/'.$spec[
'relativename'];
865 $format =
'asciidoc';
866 if (preg_match(
'/\.md$/i', $spec[
'name'])) {
867 $format =
'markdown';
870 $filecursor = @file_get_contents($spec[
'fullname']);
872 fwrite($fhandle, ($i ?
"\n<<<\n\n" :
"").$filecursor.
"\n");
874 $this->error =
'Failed to concat content of file '.$spec[
'fullname'];
883 $contentreadme = file_get_contents($dirofmoduletmp.
'/README.md');
884 $contentchangelog = file_get_contents($dirofmoduletmp.
'/ChangeLog.md');
886 include DOL_DOCUMENT_ROOT.
'/core/lib/parsemd.lib.php';
889 $arrayreplacement = array(
890 'mymodule'=>strtolower($module),
892 'MYMODULE'=>strtoupper($module),
893 'My module'=>$module,
894 'my module'=>$module,
895 'Mon module'=>$module,
896 'mon module'=>$module,
897 'htdocs/modulebuilder/template'=>strtolower($module),
898 '__MYCOMPANY_NAME__'=>$mysoc->name,
899 '__KEYWORDS__'=>$module,
900 '__USER_FULLNAME__'=>$user->getFullName($langs),
901 '__USER_EMAIL__'=>$user->email,
903 '---Put here your own copyright and developer email---'=>
dol_print_date($now,
'dayrfc').
' '.$user->getFullName($langs).($user->email ?
' <'.$user->email.
'>' :
''),
904 '__DATA_SPECIFICATION__'=>
'Not yet available',
913 $currentdir = getcwd();
916 require_once DOL_DOCUMENT_ROOT.
'/core/class/utils.class.php';
917 $utils =
new Utils($this->db);
920 $command =
getDolGlobalString(
'MODULEBUILDER_ASCIIDOCTOR') .
' '.$destfile.
' -n -o '.$dirofmoduledoc.
'/'.$FILENAMEDOC;
921 $outfile = $dirofmoduletmp.
'/out.tmp';
923 $resarray = $utils->executeCLI($command, $outfile);
924 if ($resarray[
'result'] !=
'0') {
925 $this->error = $resarray[
'error'].
' '.$resarray[
'output'];
926 $this->errors[] = $this->error;
928 $result = ($resarray[
'result'] == 0) ? 1 : 0;
929 if ($result < 0 && empty($this->errors)) {
930 $this->error = $langs->trans(
"ErrorFailToGenerateFile", $FILENAMEDOC);
931 $this->errors[] = $this->error;
935 $command =
getDolGlobalString(
'MODULEBUILDER_ASCIIDOCTORPDF') .
' '.$destfile.
' -n -o '.$dirofmoduledoc.
'/'.$FILENAMEDOCPDF;
936 $outfile = $dirofmoduletmp.
'/outpdf.tmp';
937 $resarray = $utils->executeCLI($command, $outfile);
938 if ($resarray[
'result'] !=
'0') {
939 $this->error = $resarray[
'error'].
' '.$resarray[
'output'];
940 $this->errors[] = $this->error;
942 $result = ($resarray[
'result'] == 0) ? 1 : 0;
943 if ($result < 0 && empty($this->errors)) {
944 $this->error = $langs->trans(
"ErrorFailToGenerateFile", $FILENAMEDOCPDF);
945 $this->errors[] = $this->error;
960 $langs->load(
"errors");
961 $this->error = $langs->trans(
"ErrorCheckVersionIsDefined");
1277 public function sendBackup($sendto =
'', $from =
'', $subject =
'', $message =
'', $filename =
'', $filter =
'', $sizelimit = 100000000)
1279 global $conf, $langs;
1280 global $dolibarr_main_url_root;
1286 if (!empty($from)) {
1294 if (!empty($sendto)) {
1302 if (!empty($subject)) {
1308 if (empty($message)) {
1312 $tmpfiles = array();
1313 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1315 if (
dol_is_file($conf->admin->dir_output.
'/backup/'.$filename)) {
1321 if ($tmpfiles && is_array($tmpfiles)) {
1322 foreach ($tmpfiles as $key => $val) {
1323 if ($key ==
'fullname') {
1324 $filepath = array($val);
1327 if ($key ==
'type') {
1328 $mimetype = array($val);
1330 if ($key ==
'relativename') {
1331 $filename = array($val);
1337 if ($filesize > $sizelimit) {
1338 $message .=
'<br>'.$langs->trans(
"BackupIsTooLargeSend");
1339 $documenturl = $dolibarr_main_url_root.
'/document.php?modulepart=systemtools&atachement=1&file=backup/'.urlencode($filename[0]);
1340 $message .=
'<br><a href='.$documenturl.
'>Lien de téléchargement</a>';
1346 $output =
'No backup file found';
1351 include_once DOL_DOCUMENT_ROOT .
'/core/class/CMailFile.class.php';
1352 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename,
'',
'', 0, -1);
1353 if ($mailfile->error) {
1355 $output = $mailfile->error;
1360 $result = $mailfile->sendfile();
1363 $output = $mailfile->error;
1369 $this->error = $error;
1370 $this->output = $output;
1372 if ($result ==
true) {