diff --git a/htdocs/website/class/website.class.php b/htdocs/website/class/website.class.php
index be91f6640a1..d579a8b3153 100644
--- a/htdocs/website/class/website.class.php
+++ b/htdocs/website/class/website.class.php
@@ -1206,12 +1206,12 @@ class Website extends CommonObject
$newid = ($reg[2] + $maxrowid);
$aliasesarray = explode(',', $reg[3]);
- $objectpagestatic->fetch($newid);
-
dol_syslog("Found ID ".$oldid." to replace with ID ".$newid." and shortcut aliases to create: ".$reg[3]);
dol_move($conf->website->dir_output.'/'.$object->ref.'/page'.$oldid.'.tpl.php', $conf->website->dir_output.'/'.$object->ref.'/page'.$newid.'.tpl.php', 0, 1, 0, 0);
+ $objectpagestatic->fetch($newid);
+
// The move is not enough, so we regenerate page
$filetpl = $conf->website->dir_output.'/'.$object->ref.'/page'.$newid.'.tpl.php';
$result = dolSavePageContent($filetpl, $object, $objectpagestatic);
@@ -1270,6 +1270,84 @@ class Website extends CommonObject
}
}
+ /**
+ * Rebuild all files of a containers of a website. TODO Add other files too.
+ * Note: Files are already regenerated during importWebSite so this function is useless when importing a website.
+ *
+ * @return int <0 if KO, >0 if OK
+ */
+ public function rebuildWebSiteFiles()
+ {
+ global $conf;
+
+ $error = 0;
+
+ $object = $this;
+ if (empty($object->ref))
+ {
+ $this->error = 'Function importWebSite called on object not loaded (object->ref is empty)';
+ return -1;
+ }
+
+ $objectpagestatic = new WebsitePage($this->db);
+
+ $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'website_page WHERE fk_website = '.$this->id;
+
+ $resql = $this->db->query($sql);
+ if (! $resql) {
+ $this->error = $this->db->lasterror();
+ return -1;
+ }
+
+ $num = $this->db->num_rows($resql);
+
+ $i=0;
+ while ($i < $num) {
+ $obj = $this->db->fetch_object($resql);
+
+ $newid = $obj->rowid;
+
+ $objectpagestatic->fetch($newid);
+
+ $aliasesarray = explode(',', $objectpagestatic->aliasalt);
+
+ $filetpl = $conf->website->dir_output.'/'.$object->ref.'/page'.$newid.'.tpl.php';
+ $result = dolSavePageContent($filetpl, $object, $objectpagestatic);
+ if (!$result) {
+ $this->errors[] = 'Failed to write file '.basename($filetpl);
+ $error++;
+ }
+
+ // Regenerate alternative aliases pages
+ if (is_array($aliasesarray))
+ {
+ foreach ($aliasesarray as $aliasshortcuttocreate)
+ {
+ if (trim($aliasshortcuttocreate))
+ {
+ $filealias = $conf->website->dir_output.'/'.$object->ref.'/'.trim($aliasshortcuttocreate).'.php';
+ $result = dolSavePageAlias($filealias, $object, $objectpagestatic);
+ if (!$result) {
+ $this->errors[] = 'Failed to write file '.basename($filealias);
+ $error++;
+ }
+ }
+ }
+ }
+
+ $i++;
+ }
+
+ if ($error)
+ {
+ return -1;
+ }
+ else
+ {
+ return 1;
+ }
+ }
+
/**
* Return if web site is a multilanguage web site. Return false if there is only 0 or 1 language.
*
diff --git a/htdocs/website/index.php b/htdocs/website/index.php
index 1786cfbf078..ba539ccb653 100644
--- a/htdocs/website/index.php
+++ b/htdocs/website/index.php
@@ -1946,7 +1946,23 @@ if ($action == 'exportsite')
else
{
setEventMessages($object->error, $object->errors, 'errors');
- $action = '';
+ $action = 'preview';
+ }
+}
+
+// Regenerate site
+if ($action == 'regeneratesite')
+{
+ $result = $object->rebuildWebSiteFiles();
+ if ($result > 0)
+ {
+ setEventMessages($langs->trans("PagesRegenerated"), null, 'mesgs');
+ $action = 'preview';
+ }
+ else
+ {
+ setEventMessages($object->error, $object->errors, 'errors');
+ $action = 'preview';
}
}
@@ -2254,6 +2270,9 @@ if (!GETPOST('hide_websitemenu'))
*/
print 'ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("ReplaceWebsiteContent")).'">';
+ if (! empty($conf->global->WEBSITE_ADD_REGENERATE_BUTTON)) {
+ print 'ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("RegenerateWebsiteContent")).'">';
+ }
}
print '';