Some fix into dol_compress_dir function.
This commit is contained in:
parent
330f3af74d
commit
d832bfc056
@ -47,7 +47,7 @@ function dol_basename($pathfile)
|
||||
* @param string $filter Regex filter to restrict list. This regex value must be escaped for '/' by doing preg_quote($var,'/'), since this char is used for preg_match function,
|
||||
* but must not contains the start and end '/'. Filter is checked into basename only.
|
||||
* @param array $excludefilter Array of Regex for exclude filter (example: array('(\.meta|_preview.*\.png)$','^\.')). Exclude is checked into fullpath.
|
||||
* @param string $sortcriteria Sort criteria ("","fullname","name","date","size")
|
||||
* @param string $sortcriteria Sort criteria ("","fullname","relativename","name","date","size")
|
||||
* @param string $sortorder Sort order (SORT_ASC, SORT_DESC)
|
||||
* @param int $mode 0=Return array minimum keys loaded (faster), 1=Force all keys like date and size to be loaded (slower), 2=Force load of date only, 3=Force load of size only
|
||||
* @param int $nohook Disable all hooks
|
||||
@ -1692,7 +1692,7 @@ function dol_uncompress($inputfile,$outputdir)
|
||||
* Compress a directory and subdirectories into a package file.
|
||||
*
|
||||
* @param string $inputdir Source dir name
|
||||
* @param string $outputfile Target file name
|
||||
* @param string $outputfile Target file name (output directory must exists and be writable)
|
||||
* @param string $mode 'zip'
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
@ -1701,6 +1701,15 @@ function dol_compress_dir($inputdir, $outputfile, $mode="zip")
|
||||
$foundhandler=0;
|
||||
|
||||
dol_syslog("Try to zip dir ".$inputdir." into ".$outputdir." mode=".$mode);
|
||||
|
||||
if (! dol_is_dir(dirname($outputfile)) || ! is_writable(dirname($outputfile)))
|
||||
{
|
||||
global $langs, $errormsg;
|
||||
$langs->load("errors");
|
||||
$errormsg=$langs->trans("ErrorFailedToWriteInDir",$outputfile);
|
||||
return -3;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if ($mode == 'gz') { $foundhandler=0; }
|
||||
@ -1724,7 +1733,7 @@ function dol_compress_dir($inputdir, $outputfile, $mode="zip")
|
||||
|
||||
// Initialize archive object
|
||||
$zip = new ZipArchive();
|
||||
$zip->open($outputfile, ZipArchive::CREATE | ZipArchive::OVERWRITE);
|
||||
$result = $zip->open($outputfile, ZipArchive::CREATE | ZipArchive::OVERWRITE);
|
||||
|
||||
// Create recursive directory iterator
|
||||
/** @var SplFileInfo[] $files */
|
||||
@ -1759,6 +1768,10 @@ function dol_compress_dir($inputdir, $outputfile, $mode="zip")
|
||||
dol_syslog("Try to zip with format ".$mode." with no handler for this format",LOG_ERR);
|
||||
return -2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
@ -17,6 +17,7 @@ TextPreviousMonthOfInvoice=Previous month (text) of invoice date
|
||||
NextMonthOfInvoice=Following month (number 1-12) of invoice date
|
||||
TextNextMonthOfInvoice=Following month (text) of invoice date
|
||||
ZipFileGeneratedInto=Zip file generated into <b>%s</b>.
|
||||
DocFileGeneratedInto=Doc file generated into <b>%s</b>.
|
||||
|
||||
YearOfInvoice=Year of invoice date
|
||||
PreviousYearOfInvoice=Previous year of invoice date
|
||||
|
||||
@ -426,9 +426,19 @@ if ($dirins && $action == 'generatepackage')
|
||||
if (count($arrayversion))
|
||||
{
|
||||
$FILENAMEZIP="module_".$modulelowercase.'-'.$arrayversion[0].'.'.$arrayversion[1].($arrayversion[2]?".".$arrayversion[2]:"").".zip";
|
||||
$outputfile = $conf->admin->dir_temp.'/'.$FILENAMEZIP;
|
||||
|
||||
$result = dol_compress_dir($dir, $outputfile, 'zip');
|
||||
$dirofmodule = dol_buildpath($modulelowercase, 0).'/bin';
|
||||
$outputfile = $dirofmodule.'/'.$FILENAMEZIP;
|
||||
if ($dirofmodule)
|
||||
{
|
||||
if (! dol_is_dir($dirofmodule)) dol_mkdir($dirofmodule);
|
||||
$result = dol_compress_dir($dir, $outputfile, 'zip');
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = -1;
|
||||
}
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
setEventMessages($langs->trans("ZipFileGeneratedInto", $outputfile), null);
|
||||
@ -448,6 +458,76 @@ if ($dirins && $action == 'generatepackage')
|
||||
}
|
||||
}
|
||||
|
||||
if ($dirins && $action == 'generatedoc')
|
||||
{
|
||||
$modulelowercase=strtolower($module);
|
||||
|
||||
// Dir for module
|
||||
$dir = $dirins.'/'.$modulelowercase;
|
||||
// Zip file to build
|
||||
$FILENAMEDOC='';
|
||||
|
||||
// Load module
|
||||
dol_include_once($modulelowercase.'/core/modules/mod'.$module.'.class.php');
|
||||
$class='mod'.$module;
|
||||
|
||||
if (class_exists($class))
|
||||
{
|
||||
try {
|
||||
$moduleobj = new $class($db);
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
$error++;
|
||||
dol_print_error($e->getMessage());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
$langs->load("errors");
|
||||
dol_print_error($langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
|
||||
exit;
|
||||
}
|
||||
|
||||
$arrayversion=explode('.',$moduleobj->version,3);
|
||||
if (count($arrayversion))
|
||||
{
|
||||
$FILENAMEDOC=$modulelowercase.'.html';
|
||||
|
||||
$dirofmodule = dol_buildpath($modulelowercase, 0).'/doc';
|
||||
$outputfile = $dirofmodule.'/'.$FILENAMEDOC;
|
||||
if ($dirofmodule)
|
||||
{
|
||||
if (! dol_is_dir($dirofmodule)) dol_mkdir($dirofmodule);
|
||||
//...
|
||||
|
||||
$result = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = 0;
|
||||
}
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
setEventMessages($langs->trans("DocFileGeneratedInto", $outputfile), null);
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
$langs->load("errors");
|
||||
setEventMessages($langs->trans("ErrorFailToGenerateFile", $outputfile), null, 'errors');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
$langs->load("errors");
|
||||
setEventMessages($langs->trans("ErrorCheckVersionIsDefined"), null, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
// Save file
|
||||
if ($action == 'savefile' && empty($cancel))
|
||||
{
|
||||
@ -1408,10 +1488,10 @@ elseif (! empty($module))
|
||||
if (count($arrayversion))
|
||||
{
|
||||
$FILENAMEZIP="module_".$modulelowercase.'-'.$arrayversion[0].'.'.$arrayversion[1].($arrayversion[2]?".".$arrayversion[2]:"").".zip";
|
||||
$outputfile = $conf->admin->dir_temp.'/'.$FILENAMEZIP;
|
||||
$outputfile = dol_buildpath($modulelowercase, 0).'/bin/'.$FILENAMEZIP;
|
||||
|
||||
$FILENAMEDOC="module_".$modulelowercase.'-'.$arrayversion[0].'.'.$arrayversion[1].($arrayversion[2]?".".$arrayversion[2]:"").".md";
|
||||
$outputfiledoc = $conf->admin->dir_temp.'/'.$FILENAMEDOC;
|
||||
$FILENAMEDOC=$modulelowercase.'.html';
|
||||
$outputfiledoc = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOC;
|
||||
}
|
||||
|
||||
print '<br>';
|
||||
@ -1430,7 +1510,7 @@ elseif (! empty($module))
|
||||
print '<input type="hidden" name="action" value="generatepackage">';
|
||||
print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
|
||||
print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
|
||||
print '<input type="submit" class="button" value="'.$langs->trans("BuildPackage").'">';
|
||||
print '<input type="submit" class="button" name="generatepackage" value="'.$langs->trans("BuildPackage").'">';
|
||||
print '</form>';
|
||||
|
||||
print '<br><br><br>';
|
||||
@ -1445,11 +1525,11 @@ elseif (! empty($module))
|
||||
|
||||
print '<br>';
|
||||
|
||||
print '<form name="generatepackage">';
|
||||
print '<form name="generatedoc">';
|
||||
print '<input type="hidden" name="action" value="generatedoc">';
|
||||
print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
|
||||
print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
|
||||
print '<input type="submit" class="button" value="'.$langs->trans("BuildDocumentation").'">';
|
||||
print '<input type="submit" class="button" name="generatedoc" value="'.$langs->trans("BuildDocumentation").'">';
|
||||
print '</form>';
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user