forked from Wavyzz/dolibarr
FIX Bad error management in zip compress and web site export
This commit is contained in:
@@ -1893,6 +1893,8 @@ function dol_compress_file($inputfile, $outputfile, $mode = "gz")
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
dol_syslog("dol_compress_file mode=".$mode." inputfile=".$inputfile." outputfile=".$outputfile);
|
||||||
|
|
||||||
$data = implode("", file(dol_osencode($inputfile)));
|
$data = implode("", file(dol_osencode($inputfile)));
|
||||||
if ($mode == 'gz') { $foundhandler=1; $compressdata = gzencode($data, 9); }
|
if ($mode == 'gz') { $foundhandler=1; $compressdata = gzencode($data, 9); }
|
||||||
elseif ($mode == 'bz') { $foundhandler=1; $compressdata = bzcompress($data, 9); }
|
elseif ($mode == 'bz') { $foundhandler=1; $compressdata = bzcompress($data, 9); }
|
||||||
@@ -1904,11 +1906,27 @@ function dol_compress_file($inputfile, $outputfile, $mode = "gz")
|
|||||||
|
|
||||||
include_once ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php';
|
include_once ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php';
|
||||||
$archive = new PclZip($outputfile);
|
$archive = new PclZip($outputfile);
|
||||||
$archive->add($inputfile, PCLZIP_OPT_REMOVE_PATH, dirname($inputfile));
|
$result = $archive->add($inputfile, PCLZIP_OPT_REMOVE_PATH, dirname($inputfile));
|
||||||
//$archive->add($inputfile);
|
|
||||||
|
if ($result === 0)
|
||||||
|
{
|
||||||
|
global $errormsg;
|
||||||
|
$errormsg=$archive->errorInfo(true);
|
||||||
|
dol_syslog("dol_compress_file failure - ".$errormsg, LOG_ERR);
|
||||||
|
if ($archive->errorCode() == PCLZIP_ERR_WRITE_OPEN_FAIL)
|
||||||
|
{
|
||||||
|
dol_syslog("dol_compress_file error PCLZIP_ERR_WRITE_OPEN_FAIL", LOG_ERR);
|
||||||
|
return -4;
|
||||||
|
}
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dol_syslog("dol_compress_file success - ".count($result)." files");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($foundhandler)
|
if ($foundhandler)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -790,7 +790,7 @@ class Website extends CommonObject
|
|||||||
/**
|
/**
|
||||||
* Generate a zip with all data of web site.
|
* Generate a zip with all data of web site.
|
||||||
*
|
*
|
||||||
* @return string Path to file with zip
|
* @return string Path to file with zip or '' if error
|
||||||
*/
|
*/
|
||||||
public function exportWebSite()
|
public function exportWebSite()
|
||||||
{
|
{
|
||||||
@@ -957,10 +957,19 @@ class Website extends CommonObject
|
|||||||
$filename = $conf->website->dir_temp.'/'.$website->ref.'/website_'.$website->ref.'-'.dol_print_date(dol_now(), 'dayhourlog').'.zip';
|
$filename = $conf->website->dir_temp.'/'.$website->ref.'/website_'.$website->ref.'-'.dol_print_date(dol_now(), 'dayhourlog').'.zip';
|
||||||
|
|
||||||
dol_delete_file($fileglob, 0);
|
dol_delete_file($fileglob, 0);
|
||||||
dol_compress_file($filedir, $filename, 'zip');
|
$result = dol_compress_file($filedir, $filename, 'zip');
|
||||||
|
|
||||||
|
if ($result > 0)
|
||||||
|
{
|
||||||
return $filename;
|
return $filename;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
global $errormsg;
|
||||||
|
$this->error = $errormsg;
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -414,6 +414,7 @@ if ($action == 'addcontainer')
|
|||||||
{
|
{
|
||||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
|
||||||
|
|
||||||
|
//if (! preg_match('/^http/', $urltograb) && ! preg_match('/^file/', $urltograb))
|
||||||
if (! preg_match('/^http/', $urltograb))
|
if (! preg_match('/^http/', $urltograb))
|
||||||
{
|
{
|
||||||
$error++;
|
$error++;
|
||||||
@@ -427,6 +428,7 @@ if ($action == 'addcontainer')
|
|||||||
// Clean url to grab, so url can be
|
// Clean url to grab, so url can be
|
||||||
// http://www.example.com/ or http://www.example.com/dir1/ or http://www.example.com/dir1/aaa
|
// http://www.example.com/ or http://www.example.com/dir1/ or http://www.example.com/dir1/aaa
|
||||||
$urltograbwithoutdomainandparam = preg_replace('/^https?:\/\/[^\/]+\/?/i', '', $urltograb);
|
$urltograbwithoutdomainandparam = preg_replace('/^https?:\/\/[^\/]+\/?/i', '', $urltograb);
|
||||||
|
//$urltograbwithoutdomainandparam = preg_replace('/^file:\/\/[^\/]+\/?/i', '', $urltograb);
|
||||||
$urltograbwithoutdomainandparam = preg_replace('/\?.*$/', '', $urltograbwithoutdomainandparam);
|
$urltograbwithoutdomainandparam = preg_replace('/\?.*$/', '', $urltograbwithoutdomainandparam);
|
||||||
if (empty($urltograbwithoutdomainandparam) && ! preg_match('/\/$/', $urltograb))
|
if (empty($urltograbwithoutdomainandparam) && ! preg_match('/\/$/', $urltograb))
|
||||||
{
|
{
|
||||||
@@ -1674,6 +1676,10 @@ if ($action == 'exportsite')
|
|||||||
readfile($fileofzip);
|
readfile($fileofzip);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setEventMessages($object->error, $object->errors, 'errors');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Import site
|
// Import site
|
||||||
@@ -3142,6 +3148,7 @@ if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpa
|
|||||||
|
|
||||||
// Ouput page under the Dolibarr top menu
|
// Ouput page under the Dolibarr top menu
|
||||||
$objectpage->fetch($pageid);
|
$objectpage->fetch($pageid);
|
||||||
|
|
||||||
$jscontent = @file_get_contents($filejs);
|
$jscontent = @file_get_contents($filejs);
|
||||||
|
|
||||||
$out = '<!-- Page content '.$filetpl.' : Div with (Htmlheader/Style of page from database + CSS Of website from file + Page content from database or by include if WEBSITE_SUBCONTAINERSINLINE is on) -->'."\n";
|
$out = '<!-- Page content '.$filetpl.' : Div with (Htmlheader/Style of page from database + CSS Of website from file + Page content from database or by include if WEBSITE_SUBCONTAINERSINLINE is on) -->'."\n";
|
||||||
@@ -3156,6 +3163,25 @@ if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpa
|
|||||||
$out.="\n<html><head>\n";
|
$out.="\n<html><head>\n";
|
||||||
$out.="<!-- htmlheader/style of page from database -->\n";
|
$out.="<!-- htmlheader/style of page from database -->\n";
|
||||||
$out.=dolWebsiteReplacementOfLinks($object, $objectpage->htmlheader, 1, 'htmlheader');
|
$out.=dolWebsiteReplacementOfLinks($object, $objectpage->htmlheader, 1, 'htmlheader');
|
||||||
|
|
||||||
|
$out.="<!-- htmlheader/style of website from files -->\n";
|
||||||
|
// TODO Keep only the <link> or the <script> tags
|
||||||
|
/*
|
||||||
|
$htmlheadercontent = @file_get_contents($filehtmlheader);
|
||||||
|
$dom = new DOMDocument;
|
||||||
|
@$dom->loadHTML($htmlheadercontent);
|
||||||
|
$styles = $dom->getElementsByTagName('link');
|
||||||
|
$scripts = $dom->getElementsByTagName('script');
|
||||||
|
foreach($styles as $stylescursor)
|
||||||
|
{
|
||||||
|
$out.=$stylescursor;
|
||||||
|
}
|
||||||
|
foreach($scripts as $scriptscursor)
|
||||||
|
{
|
||||||
|
$out.=$scriptscursor;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
$out.="</head>\n";
|
$out.="</head>\n";
|
||||||
$out.="\n<body>";
|
$out.="\n<body>";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user