62 public function purgeFiles($choices =
'tempfilesold+logfiles', $nbsecondsold = 86400)
64 global $conf, $langs, $dolibarr_main_data_root;
66 $langs->load(
"admin");
68 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
70 if (empty($choices)) {
71 $choices =
'tempfilesold+logfiles';
73 if ($choices ==
'allfiles' && $nbsecondsold > 0) {
74 $choices =
'allfilesold';
77 dol_syslog(
"Utils::purgeFiles choice=".$choices, LOG_DEBUG);
84 $choicesarray = preg_split(
'/[\+,]/', $choices);
85 foreach ($choicesarray as $choice) {
87 $filesarray = array();
89 if ($choice ==
'tempfiles' || $choice ==
'tempfilesold') {
91 if ($dolibarr_main_data_root) {
92 $filesarray =
dol_dir_list($dolibarr_main_data_root,
"directories", 1,
'^temp$',
'',
'name', SORT_ASC, 2, 0,
'', 1);
94 if ($choice ==
'tempfilesold') {
95 foreach ($filesarray as $key => $val) {
96 if ($val[
'date'] > ($now - ($nbsecondsold))) {
97 unset($filesarray[$key]);
104 if ($choice ==
'allfiles') {
106 if ($dolibarr_main_data_root) {
107 $filesarray =
dol_dir_list($dolibarr_main_data_root,
"all", 0,
'',
'(\.lock|\.unlock)$',
'name', SORT_ASC, 0, 0,
'', 1);
111 if ($choice ==
'allfilesold') {
113 if ($dolibarr_main_data_root) {
114 $filesarray =
dol_dir_list($dolibarr_main_data_root,
"files", 1,
'',
'(\.lock|\.unlock)$',
'name', SORT_ASC, 0, 0,
'', 1, $nbsecondsold);
118 if ($choice ==
'logfile' || $choice ==
'logfiles') {
120 if ($dolibarr_main_data_root) {
121 $filesarray =
dol_dir_list($dolibarr_main_data_root,
"files", 0,
'.*\.log[\.0-9]*(\.gz)?$',
'(\.lock|\.unlock)$',
'name', SORT_ASC, 0, 0,
'', 1);
124 if (isModEnabled(
'syslog')) {
125 $filelog = $conf->global->SYSLOG_FILE;
126 $filelog = preg_replace(
'/DOL_DATA_ROOT/i', DOL_DATA_ROOT, $filelog);
128 $alreadyincluded =
false;
129 foreach ($filesarray as $tmpcursor) {
130 if ($tmpcursor[
'fullname'] == $filelog) {
131 $alreadyincluded =
true;
134 if (!$alreadyincluded) {
135 $filesarray[] = array(
'fullname'=>$filelog,
'type'=>
'file');
140 if (is_array($filesarray) && count($filesarray)) {
141 foreach ($filesarray as $key => $value) {
143 if ($filesarray[$key][
'type'] ==
'dir') {
145 $tmpcountdeleted = 0;
149 $recreatedDirs = array($conf->user->dir_temp);
151 if (isModEnabled(
'api')) {
152 $recreatedDirs[] = $conf->api->dir_temp;
155 if (!in_array($filesarray[$key][
'fullname'], $recreatedDirs)) {
157 $countdeleted += $tmpcountdeleted;
159 } elseif ($filesarray[$key][
'type'] ==
'file') {
160 if ($choice !=
'allfilesold' || $filesarray[$key][
'date'] < ($now - $nbsecondsold)) {
162 if ($filesarray[$key][
'fullname'] != $filelog || $choice ==
'logfile' || $choice ==
'logfiles') {
176 if (isModEnabled(
'ecm') && $choice ==
'allfiles') {
177 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
179 $result = $ecmdirstatic->refreshcachenboffile(1);
185 $langs->load(
"admin");
186 $this->output = $langs->trans(
"PurgeNDirectoriesDeleted", $countdeleted);
187 if ($count > $countdeleted) {
188 $this->output .=
'<br>'.$langs->trans(
"PurgeNDirectoriesFailed", ($count - $countdeleted));
191 $this->output = $langs->trans(
"PurgeNothingToDelete").(in_array(
'tempfilesold', $choicesarray) ?
' (older than 24h for temp files)' :
'');
195 if (isModEnabled(
'api')) {
218 public function dumpDatabase($compression =
'none', $type =
'auto', $usedefault = 1, $file =
'auto', $keeplastnfiles = 0, $execmethod = 0, $lowmemorydump = 0)
220 global
$db, $conf, $langs, $dolibarr_main_data_root;
221 global $dolibarr_main_db_name, $dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_port, $dolibarr_main_db_pass;
222 global $dolibarr_main_db_character_set;
224 $langs->load(
"admin");
226 dol_syslog(
"Utils::dumpDatabase type=".$type.
" compression=".$compression.
" file=".$file, LOG_DEBUG);
227 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
233 if (!in_array($compression, array(
'none',
'gz',
'bz',
'zip',
'zstd'))) {
234 $langs->load(
"errors");
235 $this->error = $langs->transnoentitiesnoconv(
"ErrorBadValueForParameter", $compression,
"Compression");
240 if ($type ==
'auto') {
241 $type = $this->db->type;
243 if (!in_array($type, array(
'postgresql',
'pgsql',
'mysql',
'mysqli',
'mysqlnobin'))) {
244 $langs->load(
"errors");
245 $this->error = $langs->transnoentitiesnoconv(
"ErrorBadValueForParameter", $type,
"Basetype");
250 if ($file ==
'auto') {
253 if (in_array($type, array(
'mysql',
'mysqli'))) {
254 $prefix =
'mysqldump';
258 if (in_array($type, array(
'pgsql'))) {
265 $outputdir = $conf->admin->dir_output.
'/backup';
270 if ($type ==
'mysql' || $type ==
'mysqli') {
271 if (empty($conf->global->SYSTEMTOOLS_MYSQLDUMP)) {
272 $cmddump =
$db->getPathOfDump();
274 $cmddump = $conf->global->SYSTEMTOOLS_MYSQLDUMP;
276 if (empty($cmddump)) {
277 $this->error =
"Failed to detect command to use for mysqldump. Try a manual backup before to set path of command.";
281 $outputfile = $outputdir.
'/'.$file;
283 $compression = $compression ? $compression :
'none';
284 if ($compression ==
'gz') {
285 $outputfile .=
'.gz';
286 } elseif ($compression ==
'bz') {
287 $outputfile .=
'.bz2';
288 } elseif ($compression ==
'zstd') {
289 $outputfile .=
'.zst';
291 $outputerror = $outputfile.
'.err';
292 dol_mkdir($conf->admin->dir_output.
'/backup');
296 $command = preg_replace(
'/(\$|%)/',
'', $command);
297 if (preg_match(
"/\s/", $command)) {
298 $command = escapeshellarg($command);
302 $param = $dolibarr_main_db_name.
" -h ".$dolibarr_main_db_host;
303 $param .=
" -u ".$dolibarr_main_db_user;
304 if (!empty($dolibarr_main_db_port)) {
305 $param .=
" -P ".$dolibarr_main_db_port.
" --protocol=tcp";
307 if (
GETPOST(
"use_transaction",
"alpha")) {
308 $param .=
" --single-transaction";
310 if (
GETPOST(
"disable_fk",
"alpha") || $usedefault) {
313 if (
GETPOST(
"sql_compat",
"alpha") &&
GETPOST(
"sql_compat",
"alpha") !=
'NONE') {
314 $param .=
" --compatible=".escapeshellarg(
GETPOST(
"sql_compat",
"alpha"));
316 if (
GETPOST(
"drop_database",
"alpha")) {
317 $param .=
" --add-drop-database";
319 if (
GETPOST(
"use_mysql_quick_param",
"alpha")) {
320 $param .=
" --quick";
322 if (
GETPOST(
"sql_structure",
"alpha") || $usedefault) {
323 if (
GETPOST(
"drop",
"alpha") || $usedefault) {
324 $param .=
" --add-drop-table=TRUE";
326 $param .=
" --add-drop-table=FALSE";
331 if (
GETPOST(
"disable-add-locks",
"alpha")) {
332 $param .=
" --add-locks=FALSE";
334 if (
GETPOST(
"sql_data",
"alpha") || $usedefault) {
335 $param .=
" --tables";
336 if (
GETPOST(
"showcolumns",
"alpha") || $usedefault) {
339 if (
GETPOST(
"extended_ins",
"alpha") || $usedefault) {
342 $param .=
" --skip-extended-insert";
344 if (
GETPOST(
"delayed",
"alpha")) {
345 $param .=
" --delayed-insert";
347 if (
GETPOST(
"sql_ignore",
"alpha")) {
348 $param .=
" --insert-ignore";
350 if (
GETPOST(
"hexforbinary",
"alpha") || $usedefault) {
351 $param .=
" --hex-blob";
356 if ($dolibarr_main_db_character_set ==
'utf8mb4') {
358 $param .=
" --default-character-set=utf8mb4 --no-tablespaces";
360 $param .=
" --default-character-set=utf8 --no-tablespaces";
362 $paramcrypted = $param;
363 $paramclear = $param;
364 if (!empty($dolibarr_main_db_pass)) {
365 $paramcrypted .=
' -p"'.preg_replace(
'/./i',
'*', $dolibarr_main_db_pass).
'"';
366 $paramclear .=
' -p"'.str_replace(array(
'"',
'`',
'$'), array(
'\"',
'\`',
'\$'), $dolibarr_main_db_pass).
'"';
372 $fullcommandcrypted = $command.
" ".$paramcrypted.
" 2>&1";
373 $fullcommandclear = $command.
" ".$paramclear.
" 2>&1";
374 if (!$lowmemorydump) {
375 if ($compression ==
'none') {
376 $handle = fopen($outputfile,
'w');
377 } elseif ($compression ==
'gz') {
378 $handle = gzopen($outputfile,
'w');
379 } elseif ($compression ==
'bz') {
380 $handle = bzopen($outputfile,
'w');
381 } elseif ($compression ==
'zstd') {
382 $handle = fopen($outputfile,
'w');
385 if ($compression ==
'none') {
386 $fullcommandclear .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." > "'.dol_sanitizePathName($outputfile).
'"';
387 $fullcommandcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." > "'.dol_sanitizePathName($outputfile).
'"';
389 } elseif ($compression ==
'gz') {
390 $fullcommandclear .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | gzip > "'.dol_sanitizePathName($outputfile).
'"';
391 $fullcommandcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | gzip > "'.dol_sanitizePathName($outputfile).
'"';
392 $paramcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | gzip';
394 } elseif ($compression ==
'bz') {
395 $fullcommandclear .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | bzip2 > "'.dol_sanitizePathName($outputfile).
'"';
396 $fullcommandcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | bzip2 > "'.dol_sanitizePathName($outputfile).
'"';
397 $paramcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | bzip2';
399 } elseif ($compression ==
'zstd') {
400 $fullcommandclear .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | zstd > "'.dol_sanitizePathName($outputfile).
'"';
401 $fullcommandcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | zstd > "'.dol_sanitizePathName($outputfile).
'"';
402 $paramcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | zstd';
409 if (!empty($conf->global->MAIN_EXEC_USE_POPEN)) {
410 $execmethod = $conf->global->MAIN_EXEC_USE_POPEN;
412 if (empty($execmethod)) {
416 dol_syslog(
"Utils::dumpDatabase execmethod=".$execmethod.
" command:".$fullcommandcrypted, LOG_INFO);
421 if (!empty($MemoryLimit)) {
422 @ini_set(
'memory_limit', $MemoryLimit);
426 if ($execmethod == 1) {
427 $output_arr = array();
430 exec($fullcommandclear, $output_arr, $retval);
438 $langs->load(
"errors");
439 dol_syslog(
"Datadump retval after exec=".$retval, LOG_ERR);
440 $errormsg =
'Error '.$retval;
444 if (!empty($output_arr)) {
445 foreach ($output_arr as $key => $read) {
447 if ($i == 1 && preg_match(
'/Warning.*Using a password/i', $read)) {
452 if (!$lowmemorydump) {
453 fwrite($handle, $read.($execmethod == 2 ?
'' :
"\n"));
454 if (preg_match(
'/'.preg_quote(
'-- Dump completed',
'/').
'/i', $read)) {
456 } elseif (preg_match(
'/'.preg_quote(
'SET SQL_NOTES=@OLD_SQL_NOTES',
'/').
'/i', $read)) {
463 } elseif ($lowmemorydump) {
469 if ($execmethod == 2) {
470 $handlein = popen($fullcommandclear,
'r');
473 while (!feof($handlein)) {
475 $read = fgets($handlein);
477 if ($i == 1 && preg_match(
'/Warning.*Using a password/i', $read)) {
480 fwrite($handle, $read);
481 if (preg_match(
'/'.preg_quote(
'-- Dump completed').
'/i', $read)) {
483 } elseif (preg_match(
'/'.preg_quote(
'SET SQL_NOTES=@OLD_SQL_NOTES').
'/i', $read)) {
491 if (!$lowmemorydump) {
492 if ($compression ==
'none') {
494 } elseif ($compression ==
'gz') {
496 } elseif ($compression ==
'bz') {
498 } elseif ($compression ==
'zstd') {
505 $langs->load(
"errors");
506 dol_syslog(
"Failed to open file ".$outputfile, LOG_ERR);
507 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir");
511 if ($compression ==
'none') {
512 $handle = fopen($outputfile,
'r');
513 } elseif ($compression ==
'gz') {
514 $handle = gzopen($outputfile,
'r');
515 } elseif ($compression ==
'bz') {
516 $handle = bzopen($outputfile,
'r');
517 } elseif ($compression ==
'zstd') {
518 $handle = fopen($outputfile,
'r');
522 $errormsg = fgets($handle, 2048);
526 if ($compression ==
'none') {
528 } elseif ($compression ==
'gz') {
530 } elseif ($compression ==
'bz') {
532 } elseif ($compression ==
'zstd') {
535 if ($ok && preg_match(
'/^-- (MySql|MariaDB)/i', $errormsg) || preg_match(
'/^\/\*M?!999999/', $errormsg)) {
541 @
dol_move($outputfile, $outputerror,
'0', 1, 0, 0);
544 $langs->load(
"errors");
545 $errormsg = $langs->trans(
"ErrorFailedToRunExternalCommand");
551 $this->output = $errormsg;
552 $this->error = $errormsg;
553 $this->result = array(
"commandbackuplastdone" => $command.
" ".$paramcrypted,
"commandbackuptorun" =>
"");
558 if ($type ==
'mysqlnobin') {
559 $outputfile = $outputdir.
'/'.$file;
560 $outputfiletemp = $outputfile.
'-TMP.sql';
562 $compression = $compression ? $compression :
'none';
563 if ($compression ==
'gz') {
564 $outputfile .=
'.gz';
566 if ($compression ==
'bz') {
567 $outputfile .=
'.bz2';
569 $outputerror = $outputfile.
'.err';
570 dol_mkdir($conf->admin->dir_output.
'/backup');
572 if ($compression ==
'gz' or $compression ==
'bz') {
573 $this->backupTables($outputfiletemp);
574 dol_compress_file($outputfiletemp, $outputfile, $compression);
575 unlink($outputfiletemp);
577 $this->backupTables($outputfile);
581 $this->result = array(
"commandbackuplastdone" =>
"",
"commandbackuptorun" =>
"");
585 if ($type ==
'postgresql' || $type ==
'pgsql') {
586 $cmddump = $conf->global->SYSTEMTOOLS_POSTGRESQLDUMP;
588 $outputfile = $outputdir.
'/'.$file;
590 $compression = $compression ? $compression :
'none';
591 if ($compression ==
'gz') {
592 $outputfile .=
'.gz';
594 if ($compression ==
'bz') {
595 $outputfile .=
'.bz2';
597 $outputerror = $outputfile.
'.err';
598 dol_mkdir($conf->admin->dir_output.
'/backup');
602 $command = preg_replace(
'/(\$|%)/',
'', $command);
603 if (preg_match(
"/\s/", $command)) {
604 $command = escapeshellarg($command);
610 $param .=
" --no-tablespaces --inserts -h ".$dolibarr_main_db_host;
611 $param .=
" -U ".$dolibarr_main_db_user;
612 if (!empty($dolibarr_main_db_port)) {
613 $param .=
" -p ".$dolibarr_main_db_port;
616 $param .=
" --disable-dollar-quoting";
618 if (
GETPOST(
"drop_database")) {
621 if (
GETPOST(
"sql_structure")) {
623 $param .=
" --add-drop-table";
630 if (!
GETPOST(
"sql_structure")) {
637 $param .=
' -f "'.$outputfile.
'"';
639 if ($compression ==
'gz') {
643 $paramcrypted = $param;
644 $paramclear = $param;
650 $paramcrypted .=
" -w ".$dolibarr_main_db_name;
651 $paramclear .=
" -w ".$dolibarr_main_db_name;
654 $this->result = array(
"commandbackuplastdone" =>
"",
"commandbackuptorun" => $command.
" ".$paramcrypted);
658 if (!$errormsg && $keeplastnfiles > 0) {
659 $tmpfiles =
dol_dir_list($conf->admin->dir_output.
'/backup',
'files', 0,
'',
'(\.err|\.old|\.sav)$',
'date', SORT_DESC);
661 if (is_array($tmpfiles)) {
662 foreach ($tmpfiles as $key => $val) {
664 if ($i <= $keeplastnfiles) {
672 return ($errormsg ? -1 : 0);
690 public function executeCLI($command, $outputfile, $execmethod = 0, $redirectionfile =
null, $noescapecommand = 0, $redirectionfileerr =
null)
692 global $conf, $langs;
698 if (empty($noescapecommand)) {
699 $command = escapeshellcmd($command);
702 if ($redirectionfile) {
703 $command .=
" > ".dol_sanitizePathName($redirectionfile);
706 if ($redirectionfileerr && ($redirectionfileerr != $redirectionfile)) {
708 $command .=
" 2> ".dol_sanitizePathName($redirectionfileerr);
713 if (!empty($conf->global->MAIN_EXEC_USE_POPEN)) {
714 $execmethod = $conf->global->MAIN_EXEC_USE_POPEN;
716 if (empty($execmethod)) {
720 dol_syslog(
"Utils::executeCLI execmethod=".$execmethod.
" command=".$command, LOG_DEBUG);
721 $output_arr = array();
723 if ($execmethod == 1) {
725 exec($command, $output_arr, $retval);
728 $langs->load(
"errors");
729 dol_syslog(
"Utils::executeCLI retval after exec=".$retval, LOG_ERR);
730 $error =
'Error '.$retval;
733 if ($execmethod == 2) {
734 $handle = fopen($outputfile,
'w+b');
736 dol_syslog(
"Utils::executeCLI run command ".$command);
737 $handlein = popen($command,
'r');
738 while (!feof($handlein)) {
739 $read = fgets($handlein);
740 fwrite($handle, $read);
741 $output_arr[] = $read;
750 if (is_array($output_arr) && count($output_arr) > 0) {
751 foreach ($output_arr as $val) {
752 $output .= $val.($execmethod == 2 ?
'' :
"\n");
756 dol_syslog(
"Utils::executeCLI result=".$result.
" output=".$output.
" error=".$error, LOG_DEBUG);
758 return array(
'result'=>$result,
'output'=>$output,
'error'=>$error);
769 global $conf, $langs, $user, $mysoc;
774 $modulelowercase = strtolower($module);
778 $dir = $dirins.
'/'.$modulelowercase;
783 dol_include_once($modulelowercase.
'/core/modules/mod'.$module.
'.class.php');
784 $class =
'mod'.$module;
786 if (class_exists($class)) {
788 $moduleobj =
new $class($this->db);
795 $langs->load(
"errors");
796 dol_print_error($langs->trans(
"ErrorFailedToLoadModuleDescriptorForXXX", $module));
800 $arrayversion = explode(
'.', $moduleobj->version, 3);
801 if (count($arrayversion)) {
802 $FILENAMEASCII = strtolower($module).
'.asciidoc';
803 $FILENAMEDOC = strtolower($module).
'.html';
804 $FILENAMEDOCPDF = strtolower($module).
'.pdf';
807 $dirofmoduledoc =
dol_buildpath(strtolower($module), 0).
'/doc';
808 $dirofmoduletmp =
dol_buildpath(strtolower($module), 0).
'/doc/temp';
809 $outputfiledoc = $dirofmoduledoc.
'/'.$FILENAMEDOC;
810 if ($dirofmoduledoc) {
817 if (!is_writable($dirofmoduletmp)) {
818 $this->error =
'Dir '.$dirofmoduletmp.
' does not exists or is not writable';
822 if (empty($conf->global->MODULEBUILDER_ASCIIDOCTOR) && empty($conf->global->MODULEBUILDER_ASCIIDOCTORPDF)) {
823 $this->error =
'Setup of module ModuleBuilder not complete';
828 dol_copy($dirofmodule.
'/README.md', $dirofmoduletmp.
'/README.md', 0, 1);
829 dol_copy($dirofmodule.
'/ChangeLog.md', $dirofmoduletmp.
'/ChangeLog.md', 0, 1);
832 $arrayreplacement = array();
833 $arrayreplacement[
'/^#\s.*/m'] =
'';
834 $arrayreplacement[
'/^#/m'] =
'##';
836 dolReplaceInFile($dirofmoduletmp.
'/README.md', $arrayreplacement,
'', 0, 0, 1);
837 dolReplaceInFile($dirofmoduletmp.
'/ChangeLog.md', $arrayreplacement,
'', 0, 0, 1);
840 $destfile = $dirofmoduletmp.
'/'.$FILENAMEASCII;
842 $fhandle = fopen($destfile,
'w+');
844 $specs =
dol_dir_list(
dol_buildpath(strtolower($module).
'/doc', 0),
'files', 1,
'(\.md|\.asciidoc)$', array(
'\/temp\/'));
847 foreach ($specs as $spec) {
848 if (preg_match(
'/notindoc/', $spec[
'relativename'])) {
851 if (preg_match(
'/example/', $spec[
'relativename'])) {
854 if (preg_match(
'/disabled/', $spec[
'relativename'])) {
858 $pathtofile = strtolower($module).
'/doc/'.$spec[
'relativename'];
859 $format =
'asciidoc';
860 if (preg_match(
'/\.md$/i', $spec[
'name'])) {
861 $format =
'markdown';
864 $filecursor = @file_get_contents($spec[
'fullname']);
866 fwrite($fhandle, ($i ?
"\n<<<\n\n" :
"").$filecursor.
"\n");
868 $this->error =
'Failed to concat content of file '.$spec[
'fullname'];
877 $contentreadme = file_get_contents($dirofmoduletmp.
'/README.md');
878 $contentchangelog = file_get_contents($dirofmoduletmp.
'/ChangeLog.md');
880 include DOL_DOCUMENT_ROOT.
'/core/lib/parsemd.lib.php';
883 $arrayreplacement = array(
884 'mymodule'=>strtolower($module),
886 'MYMODULE'=>strtoupper($module),
887 'My module'=>$module,
888 'my module'=>$module,
889 'Mon module'=>$module,
890 'mon module'=>$module,
891 'htdocs/modulebuilder/template'=>strtolower($module),
892 '__MYCOMPANY_NAME__'=>$mysoc->name,
893 '__KEYWORDS__'=>$module,
894 '__USER_FULLNAME__'=>$user->getFullName($langs),
895 '__USER_EMAIL__'=>$user->email,
897 '---Put here your own copyright and developer email---'=>
dol_print_date($now,
'dayrfc').
' '.$user->getFullName($langs).($user->email ?
' <'.$user->email.
'>' :
''),
898 '__DATA_SPECIFICATION__'=>
'Not yet available',
907 $currentdir = getcwd();
910 require_once DOL_DOCUMENT_ROOT.
'/core/class/utils.class.php';
911 $utils =
new Utils($this->db);
914 $command = $conf->global->MODULEBUILDER_ASCIIDOCTOR.
' '.$destfile.
' -n -o '.$dirofmoduledoc.
'/'.$FILENAMEDOC;
915 $outfile = $dirofmoduletmp.
'/out.tmp';
917 $resarray = $utils->executeCLI($command, $outfile);
918 if ($resarray[
'result'] !=
'0') {
919 $this->error = $resarray[
'error'].
' '.$resarray[
'output'];
920 $this->errors[] = $this->error;
922 $result = ($resarray[
'result'] == 0) ? 1 : 0;
923 if ($result < 0 && empty($this->errors)) {
924 $this->error = $langs->trans(
"ErrorFailToGenerateFile", $FILENAMEDOC);
925 $this->errors[] = $this->error;
929 $command = $conf->global->MODULEBUILDER_ASCIIDOCTORPDF.
' '.$destfile.
' -n -o '.$dirofmoduledoc.
'/'.$FILENAMEDOCPDF;
930 $outfile = $dirofmoduletmp.
'/outpdf.tmp';
931 $resarray = $utils->executeCLI($command, $outfile);
932 if ($resarray[
'result'] !=
'0') {
933 $this->error = $resarray[
'error'].
' '.$resarray[
'output'];
934 $this->errors[] = $this->error;
936 $result = ($resarray[
'result'] == 0) ? 1 : 0;
937 if ($result < 0 && empty($this->errors)) {
938 $this->error = $langs->trans(
"ErrorFailToGenerateFile", $FILENAMEDOCPDF);
939 $this->errors[] = $this->error;
954 $langs->load(
"errors");
955 $this->error = $langs->trans(
"ErrorCheckVersionIsDefined");
1271 public function sendBackup($sendto =
'', $from =
'', $subject =
'', $message =
'', $filename =
'', $filter =
'', $sizelimit = 100000000)
1273 global $conf, $langs;
1274 global $dolibarr_main_url_root;
1280 if (!empty($from)) {
1282 } elseif (!empty($conf->global->MAIN_INFO_SOCIETE_MAIL)) {
1288 if (!empty($sendto)) {
1290 } elseif (!empty($conf->global->MAIN_INFO_SOCIETE_MAIL)) {
1296 if (!empty($subject)) {
1302 if (empty($message)) {
1306 $tmpfiles = array();
1307 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1309 if (
dol_is_file($conf->admin->dir_output.
'/backup/'.$filename)) {
1315 if ($tmpfiles && is_array($tmpfiles)) {
1316 foreach ($tmpfiles as $key => $val) {
1317 if ($key ==
'fullname') {
1318 $filepath = array($val);
1321 if ($key ==
'type') {
1322 $mimetype = array($val);
1324 if ($key ==
'relativename') {
1325 $filename = array($val);
1331 if ($filesize > $sizelimit) {
1332 $message .=
'<br>'.$langs->trans(
"BackupIsTooLargeSend");
1333 $documenturl = $dolibarr_main_url_root.
'/document.php?modulepart=systemtools&atachement=1&file=backup/'.urlencode($filename[0]);
1334 $message .=
'<br><a href='.$documenturl.
'>Lien de téléchargement</a>';
1340 $output =
'No backup file found';
1345 include_once DOL_DOCUMENT_ROOT .
'/core/class/CMailFile.class.php';
1346 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename,
'',
'', 0, -1);
1347 if ($mailfile->error) {
1349 $output = $mailfile->error;
1354 $result = $mailfile->sendfile();
1357 $output = $mailfile->error;
1363 $this->error = $error;
1364 $this->output = $output;
1366 if ($result ==
true) {