Skip to content

Commit

Permalink
FIX Bad error management in zip compress and web site export
Browse files Browse the repository at this point in the history
Conflicts:
	htdocs/website/index.php
  • Loading branch information
eldy committed Aug 14, 2019
1 parent e1ab508 commit 6de2118
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 7 deletions.
24 changes: 21 additions & 3 deletions htdocs/core/lib/files.lib.php
Expand Up @@ -1892,6 +1892,8 @@ function dol_compress_file($inputfile, $outputfile, $mode = "gz")

try
{
dol_syslog("dol_compress_file mode=".$mode." inputfile=".$inputfile." outputfile=".$outputfile);

$data = implode("", file(dol_osencode($inputfile)));
if ($mode == 'gz') { $foundhandler=1; $compressdata = gzencode($data, 9); }
elseif ($mode == 'bz') { $foundhandler=1; $compressdata = bzcompress($data, 9); }
Expand All @@ -1903,9 +1905,25 @@ function dol_compress_file($inputfile, $outputfile, $mode = "gz")

include_once ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php';
$archive = new PclZip($outputfile);
$archive->add($inputfile, PCLZIP_OPT_REMOVE_PATH, dirname($inputfile));
//$archive->add($inputfile);
return 1;
$result = $archive->add($inputfile, PCLZIP_OPT_REMOVE_PATH, dirname($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;
}
}
}

Expand Down
15 changes: 12 additions & 3 deletions htdocs/website/class/website.class.php
Expand Up @@ -790,7 +790,7 @@ public function initAsSpecimen()
/**
* 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()
{
Expand Down Expand Up @@ -957,9 +957,18 @@ public function exportWebSite()
$filename = $conf->website->dir_temp.'/'.$website->ref.'/website_'.$website->ref.'-'.dol_print_date(dol_now(), 'dayhourlog').'.zip';

dol_delete_file($fileglob, 0);
dol_compress_file($filedir, $filename, 'zip');
$result = dol_compress_file($filedir, $filename, 'zip');

return $filename;
if ($result > 0)
{
return $filename;
}
else
{
global $errormsg;
$this->error = $errormsg;
return '';
}
}


Expand Down
28 changes: 27 additions & 1 deletion htdocs/website/index.php
Expand Up @@ -289,7 +289,7 @@
{
$db->begin();

if (GETPOST('virtualhost', 'alpha') && ! preg_match('/^http/', GETPOST('virtualhost', 'alpha')))
if (GETPOST('virtualhost', 'alpha') && ! preg_match('/^http/', GETPOST('virtualhost', 'alpha')))
{
$error++;
setEventMessages($langs->trans('ErrorURLMustStartWithHttp', $langs->transnoentitiesnoconv("VirtualHost")), null, 'errors');
Expand Down Expand Up @@ -365,6 +365,7 @@
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';

//if (! preg_match('/^http/', $urltograb) && ! preg_match('/^file/', $urltograb))
if (! preg_match('/^http/', $urltograb))
{
$error++;
Expand All @@ -378,6 +379,7 @@
// 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
$urltograbwithoutdomainandparam = preg_replace('/^https?:\/\/[^\/]+\/?/i', '', $urltograb);
//$urltograbwithoutdomainandparam = preg_replace('/^file:\/\/[^\/]+\/?/i', '', $urltograb);
$urltograbwithoutdomainandparam = preg_replace('/\?.*$/', '', $urltograbwithoutdomainandparam);
if (empty($urltograbwithoutdomainandparam) && ! preg_match('/\/$/', $urltograb))
{
Expand Down Expand Up @@ -1600,6 +1602,10 @@
readfile($fileofzip);
exit;
}
else
{
setEventMessages($object->error, $object->errors, 'errors');
}
}

// Import site
Expand Down Expand Up @@ -2949,6 +2955,7 @@

// Ouput page under the Dolibarr top menu
$objectpage->fetch($pageid);

$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";
Expand All @@ -2963,6 +2970,25 @@
$out.="\n<html><head>\n";
$out.="<!-- htmlheader/style of page from database -->\n";
$out.=dolWebsiteReplacementOfLinks($object, $objectpage->htmlheader, 1);

$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.="\n<body>";

Expand Down

0 comments on commit 6de2118

Please sign in to comment.