public function copyPageVersionToAnotherPage($fromVersion, $toPage) { // create a new page version $newVersion = $this->createNewPageVersion($toPage->id, $fromVersion->name, $this->UserHelper->currentUserId()); $this->copyFieldsFromVersionToVersion($fromVersion, $newVersion); $this->copyCollectionsFromVersionToVersion($fromVersion, $newVersion); return $newVersion; }
/** * Takes the input provided and runs the create method after stripping necessary fields. * * @param integer $fromPageId * @param array $input * @return DvsPage */ 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) { $input = $this->getTranslatedFromPageId($fromPageId, $input); } $toPage = $this->createPageFromInput($input); if (!$toPage) { return false; } $this->PageVersionManager->copyPageVersionToAnotherPage($fromPageVersion, $toPage); $this->cacheDeviseRoutes(); return $toPage; }