public function copyPage($fromPageId, $input) { $fromPage = $this->Page->findOrFail($fromPageId); if (isset($input['page_version_id'])) { // a specific version has been requested to copy $fromPageVersion = $fromPage->versions()->findOrFail($input['page_version_id']); $fromPageVersion->name = 'Default'; } else { // we'll use the current live version to copy $fromPageVersion = $fromPage->getLiveVersion(); } // get translated page id, if page copy is translation and langauges are different if (array_get($input, 'copy_reason') == 'translate' && array_get($input, 'language_id') !== $fromPage->language_id) { $this->setTranslatedFromPageId($fromPage, $input); $this->setTranslatedFromRouteName($fromPage, $input); } $toPage = $this->createPageFromInput($input); if (!$toPage) { return false; } $this->PageVersionManager->copyPageVersionToAnotherPage($fromPageVersion, $toPage); $this->cacheDeviseRoutes(); return $toPage; }
/** * Request the page be copied to another page (duplicated) * * @param integer $id * @param array $input * @return Redirector */ public function requestCopyPage($id, $input) { $page = $this->PageManager->copyPage($id, $input); if ($page) { return $this->Redirect->route('dvs-pages')->with('warnings', $this->PageManager->warnings)->with('message', $this->PageManager->message); } return $this->Redirect->route('dvs-pages-copy', $id)->withInput()->withErrors($this->PageManager->errors)->with('message', $this->PageManager->message); }