duplicateSitePageExist

@param PageEntity $page

@return bool
509141
public function duplicateSitePageExist(
        \Rcm\Entity\Page $page
    ) {
        // @todo This could be a query for speed
        $pages = $this->getPagesByName(
            $page->getSite(),
            $page->getName(),
            $page->getPageType()
        );

        /** @var \Rcm\Entity\Page $otherPage */
        foreach ($pages as $otherPage) {
            if ($otherPage->getPageId() !== $page->getPageId()) {
                return true;
            }
        }

        return false;
    }
512941
private function setMainNode(AbstractClassContent $content, Page $page)
    {
        if (null !== $content->getMainNode()) {
            return;
        }

        $content->setMainNode($page);

        if (null !== $this->entityManager) {
            $uow = $this->entityManager->getUnitOfWork();
            $meta = $this->entityManager->getClassMetadata(get_class($content));
            if ($uow->isEntityScheduled($content)) {
                $uow->recomputeSingleEntityChangeSet($meta, $content);
            } elseif ($uow->isEntityScheduled($page)) {
                $uow->computeChangeSet($meta, $content);
            }
        }
    }
1181439
public function duplicate($doWrite = true, $manyMany = 'many_many')
    {
        $duplicate = parent::duplicate($doWrite);

        $oldSubsiteID = SubsiteState::singleton()->getSubsiteId();
        self::changeSubsite($this->ID);

        /*
         * Copy data from this object to the given subsite. Does this using an iterative depth-first search.
         * This will make sure that the new parents on the new subsite are correct, and there are no funny
         * issues with having to check whether or not the new parents have been added to the site tree
         * when a page, etc, is duplicated
         */
        $stack = [[0, 0]];
        while (count($stack) > 0) {
            list($sourceParentID, $destParentID) = array_pop($stack);
            $children = Versioned::get_by_stage('Page', 'Live', "\"ParentID\" = $sourceParentID", '');

            if ($children) {
                foreach ($children as $child) {
                    self::changeSubsite($duplicate->ID); //Change to destination subsite

                    $childClone = $child->duplicateToSubsite($duplicate, false);
                    $childClone->ParentID = $destParentID;
                    $childClone->writeToStage('Stage');
                    $childClone->copyVersionToStage('Stage', 'Live');

                    self::changeSubsite($this->ID); //Change Back to this subsite

                    array_push($stack, [$child->ID, $childClone->ID]);
                }
            }
        }

        self::changeSubsite($oldSubsiteID);

        return $duplicate;
    }
981807
public function duplicateEntity($id)
    {
        $query = $this->_table;
        foreach ($this->_getFinder() as $finder) {
            $query = $query->find($finder);
        }

        $contain = $this->_getContain();

        if (!empty($contain)) {
            $query = $query->contain($contain);
        }

        $entity = $query->where([$this->_table->getAlias() . '.' . $this->_table->getPrimaryKey() => $id])->firstOrFail();

        // process entity
        foreach ($this->getConfig('contain') as $contain) {
            $parts = explode('.', $contain);
            $this->_drillDownAssoc($entity, $this->_table, $parts);
        }

        $this->_modifyEntity($entity, $this->_table);

        foreach ($this->getConfig('remove') as $field) {
            $parts = explode('.', $field);
            $this->_drillDownEntity('remove', $entity, $parts);
        }

        foreach (['set', 'prepend', 'append'] as $action) {
            foreach ($this->getConfig($action) as $field => $value) {
                $parts = explode('.', $field);
                $this->_drillDownEntity($action, $entity, $parts, $value);
            }
        }

        return $entity;
    }
454355
public function updatePage(
        PageEntity $page,
        $pageData,
        $doFlush = true
    ) {

        if (empty($pageData['modifiedByUserId'])) {
            throw new InvalidArgumentException(
                'Missing needed information (modifiedByUserId) to create page copy.'
            );
        }

        if (empty($pageData['modifiedReason'])) {
            $pageData['modifiedReason'] = 'Update page in ' . get_class($this);
        }

        // Values cannot be changed
        unset($pageData['pageId']);
        unset($pageData['author']);
        unset($pageData['createdDate']);
        unset($pageData['lastPublished']);

        $page->populate($pageData);
        $page->setModifiedByUserId(
            $pageData['modifiedByUserId'],
            $pageData['modifiedReason']
        );

        $this->assertCanUpdateSitePage(
            $page
        );

        $this->getEntityManager()->persist($page);

        if ($doFlush) {
            $this->getEntityManager()->flush($page);
        }

        return $page;
    }
1173289
public function sitePageExists(
        SiteEntity $site,
        $pageName,
        $pageType
    ) {
        try {
            $page = $this->getPageByName(
                $site,
                $pageName,
                $pageType
            );
        } catch (\Exception $e) {
            $page = null;
        }

        return !empty($page);
    }
317245
public function areEqual($firstEntity, $secondEntity)
    {
        $entityDefinition = $this->definitions->getDefinition($firstEntity);

        if (!$entityDefinition->fitsFor($secondEntity)) {
            throw new InvalidArgumentException("You can't compare entities of different type.");
        }

        foreach ($entityDefinition->getObservedProperties() as $property) {
            if ($this->propertyValueComparer->hasDifferentValue($property, $firstEntity, $secondEntity)) {
                return false;
            }
        }

        return true;
    }
943424
private function doPersistIfValid(Page $page)
    {
        if (null === $page->getParent() && !empty($this->persist)) {
            // If root, only persist
            $this->em->persist($page);
            return;
        }

        $method = '';
        if (self::PERSIST_AS_FIRST_CHILD === $this->persist) {
            $method = 'insertNodeAsFirstChildOf';
        } elseif (self::PERSIST_AS_LAST_CHILD === $this->persist) {
            $method = 'insertNodeAsLastChildOf';
        }

        if (!empty($method)) {
            $this->em->getRepository('BackBee\NestedNode\Page')->$method($page, $page->getParent(), $this->isSection);
            $this->em->persist($page);
        }
    }
884838
public function onAfterDuplicate(\Page $page)
    {
        foreach ($this->owner->PageSlices() as $slice) {
            /** @var PageSlice $slice */
            $sliceCopy = $slice->duplicate(true);
            $page->PageSlices()->add($sliceCopy);
            $sliceCopy->publishRecursive();
        }
    }
1209733
public function forget($page)
    {
        if ($page = $this->getPage($page)) {
            /** @todo Implement forgetting pages completely */

            /** @var Connection $database */
            $database = $this->app['database']->connection();
            $database->executeQuery('DELETE FROM PageSearchIndex WHERE cID=?', [$page->getCollectionID()]);
        }

        return false;
    }
1020196
public function duplicatePageAction()
    {
        $success = 0;
        $title   = 'tr_meliscms_duplicate_page_title';
        $message = 'tr_meliscms_duplicate_error';
        $pageId  = null;
        $errors  = array();
        $data    = array();
        $request = $this->getRequest();

        if($request->isPost()) {
            $pageId = (int) $request->getPost('id');
            $cachePageId = $pageId;
            $pageService = $this->getServiceLocator()->get('MelisEnginePage');
            $pageData    = $pageService->getDatasPage($pageId);
            if(empty($pageData->getMelisTemplate())) {
                $pageData    = $pageService->getDatasPage($pageId, 'saved');
            }
            
            $templateData = $pageData->getMelisTemplate();
            $pageTreeData = $pageData->getMelisPageTree();

            // select page lang
            $langLocale = $pageTreeData->lang_cms_locale;
            $langName   = $pageTreeData->lang_cms_name;
            $langId     = $pageTreeData->lang_cms_id;

            // parent ID of the selected page that will be duplicated
            $parentId   = $pageTreeData->tree_father_page_id;

            // if set to "true" then if duplication is successful,
            // it will automatically open's the duplicated page
            $openPageAfterDuplicate = true;

            $iconTypes = array(
                'SITE'   => 'fa-home',
                'FOLDER' => 'fa-folder-open-o',
                'PAGE'   => 'fa-file-o'
            );

            $duplicatePageData = array(
                'page_duplicate_event_flag' => true,
                'page_name' => $pageTreeData->page_name . ' ' . $this->getTool()->getTranslation('tr_melis_cms_duplicate_text_identifier'),
                'page_type' => $pageTreeData->page_type,
                'plang_lang_id' => $langId,
                'page_menu' => $pageTreeData->page_menu,
                'page_tpl_id' => $pageTreeData->page_tpl_id,
                'page_taxonomy' => $pageTreeData->page_taxonomy,
                'fatherPageId'  => $pageId,
                'page_search_type' => $pageTreeData->page_search_type,
            );


            $results = $this->forward()->dispatch('MelisCms\Controller\PageProperties', array_merge(['action' => 'savePageTree'], $duplicatePageData))->getVariables();
            if(isset($results['datas']['idPage']) && ( (int) $results['datas']['idPage'])) {
                $pageId = (int) $results['datas']['idPage'];
                $duplicatePageData['page_id'] = $pageId;
                $duplicatePageData['idPage'] = $pageId;
                $results = $this->forward()->dispatch('MelisCms\Controller\PageProperties', array_merge(['action' => 'saveProperties'], $duplicatePageData))->getVariables();
            }

            if($pageId) {
                // page content
                $melisPageSavedTable = $this->getServiceLocator()->get('MelisEngineTablePageSaved');
                $melisPageSavedTable->save([
                    'page_content' => $pageTreeData->page_content,
                    'page_creation_date' => date('Y-m-d H:i:s'),
                ], $pageId);
                
                // page SEO
                $pageSeoTable = $this->getServiceLocator()->get('MelisEngineTablePageSeo');
                $pageSeoData  = $pageSeoTable->getEntryById($cachePageId)->current();
                if($pageSeoData) {
                    $pageSeoTable->save([
                        'pseo_id' =>  $pageId,
                        'pseo_url' => '',
                        'pseo_url_redirect' => '',
                        'pseo_url_301' => '',
                        'pseo_meta_title' => $pageSeoData->pseo_meta_title,
                        'pseo_meta_description' => $pageSeoData->pseo_meta_description
                    ]);
                }

                // response data
                $data = array(
                    'name'   => $duplicatePageData['page_name'],
                    'pageId' => $pageId,
                    'openPageAfterDuplicate' => $openPageAfterDuplicate,
                    'icon' => $iconTypes[$pageTreeData->page_type]
                );
                $success = 1;
                $message = $this->getTool()->getTranslation('tr_melis_cms_duplicate_success', [$pageTreeData->page_name]);
            }

        }

        $response = array(
            'success' => $success,
            'textTitle' => $this->getTool()->getTranslation($title),
            'textMessage' => $this->getTool()->getTranslation($message),
            'pageId'  => $pageId,
            'response' => $data,
            'errors'  => $errors
        );

        $this->getEventManager()->trigger('meliscms_page_duplicate_end', $this, $response);

        return new JsonModel($response);
    }
446942
private function checkEntityExist()
    {
        if (!file_exists(PATH_HOME . "entity/cache/{$this->entity}.json")) {
            foreach (Helper::listFolder(PATH_HOME . VENDOR) as $lib)
                new \LinkControl\EntityImport($lib);
        }
    }
1359356
public function postUpdate(PageInterface $page, LifecycleEventArgs $event)
    {
        /** @var \Doctrine\ORM\EntityManagerInterface $em */
        $em = $event->getObjectManager();
        $uow = $em->getUnitOfWork();

        $changeSet = $uow->getEntityChangeSet($page);
        if (array_key_exists('enabled', $changeSet)) {
            if ($page->isEnabled()) {
                $this->discardPageRedirections($page);
            } else {
                $this->buildPageRedirections($page);
            }
        }
    }
788122
public function duplicatePage(Node $node, $locale, $title = 'New page')
    {
        $user = $this->getAdminUser();

        $sourceNodeTranslations = $node->getNodeTranslation($locale, true);
        $sourcePage = $sourceNodeTranslations->getPublicNodeVersion()->getRef($this->em);
        $targetPage = $this->cloneHelper->deepCloneAndSave($sourcePage);
        $targetPage->setTitle($title);

        if ($node->getParent()) {
            $parentNodeTranslation = $node->getParent()->getNodeTranslation($locale, true);
            $parent = $parentNodeTranslation->getPublicNodeVersion()->getRef($this->em);
            $targetPage->setParent($parent);
        }
        $this->em->persist($targetPage);
        $this->em->flush();

        /* @var Node $nodeNewPage */
        $nodeNewPage = $this->em->getRepository(Node::class)->createNodeFor($targetPage, $locale, $user);

        $nodeTranslation = $nodeNewPage->getNodeTranslation($locale, true);
        if ($targetPage->isStructureNode()) {
            $nodeTranslation->setSlug('');
            $this->em->persist($nodeTranslation);
        }
        $this->em->flush();

        return $nodeTranslation;
    }
1228321
public function setPage($page)
    {
        if (!isset($this->_persistence) || !($this->_persistence instanceof IPersistance)) {
            throw new Exception("Repository Exception : No existe la interfaz de la persistencia o no implementa la interfaz IPersistance.");
        }

        $limit = $this->_persistence->getLimit();

        if (!isset($limit)) {
            throw new Exception("Repository Exception : No estña seteado el limite de la operación de lectura.");
        }

        $this->_persistence->setOffset($limit * $page);

        return $this;
    }
763407
public function duplicate(Entity $entity = null)
    {
        $entity = $this->getEntityIfEmpty($entity);

        $data = $this->toArray();
        if (isset($data['id'])) {
            unset($data['id']);
        }

        foreach ($data as $key => &$val) {
            if ($key && array_key_exists($key . '_x', $data) && array_key_exists($key . '_y', $data)) {
                $val = [
                    $data[$key . '_x'],
                    $data[$key . '_y'],
                ];
            }
        }

        $record = new static($data);
        $record->save($entity);

        return $record;
    }
937253
public function copy_page() {
        if (!$this->filename) {
            return false;
        }
        if ($this->currentpage>=$this->pagecount) {
            return false;
        }
        $this->currentpage++;
        $this->create_page_from_source($this->currentpage);
        return true;
    }