Ejemplo n.º 1
0
 protected function fetchMaxChildTreeID(Node $myNode, TagDef $treeOriginTagDef, TagPartial $treeOriginPartial, $parentTreeID = '')
 {
     $nq = new NodeQuery();
     $nq->setParameter('Status.all', true);
     $nq->setParameter('TreeID.childOf', $parentTreeID);
     $nq->setParameter('Elements.in', $myNode->getNodeRef()->getElement()->getSlug());
     if ($treeOriginTagDef->Direction == 'out') {
         $nq->setParameter('OutTags.exist', $treeOriginPartial->toString());
     } else {
         $nq->setParameter('InTags.exist', $treeOriginPartial->toString());
     }
     $nq->setOrderBy('TreeID', 'DESC');
     $nq->setLimit(1);
     $result = $this->NodeFindAllDAO->findAll($nq, true)->getResult();
     if (!empty($result)) {
         $lastNodeTreeID = $result['TreeID'];
         // if on the same level, return blank, in order to append as first child
         if (strcmp($lastNodeTreeID, $parentTreeID) === 0) {
             //                error_log('No children, same level');
             return '';
         } else {
             if (empty($parentTreeID)) {
                 return substr($lastNodeTreeID, 0, 4);
             }
         }
         //            error_log('Last TreeID = '.$lastNodeTreeID);
         return $lastNodeTreeID;
     }
     return '';
 }
 protected function elementHasRecords($slug)
 {
     $nq = new NodeQuery();
     $nq->setParameter('Elements.in', $slug);
     //        $nq->setParameter('Status.all', true);
     $nq->setLimit(1);
     $count = $this->NodeService->findAll($nq)->getResult();
     return $count !== null;
 }
 public function tagGalleryPhotos()
 {
     $galleryNodeRef = $this->NodeRefService->parseFromString('media-gallery:test-gallery');
     $interval = 25;
     $offset = 0;
     $nq = new NodeQuery();
     $nq->setParameter('Elements.in', 'image');
     $nq->setParameter('NodeRefs.only', true);
     $nq->setOrderBy('ActiveDate', 'DESC');
     $nq->setLimit($interval);
     $nq->setOffset($offset);
     $nq = $this->NodeService->findAll($nq, true);
     $nodes = $nq->getResults();
     while (count($nodes) > 0) {
         foreach ($nodes as $node) {
             $tag = new Tag($node->getElement()->getSlug(), $node->getSlug(), '#media-gallery-items');
             try {
                 $this->NodeService->addOutTag($galleryNodeRef, $tag);
                 echo $node->Slug . "\n";
             } catch (Exception $e) {
                 echo $node->Slug . " error: " . $e->getMessage() . "\n";
             }
         }
         $offset = $offset + $interval;
         unset($nodes);
         $nq->setLimit($interval);
         $nq->setOffset($offset);
         $nq->clearResults();
         $nq = $this->NodeService->findAll($nq, true);
         $nodes = $nq->getResults();
     }
 }
 protected function single()
 {
     $dto = new NodeQuery();
     $dto->setLimit(1);
     if ($this->getTemplateVariable('Site.all') == null) {
         if ($this->getTemplateVariable('Sites.in') == null) {
             $site = $this->RequestContext->getSite();
             $dto->setParameter('Sites.in', $site->getSlug());
         }
         $this->passthruTemplateVariable($dto, 'Sites.in');
         //$this->passthruTemplateVariable($dto, 'SiteIDs.in');
     }
     $this->passthruTemplateVariable($dto, 'Elements.in');
     //        $this->passthruTemplateVariable($dto, 'Slugs.in');
     $this->passthruTemplateVariable($dto, 'Meta.select');
     $this->passthruTemplateVariable($dto, 'OutTags.select');
     $this->passthruTemplateVariable($dto, 'InTags.select');
     //        $this->passthruTemplateVariable($dto, 'Sections.select');
     //        $this->passthruTemplateVariable($dto, 'Title.like');
     //        $this->passthruTemplateVariable($dto, 'Title.ieq');
     //        $this->passthruTemplateVariable($dto, 'Title.eq');
     //        $this->passthruTemplateVariable($dto, 'Title.firstChar');
     //
     //        if(!$this->Permissions->checkPermission('cms-view')) {
     //            $dto->setParameter('Status.isActive', true);
     //        }
     //        $this->passthruTemplateVariable($dto, 'ActiveDate.before');
     //        $this->passthruTemplateVariable($dto, 'ActiveDate.after');
     //        $this->passthruTemplateVariable($dto, 'ActiveDate.start');
     //        $this->passthruTemplateVariable($dto, 'ActiveDate.end');
     //
     //        $this->passthruTemplateVariable($dto, 'CreationDate.before');
     //        $this->passthruTemplateVariable($dto, 'CreationDate.after');
     //        $this->passthruTemplateVariable($dto, 'CreationDate.start');
     //        $this->passthruTemplateVariable($dto, 'CreationDate.end');
     //
     //        $this->passthruTemplateVariable($dto, 'OutTags.exist');
     //        $this->passthruTemplateVariable($dto, 'InTags.exist');
     //        $this->passthruTemplateVariable($dto, 'Meta.exist');
     //        $this->passthruTemplateVariable($dto, 'Sections.exist');
     //
     //        foreach($this->templateVars as $name => $value)
     //        {
     //            if(strpos($name, '#') === 0)
     //                $dto->setParameter($name, $value);
     //        }
     $slug = $this->getTemplateVariable('Slugs.in');
     if ($slug != null) {
         $dto->setParameter('Slugs.in', $slug);
         $dto = $this->NodeRefService->normalizeNodeQuery($dto);
         $nodeRefs = $dto->getParameter('NodeRefs.normalized');
         $nodePartials = $dto->getParameter('NodePartials.eq');
         $allFullyQualified = $dto->getParameter('NodeRefs.fullyQualified');
         if (!$allFullyQualified || count($nodeRefs) > 1) {
             $this->Logger->debug('node-single query is not fully-qualified NodeRef or more than 1 node is being returned');
             $dto->setResults(array());
         } else {
             $row = $this->RegulatedNodeService->getByNodeRef(current($nodeRefs), $nodePartials, $this->getTemplateVariable('ForceReadWrite') != null ? StringUtils::strToBool($this->getTemplateVariable('ForceReadWrite')) : false);
             $showPending = StringUtils::strToBool($this->getTemplateVariable('Status.allowInactive')) || $this->Permissions->checkPermission('cms-view');
             //Allow draft records to be viewed if exact URL is known.
             if (empty($row)) {
                 $this->Logger->debug('Row not found');
                 $dto->setResults(array());
             } else {
                 if ($row->Status == 'deleted') {
                     $this->Logger->debug('Node status is deleted');
                     $dto->setResults(array());
                 } else {
                     if (!$row->isIsActive() && !$showPending) {
                         $this->Logger->debug('Record is not active (and user is not permitted to see pending status)');
                         $dto->setResults(array());
                     } else {
                         $this->Logger->debug('Found node [' . $row->getNodeRef() . ']');
                         $this->Events->trigger('NodeWebController.single', $this->templateVars, $row);
                         foreach ((array) $row->getNodeRef()->getElement()->getAspects() as $aspect) {
                             $this->Events->trigger('NodeWebController' . '.@' . $aspect->Slug . '.' . 'single', $this->templateVars, $row);
                         }
                         $dto->setResults(array($row));
                     }
                 }
             }
         }
     } else {
         $dto->setResults(array());
     }
     return $this->readNodeQuery($dto);
 }
 protected function purgeAll()
 {
     $interval = 1000;
     // Allow the caller to specify a delay in ms between purge calls.
     // (to keep database load to a minimum if running this over a long period of time...)
     $delay = $this->Request->getParameter('delay');
     if (!empty($delay)) {
         $delay = intval($delay) * 1000;
     }
     $elements = array();
     $elementSlugs = $this->Request->getRequiredParameter('elements');
     if ($elementSlugs == 'all') {
         $elements = $this->ElementService->findAll()->getResults();
     } else {
         $elementSlugs = StringUtils::smartExplode($elementSlugs);
         foreach ($elementSlugs as $slug) {
             $elements[] = $this->ElementService->getBySlug($slug);
         }
     }
     // Support passing a list of element slugs that will not be purged, even if the "elements" attribute is "all".
     $ignoreElementSlugs = $this->Request->getParameter('ignore_elements');
     if (!empty($ignoreElementSlugs)) {
         $ignoreElementSlugs = StringUtils::smartExplode($ignoreElementSlugs);
         foreach ($ignoreElementSlugs as $slug) {
             // Do this step just to validate that the user has passed in real element slugs and not made any typos.
             $this->ElementService->getBySlug($slug);
         }
     }
     foreach ($elements as $element) {
         // Skip over any elements we've been told to ignore.
         if (!empty($ignoreElementSlugs) && in_array($element->getSlug(), $ignoreElementSlugs)) {
             continue;
         }
         $nq = new NodeQuery();
         $nq->setParameter('NodeRefs.only', true);
         $nq->setParameter('Elements.in', $element->getSlug());
         $nq->setParameter('Status.eq', 'deleted');
         $nq->setLimit($interval);
         $nq = $this->NodeService->findAll($nq, true);
         $nodes = $nq->getResults();
         $count = 0;
         while (count($nodes) > 0) {
             foreach ($nodes as $nodeRef) {
                 ++$count;
                 try {
                     $this->NodeService->purge($nodeRef);
                     echo $count, ". " . $nodeRef, " purged\n";
                     if ($count % 10 == 0) {
                         $this->TransactionManager->commit()->begin();
                         echo "commit\n";
                     }
                 } catch (Exception $e) {
                     echo "Exception caught: " . $e->getMessage() . "\n";
                 }
                 unset($nodeRef);
                 if ($delay > 0) {
                     usleep($delay);
                 }
             }
             $this->TransactionManager->commit()->begin();
             $nq->clearResults();
             $nodes = $this->NodeService->findAll($nq, true)->getResults();
         }
     }
 }
 public function populateDefaults($elements = 'all')
 {
     $log = '';
     if ($elements == 'all') {
         $elements = $this->ElementService->findAll()->getResults();
     } else {
         $elementSlugs = StringUtils::smartExplode($elements);
         $elements = array();
         foreach ($elementSlugs as $eSlug) {
             $elements[] = $this->ElementService->getBySlug($eSlug);
         }
     }
     foreach ($elements as $element) {
         $offset = 0;
         $nq = new NodeQuery();
         $nq->setParameter('Elements.in', $element->getSlug());
         $nq->setParameter('Meta.select', 'all');
         $nq->setLimit(1000);
         $nq->setOffset($offset);
         $nq->asObjects();
         $nq->isRetrieveTotalRecords(true);
         $nq = $this->NodeService->findAll($nq, true);
         $nodes = $nq->getResults();
         $tCount = $nq->getTotalRecords();
         $count = 0;
         while (count($nodes) > 0) {
             foreach ($nodes as $node) {
                 $this->NodeMapper->defaultsOnNode($node);
                 $this->NodeService->edit($node);
                 ++$count;
             }
             $offset += 1000;
             $nq = new NodeQuery();
             $nq->setParameter('Elements.in', $element->getSlug());
             $nq->setParameter('Meta.select', 'all');
             $nq->setLimit(1000);
             $nq->setOffset($offset);
             $nq->asObjects();
             $nodes = $this->NodeService->findAll($nq)->getResults();
         }
         $log .= 'Updated defaults on ' . $count . ' of ' . $tCount . ' ' . $element->getSlug() . " nodes.\n";
     }
     return $log;
 }