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 $recreatedDirs = array($conf->user->dir_temp);
160 if (isModEnabled(
'api')) {
161 $recreatedDirs[] = $conf->api->dir_temp;
164 if (!in_array($filesarray[$key][
'fullname'], $recreatedDirs)) {
166 $countdeleted += $tmpcountdeleted;
168 } elseif ($filesarray[$key][
'type'] ==
'file') {
169 if ($choice !=
'allfilesold' || $filesarray[$key][
'date'] < ($now - $nbsecondsold)) {
171 if ($filesarray[$key][
'fullname'] != $filelog || $choice ==
'logfile' || $choice ==
'logfiles') {
185 if (isModEnabled(
'ecm') && $choice ==
'allfiles') {
186 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
188 $result = $ecmdirstatic->refreshcachenboffile(1);
194 $langs->load(
"admin");
195 $this->output = $langs->trans(
"PurgeNDirectoriesDeleted", $countdeleted);
196 if ($count > $countdeleted) {
197 $this->output .=
'<br>'.$langs->trans(
"PurgeNDirectoriesFailed", ($count - $countdeleted));
200 $this->output = $langs->trans(
"PurgeNothingToDelete").(in_array(
'tempfilesold', $choicesarray) ?
' (older than 24h for temp files)' :
'');
204 if (isModEnabled(
'api')) {
227 public function dumpDatabase($compression =
'none', $type =
'auto', $usedefault = 1, $file =
'auto', $keeplastnfiles = 0, $execmethod = 0, $lowmemorydump = 0)
229 global
$db, $conf, $langs, $dolibarr_main_data_root;
230 global $dolibarr_main_db_name, $dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_port, $dolibarr_main_db_pass;
231 global $dolibarr_main_db_character_set;
233 $langs->load(
"admin");
235 dol_syslog(
"Utils::dumpDatabase type=".$type.
" compression=".$compression.
" file=".$file, LOG_DEBUG);
236 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
242 if (!in_array($compression, array(
'none',
'gz',
'bz',
'zip',
'zstd'))) {
243 $langs->load(
"errors");
244 $this->error = $langs->transnoentitiesnoconv(
"ErrorBadValueForParameter", $compression,
"Compression");
249 if ($type ==
'auto') {
250 $type = $this->db->type;
252 if (!in_array($type, array(
'postgresql',
'pgsql',
'mysql',
'mysqli',
'mysqlnobin'))) {
253 $langs->load(
"errors");
254 $this->error = $langs->transnoentitiesnoconv(
"ErrorBadValueForParameter", $type,
"Basetype");
259 if ($file ==
'auto') {
262 if (in_array($type, array(
'mysql',
'mysqli'))) {
263 $prefix =
'mysqldump';
267 if (in_array($type, array(
'pgsql'))) {
274 $outputdir = $conf->admin->dir_output.
'/backup';
279 if ($type ==
'mysql' || $type ==
'mysqli') {
281 $cmddump =
$db->getPathOfDump();
283 $cmddump = $conf->global->SYSTEMTOOLS_MYSQLDUMP;
285 if (empty($cmddump)) {
286 $this->error =
"Failed to detect command to use for mysqldump. Try a manual backup before to set path of command.";
290 $outputfile = $outputdir.
'/'.$file;
292 $compression = $compression ? $compression :
'none';
293 if ($compression ==
'gz') {
294 $outputfile .=
'.gz';
295 } elseif ($compression ==
'bz') {
296 $outputfile .=
'.bz2';
297 } elseif ($compression ==
'zstd') {
298 $outputfile .=
'.zst';
300 $outputerror = $outputfile.
'.err';
301 dol_mkdir($conf->admin->dir_output.
'/backup');
305 $command = preg_replace(
'/(\$|%)/',
'', $command);
306 if (preg_match(
"/\s/", $command)) {
307 $command = escapeshellarg($command);
311 $param = $dolibarr_main_db_name.
" -h ".$dolibarr_main_db_host;
312 $param .=
" -u ".$dolibarr_main_db_user;
313 if (!empty($dolibarr_main_db_port)) {
314 $param .=
" -P ".$dolibarr_main_db_port.
" --protocol=tcp";
316 if (
GETPOST(
"use_transaction",
"alpha")) {
317 $param .=
" --single-transaction";
319 if (
GETPOST(
"disable_fk",
"alpha") || $usedefault) {
322 if (
GETPOST(
"sql_compat",
"alpha") &&
GETPOST(
"sql_compat",
"alpha") !=
'NONE') {
323 $param .=
" --compatible=".escapeshellarg(
GETPOST(
"sql_compat",
"alpha"));
325 if (
GETPOST(
"drop_database",
"alpha")) {
326 $param .=
" --add-drop-database";
328 if (
GETPOST(
"use_mysql_quick_param",
"alpha")) {
329 $param .=
" --quick";
331 if (
GETPOST(
"use_force",
"alpha")) {
334 if (
GETPOST(
"sql_structure",
"alpha") || $usedefault) {
335 if (
GETPOST(
"drop",
"alpha") || $usedefault) {
336 $param .=
" --add-drop-table=TRUE";
338 $param .=
" --add-drop-table=FALSE";
343 if (
GETPOST(
"disable-add-locks",
"alpha")) {
344 $param .=
" --add-locks=FALSE";
346 if (
GETPOST(
"sql_data",
"alpha") || $usedefault) {
347 $param .=
" --tables";
348 if (
GETPOST(
"showcolumns",
"alpha") || $usedefault) {
351 if (
GETPOST(
"extended_ins",
"alpha") || $usedefault) {
354 $param .=
" --skip-extended-insert";
356 if (
GETPOST(
"delayed",
"alpha")) {
357 $param .=
" --delayed-insert";
359 if (
GETPOST(
"sql_ignore",
"alpha")) {
360 $param .=
" --insert-ignore";
362 if (
GETPOST(
"hexforbinary",
"alpha") || $usedefault) {
363 $param .=
" --hex-blob";
368 if ($dolibarr_main_db_character_set ==
'utf8mb4') {
370 $param .=
" --default-character-set=utf8mb4 --no-tablespaces";
372 $param .=
" --default-character-set=utf8 --no-tablespaces";
374 $paramcrypted = $param;
375 $paramclear = $param;
376 if (!empty($dolibarr_main_db_pass)) {
377 $paramcrypted .=
' -p"'.preg_replace(
'/./i',
'*', $dolibarr_main_db_pass).
'"';
378 $paramclear .=
' -p"'.str_replace(array(
'"',
'`',
'$'), array(
'\"',
'\`',
'\$'), $dolibarr_main_db_pass).
'"';
384 $fullcommandcrypted = $command.
" ".$paramcrypted.
" 2>&1";
385 $fullcommandclear = $command.
" ".$paramclear.
" 2>&1";
386 if (!$lowmemorydump) {
387 if ($compression ==
'none') {
388 $handle = fopen($outputfile,
'w');
389 } elseif ($compression ==
'gz') {
390 $handle = gzopen($outputfile,
'w');
391 } elseif ($compression ==
'bz') {
392 $handle = bzopen($outputfile,
'w');
393 } elseif ($compression ==
'zstd') {
394 $handle = fopen($outputfile,
'w');
397 if ($compression ==
'none') {
398 $fullcommandclear .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." > "'.dol_sanitizePathName($outputfile).
'"';
399 $fullcommandcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." > "'.dol_sanitizePathName($outputfile).
'"';
401 } elseif ($compression ==
'gz') {
402 $fullcommandclear .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | gzip > "'.dol_sanitizePathName($outputfile).
'"';
403 $fullcommandcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | gzip > "'.dol_sanitizePathName($outputfile).
'"';
404 $paramcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | gzip';
406 } elseif ($compression ==
'bz') {
407 $fullcommandclear .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | bzip2 > "'.dol_sanitizePathName($outputfile).
'"';
408 $fullcommandcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | bzip2 > "'.dol_sanitizePathName($outputfile).
'"';
409 $paramcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | bzip2';
411 } elseif ($compression ==
'zstd') {
412 $fullcommandclear .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | zstd > "'.dol_sanitizePathName($outputfile).
'"';
413 $fullcommandcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | zstd > "'.dol_sanitizePathName($outputfile).
'"';
414 $paramcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | zstd';
422 $execmethod = $conf->global->MAIN_EXEC_USE_POPEN;
424 if (empty($execmethod)) {
428 dol_syslog(
"Utils::dumpDatabase execmethod=".$execmethod.
" command:".$fullcommandcrypted, LOG_INFO);
433 if (!empty($MemoryLimit)) {
434 @ini_set(
'memory_limit', $MemoryLimit);
438 if ($execmethod == 1) {
439 $output_arr = array();
442 exec($fullcommandclear, $output_arr, $retval);
450 $langs->load(
"errors");
451 dol_syslog(
"Datadump retval after exec=".$retval, LOG_ERR);
452 $errormsg =
'Error '.$retval;
456 if (!empty($output_arr)) {
457 foreach ($output_arr as $key => $read) {
459 if ($i == 1 && preg_match(
'/Warning.*Using a password/i', $read)) {
464 if (!$lowmemorydump) {
465 fwrite($handle, $read.($execmethod == 2 ?
'' :
"\n"));
466 if (preg_match(
'/'.preg_quote(
'-- Dump completed',
'/').
'/i', $read)) {
468 } elseif (preg_match(
'/'.preg_quote(
'SET SQL_NOTES=@OLD_SQL_NOTES',
'/').
'/i', $read)) {
475 } elseif ($lowmemorydump) {
481 if ($execmethod == 2) {
482 $handlein = popen($fullcommandclear,
'r');
485 while (!feof($handlein)) {
487 $read = fgets($handlein);
489 if ($i == 1 && preg_match(
'/Warning.*Using a password/i', $read)) {
492 fwrite($handle, $read);
493 if (preg_match(
'/'.preg_quote(
'-- Dump completed').
'/i', $read)) {
495 } elseif (preg_match(
'/'.preg_quote(
'SET SQL_NOTES=@OLD_SQL_NOTES').
'/i', $read)) {
503 if (!$lowmemorydump) {
504 if ($compression ==
'none') {
506 } elseif ($compression ==
'gz') {
508 } elseif ($compression ==
'bz') {
510 } elseif ($compression ==
'zstd') {
517 $langs->load(
"errors");
518 dol_syslog(
"Failed to open file ".$outputfile, LOG_ERR);
519 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir");
523 if ($compression ==
'none') {
524 $handle = fopen($outputfile,
'r');
525 } elseif ($compression ==
'gz') {
526 $handle = gzopen($outputfile,
'r');
527 } elseif ($compression ==
'bz') {
528 $handle = bzopen($outputfile,
'r');
529 } elseif ($compression ==
'zstd') {
530 $handle = fopen($outputfile,
'r');
534 $errormsg = fgets($handle, 2048);
538 if ($compression ==
'none') {
540 } elseif ($compression ==
'gz') {
542 } elseif ($compression ==
'bz') {
544 } elseif ($compression ==
'zstd') {
547 if ($ok && preg_match(
'/^-- (MySql|MariaDB)/i', $errormsg) || preg_match(
'/^\/\*M?!999999/', $errormsg)) {
553 @
dol_move($outputfile, $outputerror,
'0', 1, 0, 0);
556 $langs->load(
"errors");
557 $errormsg = $langs->trans(
"ErrorFailedToRunExternalCommand");
563 $this->output = $errormsg;
564 $this->error = $errormsg;
565 $this->result = array(
"commandbackuplastdone" => $command.
" ".$paramcrypted,
"commandbackuptorun" =>
"");
570 if ($type ==
'mysqlnobin') {
571 $outputfile = $outputdir.
'/'.$file;
572 $outputfiletemp = $outputfile.
'-TMP.sql';
574 $compression = $compression ? $compression :
'none';
575 if ($compression ==
'gz') {
576 $outputfile .=
'.gz';
578 if ($compression ==
'bz') {
579 $outputfile .=
'.bz2';
581 $outputerror = $outputfile.
'.err';
582 dol_mkdir($conf->admin->dir_output.
'/backup');
584 if ($compression ==
'gz' or $compression ==
'bz') {
585 $this->backupTables($outputfiletemp);
586 dol_compress_file($outputfiletemp, $outputfile, $compression);
587 unlink($outputfiletemp);
589 $this->backupTables($outputfile);
593 $this->result = array(
"commandbackuplastdone" =>
"",
"commandbackuptorun" =>
"");
597 if ($type ==
'postgresql' || $type ==
'pgsql') {
598 $cmddump = $conf->global->SYSTEMTOOLS_POSTGRESQLDUMP;
600 $outputfile = $outputdir.
'/'.$file;
602 $compression = $compression ? $compression :
'none';
603 if ($compression ==
'gz') {
604 $outputfile .=
'.gz';
606 if ($compression ==
'bz') {
607 $outputfile .=
'.bz2';
609 $outputerror = $outputfile.
'.err';
610 dol_mkdir($conf->admin->dir_output.
'/backup');
614 $command = preg_replace(
'/(\$|%)/',
'', $command);
615 if (preg_match(
"/\s/", $command)) {
616 $command = escapeshellarg($command);
622 $param .=
" --no-tablespaces --inserts -h ".$dolibarr_main_db_host;
623 $param .=
" -U ".$dolibarr_main_db_user;
624 if (!empty($dolibarr_main_db_port)) {
625 $param .=
" -p ".$dolibarr_main_db_port;
628 $param .=
" --disable-dollar-quoting";
630 if (
GETPOST(
"drop_database")) {
633 if (
GETPOST(
"sql_structure")) {
635 $param .=
" --add-drop-table";
642 if (!
GETPOST(
"sql_structure")) {
649 $param .=
' -f "'.$outputfile.
'"';
651 if ($compression ==
'gz') {
655 $paramcrypted = $param;
656 $paramclear = $param;
662 $paramcrypted .=
" -w ".$dolibarr_main_db_name;
663 $paramclear .=
" -w ".$dolibarr_main_db_name;
666 $this->result = array(
"commandbackuplastdone" =>
"",
"commandbackuptorun" => $command.
" ".$paramcrypted);
670 if (!$errormsg && $keeplastnfiles > 0) {
671 $tmpfiles =
dol_dir_list($conf->admin->dir_output.
'/backup',
'files', 0,
'',
'(\.err|\.old|\.sav)$',
'date', SORT_DESC);
673 if (is_array($tmpfiles)) {
674 foreach ($tmpfiles as $key => $val) {
676 if ($i <= $keeplastnfiles) {
684 return ($errormsg ? -1 : 0);
702 public function executeCLI($command, $outputfile, $execmethod = 0, $redirectionfile =
null, $noescapecommand = 0, $redirectionfileerr =
null)
704 global $conf, $langs;
710 if (empty($noescapecommand)) {
711 $command = escapeshellcmd($command);
714 if ($redirectionfile) {
715 $command .=
" > ".dol_sanitizePathName($redirectionfile);
718 if ($redirectionfileerr && ($redirectionfileerr != $redirectionfile)) {
720 $command .=
" 2> ".dol_sanitizePathName($redirectionfileerr);
726 $execmethod = $conf->global->MAIN_EXEC_USE_POPEN;
728 if (empty($execmethod)) {
732 dol_syslog(
"Utils::executeCLI execmethod=".$execmethod.
" command=".$command, LOG_DEBUG);
733 $output_arr = array();
735 if ($execmethod == 1) {
737 exec($command, $output_arr, $retval);
740 $langs->load(
"errors");
741 dol_syslog(
"Utils::executeCLI retval after exec=".$retval, LOG_ERR);
742 $error =
'Error '.$retval;
745 if ($execmethod == 2) {
746 $handle = fopen($outputfile,
'w+b');
748 dol_syslog(
"Utils::executeCLI run command ".$command);
749 $handlein = popen($command,
'r');
750 while (!feof($handlein)) {
751 $read = fgets($handlein);
752 fwrite($handle, $read);
753 $output_arr[] = $read;
762 if (is_array($output_arr) && count($output_arr) > 0) {
763 foreach ($output_arr as $val) {
764 $output .= $val.($execmethod == 2 ?
'' :
"\n");
768 dol_syslog(
"Utils::executeCLI result=".$result.
" output=".$output.
" error=".$error, LOG_DEBUG);
770 return array(
'result'=>$result,
'output'=>$output,
'error'=>$error);
781 global $conf, $langs, $user, $mysoc;
786 $modulelowercase = strtolower($module);
790 $dir = $dirins.
'/'.$modulelowercase;
795 dol_include_once($modulelowercase.
'/core/modules/mod'.$module.
'.class.php');
796 $class =
'mod'.$module;
798 if (class_exists($class)) {
800 $moduleobj =
new $class($this->db);
807 $langs->load(
"errors");
808 dol_print_error($langs->trans(
"ErrorFailedToLoadModuleDescriptorForXXX", $module));
812 $arrayversion = explode(
'.', $moduleobj->version, 3);
813 if (count($arrayversion)) {
814 $FILENAMEASCII = strtolower($module).
'.asciidoc';
815 $FILENAMEDOC = strtolower($module).
'.html';
816 $FILENAMEDOCPDF = strtolower($module).
'.pdf';
819 $dirofmoduledoc =
dol_buildpath(strtolower($module), 0).
'/doc';
820 $dirofmoduletmp =
dol_buildpath(strtolower($module), 0).
'/doc/temp';
821 $outputfiledoc = $dirofmoduledoc.
'/'.$FILENAMEDOC;
822 if ($dirofmoduledoc) {
829 if (!is_writable($dirofmoduletmp)) {
830 $this->error =
'Dir '.$dirofmoduletmp.
' does not exists or is not writable';
835 $this->error =
'Setup of module ModuleBuilder not complete';
840 dol_copy($dirofmodule.
'/README.md', $dirofmoduletmp.
'/README.md', 0, 1);
841 dol_copy($dirofmodule.
'/ChangeLog.md', $dirofmoduletmp.
'/ChangeLog.md', 0, 1);
844 $arrayreplacement = array();
845 $arrayreplacement[
'/^#\s.*/m'] =
'';
846 $arrayreplacement[
'/^#/m'] =
'##';
848 dolReplaceInFile($dirofmoduletmp.
'/README.md', $arrayreplacement,
'', 0, 0, 1);
849 dolReplaceInFile($dirofmoduletmp.
'/ChangeLog.md', $arrayreplacement,
'', 0, 0, 1);
852 $destfile = $dirofmoduletmp.
'/'.$FILENAMEASCII;
854 $fhandle = fopen($destfile,
'w+');
856 $specs =
dol_dir_list(
dol_buildpath(strtolower($module).
'/doc', 0),
'files', 1,
'(\.md|\.asciidoc)$', array(
'\/temp\/'));
859 foreach ($specs as $spec) {
860 if (preg_match(
'/notindoc/', $spec[
'relativename'])) {
863 if (preg_match(
'/example/', $spec[
'relativename'])) {
866 if (preg_match(
'/disabled/', $spec[
'relativename'])) {
870 $pathtofile = strtolower($module).
'/doc/'.$spec[
'relativename'];
871 $format =
'asciidoc';
872 if (preg_match(
'/\.md$/i', $spec[
'name'])) {
873 $format =
'markdown';
876 $filecursor = @file_get_contents($spec[
'fullname']);
878 fwrite($fhandle, ($i ?
"\n<<<\n\n" :
"").$filecursor.
"\n");
880 $this->error =
'Failed to concat content of file '.$spec[
'fullname'];
889 $contentreadme = file_get_contents($dirofmoduletmp.
'/README.md');
890 $contentchangelog = file_get_contents($dirofmoduletmp.
'/ChangeLog.md');
892 include DOL_DOCUMENT_ROOT.
'/core/lib/parsemd.lib.php';
895 $arrayreplacement = array(
896 'mymodule'=>strtolower($module),
898 'MYMODULE'=>strtoupper($module),
899 'My module'=>$module,
900 'my module'=>$module,
901 'Mon module'=>$module,
902 'mon module'=>$module,
903 'htdocs/modulebuilder/template'=>strtolower($module),
904 '__MYCOMPANY_NAME__'=>$mysoc->name,
905 '__KEYWORDS__'=>$module,
906 '__USER_FULLNAME__'=>$user->getFullName($langs),
907 '__USER_EMAIL__'=>$user->email,
909 '---Put here your own copyright and developer email---'=>
dol_print_date($now,
'dayrfc').
' '.$user->getFullName($langs).($user->email ?
' <'.$user->email.
'>' :
''),
910 '__DATA_SPECIFICATION__'=>
'Not yet available',
919 $currentdir = getcwd();
922 require_once DOL_DOCUMENT_ROOT.
'/core/class/utils.class.php';
923 $utils =
new Utils($this->db);
926 $command =
getDolGlobalString(
'MODULEBUILDER_ASCIIDOCTOR') .
' '.$destfile.
' -n -o '.$dirofmoduledoc.
'/'.$FILENAMEDOC;
927 $outfile = $dirofmoduletmp.
'/out.tmp';
929 $resarray = $utils->executeCLI($command, $outfile);
930 if ($resarray[
'result'] !=
'0') {
931 $this->error = $resarray[
'error'].
' '.$resarray[
'output'];
932 $this->errors[] = $this->error;
934 $result = ($resarray[
'result'] == 0) ? 1 : 0;
935 if ($result < 0 && empty($this->errors)) {
936 $this->error = $langs->trans(
"ErrorFailToGenerateFile", $FILENAMEDOC);
937 $this->errors[] = $this->error;
941 $command =
getDolGlobalString(
'MODULEBUILDER_ASCIIDOCTORPDF') .
' '.$destfile.
' -n -o '.$dirofmoduledoc.
'/'.$FILENAMEDOCPDF;
942 $outfile = $dirofmoduletmp.
'/outpdf.tmp';
943 $resarray = $utils->executeCLI($command, $outfile);
944 if ($resarray[
'result'] !=
'0') {
945 $this->error = $resarray[
'error'].
' '.$resarray[
'output'];
946 $this->errors[] = $this->error;
948 $result = ($resarray[
'result'] == 0) ? 1 : 0;
949 if ($result < 0 && empty($this->errors)) {
950 $this->error = $langs->trans(
"ErrorFailToGenerateFile", $FILENAMEDOCPDF);
951 $this->errors[] = $this->error;
966 $langs->load(
"errors");
967 $this->error = $langs->trans(
"ErrorCheckVersionIsDefined");
1283 public function sendBackup($sendto =
'', $from =
'', $subject =
'', $message =
'', $filename =
'', $filter =
'', $sizelimit = 100000000)
1285 global $conf, $langs;
1286 global $dolibarr_main_url_root;
1292 if (!empty($from)) {
1300 if (!empty($sendto)) {
1308 if (!empty($subject)) {
1314 if (empty($message)) {
1318 $tmpfiles = array();
1319 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1321 if (
dol_is_file($conf->admin->dir_output.
'/backup/'.$filename)) {
1327 if ($tmpfiles && is_array($tmpfiles)) {
1328 foreach ($tmpfiles as $key => $val) {
1329 if ($key ==
'fullname') {
1330 $filepath = array($val);
1333 if ($key ==
'type') {
1334 $mimetype = array($val);
1336 if ($key ==
'relativename') {
1337 $filename = array($val);
1343 if ($filesize > $sizelimit) {
1344 $message .=
'<br>'.$langs->trans(
"BackupIsTooLargeSend");
1345 $documenturl = $dolibarr_main_url_root.
'/document.php?modulepart=systemtools&atachement=1&file=backup/'.urlencode($filename[0]);
1346 $message .=
'<br><a href='.$documenturl.
'>Lien de téléchargement</a>';
1352 $output =
'No backup file found';
1357 include_once DOL_DOCUMENT_ROOT .
'/core/class/CMailFile.class.php';
1358 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename,
'',
'', 0, -1);
1359 if ($mailfile->error) {
1361 $output = $mailfile->error;
1366 $result = $mailfile->sendfile();
1369 $output = $mailfile->error;
1375 $this->error = $error;
1376 $this->output = $output;
1378 if ($result ==
true) {