Merge branch '12.0' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2020-05-20 13:20:12 +02:00
commit 3b7f3cf76a
2 changed files with 100 additions and 3 deletions

View File

@ -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.
*

View File

@ -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 '<a href="'.$_SERVER["PHP_SEFL"].'?action=replacesite&website='.$website->ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("ReplaceWebsiteContent")).'"><span class="fa fa-search"><span></a>';
if (! empty($conf->global->WEBSITE_ADD_REGENERATE_BUTTON)) {
print '<a href="'.$_SERVER["PHP_SEFL"].'?action=regeneratesite&website='.$website->ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("RegenerateWebsiteContent")).'"><span class="fa fa-cogs"><span></a>';
}
}
print '</span>';