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();
     }
 }
 public function findAll(NodeQuery $nodeQuery, $forceReadWrite = false)
 {
     // NODEREFS
     $nodeQuery2 = $this->NodeRefService->normalizeNodeQuery($nodeQuery);
     $nodeRefs = $nodeQuery2->getParameter('NodeRefs.normalized');
     $nodePartials = $nodeQuery2->getParameter('NodePartials.eq');
     foreach ((array) $nodeRefs as $k => $nodeRef) {
         if (!$this->NodePermissions->check('get', $nodeRef, $nodePartials, true)) {
             unset($nodeRefs[$k]);
         }
     }
     $nodeQuery->setParameter('NodeRefs.normalized', $nodeRefs);
     $nodeQuery->setParameter('Permissions.check', true);
     return parent::findAll($nodeQuery, $forceReadWrite);
 }