Fix export of website

This commit is contained in:
Laurent Destailleur 2022-08-03 21:30:40 +02:00
parent 661bf6a131
commit 3108cd12fb
2 changed files with 22 additions and 3 deletions

View File

@ -164,6 +164,8 @@ class modWebsite extends DolibarrModules
{
global $conf, $langs;
$error = 0;
$result = $this->_load_tables('/install/mysql/', 'website');
if ($result < 0) {
return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default')
@ -185,11 +187,16 @@ class modWebsite extends DolibarrModules
if ($result < 0) {
$langs->load("errors");
$this->error = $langs->trans('ErrorFailToCopyDir', $src, $dest);
return 0;
$this->errors[] = $langs->trans('ErrorFailToCopyDir', $src, $dest);
$error++;
}
}
}
if ($error) {
return 0;
}
// Website templates
$srcroot = DOL_DOCUMENT_ROOT.'/install/doctemplates/websites';
$destroot = DOL_DATA_ROOT.'/doctemplates/websites';
@ -205,9 +212,15 @@ class modWebsite extends DolibarrModules
if ($result < 0) {
$langs->load("errors");
$this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
$this->errors[] = $langs->trans('ErrorFailToCopyFile', $src, $dest);
$error++;
}
}
if ($error) {
return 0;
}
$sql = array();
return $this->_init($sql, $options);

View File

@ -1059,29 +1059,35 @@ class Website extends CommonObject
$line .= "'".$this->db->escape($objectpageold->grabbed_from)."', ";
$line .= "'".$this->db->escape($objectpageold->type_container)."', ";
// Make substitution with a generic path into htmlheader content
$stringtoexport = $objectpageold->htmlheader;
$stringtoexport = str_replace(array("\r\n", "\r", "\n"), "__N__", $stringtoexport);
$stringtoexport = str_replace('file=image/'.$website->ref.'/', "file=image/__WEBSITE_KEY__/", $stringtoexport);
$stringtoexport = str_replace('file=js/'.$website->ref.'/', "file=js/__WEBSITE_KEY__/", $stringtoexport);
$stringtoexport = str_replace('medias/image/'.$website->ref.'/', "medias/image/__WEBSITE_KEY__/", $stringtoexport);
$stringtoexport = str_replace('medias/js/'.$website->ref.'/', "medias/js/__WEBSITE_KEY__/", $stringtoexport);
$stringtoexport = str_replace('file=logos%2Fthumbs%2F'.$mysoc->logo_small, "file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__", $stringtoexport);
$stringtoexport = str_replace('file=logos%2Fthumbs%2F'.$mysoc->logo_mini, "file=logos%2Fthumbs%2F__LOGO_MINI_KEY__", $stringtoexport);
$stringtoexport = str_replace('file=logos%2Fthumbs%2F'.$mysoc->logo, "file=logos%2Fthumbs%2F__LOGO_KEY__", $stringtoexport);
$line .= "'".$this->db->escape(str_replace(array("\r\n", "\r", "\n"), "__N__", $stringtoexport))."', "; // Replace \r \n to have record on 1 line
// Make substitution with a generic path into page content
$stringtoexport = $objectpageold->content;
$stringtoexport = str_replace(array("\r\n", "\r", "\n"), "__N__", $stringtoexport);
$stringtoexport = str_replace('file=image/'.$website->ref.'/', "file=image/__WEBSITE_KEY__/", $stringtoexport);
$stringtoexport = str_replace('file=js/'.$website->ref.'/', "file=js/__WEBSITE_KEY__/", $stringtoexport);
$stringtoexport = str_replace('medias/image/'.$website->ref.'/', "medias/image/__WEBSITE_KEY__/", $stringtoexport);
$stringtoexport = str_replace('medias/js/'.$website->ref.'/', "medias/js/__WEBSITE_KEY__/", $stringtoexport);
$stringtoexport = str_replace('"image/'.$website->ref.'/', '"image/__WEBSITE_KEY__/', $stringtoexport); // When we have a link src="image/websiteref/file.png" into html content
$stringtoexport = str_replace('"/image/'.$website->ref.'/', '"/image/__WEBSITE_KEY__/', $stringtoexport); // When we have a link src="/image/websiteref/file.png" into html content
$stringtoexport = str_replace('"js/'.$website->ref.'/', '"js/__WEBSITE_KEY__/', $stringtoexport);
$stringtoexport = str_replace('"/js/'.$website->ref.'/', '"/js/__WEBSITE_KEY__/', $stringtoexport);
$stringtoexport = str_replace('file=logos%2Fthumbs%2F'.$mysoc->logo_small, "file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__", $stringtoexport);
$stringtoexport = str_replace('file=logos%2Fthumbs%2F'.$mysoc->logo_mini, "file=logos%2Fthumbs%2F__LOGO_MINI_KEY__", $stringtoexport);
$stringtoexport = str_replace('file=logos%2Fthumbs%2F'.$mysoc->logo, "file=logos%2Fthumbs%2F__LOGO_KEY__", $stringtoexport);
// When we have a link src="image/websiteref/file.png" into html content
$stringtoexport = str_replace('="image/'.$website->ref.'/', '="image/__WEBSITE_KEY__/', $stringtoexport);
$line .= "'".$this->db->escape($stringtoexport)."', "; // Replace \r \n to have record on 1 line
$line .= "'".$this->db->escape($objectpageold->author_alias)."', ";