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);
151 if (isModEnabled(
'syslog')) {
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;
176 $conf->user->dir_temp,
178 if (isModEnabled(
'api')) {
179 $excluded[] = $conf->api->dir_temp;
182 if (!in_array($filesarray[$key][
'fullname'], $excluded)) {
184 $countdeleted += $tmpcountdeleted;
186 } elseif ($filesarray[$key][
'type'] ==
'file') {
187 if ($choice !=
'allfilesold' || $filesarray[$key][
'date'] < ($now - $nbsecondsold)) {
189 if ($filesarray[$key][
'fullname'] != $filelog || $choice ==
'logfile' || $choice ==
'logfiles') {
203 if (isModEnabled(
'ecm') && $choice ==
'allfiles') {
204 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
206 $result = $ecmdirstatic->refreshcachenboffile(1);
212 $langs->load(
"admin");
213 $this->output = $langs->trans(
"PurgeNDirectoriesDeleted", $countdeleted);
214 if ($count > $countdeleted) {
215 $this->output .=
'<br>'.$langs->trans(
"PurgeNDirectoriesFailed", ($count - $countdeleted));
218 $this->output = $langs->trans(
"PurgeNothingToDelete").(in_array(
'tempfilesold', $choicesarray) ?
' (older than 24h for temp files)' :
'');
222 if (isModEnabled(
'api')) {
245 public function dumpDatabase($compression =
'none', $type =
'auto', $usedefault = 1, $file =
'auto', $keeplastnfiles = 0, $execmethod = 0, $lowmemorydump = 0)
247 global
$db, $conf, $langs, $dolibarr_main_data_root;
248 global $dolibarr_main_db_name, $dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_port, $dolibarr_main_db_pass;
249 global $dolibarr_main_db_character_set;
251 $langs->load(
"admin");
253 dol_syslog(
"Utils::dumpDatabase type=".$type.
" compression=".$compression.
" file=".$file, LOG_DEBUG);
254 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
260 if (!in_array($compression, array(
'none',
'gz',
'bz',
'zip',
'zstd'))) {
261 $langs->load(
"errors");
262 $this->error = $langs->transnoentitiesnoconv(
"ErrorBadValueForParameter", $compression,
"Compression");
267 if ($type ==
'auto') {
268 $type = $this->db->type;
270 if (!in_array($type, array(
'postgresql',
'pgsql',
'mysql',
'mysqli',
'mysqlnobin'))) {
271 $langs->load(
"errors");
272 $this->error = $langs->transnoentitiesnoconv(
"ErrorBadValueForParameter", $type,
"Basetype");
277 if ($file ==
'auto') {
280 if (in_array($type, array(
'mysql',
'mysqli'))) {
281 $prefix =
'mysqldump';
284 if (in_array($type, array(
'pgsql'))) {
290 $outputdir = $conf->admin->dir_output.
'/backup';
295 if ($type ==
'mysql' || $type ==
'mysqli') {
297 $cmddump =
$db->getPathOfDump();
301 if (empty($cmddump)) {
302 $this->error =
"Failed to detect command to use for mysqldump. Try a manual backup before to set path of command.";
306 $outputfile = $outputdir.
'/'.$file;
308 $compression = $compression ? $compression :
'none';
309 if ($compression ==
'gz') {
310 $outputfile .=
'.gz';
311 } elseif ($compression ==
'bz') {
312 $outputfile .=
'.bz2';
313 } elseif ($compression ==
'zstd') {
314 $outputfile .=
'.zst';
316 $outputerror = $outputfile.
'.err';
317 dol_mkdir($conf->admin->dir_output.
'/backup');
321 $command = preg_replace(
'/(\$|%)/',
'', $command);
322 if (preg_match(
"/\s/", $command)) {
323 $command = escapeshellarg($command);
327 $param = $dolibarr_main_db_name.
" -h ".$dolibarr_main_db_host;
328 $param .=
" -u ".$dolibarr_main_db_user;
329 if (!empty($dolibarr_main_db_port)) {
330 $param .=
" -P ".$dolibarr_main_db_port.
" --protocol=tcp";
332 if (
GETPOST(
"use_transaction",
"alpha")) {
333 $param .=
" --single-transaction";
335 if (
GETPOST(
"disable_fk",
"alpha") || $usedefault) {
338 if (
GETPOST(
"sql_compat",
"alpha") &&
GETPOST(
"sql_compat",
"alpha") !=
'NONE') {
339 $param .=
" --compatible=".escapeshellarg(
GETPOST(
"sql_compat",
"alpha"));
341 if (
GETPOST(
"drop_database",
"alpha")) {
342 $param .=
" --add-drop-database";
344 if (
GETPOST(
"use_mysql_quick_param",
"alpha")) {
345 $param .=
" --quick";
347 if (
GETPOST(
"use_force",
"alpha")) {
350 if (
GETPOST(
"sql_structure",
"alpha") || $usedefault) {
351 if (
GETPOST(
"drop",
"alpha") || $usedefault) {
352 $param .=
" --add-drop-table=TRUE";
354 $param .=
" --add-drop-table=FALSE";
359 if (
GETPOST(
"disable-add-locks",
"alpha")) {
360 $param .=
" --add-locks=FALSE";
362 if (
GETPOST(
"sql_data",
"alpha") || $usedefault) {
363 $param .=
" --tables";
364 if (
GETPOST(
"showcolumns",
"alpha") || $usedefault) {
367 if (
GETPOST(
"extended_ins",
"alpha") || $usedefault) {
370 $param .=
" --skip-extended-insert";
372 if (
GETPOST(
"delayed",
"alpha")) {
373 $param .=
" --delayed-insert";
375 if (
GETPOST(
"sql_ignore",
"alpha")) {
376 $param .=
" --insert-ignore";
378 if (
GETPOST(
"hexforbinary",
"alpha") || $usedefault) {
379 $param .=
" --hex-blob";
384 if ($dolibarr_main_db_character_set ==
'utf8mb4') {
386 $param .=
" --default-character-set=utf8mb4 --no-tablespaces";
388 $param .=
" --default-character-set=utf8 --no-tablespaces";
390 $paramcrypted = $param;
391 $paramclear = $param;
392 if (!empty($dolibarr_main_db_pass)) {
393 $paramcrypted .=
' -p"'.preg_replace(
'/./i',
'*', $dolibarr_main_db_pass).
'"';
394 $paramclear .=
' -p"'.str_replace(array(
'"',
'`',
'$'), array(
'\"',
'\`',
'\$'), $dolibarr_main_db_pass).
'"';
400 $fullcommandcrypted = $command.
" ".$paramcrypted.
" 2>&1";
401 $fullcommandclear = $command.
" ".$paramclear.
" 2>&1";
402 if (!$lowmemorydump) {
403 if ($compression ==
'none') {
404 $handle = fopen($outputfile,
'w');
405 } elseif ($compression ==
'gz') {
406 $handle = gzopen($outputfile,
'w');
407 } elseif ($compression ==
'bz') {
408 $handle = bzopen($outputfile,
'w');
409 } elseif ($compression ==
'zstd') {
410 $handle = fopen($outputfile,
'w');
413 if ($compression ==
'none') {
414 $fullcommandclear .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." > "'.dol_sanitizePathName($outputfile).
'"';
415 $fullcommandcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." > "'.dol_sanitizePathName($outputfile).
'"';
417 } elseif ($compression ==
'gz') {
418 $fullcommandclear .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | gzip > "'.dol_sanitizePathName($outputfile).
'"';
419 $fullcommandcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | gzip > "'.dol_sanitizePathName($outputfile).
'"';
420 $paramcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | gzip';
422 } elseif ($compression ==
'bz') {
423 $fullcommandclear .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | bzip2 > "'.dol_sanitizePathName($outputfile).
'"';
424 $fullcommandcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | bzip2 > "'.dol_sanitizePathName($outputfile).
'"';
425 $paramcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | bzip2';
427 } elseif ($compression ==
'zstd') {
428 $fullcommandclear .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | zstd > "'.dol_sanitizePathName($outputfile).
'"';
429 $fullcommandcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | zstd > "'.dol_sanitizePathName($outputfile).
'"';
430 $paramcrypted .=
' | grep -v "Warning: Using a password on the command line interface can be insecure." | zstd';
440 if (empty($execmethod)) {
444 dol_syslog(
"Utils::dumpDatabase execmethod=".$execmethod.
" command:".$fullcommandcrypted, LOG_INFO);
449 if (!empty($MemoryLimit)) {
450 @ini_set(
'memory_limit', $MemoryLimit);
454 if ($execmethod == 1) {
455 $output_arr = array();
458 exec($fullcommandclear, $output_arr, $retval);
466 $langs->load(
"errors");
467 dol_syslog(
"Datadump retval after exec=".$retval, LOG_ERR);
468 $errormsg =
'Error '.$retval;
472 if (!empty($output_arr)) {
473 foreach ($output_arr as $key => $read) {
475 if ($i == 1 && preg_match(
'/Warning.*Using a password/i', $read)) {
480 if (!$lowmemorydump) {
481 fwrite($handle, $read.($execmethod == 2 ?
'' :
"\n"));
482 if (preg_match(
'/'.preg_quote(
'-- Dump completed',
'/').
'/i', $read)) {
484 } elseif (preg_match(
'/'.preg_quote(
'SET SQL_NOTES=@OLD_SQL_NOTES',
'/').
'/i', $read)) {
491 } elseif ($lowmemorydump) {
497 if ($execmethod == 2) {
498 $handlein = popen($fullcommandclear,
'r');
501 while (!feof($handlein)) {
503 $read = fgets($handlein);
505 if ($i == 1 && preg_match(
'/Warning.*Using a password/i', $read)) {
508 fwrite($handle, $read);
509 if (preg_match(
'/'.preg_quote(
'-- Dump completed').
'/i', $read)) {
511 } elseif (preg_match(
'/'.preg_quote(
'SET SQL_NOTES=@OLD_SQL_NOTES').
'/i', $read)) {
519 if (!$lowmemorydump) {
520 if ($compression ==
'none') {
522 } elseif ($compression ==
'gz') {
524 } elseif ($compression ==
'bz') {
526 } elseif ($compression ==
'zstd') {
533 $langs->load(
"errors");
534 dol_syslog(
"Failed to open file ".$outputfile, LOG_ERR);
535 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir");
539 if ($compression ==
'none') {
540 $handle = fopen($outputfile,
'r');
541 } elseif ($compression ==
'gz') {
542 $handle = gzopen($outputfile,
'r');
543 } elseif ($compression ==
'bz') {
544 $handle = bzopen($outputfile,
'r');
545 } elseif ($compression ==
'zstd') {
546 $handle = fopen($outputfile,
'r');
550 $errormsg = fgets($handle, 2048);
554 if ($compression ==
'none') {
556 } elseif ($compression ==
'gz') {
558 } elseif ($compression ==
'bz') {
560 } elseif ($compression ==
'zstd') {
563 if ($ok && preg_match(
'/^-- (MySql|MariaDB)/i', $errormsg) || preg_match(
'/^\/\*!999999/', $errormsg)) {
569 @
dol_move($outputfile, $outputerror,
'0', 1, 0, 0);
572 $langs->load(
"errors");
573 $errormsg = $langs->trans(
"ErrorFailedToRunExternalCommand");
579 $this->output = $errormsg;
580 $this->error = $errormsg;
581 $this->result = array(
"commandbackuplastdone" => $command.
" ".$paramcrypted,
"commandbackuptorun" =>
"");
586 if ($type ==
'mysqlnobin') {
587 $outputfile = $outputdir.
'/'.$file;
588 $outputfiletemp = $outputfile.
'-TMP.sql';
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');
600 if ($compression ==
'gz' or $compression ==
'bz') {
601 $this->backupTables($outputfiletemp);
602 dol_compress_file($outputfiletemp, $outputfile, $compression);
603 unlink($outputfiletemp);
605 $this->backupTables($outputfile);
609 $this->result = array(
"commandbackuplastdone" =>
"",
"commandbackuptorun" =>
"");
613 if ($type ==
'postgresql' || $type ==
'pgsql') {
616 $outputfile = $outputdir.
'/'.$file;
618 $compression = $compression ? $compression :
'none';
619 if ($compression ==
'gz') {
620 $outputfile .=
'.gz';
622 if ($compression ==
'bz') {
623 $outputfile .=
'.bz2';
625 $outputerror = $outputfile.
'.err';
626 dol_mkdir($conf->admin->dir_output.
'/backup');
630 $command = preg_replace(
'/(\$|%)/',
'', $command);
631 if (preg_match(
"/\s/", $command)) {
632 $command = escapeshellarg($command);
638 $param .=
" --no-tablespaces --inserts -h ".$dolibarr_main_db_host;
639 $param .=
" -U ".$dolibarr_main_db_user;
640 if (!empty($dolibarr_main_db_port)) {
641 $param .=
" -p ".$dolibarr_main_db_port;
644 $param .=
" --disable-dollar-quoting";
646 if (
GETPOST(
"drop_database")) {
649 if (
GETPOST(
"sql_structure")) {
651 $param .=
" --add-drop-table";
658 if (!
GETPOST(
"sql_structure")) {
665 $param .=
' -f "'.$outputfile.
'"';
667 if ($compression ==
'gz') {
671 $paramcrypted = $param;
672 $paramclear = $param;
678 $paramcrypted .=
" -w ".$dolibarr_main_db_name;
679 $paramclear .=
" -w ".$dolibarr_main_db_name;
682 $this->result = array(
"commandbackuplastdone" =>
"",
"commandbackuptorun" => $command.
" ".$paramcrypted);
686 if (!$errormsg && $keeplastnfiles > 0) {
687 $tmpfiles =
dol_dir_list($conf->admin->dir_output.
'/backup',
'files', 0,
'',
'(\.err|\.old|\.sav)$',
'date', SORT_DESC);
689 if (is_array($tmpfiles)) {
690 foreach ($tmpfiles as $key => $val) {
692 if ($i <= $keeplastnfiles) {
700 return ($errormsg ? -1 : 0);
797 global $conf, $langs, $user, $mysoc;
802 $modulelowercase = strtolower($module);
806 $dir = $dirins.
'/'.$modulelowercase;
811 dol_include_once($modulelowercase.
'/core/modules/mod'.$module.
'.class.php');
812 $class =
'mod'.$module;
814 if (class_exists($class)) {
816 $moduleobj =
new $class($this->db);
823 $langs->load(
"errors");
824 dol_print_error(
null, $langs->trans(
"ErrorFailedToLoadModuleDescriptorForXXX", $module));
828 $arrayversion = explode(
'.', $moduleobj->version, 3);
829 if (count($arrayversion)) {
830 $FILENAMEASCII = strtolower($module).
'.asciidoc';
831 $FILENAMEDOC = strtolower($module).
'.html';
832 $FILENAMEDOCPDF = strtolower($module).
'.pdf';
835 $dirofmoduledoc =
dol_buildpath(strtolower($module), 0).
'/doc';
836 $dirofmoduletmp =
dol_buildpath(strtolower($module), 0).
'/doc/temp';
837 $outputfiledoc = $dirofmoduledoc.
'/'.$FILENAMEDOC;
838 if ($dirofmoduledoc) {
845 if (!is_writable($dirofmoduletmp)) {
846 $this->error =
'Dir '.$dirofmoduletmp.
' does not exists or is not writable';
851 $this->error =
'Setup of module ModuleBuilder not complete';
856 dol_copy($dirofmodule.
'/README.md', $dirofmoduletmp.
'/README.md', 0, 1);
857 dol_copy($dirofmodule.
'/ChangeLog.md', $dirofmoduletmp.
'/ChangeLog.md', 0, 1);
860 $arrayreplacement = array();
861 $arrayreplacement[
'/^#\s.*/m'] =
'';
862 $arrayreplacement[
'/^#/m'] =
'##';
864 dolReplaceInFile($dirofmoduletmp.
'/README.md', $arrayreplacement,
'', 0, 0, 1);
865 dolReplaceInFile($dirofmoduletmp.
'/ChangeLog.md', $arrayreplacement,
'', 0, 0, 1);
868 $destfile = $dirofmoduletmp.
'/'.$FILENAMEASCII;
870 $fhandle = fopen($destfile,
'w+');
872 $specs =
dol_dir_list(
dol_buildpath(strtolower($module).
'/doc', 0),
'files', 1,
'(\.md|\.asciidoc)$', array(
'\/temp\/'));
875 foreach ($specs as $spec) {
876 if (preg_match(
'/notindoc/', $spec[
'relativename'])) {
879 if (preg_match(
'/example/', $spec[
'relativename'])) {
882 if (preg_match(
'/disabled/', $spec[
'relativename'])) {
886 $pathtofile = strtolower($module).
'/doc/'.$spec[
'relativename'];
887 $format =
'asciidoc';
888 if (preg_match(
'/\.md$/i', $spec[
'name'])) {
889 $format =
'markdown';
892 $filecursor = @file_get_contents($spec[
'fullname']);
894 fwrite($fhandle, ($i ?
"\n<<<\n\n" :
"").$filecursor.
"\n");
896 $this->error =
'Failed to concat content of file '.$spec[
'fullname'];
905 $contentreadme = file_get_contents($dirofmoduletmp.
'/README.md');
906 $contentchangelog = file_get_contents($dirofmoduletmp.
'/ChangeLog.md');
908 include DOL_DOCUMENT_ROOT.
'/core/lib/parsemd.lib.php';
911 $arrayreplacement = array(
912 'mymodule' => strtolower($module),
913 'MyModule' => $module,
914 'MYMODULE' => strtoupper($module),
915 'My module' => $module,
916 'my module' => $module,
917 'Mon module' => $module,
918 'mon module' => $module,
919 'htdocs/modulebuilder/template' => strtolower($module),
920 '__MYCOMPANY_NAME__' => $mysoc->name,
921 '__KEYWORDS__' => $module,
922 '__USER_FULLNAME__' => $user->getFullName($langs),
923 '__USER_EMAIL__' => $user->email,
925 '---Put here your own copyright and developer email---' =>
dol_print_date($now,
'dayrfc').
' '.$user->getFullName($langs).($user->email ?
' <'.$user->email.
'>' :
''),
926 '__DATA_SPECIFICATION__' =>
'Not yet available',
936 $currentdir = getcwd();
939 require_once DOL_DOCUMENT_ROOT.
'/core/class/utils.class.php';
940 $utils =
new Utils($this->db);
943 $command =
getDolGlobalString(
'MODULEBUILDER_ASCIIDOCTOR') .
' '.$destfile.
' -n -o '.$dirofmoduledoc.
'/'.$FILENAMEDOC;
944 $outfile = $dirofmoduletmp.
'/out.tmp';
946 $resarray = $utils->executeCLI($command, $outfile);
947 if ($resarray[
'result'] !=
'0') {
948 $this->error = $resarray[
'error'].
' '.$resarray[
'output'];
949 $this->errors[] = $this->error;
951 $result = ($resarray[
'result'] == 0) ? 1 : 0;
952 if ($result < 0 && empty($this->errors)) {
953 $this->error = $langs->trans(
"ErrorFailToGenerateFile", $FILENAMEDOC);
954 $this->errors[] = $this->error;
958 $command =
getDolGlobalString(
'MODULEBUILDER_ASCIIDOCTORPDF') .
' '.$destfile.
' -n -o '.$dirofmoduledoc.
'/'.$FILENAMEDOCPDF;
959 $outfile = $dirofmoduletmp.
'/outpdf.tmp';
960 $resarray = $utils->executeCLI($command, $outfile);
961 if ($resarray[
'result'] !=
'0') {
962 $this->error = $resarray[
'error'].
' '.$resarray[
'output'];
963 $this->errors[] = $this->error;
965 $result = ($resarray[
'result'] == 0) ? 1 : 0;
966 if ($result < 0 && empty($this->errors)) {
967 $this->error = $langs->trans(
"ErrorFailToGenerateFile", $FILENAMEDOCPDF);
968 $this->errors[] = $this->error;
983 $langs->load(
"errors");
984 $this->error = $langs->trans(
"ErrorCheckVersionIsDefined");
1001 if (empty($conf->loghandlers[
'mod_syslog_file'])) {
1005 if (!function_exists(
'gzopen')) {
1006 $this->error =
'Support for gzopen not available in this PHP';
1010 require_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
1015 $mainlogdir = DOL_DATA_ROOT;
1016 $mainlog =
'dolibarr.log';
1018 $mainlogfull = str_replace(
'DOL_DATA_ROOT', DOL_DATA_ROOT, $conf->global->SYSLOG_FILE);
1019 $mainlogdir = dirname($mainlogfull);
1020 $mainlog = basename($mainlogfull);
1023 $tabfiles =
dol_dir_list(DOL_DATA_ROOT,
'files', 0,
'^(dolibarr_.+|odt2pdf)\.log$');
1024 $tabfiles[] = array(
'name' => $mainlog,
'path' => $mainlogdir);
1026 foreach ($tabfiles as $file) {
1027 $logname = $file[
'name'];
1028 $logpath = $file[
'path'];
1033 $filter =
'^'.preg_quote($logname,
'/').
'\.([0-9]+)\.gz$';
1035 $gzfilestmp =
dol_dir_list($logpath,
'files', 0, $filter);
1038 foreach ($gzfilestmp as $gzfile) {
1039 $tabmatches = array();
1040 preg_match(
'/'.$filter.
'/i', $gzfile[
'name'], $tabmatches);
1042 $numsave = intval($tabmatches[1]);
1044 $gzfiles[$numsave] = $gzfile;
1047 krsort($gzfiles, SORT_NUMERIC);
1049 foreach ($gzfiles as $numsave => $dummy) {
1050 if (
dol_is_file($logpath.
'/'.$logname.
'.'.($numsave + 1).
'.gz')) {
1054 if ($numsave >= $nbSaves) {
1055 dol_delete_file($logpath.
'/'.$logname.
'.'.$numsave.
'.gz', 0, 0, 0,
null,
false, 0);
1057 dol_move($logpath.
'/'.$logname.
'.'.$numsave.
'.gz', $logpath.
'/'.$logname.
'.'.($numsave + 1).
'.gz', 0, 1, 0, 0);
1064 $gzfilehandle = gzopen($logpath.
'/'.$logname.
'.1.gz',
'wb9');
1066 if (empty($gzfilehandle)) {
1067 $this->error =
'Failted to open file '.$logpath.
'/'.$logname.
'.1.gz';
1071 $sourcehandle = fopen($logpath.
'/'.$logname,
'r');
1073 if (empty($sourcehandle)) {
1074 $this->error =
'Failed to open file '.$logpath.
'/'.$logname;
1078 while (!feof($sourcehandle)) {
1079 gzwrite($gzfilehandle, fread($sourcehandle, 512 * 1024));
1082 fclose($sourcehandle);
1083 gzclose($gzfilehandle);
1085 dolChmod($logpath.
'/'.$logname.
'.1.gz');
1091 $newlog = fopen($logpath.
'/'.$logname,
'a+');
1099 $this->output =
'Archive log files (keeping last SYSLOG_FILE_SAVES='.$nbSaves.
' files) done.';
1300 public function sendBackup($sendto =
'', $from =
'', $subject =
'', $message =
'', $filename =
'', $filter =
'', $sizelimit = 100000000)
1302 global $conf, $langs;
1303 global $dolibarr_main_url_root;
1309 if (!empty($from)) {
1317 if (!empty($sendto)) {
1325 if (!empty($subject)) {
1331 if (empty($message)) {
1335 $tmpfiles = array();
1336 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1338 if (
dol_is_file($conf->admin->dir_output.
'/backup/'.$filename)) {
1344 if ($tmpfiles && is_array($tmpfiles)) {
1345 foreach ($tmpfiles as $key => $val) {
1346 if ($key ==
'fullname') {
1347 $filepath = array($val);
1350 if ($key ==
'type') {
1351 $mimetype = array($val);
1353 if ($key ==
'relativename') {
1354 $filename = array($val);
1360 if ($filesize > $sizelimit) {
1361 $message .=
'<br>'.$langs->trans(
"BackupIsTooLargeSend");
1362 $documenturl = $dolibarr_main_url_root.
'/document.php?modulepart=systemtools&atachement=1&file=backup/'.urlencode($filename[0]);
1363 $message .=
'<br><a href='.$documenturl.
'>Lien de téléchargement</a>';
1369 $output =
'No backup file found';
1374 include_once DOL_DOCUMENT_ROOT .
'/core/class/CMailFile.class.php';
1375 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename,
'',
'', 0, -1);
1376 if ($mailfile->error) {
1378 $output = $mailfile->error;
1384 $result = $mailfile->sendfile();
1387 $output = $mailfile->error;
1393 $this->error =
"Error sending backp file ".((string) $error);
1394 $this->output = $output;