Reduce the size of an export of website template. Removed useless files.

This commit is contained in:
Laurent Destailleur
2024-01-31 18:08:50 +01:00
parent 3f5488c3ae
commit cd7bab52ea
2 changed files with 37 additions and 7 deletions

View File

@@ -62,6 +62,11 @@ abstract class CommonObject
*/
public $id;
/**
* @var int Another ID that is the $id but with an offset so that ID of the website start at 1
*/
public $newid;
/**
* @var int The environment ID when using a multicompany module
*/

View File

@@ -1029,7 +1029,7 @@ class Website extends CommonObject
dolReplaceInFile($htmldeaderindestdir, $arrayreplacementincss);
}
// Build sql file
// Build the website_page.sql file
$filesql = $conf->website->dir_temp.'/'.$website->ref.'/website_pages.sql';
$fp = fopen($filesql, "w");
if (empty($fp)) {
@@ -1040,7 +1040,8 @@ class Website extends CommonObject
$objectpages = new WebsitePage($this->db);
$listofpages = $objectpages->fetchAll($website->id);
// Assign ->newid and ->newfk_page
// Assign ->newid and ->newfk_page starting at 1.
$i = 1;
foreach ($listofpages as $pageid => $objectpageold) {
$objectpageold->newid = $i;
@@ -1059,14 +1060,31 @@ class Website extends CommonObject
$objectpageold->newfk_page = $newfk_page;
$i++;
}
foreach ($listofpages as $pageid => $objectpageold) {
$oldpageid = $objectpageold->id;
$allaliases = $objectpageold->pageurl;
$allaliases .= ($objectpageold->aliasalt ? ','.$objectpageold->aliasalt : '');
$line = '-- File generated by Dolibarr '.DOL_VERSION.' -- '.dol_print_date(dol_now('gmt'), 'standard', 'gmt').' UTC --;';
$line .= "\n";
$line .= '-- Page ID '.$objectpageold->id.' -> '.$objectpageold->newid.'__+MAX_llx_website_page__ - Aliases '.$allaliases.' --;'; // newid start at 1, 2...
if (!getDolGlobalInt('WEBSITE_EXPORT_KEEP_FILES_OF_PAGES')) { // We don't need to keep the PHP files of pages and aliases (they are regenerated at import) so we remove them. You can ask to keep them in the export
// Delete the pageX.tpl.php page
dol_delete_file($conf->website->dir_temp.'/'.$website->ref.'/containers/page'.$objectpageold->id.'.tpl.php', 0, 0, 0, null, false, 0);
// Delete the alias page
dol_delete_file($conf->website->dir_temp.'/'.$website->ref.'/containers/'.$objectpageold->pageurl.'.php', 0, 0, 0, null, false, 0);
dol_delete_file($conf->website->dir_temp.'/'.$website->ref.'/containers/*/'.$objectpageold->pageurl.'.php', 0, 0, 0, null, false, 0);
// Delete alternative alias pages
foreach ($objectpageold->aliasalt as $tmpaliasalt) {
dol_delete_file($conf->website->dir_temp.'/'.$website->ref.'/containers/'.$tmpaliasalt.'.php', 0, 0, 0, null, false, 0);
dol_delete_file($conf->website->dir_temp.'/'.$website->ref.'/containers/*/'.$tmpaliasalt.'.php', 0, 0, 0, null, false, 0);
}
}
// This comment syntax is important, it is parsed by import to get information on page ID and all aliases to regenerate
$line .= '-- Page ID '.$oldpageid.' -> '.$objectpageold->newid.'__+MAX_llx_website_page__ - Aliases '.$allaliases.' --;'; // newid start at 1, 2...
$line .= "\n";
fputs($fp, $line);
@@ -1131,7 +1149,7 @@ class Website extends CommonObject
// Add line to update home page id during import
//var_dump($this->fk_default_home.' - '.$objectpageold->id.' - '.$objectpageold->newid);exit;
if ($this->fk_default_home > 0 && ($objectpageold->id == $this->fk_default_home) && ($objectpageold->newid > 0)) { // This is the record with home page
if ($this->fk_default_home > 0 && ($objectpageold->id == $this->fk_default_home) && ($objectpageold->newid > 0)) { // This is the page that is set as the home page
// Warning: We must keep llx_ here. It is a generic SQL.
$line = "UPDATE llx_website SET fk_default_home = ".($objectpageold->newid > 0 ? $this->db->escape($objectpageold->newid)."__+MAX_llx_website_page__" : "null")." WHERE rowid = __WEBSITE_ID__;";
$line .= "\n";
@@ -1273,7 +1291,7 @@ class Website extends CommonObject
$objectpagestatic->fetch($newid);
// The move is not enough, so we regenerate page
// The move is not enough, so we regenerate pageX.tpl.php
$filetpl = $conf->website->dir_output.'/'.$object->ref.'/page'.$newid.'.tpl.php';
$result = dolSavePageContent($filetpl, $object, $objectpagestatic);
if (!$result) {
@@ -1281,7 +1299,7 @@ class Website extends CommonObject
$error++;
}
// Regenerate alternative aliases pages
// Regenerate also the main alias + alternative aliases pages
if (is_array($aliasesarray)) {
foreach ($aliasesarray as $aliasshortcuttocreate) {
if (trim($aliasshortcuttocreate)) {
@@ -1315,7 +1333,9 @@ class Website extends CommonObject
// Regenerate index page to point to the new index page
$pathofwebsite = $conf->website->dir_output.'/'.$object->ref;
dolSaveIndexPage($pathofwebsite, $pathofwebsite.'/index.php', $pathofwebsite.'/page'.$object->fk_default_home.'.tpl.php', $pathofwebsite.'/wrapper.php', $object);
$this->initFilesStatus($pathofwebsite);
//$this->initFilesStatus($pathofwebsite);
if ($error) {
$this->db->rollback();
return -1;
@@ -1643,6 +1663,8 @@ class Website extends CommonObject
$destdir = getDolGlobalString('WEBSITE_ALLOW_OVERWRITE_GIT_SOURCE');
}
dol_mkdir($destdir);
// Export on target sources
$resultarray = dol_uncompress($pathtotmpzip, $destdir);
if (!empty($resultarray)) {
@@ -1881,9 +1903,11 @@ class Website extends CommonObject
/**
* create file for save state of all files in folder
*
* @param string $sourcedir path of folder
* @return void
*/
/*
public function initFilesStatus($sourcedir)
{
$fichierEtat = $sourcedir . '/filelist-lastwrite-doctemplates.txt';
@@ -1907,6 +1931,7 @@ class Website extends CommonObject
$this->saveState($etatFichiers, $fichierEtat);
}
}
*/
/**
* Compare two files has not same name but same content