Can clone a page

This commit is contained in:
Laurent Destailleur 2017-07-21 13:38:13 +02:00
parent 0d15bf5de1
commit aacef21cb8
5 changed files with 37 additions and 12 deletions

View File

@ -28,4 +28,6 @@
ALTER TABLE llx_facture_fourn ADD COLUMN date_pointoftax date DEFAULT NULL;
ALTER TABLE llx_facture_fourn ADD COLUMN date_valid date;
ALTER TABLE llx_website_page MODIFY COLUMN pageurl varchar(255);

View File

@ -21,7 +21,7 @@ CREATE TABLE llx_website_page
(
rowid integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
fk_website integer NOT NULL,
pageurl varchar(16) NOT NULL,
pageurl varchar(255) NOT NULL,
title varchar(255),
description varchar(255),
keywords varchar(255),

View File

@ -9,7 +9,7 @@ WEBSITE_CSS_URL=URL of external CSS file
WEBSITE_CSS_INLINE=CSS content
PageNameAliasHelp=Name or alias of the page.<br>This alias is also used to forge a SEO URL when website is ran from a Virtual host of a Web server (like Apacke, Nginx, ...). Use the button "<strong>%s</strong>" to edit this alias.
MediaFiles=Media library
EditCss=Edit Style/CSS
EditCss=Edit Style/CSS or HTML header
EditMenu=Edit menu
EditPageMeta=Edit Meta
EditPageContent=Edit Content

View File

@ -482,17 +482,17 @@ class WebsitePage extends CommonObject
/**
* Load an object from its id and create a new one in database
*
* @param int $fromid Id of object to clone
*
* @return int New id of clone
* @param int $fromid Id of object to clone
* @return int New id of clone
*/
public function createFromClone($fromid)
{
global $user, $langs;
dol_syslog(__METHOD__, LOG_DEBUG);
global $user;
$error = 0;
$object = new Websitepage($this->db);
$object = new self($this->db);
$this->db->begin();
@ -502,14 +502,17 @@ class WebsitePage extends CommonObject
$object->id = 0;
// Clear fields
// ...
$object->ref = 'copy_of_'.$object->ref;
$object->pageurl = 'copy_of_'.$object->pageurl;
$object->title = $langs->trans("CopyOf").' '.$object->title;
// Create clone
$result = $object->create($user);
// Other options
if ($result < 0) {
$error ++;
$error++;
$this->error = $object->error;
$this->errors = $object->errors;
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
}
@ -522,7 +525,7 @@ class WebsitePage extends CommonObject
} else {
$this->db->rollback();
return - 1;
return -1;
}
}

View File

@ -101,6 +101,8 @@ if (GETPOST('editmenu')) { $action='editmenu'; }
if (GETPOST('setashome')) { $action='setashome'; }
if (GETPOST('editmeta')) { $action='editmeta'; }
if (GETPOST('editcontent')) { $action='editcontent'; }
if (GETPOST('createfromclone')) { $action='createfromclone'; }
if (GETPOST('createpagefromclone')) { $action='createpagefromclone'; }
if (empty($action)) $action='preview';
@ -505,10 +507,22 @@ if ($action == 'updatemeta')
}
// Update page
if ($action == 'updatecontent' || ($action == 'preview' && (GETPOST('refreshsite') || GETPOST('refreshpage') || GETPOST('preview'))))
if (($action == 'updatecontent' || $action == 'createpagefromclone')
|| ($action == 'preview' && (GETPOST('refreshsite') || GETPOST('refreshpage') || GETPOST('preview'))))
{
$object->fetch(0, $website);
if ($action == 'createpagefromclone')
{
$objectpage = new WebsitePage($db);
$result = $objectpage->createFromClone($pageid);
if ($result < 0)
{
setEventMessages($objectpage->error, $objectpage->errors, 'errors');
$action='preview';
}
}
// Check symlink to medias and restore it if ko
$pathtomedias=DOL_DATA_ROOT.'/medias';
$pathtomediasinwebsite=$pathofwebsite.'/medias';
@ -785,7 +799,7 @@ if (count($object->records) > 0)
//print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("MediaFiles")).'" name="editmedia">';
print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditCss")).'" name="editcss">';
print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditMenu")).'" name="editmenu">';
print '<input type="submit"'.$disabled.' class="button" value="'.dol_escape_htmltag($langs->trans("AddPage")).'" name="create">';
//print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("CloneSite")).'" name="createfromclone">';
}
print '</div>';
@ -834,6 +848,11 @@ if (count($object->records) > 0)
$atleastonepage=(is_array($array) && count($array) > 0);
print '<div class="centpercent websitebar"'.($style?' style="'.$style.'"':'').'">';
print '<div class="websiteselection hideonsmartphoneimp">';
print '<input type="submit"'.$disabled.' class="button" value="'.dol_escape_htmltag($langs->trans("AddPage")).'" name="create">';
print '</div>';
print '<div class="websiteselection hideonsmartphoneimp">';
print $langs->trans("Page").': ';
print '</div>';
@ -891,6 +910,7 @@ if (count($object->records) > 0)
print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageMeta")).'" name="editmeta">';
if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) print '<input type="submit" class="button" disabled="disabled" value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
else print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("ClonePage")).'" name="createpagefromclone">';
print '<input type="submit" class="buttonDelete" name="delete" value="'.$langs->trans("Delete").'"'.($atleastonepage?'':' disabled="disabled"').'>';
}
}