80 public function purgeFiles($choices =
'tempfilesold+logfiles', $nbsecondsold = 86400)
82 global
$conf, $langs, $user;
83 global $dolibarr_main_data_root;
85 $langs->load(
"admin");
87 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
89 if (empty($choices)) {
90 $choices =
'tempfilesold+logfiles';
92 if ($choices ==
'allfiles' && $nbsecondsold > 0) {
93 $choices =
'allfilesold';
96 dol_syslog(
"Utils::purgeFiles choice=".$choices, LOG_DEBUG);
99 if (in_array($choices, array(
'allfiles',
'allfilesold'))) {
100 if (empty($user->admin)) {
101 $this->output =
'Error: to erase data files, user running the batch (currently '.$user->login.
') must be an admin user';
111 $choicesarray = preg_split(
'/[\+,]/', $choices);
112 foreach ($choicesarray as $choice) {
114 $filesarray = array();
116 if ($choice ==
'tempfiles' || $choice ==
'tempfilesold') {
118 if ($dolibarr_main_data_root) {
119 $filesarray =
dol_dir_list($dolibarr_main_data_root,
"directories", 1,
'^temp$',
'',
'name', SORT_ASC, 2, 0,
'', 1);
121 if ($choice ==
'tempfilesold') {
122 foreach ($filesarray as $key => $val) {
123 if ($val[
'date'] > ($now - ($nbsecondsold))) {
124 unset($filesarray[$key]);
131 if ($choice ==
'allfiles') {
133 if ($dolibarr_main_data_root) {
134 $filesarray =
dol_dir_list($dolibarr_main_data_root,
"all", 0,
'',
'(\.lock|\.unlock)$',
'name', SORT_ASC, 0, 0,
'', 1);
138 if ($choice ==
'allfilesold') {
140 if ($dolibarr_main_data_root) {
141 $filesarray =
dol_dir_list($dolibarr_main_data_root,
"files", 1,
'',
'(\.lock|\.unlock)$',
'name', SORT_ASC, 0, 0,
'', 1, $nbsecondsold);
145 if ($choice ==
'logfile' || $choice ==
'logfiles') {
147 if ($dolibarr_main_data_root) {
148 $filesarray =
dol_dir_list($dolibarr_main_data_root,
"files", 0,
'.*\.log[\.0-9]*(\.gz)?$',
'(\.lock|\.unlock)$',
'name', SORT_ASC, 0, 0,
'', 1);
153 $filelog = preg_replace(
'/DOL_DATA_ROOT/i', DOL_DATA_ROOT, $filelog);
155 $alreadyincluded =
false;
156 foreach ($filesarray as $tmpcursor) {
157 if ($tmpcursor[
'fullname'] == $filelog) {
158 $alreadyincluded =
true;
161 if (!$alreadyincluded) {
162 $filesarray[] = array(
'fullname' => $filelog,
'type' =>
'file');
167 if (is_array($filesarray) && count($filesarray)) {
168 foreach ($filesarray as $key => $value) {
170 if ($filesarray[$key][
'type'] ==
'dir') {
172 $tmpcountdeleted = 0;
177 $conf->user->dir_temp,
180 $excluded[] =
$conf->api->dir_temp;
183 if (!in_array($filesarray[$key][
'fullname'], $excluded)) {
185 $countdeleted += $tmpcountdeleted;
187 } elseif ($filesarray[$key][
'type'] ==
'file') {
188 if ($choice !=
'allfilesold' || $filesarray[$key][
'date'] < ($now - $nbsecondsold)) {
190 if ($filesarray[$key][
'fullname'] != $filelog || $choice ==
'logfile' || $choice ==
'logfiles') {
205 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
207 $result = $ecmdirstatic->refreshcachenboffile(1);
213 $langs->load(
"admin");
214 $this->output = $langs->trans(
"PurgeNDirectoriesDeleted", $countdeleted);
215 if ($count > $countdeleted) {
216 $this->output .=
'<br>'.$langs->trans(
"PurgeNDirectoriesFailed", ($count - $countdeleted));
219 $this->output = $langs->trans(
"PurgeNothingToDelete").(in_array(
'tempfilesold', $choicesarray) ?
' (older than 24h for temp files)' :
'');
265 public function dumpDatabase($compression =
'none', $type =
'auto', $usedefault = 1, $file =
'auto', $keeplastnfiles = 0, $execmethod = 0, $lowmemorydump = 0)
268 global $dolibarr_main_db_name, $dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_port, $dolibarr_main_db_pass;
269 global $dolibarr_main_db_character_set;
270 global $dolibarr_main_restrict_os_commands;
272 $langs->load(
"admin");
274 dol_syslog(
"Utils::dumpDatabase type=".$type.
" compression=".$compression.
" file=".$file, LOG_DEBUG);
275 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
281 if (!in_array($compression, array(
'none',
'gz',
'bz',
'zip',
'zstd'))) {
282 $langs->load(
"errors");
283 $this->error = $langs->transnoentitiesnoconv(
"ErrorBadValueForParameter", $compression,
"Compression");
288 if ($type ==
'auto') {
289 $type = $this->db->type;
291 if (!in_array($type, array(
'postgresql',
'pgsql',
'mysql',
'mysqli',
'mysqlnobin'))) {
292 $langs->load(
"errors");
293 $this->error = $langs->transnoentitiesnoconv(
"ErrorBadValueForParameter", $type,
"Basetype");
298 if ($file ==
'auto') {
301 if (in_array($type, array(
'mysql',
'mysqli'))) {
302 $prefix =
'mysqldump';
305 if (in_array($type, array(
'pgsql'))) {
311 $outputdir =
$conf->admin->dir_output.
'/backup';
316 if ($type ==
'mysql' || $type ==
'mysqli') {
318 $cmddump =
$db->getPathOfDump();
322 if (empty($cmddump)) {
323 $this->error =
"Failed to detect command to use for mysqldump. Try a manual backup before to set path of command.";
327 $outputfile = $outputdir.
'/'.$file;
329 $compression = $compression ? $compression :
'none';
330 if ($compression ==
'gz') {
331 $outputfile .=
'.gz';
332 } elseif ($compression ==
'bz') {
333 $outputfile .=
'.bz2';
334 } elseif ($compression ==
'zstd') {
335 $outputfile .=
'.zst';
337 $outputerror = $outputfile.
'.err';
342 $basenamecmddump = basename(str_replace(
'\\',
'/', $cmddump));
345 if (!empty($dolibarr_main_restrict_os_commands)) {
346 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
347 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
348 dol_syslog(
"Command are restricted to ".$dolibarr_main_restrict_os_commands.
". We check that one of this command is inside ".$cmddump);
349 if (!in_array($basenamecmddump, $arrayofallowedcommand)) {
350 $langs->load(
"errors");
351 $this->error = $langs->trans(
'CommandIsNotInsideAllowedCommands');
352 $this->error .=
'<br>'.$langs->trans(
'ErrorCheckTheCommandInsideTheAdvancedOptions');
356 $compressorcommands = array(
'gz' =>
'gzip',
'bz' =>
'bzip2',
'zstd' =>
'zstd');
357 if ($lowmemorydump && !empty($compressorcommands[$compression]) && !in_array($compressorcommands[$compression], $arrayofallowedcommand)) {
358 $langs->loadLangs(array(
"admin",
"errors"));
359 dol_syslog(
"Compression command ".$compressorcommands[$compression].
" is not inside the allowed commands", LOG_WARNING);
360 $this->error = $langs->trans(
'CommandIsNotInsideAllowedCommands');
361 $this->error .=
'<br>'.$langs->trans(
'NotAvailableCommandNotAllowed', $compressorcommands[$compression]);
368 $command = preg_replace(
'/(\$|%)/',
'', $command);
369 if (preg_match(
"/\s/", $command)) {
370 $command = escapeshellarg($command);
374 $param = $dolibarr_main_db_name.
" -h ".$dolibarr_main_db_host;
375 $param .=
" -u ".$dolibarr_main_db_user;
376 if (!empty($dolibarr_main_db_port)) {
377 $param .=
" -P ".$dolibarr_main_db_port.
" --protocol=tcp";
381 if (
GETPOST(
"use_transaction",
"alpha") || $usedefault) {
382 $param .=
" --single-transaction";
384 if (
GETPOST(
"disable_fk",
"alpha") || $usedefault) {
387 if (
GETPOST(
"sql_compat",
"alpha") &&
GETPOST(
"sql_compat",
"alpha") !=
'NONE') {
388 $param .=
" --compatible=".escapeshellarg(
GETPOST(
"sql_compat",
"alpha"));
390 if (
GETPOST(
"drop_database",
"alpha")) {
391 $param .=
" --add-drop-database";
393 if (
GETPOST(
"use_mysql_quick_param",
"alpha")) {
394 $param .=
" --quick";
396 if (
GETPOST(
"use_force",
"alpha")) {
399 if (
GETPOST(
"sql_structure",
"alpha") || $usedefault) {
400 if (
GETPOST(
"drop",
"alpha") || $usedefault) {
401 $param .=
" --add-drop-table=TRUE";
403 $param .=
" --add-drop-table=FALSE";
408 if (
GETPOST(
"disable-add-locks",
"alpha")) {
409 $param .=
" --add-locks=FALSE";
411 if (
GETPOST(
"sql_data",
"alpha") || $usedefault) {
412 $param .=
" --tables";
413 if (
GETPOST(
"showcolumns",
"alpha") || $usedefault) {
416 if (
GETPOST(
"extended_ins",
"alpha") || $usedefault) {
419 $param .=
" --skip-extended-insert";
421 if (
GETPOST(
"delayed",
"alpha")) {
422 $param .=
" --delayed-insert";
424 if (
GETPOST(
"sql_ignore",
"alpha")) {
425 $param .=
" --insert-ignore";
427 if (
GETPOST(
"hexforbinary",
"alpha") || $usedefault) {
428 $param .=
" --hex-blob";
433 if ($dolibarr_main_db_character_set ==
'utf8mb4') {
435 $param .=
" --default-character-set=utf8mb4 --no-tablespaces";
437 $param .=
" --default-character-set=utf8 --no-tablespaces";
439 $paramcrypted = $param;
440 $paramclear = $param;
441 if (!empty($dolibarr_main_db_pass)) {
442 $paramcrypted .=
' -p"'.preg_replace(
'/./i',
'*', $dolibarr_main_db_pass).
'"';
443 $paramclear .=
' '.$this->getShellPasswordParam($dolibarr_main_db_pass);
449 $fullcommandcrypted = $command.
" ".$paramcrypted.
" 2>&1";
450 $fullcommandclear = $command.
" ".$paramclear.
" 2>&1";
451 if (!$lowmemorydump) {
452 if ($compression ==
'none') {
453 $handle = fopen($outputfile,
'w');
454 } elseif ($compression ==
'gz') {
455 $handle = gzopen($outputfile,
'w');
456 } elseif ($compression ==
'bz') {
457 $handle = bzopen($outputfile,
'w');
458 } elseif ($compression ==
'zstd') {
459 $handle = fopen(
"compress.zstd://" . $outputfile,
"wb");
464 if ($compression ==
'none') {
465 $fullcommandclear .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." > "'.dol_sanitizePathName($outputfile).
'"';
466 $fullcommandcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." > "'.dol_sanitizePathName($outputfile).
'"';
468 } elseif ($compression ==
'gz') {
469 $fullcommandclear .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | gzip > "'.dol_sanitizePathName($outputfile).
'"';
470 $fullcommandcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | gzip > "'.dol_sanitizePathName($outputfile).
'"';
471 $paramcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | gzip';
473 } elseif ($compression ==
'bz') {
474 $fullcommandclear .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | bzip2 > "'.dol_sanitizePathName($outputfile).
'"';
475 $fullcommandcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | bzip2 > "'.dol_sanitizePathName($outputfile).
'"';
476 $paramcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | bzip2';
478 } elseif ($compression ==
'zstd') {
479 $fullcommandclear .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | zstd > "'.dol_sanitizePathName($outputfile).
'"';
480 $fullcommandcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | zstd > "'.dol_sanitizePathName($outputfile).
'"';
481 $paramcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | zstd';
491 if (empty($execmethod)) {
495 dol_syslog(
"Utils::dumpDatabase execmethod=".$execmethod.
", lowmemorydump=".$lowmemorydump.
", command=".$fullcommandcrypted, LOG_INFO);
500 if (!empty($MemoryLimit)) {
501 @ini_set(
'memory_limit', $MemoryLimit);
505 if ($execmethod == 1) {
506 $output_arr = array();
509 exec($fullcommandclear, $output_arr, $retval);
517 $langs->load(
"errors");
518 dol_syslog(
"Datadump retval after exec=".$retval, LOG_ERR);
519 $errormsg =
'Error '.$retval;
523 if (!empty($output_arr)) {
524 foreach ($output_arr as $key => $read) {
526 if ($i == 1 && preg_match(
'/Warning.*Using a password/i', $read)) {
531 if (!$lowmemorydump) {
534 fwrite($handle, $read.($execmethod == 2 ?
'' :
"\n"));
535 if (preg_match(
'/'.preg_quote(
'-- Dump completed',
'/').
'/i', $read)) {
537 } elseif (preg_match(
'/'.preg_quote(
'SET SQL_NOTES=@OLD_SQL_NOTES',
'/').
'/i', $read)) {
544 } elseif ($lowmemorydump) {
550 if ($execmethod == 2) {
551 $handlein = popen($fullcommandclear,
'r');
554 while (!feof($handlein)) {
556 $read = fgets($handlein);
558 if ($i == 1 && preg_match(
'/Warning.*Using a password/i', $read)) {
561 fwrite($handle, $read);
562 if (preg_match(
'/'.preg_quote(
'-- Dump completed',
'/').
'/i', $read)) {
564 } elseif (preg_match(
'/'.preg_quote(
'SET SQL_NOTES=@OLD_SQL_NOTES',
'/').
'/i', $read)) {
572 if (!$lowmemorydump) {
573 if ($compression ==
'none') {
575 } elseif ($compression ==
'gz') {
577 } elseif ($compression ==
'bz') {
579 } elseif ($compression ==
'zstd') {
586 $langs->load(
"errors");
587 dol_syslog(
"Failed to open file ".$outputfile, LOG_ERR);
588 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir");
592 if ($compression ==
'none') {
593 $handle = fopen($outputfile,
'r');
594 } elseif ($compression ==
'gz') {
595 $handle = gzopen($outputfile,
'r');
596 } elseif ($compression ==
'bz') {
597 $handle = bzopen($outputfile,
'r');
598 } elseif ($compression ==
'zstd') {
599 $handle = fopen(
"compress.zstd://" . $outputfile,
"rb");
603 $errormsg = fgets($handle, 2048);
607 if ($compression ==
'none') {
609 } elseif ($compression ==
'gz') {
611 } elseif ($compression ==
'bz') {
613 } elseif ($compression ==
'zstd') {
616 if ($ok && preg_match(
'/^-- (MySql|MariaDB)/i', $errormsg) || preg_match(
'/^\/\*M?!999999/', $errormsg)) {
622 @
dol_move($outputfile, $outputerror,
'0', 1, 0, 0);
625 $langs->load(
"errors");
626 $errormsg = $langs->trans(
"ErrorFailedToRunExternalCommand");
632 $this->output = $errormsg;
633 $this->error = $errormsg;
634 $this->result = array(
"commandbackuplastdone" => $command.
" ".$paramcrypted,
"commandbackuptorun" =>
"");
639 if ($type ==
'mysqlnobin') {
640 $outputfile = $outputdir.
'/'.$file;
641 $outputfiletemp = $outputfile.
'-TMP.sql';
643 $compression = $compression ? $compression :
'none';
644 if ($compression ==
'gz') {
645 $outputfile .=
'.gz';
647 if ($compression ==
'bz') {
648 $outputfile .=
'.bz2';
650 $outputerror = $outputfile.
'.err';
653 if ($compression ==
'gz' or $compression ==
'bz') {
654 $this->backupTables($outputfiletemp);
655 dol_compress_file($outputfiletemp, $outputfile, $compression);
656 unlink($outputfiletemp);
658 $this->backupTables($outputfile);
662 $this->result = array(
"commandbackuplastdone" =>
"",
"commandbackuptorun" =>
"");
666 if ($type ==
'postgresql' || $type ==
'pgsql') {
669 $outputfile = $outputdir.
'/'.$file;
671 $compression = $compression ? $compression :
'none';
672 if ($compression ==
'gz') {
673 $outputfile .=
'.gz';
675 if ($compression ==
'bz') {
676 $outputfile .=
'.bz2';
678 $outputerror = $outputfile.
'.err';
684 $basenamecmddump = basename(str_replace(
'\\',
'/', $cmddump));
686 if (!empty($dolibarr_main_restrict_os_commands)) {
687 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
688 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
689 dol_syslog(
"Command are restricted to ".$dolibarr_main_restrict_os_commands.
". We check that one of this command is inside ".$cmddump);
690 if (!in_array($basenamecmddump, $arrayofallowedcommand)) {
691 $langs->load(
"errors");
692 $this->error = $langs->trans(
'CommandIsNotInsideAllowedCommands');
693 $this->error .=
'<br>'.$langs->trans(
'ErrorCheckTheCommandInsideTheAdvancedOptions');
700 $command = preg_replace(
'/(\$|%)/',
'', $command);
701 if (preg_match(
"/\s/", $command)) {
702 $command = escapeshellarg($command);
708 $param .=
" --no-tablespaces --inserts -h ".$dolibarr_main_db_host;
709 $param .=
" -U ".$dolibarr_main_db_user;
710 if (!empty($dolibarr_main_db_port)) {
711 $param .=
" -p ".$dolibarr_main_db_port;
714 $param .=
" --disable-dollar-quoting";
716 if (
GETPOST(
"drop_database")) {
719 if (
GETPOST(
"sql_structure")) {
721 $param .=
" --add-drop-table";
728 if (!
GETPOST(
"sql_structure")) {
735 $param .=
' -f "'.$outputfile.
'"';
737 if ($compression ==
'gz') {
741 $paramcrypted = $param;
742 $paramclear = $param;
748 $paramcrypted .=
" -w ".$dolibarr_main_db_name;
749 $paramclear .=
" -w ".$dolibarr_main_db_name;
752 $this->result = array(
"commandbackuplastdone" =>
"",
"commandbackuptorun" => $command.
" ".$paramcrypted);
756 if (!$errormsg && $keeplastnfiles > 0) {
757 $tmpfiles =
dol_dir_list(
$conf->admin->dir_output.
'/backup',
'files', 0,
'',
'(\.err|\.old|\.sav)$',
'date', SORT_DESC);
759 if (is_array($tmpfiles)) {
760 foreach ($tmpfiles as $key => $val) {
762 if ($i <= $keeplastnfiles) {
770 return ($errormsg ? -1 : 0);
788 public function executeCLI($command, $outputfile, $execmethod = 0, $redirectionfile =
null, $noescapecommand = 0, $redirectionfileerr =
null)
796 global $dolibarr_main_restrict_os_commands;
797 if (!empty($dolibarr_main_restrict_os_commands)) {
798 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
799 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
801 $commands = preg_split(
'/\|\||&&|\||&/', $command);
802 foreach ($commands as $newcommand) {
803 $newcommand = trim($newcommand);
806 if (preg_match(
'/^(?:\'([^\']*)\'|"([^"]*)"|(\S+))/', $newcommand, $matches)) {
807 $newcommand = $matches[1] ?: ($matches[2] ?: $matches[3]);
809 if (!in_array(basename($newcommand), $arrayofallowedcommand)) {
810 dol_syslog(
"files.lib.php::executeCLI canceled because target filename ".basename($newcommand).
" is not in the whitelist of allowed commands (param dolibarr_main_restrict_os_commands).", LOG_WARNING);
811 return array(
'result' => -1,
'output' =>
'',
'error' =>
'Command '.basename($newcommand).
' is not in the whitelist of allowed commands (param dolibarr_main_restrict_os_commands)');
816 if (empty($noescapecommand)) {
817 $command = escapeshellcmd($command);
820 if ($redirectionfile) {
821 $command .=
" > ".dol_sanitizePathName($redirectionfile);
824 if ($redirectionfileerr && ($redirectionfileerr != $redirectionfile)) {
826 $command .=
" 2> ".dol_sanitizePathName($redirectionfileerr);
834 if (empty($execmethod)) {
838 dol_syslog(
"Utils::executeCLI execmethod=".$execmethod.
" command=".$command, LOG_DEBUG);
839 $output_arr = array();
841 if ($execmethod == 1) {
843 exec($command, $output_arr, $retval);
846 $langs->load(
"errors");
847 dol_syslog(
"Utils::executeCLI retval after exec=".$retval, LOG_ERR);
848 $error =
'Error '.$retval;
851 if ($execmethod == 2) {
852 $handle = fopen($outputfile,
'w+b');
854 dol_syslog(
"Utils::executeCLI run command ".$command);
855 $handlein = popen($command,
'r');
856 while (!feof($handlein)) {
857 $read = fgets($handlein);
858 fwrite($handle, $read);
859 $output_arr[] = $read;
868 if (is_array($output_arr) && count($output_arr) > 0) {
869 foreach ($output_arr as $val) {
870 $output .= $val.($execmethod == 2 ?
'' :
"\n");
874 dol_syslog(
"Utils::executeCLI result=".$result.
" output=".$output.
" error=".$error, LOG_DEBUG);
876 return array(
'result' => $result,
'output' => $output,
'error' => $error);
887 global $langs, $user,
$mysoc;
892 $modulelowercase = strtolower(
$module);
896 $dir = $dirins.
'/'.$modulelowercase;
902 $class =
'mod'.$module;
905 if (class_exists($class)) {
910 dol_print_error(
null, $e->getMessage());
914 $langs->load(
"errors");
915 dol_print_error(
null, $langs->trans(
"ErrorFailedToLoadModuleDescriptorForXXX",
$module));
920 if (count($arrayversion)) {
921 $FILENAMEASCII = strtolower(
$module).
'.asciidoc';
922 $FILENAMEDOC = strtolower(
$module).
'.html';
923 $FILENAMEDOCPDF = strtolower(
$module).
'.pdf';
928 $outputfiledoc = $dirofmoduledoc.
'/'.$FILENAMEDOC;
929 if ($dirofmoduledoc) {
936 if (!is_writable($dirofmoduletmp)) {
937 $this->error =
'Dir '.$dirofmoduletmp.
' does not exists or is not writable';
942 $this->error =
'Setup of module ModuleBuilder not complete';
947 dol_copy($dirofmodule.
'/README.md', $dirofmoduletmp.
'/README.md',
'0', 1);
948 dol_copy($dirofmodule.
'/ChangeLog.md', $dirofmoduletmp.
'/ChangeLog.md',
'0', 1);
951 $arrayreplacement = array();
952 $arrayreplacement[
'/^#\s.*/m'] =
'';
953 $arrayreplacement[
'/^#/m'] =
'##';
955 dolReplaceInFile($dirofmoduletmp.
'/README.md', $arrayreplacement,
'',
'0', 0, 1);
956 dolReplaceInFile($dirofmoduletmp.
'/ChangeLog.md', $arrayreplacement,
'',
'0', 0, 1);
959 $destfile = $dirofmoduletmp.
'/'.$FILENAMEASCII;
961 $fhandle = fopen($destfile,
'w+');
966 foreach ($specs as $spec) {
967 if (preg_match(
'/notindoc/', $spec[
'relativename'])) {
970 if (preg_match(
'/example/', $spec[
'relativename'])) {
973 if (preg_match(
'/disabled/', $spec[
'relativename'])) {
977 $pathtofile = strtolower(
$module).
'/doc/'.$spec[
'relativename'];
978 $format =
'asciidoc';
979 if (preg_match(
'/\.md$/i', $spec[
'name'])) {
980 $format =
'markdown';
983 $filecursor = @file_get_contents($spec[
'fullname']);
985 fwrite($fhandle, ($i ?
"\n<<<\n\n" :
"").$filecursor.
"\n");
987 $this->error =
'Failed to concat content of file '.$spec[
'fullname'];
996 $contentreadme = file_get_contents($dirofmoduletmp.
'/README.md');
997 $contentchangelog = file_get_contents($dirofmoduletmp.
'/ChangeLog.md');
999 include DOL_DOCUMENT_ROOT.
'/core/lib/parsemd.lib.php';
1002 $arrayreplacement = array(
1003 'mymodule' => strtolower(
$module),
1005 'MYMODULE' => strtoupper(
$module),
1010 'htdocs/modulebuilder/template' => strtolower(
$module),
1011 '__MYCOMPANY_NAME__' =>
$mysoc->name,
1013 '__USER_FULLNAME__' => $user->getFullName($langs),
1014 '__USER_EMAIL__' => $user->email,
1016 '---Put here your own copyright and developer email---' =>
dol_print_date($now,
'dayrfc').
' '.$user->getFullName($langs).($user->email ?
' <'.$user->email.
'>' :
''),
1017 '__DATA_SPECIFICATION__' =>
'Not yet available',
1027 $currentdir = getcwd();
1028 chdir($dirofmodule);
1030 require_once DOL_DOCUMENT_ROOT.
'/core/class/utils.class.php';
1031 $utils =
new Utils($this->db);
1034 $command =
getDolGlobalString(
'MODULEBUILDER_ASCIIDOCTOR') .
' '.$destfile.
' -n -o '.$dirofmoduledoc.
'/'.$FILENAMEDOC;
1035 $outfile = $dirofmoduletmp.
'/out.tmp';
1037 $resarray = $utils->executeCLI($command, $outfile);
1038 if ($resarray[
'result'] !=
'0') {
1039 $this->error = $resarray[
'error'].
' '.$resarray[
'output'];
1040 $this->errors[] = $this->error;
1042 $result = ($resarray[
'result'] == 0) ? 1 : 0;
1045 $this->error = $langs->trans(
"ErrorFailToGenerateFile", $FILENAMEDOC);
1046 $this->errors[] = $this->error;
1050 $command =
getDolGlobalString(
'MODULEBUILDER_ASCIIDOCTORPDF') .
' '.$destfile.
' -n -o '.$dirofmoduledoc.
'/'.$FILENAMEDOCPDF;
1051 $outfile = $dirofmoduletmp.
'/outpdf.tmp';
1052 $resarray = $utils->executeCLI($command, $outfile);
1053 if ($resarray[
'result'] !=
'0') {
1054 $this->error = $resarray[
'error'].
' '.$resarray[
'output'];
1055 $this->errors[] = $this->error;
1057 $result = ($resarray[
'result'] == 0) ? 1 : 0;
1060 $this->error = $langs->trans(
"ErrorFailToGenerateFile", $FILENAMEDOCPDF);
1061 $this->errors[] = $this->error;
1076 $langs->load(
"errors");
1077 $this->error = $langs->trans(
"ErrorCheckVersionIsDefined");