/** * For event in shared context: * Node.@images.add.post * * @param NodeRef $nodeRef NodeRef Being Added * @param Node $node Node Being added * @param null $notUsed Paramater passed in via Events::trigger, but set to null, and not used. * @param bool $asyncRebuild Wether to rebuildThumbnails asyncronously or not (defaults to true) * * @return void */ public function processAdd(NodeRef $nodeRef, Node $node, $notUsed = null, $asyncRebuild = true) { $node = $this->RegulatedNodeService->getByNodeRef($nodeRef, new NodePartials('', '#original.fields')); //----------- // Build CMS thumbnail separately so that it's ready when this action completes. $file = $this->FileService->retrieveFileFromNode($node->getElement(), $node->getOutTag('#original')->TagLinkNodeRef); if ($file === null) { throw new Exception('File cannot be retrieved for Node'); } $cmsThumb = $this->ImageService->createAndStoreThumbnail($node->getElement(), $this->imagesThumbnailCmsSize, $file->getLocalPath(), $this->ImageService->filenameForNode($node)); $tag = new Tag($cmsThumb->getElement()->getSlug(), $cmsThumb->Slug, '#thumbnails', $this->imagesThumbnailCmsSize, $this->imagesThumbnailCmsSize); $node->replaceOutTags('#thumbnails', array($tag)); $this->RegulatedNodeService->edit($node); if ($asyncRebuild) { // commit so the node is ready for the worker $this->TransactionManager->commit()->begin(); //----------- // Rebuild thumbnails asynchronously $workerParams = array('nodeRef' => '' . $node->getNodeRef(), 'forceRebuildExisting' => false); $this->GearmanService->doBackgroundJob('ImagesWorker', 'rebuildThumbnails', $workerParams, 'high'); } else { $this->ImageService->rebuildMissingThumbnails($node->getNodeRef(), false); } // remove storage facility generated temp file @unlink($file->getLocalPath()); }
protected function _buildCmsThumbnail($node) { $node = $this->RegulatedNodeService->getByNodeRef($node->getNodeRef(), new NodePartials('', '#original.fields')); //----------- // Build CMS thumbnail separately so that it's ready when this action completes. $file = $this->FileService->retrieveFileFromNode($node->getElement(), $node->getOutTag('#original')->TagLinkNodeRef); $cmsThumb = $this->ImageService->createAndStoreThumbnail($node->getElement(), $this->imagesThumbnailCmsSize, $file->getLocalPath(), $this->ImageService->filenameForNode($node)); $tag = new Tag($cmsThumb->getElement()->getSlug(), $cmsThumb->Slug, '#thumbnails', $this->imagesThumbnailCmsSize, $this->imagesThumbnailCmsSize); $node->replaceOutTags('#thumbnails', array($tag)); $this->RegulatedNodeService->edit($node); }
public function findAll() { $dto = new NodeQuery(); $this->buildLimitOffset($dto); $this->buildSorts($dto); $this->buildFilters($dto); $this->passthruParameter($dto, 'Elements.in'); $this->passthruParameter($dto, 'Sites.in'); //$this->passthruParameter($dto, 'SiteIDs.in'); $this->passthruParameter($dto, 'Slugs.in'); $this->passthruParameter($dto, 'Meta.select'); $this->passthruParameter($dto, 'OutTags.select'); $this->passthruParameter($dto, 'InTags.select'); $this->passthruParameter($dto, 'Sections.select'); $this->passthruParameter($dto, 'OrderByInTag'); $this->passthruParameter($dto, 'OrderByOutTag'); $this->passthruParameter($dto, 'Title.like'); $this->passthruParameter($dto, 'Title.ieq'); $this->passthruParameter($dto, 'Title.eq'); $this->passthruParameter($dto, 'Title.firstChar'); $this->passthruParameter($dto, 'Status.isActive'); $this->passthruParameter($dto, 'Status.all'); $this->passthruParameter($dto, 'Status.eq'); $this->passthruParameter($dto, 'TreeID.childOf'); $this->passthruParameter($dto, 'TreeID.eq'); $this->passthruParameter($dto, 'ActiveDate.before'); $this->passthruParameter($dto, 'ActiveDate.after'); $this->passthruParameter($dto, 'ActiveDate.start'); $this->passthruParameter($dto, 'ActiveDate.end'); $this->passthruParameter($dto, 'CreationDate.before'); $this->passthruParameter($dto, 'CreationDate.after'); $this->passthruParameter($dto, 'CreationDate.start'); $this->passthruParameter($dto, 'CreationDate.end'); $this->passthruParameter($dto, 'OutTags.exist'); $this->passthruParameter($dto, 'InTags.exist'); $this->passthruParameter($dto, 'Meta.exist'); $this->passthruParameter($dto, 'Sections.exist'); foreach ($this->Request->getParameters() as $name => $value) { if (strpos($name, '#') === 0) { $dto->setParameter(str_replace('_', '.', $name), $value); } } $dto->isRetrieveTotalRecords(true); if ($this->Request->getParameter('OrderBy') != null) { $dto->setOrderBys(array()); $dto->setOrderBy($this->Request->getParameter('OrderBy')); } $this->Events->trigger('NodeApiController.findAll', $dto); $dto = $this->RegulatedNodeService->findAll($dto, $this->Request->getParameter('ForceReadWrite') != null ? StringUtils::strToBool($this->Request->getParameter('ForceReadWrite')) : false); echo $this->readDTO($dto); return null; }