Fix clone of page
This commit is contained in:
parent
58e5eeabdd
commit
4716b82249
@ -421,10 +421,10 @@ class WebsitePage extends CommonObject
|
||||
* @param string $newlang New language
|
||||
* @param int $istranslation 1=New page is a translation of the cloned page.
|
||||
* @param int $newwebsite 0=Same web site, >0=Id of new website
|
||||
* @param int $keeptitleunchanged 1=Keep title unchanged
|
||||
* @param string $newtitle New title
|
||||
* @return mixed New object created, <0 if KO
|
||||
*/
|
||||
public function createFromClone(User $user, $fromid, $newref, $newlang = '', $istranslation = 0, $newwebsite = 0, $keeptitleunchanged = 0)
|
||||
public function createFromClone(User $user, $fromid, $newref, $newlang = '', $istranslation = 0, $newwebsite = 0, $newtitle = '')
|
||||
{
|
||||
global $hookmanager, $langs;
|
||||
|
||||
@ -435,6 +435,18 @@ class WebsitePage extends CommonObject
|
||||
|
||||
$object = new self($this->db);
|
||||
|
||||
// Clean parameters
|
||||
if (empty($newref) && ! empty($newtitle)) {
|
||||
$newref=strtolower(dol_sanitizeFileName(preg_replace('/\s+/', '-', $newtitle), '-', 1));
|
||||
}
|
||||
|
||||
// Check parameters
|
||||
if (empty($newref)) {
|
||||
$langs->load("errors");
|
||||
$this->error=$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_TITLE"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
// Load source object
|
||||
@ -448,7 +460,7 @@ class WebsitePage extends CommonObject
|
||||
$object->aliasalt = '';
|
||||
$object->fk_user_creat = $user->id;
|
||||
$object->date_creation = $now;
|
||||
$object->title = ($keeptitleunchanged ? '' : $langs->trans("CopyOf").' ').$object->title;
|
||||
$object->title = ($newtitle == '1' ? $object->title : ($newtitle ? $newtitle : $object->title));
|
||||
if (!empty($newlang)) $object->lang = $newlang;
|
||||
if ($istranslation) $object->fk_page = $fromid;
|
||||
else $object->fk_page = 0;
|
||||
|
||||
@ -1563,6 +1563,7 @@ if (($action == 'updatesource' || $action == 'updatecontent' || $action == 'conf
|
||||
if ($action == 'confirm_createpagefromclone')
|
||||
{
|
||||
$istranslation = (GETPOST('is_a_translation', 'aZ09') == 'on' ? 1 : 0);
|
||||
// Protection if it is a translation page
|
||||
if ($istranslation)
|
||||
{
|
||||
if (GETPOST('newlang', 'aZ09') == $objectpage->lang)
|
||||
@ -1571,6 +1572,11 @@ if (($action == 'updatesource' || $action == 'updatecontent' || $action == 'conf
|
||||
setEventMessages($langs->trans("LanguageMustNotBeSameThanClonedPage"), null, 'errors');
|
||||
$action = 'preview';
|
||||
}
|
||||
if (GETPOST('newwebsite', 'int') != $object->id) {
|
||||
$error++;
|
||||
setEventMessages($langs->trans("WebsiteMustBeSameThanClonedPageIfTranslation"), null, 'errors');
|
||||
$action = 'preview';
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
@ -1592,7 +1598,7 @@ if (($action == 'updatesource' || $action == 'updatecontent' || $action == 'conf
|
||||
}
|
||||
|
||||
$objectpage = new WebsitePage($db);
|
||||
$resultpage = $objectpage->createFromClone($user, $pageid, GETPOST('pageurl', 'aZ09'), (GETPOST('newlang', 'aZ09') ?GETPOST('newlang', 'aZ09') : ''), $istranslation, $newwebsiteid);
|
||||
$resultpage = $objectpage->createFromClone($user, $pageid, GETPOST('newpageurl', 'aZ09'), (GETPOST('newlang', 'aZ09') ? GETPOST('newlang', 'aZ09') : ''), $istranslation, $newwebsiteid, GETPOST('newtitle', 'alphanohtml'));
|
||||
if ($resultpage < 0)
|
||||
{
|
||||
$error++;
|
||||
@ -2283,10 +2289,7 @@ if (!GETPOST('hide_websitemenu'))
|
||||
if ($action == 'createfromclone') {
|
||||
// Create an array for form
|
||||
$formquestion = array(
|
||||
array('type' => 'text', 'name' => 'siteref', 'label'=> $langs->trans("WebSite"), 'value'=> 'copy_of_'.$object->ref),
|
||||
//array('type' => 'checkbox', 'name' => 'is_a_translation', 'label' => $langs->trans("SiteIsANewTranslation"), 'value' => 0),
|
||||
//array('type' => 'other','name' => 'newlang','label' => $langs->trans("Language"), 'value' => $formadmin->select_language(GETPOST('newlang', 'aZ09')?GETPOST('newlang', 'aZ09'):$langs->defaultlang, 'newlang', 0, null, '', 0, 0, 'minwidth200')),
|
||||
//array('type' => 'other','name' => 'newwebsite','label' => $langs->trans("WebSite"), 'value' => $formwebsite->selectWebsite($object->id, 'newwebsite', 0))
|
||||
array('type' => 'text', 'name' => 'siteref', 'label'=> $langs->trans("WebSite"), 'value'=> 'copy_of_'.$object->ref)
|
||||
);
|
||||
|
||||
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('CloneSite'), '', 'confirm_createfromclone', $formquestion, 0, 1, 200);
|
||||
@ -2305,7 +2308,8 @@ if (!GETPOST('hide_websitemenu'))
|
||||
array('type' => 'checkbox', 'tdclass'=>'maxwidth200', 'name' => 'is_a_translation', 'label' => $langs->trans("PageIsANewTranslation"), 'value' => 0),
|
||||
array('type' => 'other', 'name' => 'newlang', 'label' => $langs->trans("Language"), 'value' => $formadmin->select_language($preselectedlanguage, 'newlang', 0, null, 1, 0, 0, 'minwidth200', 0, 1)),
|
||||
array('type' => 'other', 'name' => 'newwebsite', 'label' => $langs->trans("WebSite"), 'value' => $formwebsite->selectWebsite($object->id, 'newwebsite', 0)),
|
||||
array('type' => 'text', 'tdclass'=>'maxwidth200 fieldrequired', 'name' => 'pageurl', 'label'=> $langs->trans("WEBSITE_PAGENAME"), 'value'=> 'copy_of_'.$objectpage->pageurl),
|
||||
array('type' => 'text', 'tdclass'=>'maxwidth200 fieldrequired', 'name' => 'newtitle', 'label'=> $langs->trans("WEBSITE_TITLE"), 'value'=> $langs->trans("CopyOf").' '.$objectpage->title),
|
||||
array('type' => 'text', 'tdclass'=>'maxwidth200', 'name' => 'newpageurl', 'label'=> $langs->trans("WEBSITE_PAGENAME"), 'value'=> ''),
|
||||
);
|
||||
|
||||
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$pageid, $langs->trans('ClonePage'), '', 'confirm_createpagefromclone', $formquestion, 0, 1, 300, 550);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user