Merge pull request #13776 from ATM-Consulting/9.0_backport_FIX_document_export

FIX Several pb in export of documents
This commit is contained in:
Laurent Destailleur 2020-05-01 20:48:15 +02:00 committed by GitHub
commit 8ed100ca87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 520 additions and 372 deletions

View File

@ -29,15 +29,15 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
$langs->load("admin");
$action=GETPOST('action','alpha');
$action=GETPOST('action', 'alpha');
$sortfield = GETPOST('sortfield','alpha');
$sortorder = GETPOST('sortorder','alpha');
$page = GETPOST('page','int');
$sortfield = GETPOST('sortfield', 'alpha');
$sortorder = GETPOST('sortorder', 'alpha');
$page = GETPOST('page', 'int');
if (! $sortorder) $sortorder="DESC";
if (! $sortfield) $sortfield="date";
if (empty($page) || $page == -1) { $page = 0; }
$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
$limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit;
$offset = $limit * $page;
if (! $user->admin)
@ -50,10 +50,20 @@ if (! $user->admin)
if ($action == 'delete')
{
$file=$conf->admin->dir_output.'/backup/'.basename(GETPOST('urlfile', 'alpha'));
$ret=dol_delete_file($file, 1);
if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
if (preg_match('/^backup\//', GETPOST('urlfile', 'alpha')))
{
$file=$conf->admin->dir_output.'/backup/'.basename(GETPOST('urlfile', 'alpha'));
$ret=dol_delete_file($file, 1);
if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
}
else
{
$file=$conf->admin->dir_output.'/documents/'.basename(GETPOST('urlfile', 'alpha'));
$ret=dol_delete_file($file, 1);
if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
}
$action='';
}
@ -70,7 +80,7 @@ $type=$db->type;
//var_dump($db);
$help_url='EN:Backups|FR:Sauvegardes|ES:Copias_de_seguridad';
llxHeader('','',$help_url);
llxHeader('', '', $help_url);
?>
<script type="text/javascript">
@ -110,11 +120,11 @@ jQuery(document).ready(function() {
</script>
<?php
print load_fiche_titre($langs->trans("Backup"),'','title_setup');
print load_fiche_titre($langs->trans("Backup"), '', 'title_setup');
//print_barre_liste($langs->trans("Backup"), '', '', '', '', '', $langs->trans("BackupDesc",DOL_DATA_ROOT), 0, 0, 'title_setup');
print '<div class="center">';
print $langs->trans("BackupDesc",DOL_DATA_ROOT);
print '<div class="center opacitymedium">';
print $langs->trans("BackupDesc", DOL_DATA_ROOT);
print '</div>';
print '<br>';
@ -128,7 +138,7 @@ print '<br>';
<fieldset id="fieldsetexport"><legend class="legendforfieldsetstep" style="font-size: 3em">1</legend>
<?php
print $langs->trans("BackupDesc3",$dolibarr_main_db_name).'<br>';
print $langs->trans("BackupDesc3", $dolibarr_main_db_name).'<br>';
//print $langs->trans("BackupDescY").'<br>';
print '<br>';
?>
@ -166,7 +176,7 @@ print '<tr '.$bc[false].'><td style="padding-left: 8px">';
</div>
<?php
}
else if (in_array($type, array('pgsql')))
elseif (in_array($type, array('pgsql')))
{
?>
<div class="formelementrow"><input type="radio" name="what" value="postgresql" id="radio_dump_postgresql" />
@ -211,6 +221,7 @@ print '<tr '.$bc[false].'><td style="padding-left: 8px">';
<div class="formelementrow"><input type="checkbox"
name="use_transaction" value="yes" id="checkbox_use_transaction" /> <label
for="checkbox_use_transaction"> <?php echo $langs->trans("UseTransactionnalMode"); ?></label>
</div>
<?php if (! empty($conf->global->MYSQL_OLD_OPTION_DISABLE_FK)) { ?>
@ -233,14 +244,6 @@ print '<tr '.$bc[false].'><td style="padding-left: 8px">';
<option value="ORACLE">ORACLE</option>
<option value="POSTGRESQL">POSTGRESQL</option>
</select> <br>
<input type="checkbox" name="use_mysql_quick_param" value="yes" id="checkbox_use_quick" />
<label for="checkbox_use_quick">
<?php echo $form->textwithpicto(
$langs->trans('ExportUseMySQLQuickParameter'),
$langs->trans('ExportUseMySQLQuickParameterHelp')
); ?>
</label>
<br/>
<!-- <input type="checkbox" name="drop_database" value="yes"
id="checkbox_drop_database" /> <label for="checkbox_drop_database"><?php echo $langs->trans("AddDropDatabase"); ?></label>
-->
@ -453,8 +456,10 @@ print "\n";
<br>
<div align="center"><input type="submit" class="button"
value="<?php echo $langs->trans("GenerateBackup") ?>" id="buttonGo" /><br>
<div class="center">
<input type="submit" class="button reposition" value="<?php echo $langs->trans("GenerateBackup") ?>" id="buttonGo">
<input type="hidden" name="page_y" value="<?php echo GETPOST('page_y', 'int'); ?>">
<br>
<br>
<?php
@ -466,7 +471,7 @@ if (! empty($_SESSION["commandbackuplastdone"]))
//print $paramclear;
// Now run command and show result
// Now show result
print '<b>'.$langs->trans("BackupResult").':</b> ';
print $_SESSION["commandbackupresult"];
@ -476,7 +481,7 @@ if (! empty($_SESSION["commandbackuplastdone"]))
}
if (! empty($_SESSION["commandbackuptorun"]))
{
print '<br><font class="warning">'.$langs->trans("YouMustRunCommandFromCommandLineAfterLoginToUser",$dolibarr_main_db_user,$dolibarr_main_db_user).':</font><br>'."\n";
print '<br><font class="warning">'.$langs->trans("YouMustRunCommandFromCommandLineAfterLoginToUser", $dolibarr_main_db_user, $dolibarr_main_db_user).':</font><br>'."\n";
print '<textarea id="commandbackuptoruntext" rows="'.ROWS_2.'" class="centpercent">'.$_SESSION["commandbackuptorun"].'</textarea><br>'."\n";
print ajax_autoselect("commandbackuptoruntext", 0);
print '<br>';
@ -505,8 +510,8 @@ print '</table>';
<div class="ficheaddleft">
<?php
$filearray=dol_dir_list($conf->admin->dir_output.'/backup','files',0,'','',$sortfield,(strtolower($sortorder)=='asc'?SORT_ASC:SORT_DESC),1);
$result=$formfile->list_of_documents($filearray,null,'systemtools','',1,'backup/',1,0,$langs->trans("NoBackupFileAvailable"),0,$langs->trans("PreviousDumpFiles"));
$filearray=dol_dir_list($conf->admin->dir_output.'/backup', 'files', 0, '', '', $sortfield, (strtolower($sortorder)=='asc'?SORT_ASC:SORT_DESC), 1);
$result=$formfile->list_of_documents($filearray, null, 'systemtools', '', 1, 'backup/', 1, 0, $langs->trans("NoBackupFileAvailable"), 0, $langs->trans("PreviousDumpFiles"));
print '<br>';
?>
@ -526,7 +531,7 @@ print '<br>';
<fieldset><legend class="legendforfieldsetstep" style="font-size: 3em">2</legend>
<?php
print $langs->trans("BackupDesc2",DOL_DATA_ROOT).'<br>';
print $langs->trans("BackupDesc2", DOL_DATA_ROOT).'<br>';
print $langs->trans("BackupDescX").'<br><br>';
?>
@ -582,7 +587,7 @@ print "\n";
?>
<br>
<div align="center"><input type="submit" class="button"
<div class="center"><input type="submit" class="button reposition"
value="<?php echo $langs->trans("GenerateBackup") ?>" id="buttonGo" /><br>
<br>
</div>
@ -593,8 +598,8 @@ print "\n";
<div class="ficheaddleft">
<?php
$filearray=dol_dir_list($conf->admin->dir_output.'/documents','files',0,'','',$sortfield,(strtolower($sortorder)=='asc'?SORT_ASC:SORT_DESC),1);
$result=$formfile->list_of_documents($filearray,null,'systemtools','',1,'documents/',1,0,$langs->trans("NoBackupFileAvailable"),0,$langs->trans("PreviousDumpFiles"));
$filearray=dol_dir_list($conf->admin->dir_output.'/documents', 'files', 0, '', '', $sortfield, (strtolower($sortorder)=='asc'?SORT_ASC:SORT_DESC), 1);
$result=$formfile->list_of_documents($filearray, null, 'systemtools', '', 1, 'documents/', 1, 0, $langs->trans("NoBackupFileAvailable"), 0, $langs->trans("PreviousDumpFiles"));
print '<br>';
?>
@ -605,9 +610,6 @@ print '<br>';
</fieldset>
</form>
<?php
// End of page

View File

@ -30,22 +30,22 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
$langs->load("admin");
$action=GETPOST('action','alpha');
$what=GETPOST('what','alpha');
$export_type=GETPOST('export_type','alpha');
$file=GETPOST('zipfilename_template','alpha');
$action=GETPOST('action', 'alpha');
$what=GETPOST('what', 'alpha');
$export_type=GETPOST('export_type', 'alpha');
$file=GETPOST('zipfilename_template', 'alpha');
$compression = GETPOST('compression');
$file = dol_sanitizeFileName($file);
$sortfield = GETPOST('sortfield','alpha');
$sortorder = GETPOST('sortorder','alpha');
$page = GETPOST("page",'int');
$sortfield = GETPOST('sortfield', 'alpha');
$sortorder = GETPOST('sortorder', 'alpha');
$page = GETPOST("page", 'int');
if (! $sortorder) $sortorder="DESC";
if (! $sortfield) $sortfield="date";
if ($page < 0) { $page = 0; }
elseif (empty($page)) $page = 0;
$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
$limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit;
$offset = $limit * $page;
if (! $user->admin) accessforbidden();
@ -112,21 +112,27 @@ $utils = new Utils($db);
if ($compression == 'zip')
{
$ret = dol_compress_dir(DOL_DATA_ROOT, $outputdir."/".$file, $compression);
$ret = dol_compress_dir(DOL_DATA_ROOT, $outputdir."/".$file, $compression, '/(\.log|\/temp\/|documents\/admin\/documents\/)/');
if ($ret < 0)
{
$errormsg = $langs->trans("ErrorFailedToWriteInDir",$outputfile);
$errormsg = $langs->trans("ErrorFailedToWriteInDir", $outputdir);
}
}
elseif (in_array($compression, array('gz', 'bz')))
{
$file = substr($file, 0, strrpos($file, '.'));
$file .= '.tar';
$cmd = 'tar -cf '.$outputdir."/".$file." --exclude=documents/admin/documents -C ".DOL_DATA_ROOT." ".DOL_DATA_ROOT."/../documents/";
exec($cmd, $out, $retval);
//var_dump($cmd, DOL_DATA_ROOT);exit;
$userlogin = ($user->login ? $user->login : 'unknown');
if ($retval != 0)
$outputfile = $conf->admin->dir_temp.'/export_files.'.$userlogin.'.out'; // File used with popen method
$file = substr($file, 0, strrpos($file, '.'));
$file .= '.tar';
// We also exclude '/temp/' dir and 'documents/admin/documents'
$cmd = "tar -cf ".$outputdir."/".$file." --exclude-vcs --exclude 'temp' --exclude 'dolibarr.log' --exclude='documents/admin/documents' -C ".dirname(DOL_DATA_ROOT)." ".basename(DOL_DATA_ROOT);
$result = $utils->executeCLI($cmd, $outputfile);
$retval = $result['error'];
if ($result['result'] || ! empty($retval))
{
$langs->load("errors");
dol_syslog("Documents tar retval after exec=".$retval, LOG_ERR);
@ -136,15 +142,17 @@ elseif (in_array($compression, array('gz', 'bz')))
{
if ($compression == 'gz')
{
$cmd = "gzip " . $outputdir."/".$file;
$cmd = "gzip -f " . $outputdir."/".$file;
}
if ($compression == 'bz')
{
$cmd = "bzip2 " . $outputdir."/".$file;
$cmd = "bzip2 -f " . $outputdir."/".$file;
}
exec($cmd, $out, $retval);
if ($retval != 0)
$result = $utils->executeCLI($cmd, $outputfile);
$retval = $result['error'];
if ($result['result'] || ! empty($retval))
{
$errormsg = 'Error '.$compression.' generation return '.$retval;
unlink($outputdir."/".$file);
@ -166,4 +174,3 @@ header("Location: dolibarr_export.php");
$time_end = time();
$db->close();

View File

@ -32,15 +32,15 @@ class Utils
*/
public $db;
var $output; // Used by Cron method to return message
var $result; // Used by Cron method to return data
public $output; // Used by Cron method to return message
public $result; // Used by Cron method to return data
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
function __construct($db)
public function __construct($db)
{
$this->db = $db;
}
@ -54,7 +54,7 @@ class Utils
* @param int $nbsecondsold Nb of seconds old to accept deletion of a directory if $choice is 'tempfilesold'
* @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK)
*/
function purgeFiles($choice = 'tempfilesold', $nbsecondsold = 86400)
public function purgeFiles($choice = 'tempfilesold', $nbsecondsold = 86400)
{
global $conf, $langs, $dolibarr_main_data_root;
@ -106,7 +106,7 @@ class Utils
if (! empty($conf->syslog->enabled))
{
$filelog=$conf->global->SYSLOG_FILE;
$filelog=preg_replace('/DOL_DATA_ROOT/i',DOL_DATA_ROOT,$filelog);
$filelog=preg_replace('/DOL_DATA_ROOT/i', DOL_DATA_ROOT, $filelog);
$alreadyincluded=false;
foreach ($filesarray as $tmpcursor)
@ -193,7 +193,7 @@ class Utils
* @param int $execmethod 0=Use default method (that is 1 by default), 1=Use the PHP 'exec', 2=Use the 'popen' method
* @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK)
*/
function dumpDatabase($compression='none', $type='auto', $usedefault=1, $file='auto', $keeplastnfiles=0, $execmethod=0)
public function dumpDatabase($compression = 'none', $type = 'auto', $usedefault = 1, $file = 'auto', $keeplastnfiles = 0, $execmethod = 0)
{
global $db, $conf, $langs, $dolibarr_main_data_root;
global $dolibarr_main_db_name, $dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_port, $dolibarr_main_db_pass;
@ -251,8 +251,8 @@ class Utils
// Parameteres execution
$command = $cmddump;
$command = preg_replace('/(\$|%)/', '', $command); // We removed chars that can be used to inject vars that contains space inside path of command without seeing there is a space to bypass the escapeshellarg.
if (preg_match("/\s/",$command)) $command=escapeshellarg($command); // If there is spaces, we add quotes on command to be sure $command is only a program and not a program+parameters
$command = preg_replace('/(\$|%)/', '', $command); // We removed chars that can be used to inject vars that contains space inside path of command without seeing there is a space to bypass the escapeshellarg.
if (preg_match("/\s/", $command)) $command=escapeshellarg($command); // If there is spaces, we add quotes on command to be sure $command is only a program and not a program+parameters
//$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass);
$param=$dolibarr_main_db_name." -h ".$dolibarr_main_db_host;
@ -262,7 +262,6 @@ class Utils
if (GETPOST("disable_fk", "alpha") || $usedefault) $param.=" -K";
if (GETPOST("sql_compat", "alpha") && GETPOST("sql_compat", "alpha") != 'NONE') $param.=" --compatible=".escapeshellarg(GETPOST("sql_compat", "alpha"));
if (GETPOST("drop_database", "alpha")) $param.=" --add-drop-database";
if (GETPOST("use_mysql_quick_param", "alpha"))$param.=" --quick";
if (GETPOST("sql_structure", "alpha") || $usedefault)
{
if (GETPOST("drop", "alpha") || $usedefault) $param.=" --add-drop-table=TRUE";
@ -292,8 +291,8 @@ class Utils
$paramclear=$param;
if (! empty($dolibarr_main_db_pass))
{
$paramcrypted.=' -p"'.preg_replace('/./i','*',$dolibarr_main_db_pass).'"';
$paramclear.=' -p"'.str_replace(array('"','`'),array('\"','\`'),$dolibarr_main_db_pass).'"';
$paramcrypted.=' -p"'.preg_replace('/./i', '*', $dolibarr_main_db_pass).'"';
$paramclear.=' -p"'.str_replace(array('"','`'), array('\"','\`'), $dolibarr_main_db_pass).'"';
}
$errormsg='';
@ -317,27 +316,29 @@ class Utils
// TODO Replace with executeCLI function
if ($execmethod == 1)
{
exec($fullcommandclear, $readt, $retval);
$result = $retval;
$output_arr = array(); $retval = null;
exec($fullcommandclear, $output_arr, $retval);
if ($retval != 0)
{
$langs->load("errors");
dol_syslog("Datadump retval after exec=".$retval, LOG_ERR);
$error = 'Error '.$retval;
$errormsg = 'Error '.$retval;
$ok=0;
}
else
{
$i=0;
if (!empty($readt))
foreach($readt as $key=>$read)
if (!empty($output_arr))
{
$i++; // output line number
if ($i == 1 && preg_match('/Warning.*Using a password/i', $read)) continue;
fwrite($handle, $read.($execmethod == 2 ? '' : "\n"));
if (preg_match('/'.preg_quote('-- Dump completed').'/i',$read)) $ok=1;
elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES').'/i',$read)) $ok=1;
foreach($output_arr as $key => $read)
{
$i++; // output line number
if ($i == 1 && preg_match('/Warning.*Using a password/i', $read)) continue;
fwrite($handle, $read.($execmethod == 2 ? '' : "\n"));
if (preg_match('/'.preg_quote('-- Dump completed').'/i', $read)) $ok=1;
elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES').'/i', $read)) $ok=1;
}
}
}
}
@ -351,9 +352,9 @@ class Utils
$read = fgets($handlein);
// Exclude warning line we don't want
if ($i == 1 && preg_match('/Warning.*Using a password/i', $read)) continue;
fwrite($handle,$read);
if (preg_match('/'.preg_quote('-- Dump completed').'/i',$read)) $ok=1;
elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES').'/i',$read)) $ok=1;
fwrite($handle, $read);
if (preg_match('/'.preg_quote('-- Dump completed').'/i', $read)) $ok=1;
elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES').'/i', $read)) $ok=1;
}
pclose($handlein);
}
@ -369,7 +370,7 @@ class Utils
else
{
$langs->load("errors");
dol_syslog("Failed to open file ".$outputfile,LOG_ERR);
dol_syslog("Failed to open file ".$outputfile, LOG_ERR);
$errormsg=$langs->trans("ErrorFailedToWriteInDir");
}
@ -380,18 +381,18 @@ class Utils
if ($handle)
{
// Get 2048 first chars of error message.
$errormsg = fgets($handle,2048);
$errormsg = fgets($handle, 2048);
// Close file
if ($compression == 'none') fclose($handle);
if ($compression == 'gz') gzclose($handle);
if ($compression == 'bz') bzclose($handle);
if ($ok && preg_match('/^-- MySql/i',$errormsg)) $errormsg=''; // Pas erreur
if ($ok && preg_match('/^-- MySql/i', $errormsg)) $errormsg=''; // Pas erreur
else
{
// Renommer fichier sortie en fichier erreur
//print "$outputfile -> $outputerror";
@dol_delete_file($outputerror, 1, 0, 0, null, false, 0);
@rename($outputfile,$outputerror);
@rename($outputfile, $outputerror);
// Si safe_mode on et command hors du parametre exec, on a un fichier out vide donc errormsg vide
if (! $errormsg)
{
@ -450,8 +451,8 @@ class Utils
// Parameteres execution
$command = $cmddump;
$command = preg_replace('/(\$|%)/', '', $command); // We removed chars that can be used to inject vars that contains space inside path of command without seeing there is a space to bypass the escapeshellarg.
if (preg_match("/\s/",$command)) $command=escapeshellarg($command); // If there is spaces, we add quotes on command to be sure $command is only a program and not a program+parameters
$command = preg_replace('/(\$|%)/', '', $command); // We removed chars that can be used to inject vars that contains space inside path of command without seeing there is a space to bypass the escapeshellarg.
if (preg_match("/\s/", $command)) $command=escapeshellarg($command); // If there is spaces, we add quotes on command to be sure $command is only a program and not a program+parameters
//$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass);
//$param="-F c";
@ -515,7 +516,7 @@ class Utils
* @param int $execmethod 0=Use default method (that is 1 by default), 1=Use the PHP 'exec', 2=Use the 'popen' method
* @return array array('result'=>...,'output'=>...,'error'=>...). result = 0 means OK.
*/
function executeCLI($command, $outputfile, $execmethod=0)
public function executeCLI($command, $outputfile, $execmethod = 0)
{
global $conf, $langs;
@ -535,6 +536,7 @@ class Utils
if ($execmethod == 1)
{
$retval = null;
exec($command, $output_arr, $retval);
$result = $retval;
if ($retval != 0)
@ -546,7 +548,6 @@ class Utils
}
if ($execmethod == 2) // With this method, there is no way to get the return code, only output
{
$ok=0;
$handle = fopen($outputfile, 'w+b');
if ($handle)
{
@ -555,7 +556,7 @@ class Utils
while (!feof($handlein))
{
$read = fgets($handlein);
fwrite($handle,$read);
fwrite($handle, $read);
$output_arr[]=$read;
}
pclose($handlein);
@ -584,14 +585,15 @@ class Utils
* @param string $module Module name
* @return int <0 if KO, >0 if OK
*/
function generateDoc($module)
public function generateDoc($module)
{
global $conf, $langs;
global $conf, $langs, $user, $mysoc;
global $dirins;
$error = 0;
$modulelowercase=strtolower($module);
$now=dol_now();
// Dir for module
$dir = $dirins.'/'.$modulelowercase;
@ -621,11 +623,12 @@ class Utils
exit;
}
$arrayversion=explode('.',$moduleobj->version,3);
$arrayversion=explode('.', $moduleobj->version, 3);
if (count($arrayversion))
{
$FILENAMEASCII=strtolower($module).'.asciidoc';
$FILENAMEDOC=strtolower($module).'.html'; // TODO Use/text PDF
$FILENAMEDOC=strtolower($module).'.html';
$FILENAMEDOCPDF=strtolower($module).'.pdf';
$dirofmodule = dol_buildpath(strtolower($module), 0);
$dirofmoduledoc = dol_buildpath(strtolower($module), 0).'/doc';
@ -641,13 +644,25 @@ class Utils
return -1;
}
$conf->global->MODULEBUILDER_ASCIIDOCTOR='asciidoctor';
if (empty($conf->global->MODULEBUILDER_ASCIIDOCTOR))
if (empty($conf->global->MODULEBUILDER_ASCIIDOCTOR) && empty($conf->global->MODULEBUILDER_ASCIIDOCTORPDF))
{
$this->error = 'Setup of module ModuleBuilder not complete';
return -1;
}
// Copy some files into temp directory, so instruction include::ChangeLog.md[] will works inside the asciidoc file.
dol_copy($dirofmodule.'/README.md', $dirofmoduletmp.'/README.md', 0, 1);
dol_copy($dirofmodule.'/ChangeLog.md', $dirofmoduletmp.'/ChangeLog.md', 0, 1);
// Replace into README.md and ChangeLog.md (in case they are included into documentation with tag __README__ or __CHANGELOG__)
$arrayreplacement=array();
$arrayreplacement['/^#\s.*/m']=''; // Remove first level of title into .md files
$arrayreplacement['/^#/m']='##'; // Add on # to increase level
dolReplaceInFile($dirofmoduletmp.'/README.md', $arrayreplacement, '', 0, 0, 1);
dolReplaceInFile($dirofmoduletmp.'/ChangeLog.md', $arrayreplacement, '', 0, 0, 1);
$destfile=$dirofmoduletmp.'/'.$FILENAMEASCII;
$fhandle = fopen($destfile, 'w+');
@ -680,35 +695,48 @@ class Utils
$i++;
}
fwrite($fhandle, "\n\n\n== DATA SPECIFICATIONS...\n\n");
// TODO
fwrite($fhandle, "TODO...");
fwrite($fhandle, "\n\n\n== CHANGELOG...\n\n");
// TODO
fwrite($fhandle, "TODO...");
fclose($fhandle);
}
// Copy some files into temp directory
dol_copy($dirofmodule.'/README.md', $dirofmoduletmp.'/README.md', 0, 1);
dol_copy($dirofmodule.'/ChangeLog.md', $dirofmoduletmp.'/ChangeLog.md', 0, 1);
$contentreadme=file_get_contents($dirofmoduletmp.'/README.md');
$contentchangelog=file_get_contents($dirofmoduletmp.'/ChangeLog.md');
include DOL_DOCUMENT_ROOT.'/core/lib/parsemd.lib.php';
//var_dump($phpfileval['fullname']);
$arrayreplacement=array(
'mymodule'=>strtolower($module),
'MyModule'=>$module,
'MYMODULE'=>strtoupper($module),
'My module'=>$module,
'my module'=>$module,
'Mon module'=>$module,
'mon module'=>$module,
'htdocs/modulebuilder/template'=>strtolower($module),
'__MYCOMPANY_NAME__'=>$mysoc->name,
'__KEYWORDS__'=>$module,
'__USER_FULLNAME__'=>$user->getFullName($langs),
'__USER_EMAIL__'=>$user->email,
'__YYYY-MM-DD__'=>dol_print_date($now, 'dayrfc'),
'---Put here your own copyright and developer email---'=>dol_print_date($now, 'dayrfc').' '.$user->getFullName($langs).($user->email?' <'.$user->email.'>':''),
'__DATA_SPECIFICATION__'=>'Not yet available',
'__README__'=>dolMd2Asciidoc($contentreadme),
'__CHANGELOG__'=>dolMd2Asciidoc($contentchangelog),
);
dolReplaceInFile($destfile, $arrayreplacement);
}
// Launch doc generation
$currentdir = getcwd();
chdir($dirofmodule);
require_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
$utils = new Utils($db);
// Build HTML doc
$command=$conf->global->MODULEBUILDER_ASCIIDOCTOR.' '.$destfile.' -n -o '.$dirofmoduledoc.'/'.$FILENAMEDOC;
$outfile=$dirofmoduletmp.'/out.tmp';
require_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
$utils = new Utils($this->db);
$resarray = $utils->executeCLI($command, $outfile);
if ($resarray['result'] != '0')
{
@ -716,6 +744,16 @@ class Utils
}
$result = ($resarray['result'] == 0) ? 1 : 0;
// Build PDF doc
$command=$conf->global->MODULEBUILDER_ASCIIDOCTORPDF.' '.$destfile.' -n -o '.$dirofmoduledoc.'/'.$FILENAMEDOCPDF;
$outfile=$dirofmoduletmp.'/outpdf.tmp';
$resarray = $utils->executeCLI($command, $outfile);
if ($resarray['result'] != '0')
{
$this->error = $resarray['error'].' '.$resarray['output'];
}
$result = ($resarray['result'] == 0) ? 1 : 0;
chdir($currentdir);
}
else
@ -751,7 +789,7 @@ class Utils
*
* @return int 0 if OK, < 0 if KO
*/
function compressSyslogs()
public function compressSyslogs()
{
global $conf;
@ -857,7 +895,7 @@ class Utils
$this->output = 'Archive log files (keeping last SYSLOG_FILE_SAVES='.$nbSaves.' files) done.';
return 0;
}
}
/** Backup the db OR just a table without mysqldump binary, with PHP only (does not require any exec permission)
* Author: David Walsh (http://davidwalsh.name/backup-mysql-database-php)
@ -869,7 +907,7 @@ class Utils
* @param string $tables Table name or '*' for all
* @return int <0 if KO, >0 if OK
*/
function backupTables($outputfile, $tables='*')
public function backupTables($outputfile, $tables = '*')
{
global $db, $langs;
global $errormsg;
@ -896,7 +934,7 @@ class Utils
}
else
{
$tables = is_array($tables) ? $tables : explode(',',$tables);
$tables = is_array($tables) ? $tables : explode(',', $tables);
}
//cycle through
@ -904,7 +942,7 @@ class Utils
if (fwrite($handle, '') === false)
{
$langs->load("errors");
dol_syslog("Failed to open file ".$outputfile,LOG_ERR);
dol_syslog("Failed to open file ".$outputfile, LOG_ERR);
$errormsg=$langs->trans("ErrorFailedToWriteInDir");
return -1;
}
@ -947,9 +985,9 @@ class Utils
// Saving the table structure
fwrite($handle, "\n--\n-- Table structure for table `".$table."`\n--\n");
if (GETPOST("nobin_drop")) fwrite($handle,"DROP TABLE IF EXISTS `".$table."`;\n"); // Dropping table if exists prior to re create it
fwrite($handle,"/*!40101 SET @saved_cs_client = @@character_set_client */;\n");
fwrite($handle,"/*!40101 SET character_set_client = utf8 */;\n");
if (GETPOST("nobin_drop")) fwrite($handle, "DROP TABLE IF EXISTS `".$table."`;\n"); // Dropping table if exists prior to re create it
fwrite($handle, "/*!40101 SET @saved_cs_client = @@character_set_client */;\n");
fwrite($handle, "/*!40101 SET character_set_client = utf8 */;\n");
$resqldrop=$db->query('SHOW CREATE TABLE '.$table);
$row2 = $db->fetch_row($resqldrop);
if (empty($row2[1]))
@ -958,7 +996,7 @@ class Utils
}
else
{
fwrite($handle,$row2[1].";\n");
fwrite($handle, $row2[1].";\n");
//fwrite($handle,"/*!40101 SET character_set_client = @saved_cs_client */;\n\n");
// Dumping the data (locking the table and disabling the keys check while doing the process)
@ -972,7 +1010,7 @@ class Utils
while($row = $db->fetch_row($result))
{
// For each row of data we print a line of INSERT
fwrite($handle,'INSERT '.$delayed.$ignore.'INTO `'.$table.'` VALUES (');
fwrite($handle, 'INSERT '.$delayed.$ignore.'INTO `'.$table.'` VALUES (');
$columns = count($row);
for($j=0; $j<$columns; $j++) {
// Processing each columns of the row to ensure that we correctly save the value (eg: add quotes for string - in fact we add quotes for everything, it's easier)
@ -991,11 +1029,11 @@ class Utils
$row[$j] = "'".$row[$j]."'";
}
}
fwrite($handle,implode(',', $row).");\n");
fwrite($handle, implode(',', $row).");\n");
}
if (GETPOST("nobin_disable_fk")) fwrite($handle, "ALTER TABLE `".$table."` ENABLE KEYS;\n"); // Enabling back the keys/index checking
if (!GETPOST("nobin_nolocks")) fwrite($handle, "UNLOCK TABLES;\n"); // Unlocking the table
fwrite($handle,"\n\n\n");
fwrite($handle, "\n\n\n");
}
}

File diff suppressed because it is too large Load Diff