function duplicatePage($user, $page, $pageToAttachTo) { global $pageDuplicated, $duplicatedCodenames, $cms_user; if (is_a($page, "CMS_page") && is_a($pageToAttachTo, "CMS_page") && $page->getTemplate()) { //check codename duplication $removeCodename = false; if ($page->getCodename()) { //if codename already exists in website destination, then we must remove it if (CMS_tree::getPageByCodename($page->getCodename(), $pageToAttachTo->getWebsite(), false, false)) { $removeCodename = true; } } //Duplicate page template $tpl = $page->getTemplate(); $tpl_copy = CMS_pageTemplatesCatalog::getCloneFromID($tpl->getID(), false, true, false, $tpl->getID()); $_tplID = $tpl_copy->getID(); //Create copy of given page $newPage = $page->duplicate($user, $_tplID); if ($removeCodename) { $newPage->setCodename('', $cms_user); $newPage->writeToPersistence(); $duplicatedCodenames[] = $page->getCodename(); } //Move to destination in tree if (is_null($newPage) || !CMS_tree::attachPageToTree($newPage, $pageToAttachTo)) { return null; } $pageDuplicated[] = $newPage->getID(); //Proceed with siblings $sibs = CMS_tree::getSiblings($page); if (!$sibs || !sizeof($sibs)) { return $pageToAttachTo; } else { $pageToAttachTo = $newPage; } foreach ($sibs as $sib) { if ($user->hasPageClearance($sib->getID(), CLEARANCE_PAGE_EDIT) && !in_array($sib->getID(), $pageDuplicated)) { duplicatePage($user, $sib, $pageToAttachTo); } } } }
/** * Process the daily routine publication part : publish page that needs to be * * @return void * @access private */ protected function _dailyRoutinePublish() { $today = new CMS_date(); $today->setNow(); //process all pages that have to be published $sql = "\n\t\t\tselect\n\t\t\t\tid_pag\n\t\t\tfrom\n\t\t\t\tpages,\n\t\t\t\tresources,\n\t\t\t\tresourceStatuses\n\t\t\twhere\n\t\t\t\tresource_pag=id_res\n\t\t\t\tand status_res=id_rs\n\t\t\t\tand location_rs='" . RESOURCE_LOCATION_USERSPACE . "'\n\t\t\t\tand publication_rs='" . RESOURCE_PUBLICATION_VALIDATED . "'\n\t\t\t\tand\tpublicationDateStart_rs <= '" . $today->getDBValue(true) . "'\n\t\t\t\tand (publicationDateEnd_rs >= '" . $today->getDBValue(true) . "' or publicationDateEnd_rs = '0000-00-00')\n\t\t"; $q = new CMS_query($sql); $published = array(); while ($id = $q->getValue("id_pag")) { $published[] = $id; } $regen_pages = array(); foreach ($published as $page_id) { $page = CMS_tree::getPageByID($page_id); //apply changes on the page $father = CMS_tree::getAncestor($page, 1); CMS_tree::attachPageToTree($page, $father, true); CMS_tree::submitToRegenerator($page->getID(), true); //calculate the pages to regenerate $temp_regen = CMS_linxesCatalog::getLinkers($page); if ($temp_regen) { $regen_pages = array_merge($regen_pages, $temp_regen); } $father = CMS_tree::getAncestor($page, 1); if ($father) { $temp_regen = CMS_linxesCatalog::getWatchers($father); if ($temp_regen) { $regen_pages = array_merge($regen_pages, $temp_regen); } } } //regenerate the pages that needs to be, but first pull off the array the ids of the unpublished pages $regen_pages = array_unique(array_diff($regen_pages, $published)); CMS_tree::submitToRegenerator($regen_pages, true); }
if (APPLICATION_ENFORCES_WORKFLOW) { $pg->addEdition(RESOURCE_EDITION_CONTENT, $cms_user); } //don't add an edition (siblings order) to the father (which was the previous behavior) //$father->addEdition(RESOURCE_EDITION_SIBLINGSORDER, $cms_user); $pg->writeToPersistence(); $father->writeToPersistence(); //move the data if ($pg->getPublication() == RESOURCE_PUBLICATION_PUBLIC) { CMS_module_standard::_changeDataLocation($pg, RESOURCE_DATA_LOCATION_ARCHIVED, RESOURCE_DATA_LOCATION_PUBLIC, true); } CMS_module_standard::_changeDataLocation($pg, RESOURCE_DATA_LOCATION_ARCHIVED, RESOURCE_DATA_LOCATION_EDITED, false); //attach the page to the tree CMS_tree::attachPageToTree($pg, $father); if ($pg->getPublication() != RESOURCE_PUBLICATION_NEVERVALIDATED) { CMS_tree::attachPageToTree($pg, $father, true); } if (!APPLICATION_ENFORCES_WORKFLOW) { //submit the page to the regenerator CMS_tree::submitToRegenerator($pg->getID(), true); //validate the father $pg->regenerate(true); $validation = new CMS_resourceValidation(MOD_STANDARD_CODENAME, RESOURCE_EDITION_SIBLINGSORDER + RESOURCE_EDITION_CONTENT, $father); $mod = CMS_modulesCatalog::getByCodename(MOD_STANDARD_CODENAME); $mod->processValidation($validation, VALIDATION_OPTION_ACCEPT); } $cms_message = $cms_language->getMessage(MESSAGE_ACTION_OPERATION_DONE); $archives = CMS_tree::getArchivedPagesData(); $log = new CMS_log(); $log->logResourceAction(CMS_log::LOG_ACTION_RESOURCE_UNARCHIVE, $cms_user, MOD_STANDARD_CODENAME, $pg->getStatus(), "", $pg); }
/** * Move a page in the tree structure * Static function. * * @param CMS_page $page The page to move * @param CMS_page $newFather The new father of the page * @param array of CMS_page id $newSiblingOrder The sibling pages to move in the good order * @param CMS_profile_user $user The user operating the change. * @return string The error string (abbreviated) or false if no error * @access public */ static function movePage(&$page, &$newFather, $newSiblingOrder, &$user) { //check arguments are pages if (!is_a($page, "CMS_page") || !is_a($newFather, "CMS_page")) { CMS_grandFather::_raiseError("CMS_tree : movePage : ancestor and page must be instances of CMS_page"); return false; } //get page current father $father = CMS_tree::getAncestor($page, 1); //can't move page to the same father (useless...) if (is_object($father) && $newFather->getID() == $father->getID()) { CMS_grandFather::_raiseError("CMS_tree : movePage : can't move page under the same father (use changePagesOrder instead)"); return false; } //check that the page to move ain't the root. $root = CMS_tree::getRoot(); if ($root->getID() == $page->getID()) { CMS_grandFather::_raiseError("CMS_tree : movePage : can't move root"); return false; } //check that the page to move ain't an ancestor of new father. $lineage = CMS_tree::getLineage($page, $newFather); if ($lineage) { CMS_grandFather::_raiseError("CMS_tree : movePage : can't move a page to a descendant of it"); return false; } //detach the page from the edited tree CMS_tree::detachPageFromTree($page, false); //attach the page to the edited tree under the new father CMS_tree::attachPageToTree($page, $newFather, false); //set new pages order foreach ($newSiblingOrder as $newOrder => $sibling) { $newOrder += 1; //because array keys start to 0 and sibling number to 1 //move the siblings order $sql = "\n\t\t\t\tupdate\n\t\t\t\t\tlinx_tree_edited\n\t\t\t\tset\n\t\t\t\t\torder_ltr='" . $newOrder . "'\n\t\t\t\twhere\n\t\t\t\t\tsibling_ltr='" . $sibling . "'\n\t\t\t"; $q = new CMS_query($sql); } //set the page status editions $page->addEdition(RESOURCE_EDITION_MOVE, $user); $page->writeToPersistence(); return true; }