Skip to content

Commit

Permalink
Can clone a page
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jul 21, 2017
1 parent 0d15bf5 commit aacef21
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
2 changes: 2 additions & 0 deletions htdocs/install/mysql/migration/6.0.0-7.0.0.sql
Expand Up @@ -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);


2 changes: 1 addition & 1 deletion htdocs/install/mysql/tables/llx_website_page.sql
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion htdocs/langs/en_US/website.lang
Expand Up @@ -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
Expand Down
19 changes: 11 additions & 8 deletions htdocs/websites/class/websitepage.class.php
Expand Up @@ -482,17 +482,17 @@ public function delete(User $user, $notrigger = false)
/**
* 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();

Expand All @@ -502,14 +502,17 @@ public function createFromClone($fromid)
$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);
}
Expand All @@ -522,7 +525,7 @@ public function createFromClone($fromid)
} else {
$this->db->rollback();

return - 1;
return -1;
}
}

Expand Down
24 changes: 22 additions & 2 deletions htdocs/websites/index.php
Expand Up @@ -101,6 +101,8 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0,
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';

Expand Down Expand Up @@ -505,10 +507,22 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0,
}

// 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';
Expand Down Expand Up @@ -785,7 +799,7 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=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>';
Expand Down Expand Up @@ -834,6 +848,11 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=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>';
Expand Down Expand Up @@ -891,6 +910,7 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=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"').'>';
}
}
Expand Down

0 comments on commit aacef21

Please sign in to comment.