public function add(Node $node) { $this->NodePermissions->checkThrow(__FUNCTION__, $node->getNodeRef(), $node, false); if ($node->Status == 'published') { $this->NodePermissions->checkThrow('publish', $node->getNodeRef(), $node, false); } return parent::add($node); }
protected function _importPhotosFromJson($file) { try { $contents = file_get_contents($file); $json = JSONUtils::decode($contents); foreach ($json as $v) { echo "importing {$v->title}..."; $url = $v->src; $parts = parse_url($url); $slug = SlugUtils::createSlug(basename($parts['path'])); preg_match('/(\\.\\w*)$/', $parts['path'], $ext); $nodeRef = $this->NodeRefService->oneFromAspect('@images'); $nodeRef = $this->NodeRefService->generateNodeRef($nodeRef, $slug); $node = $nodeRef->generateNode(); if (!$this->NodeService->refExists($node->getNodeRef())) { // go fetch file from url $data = $this->HttpRequest->fetchURL($url); // create a unique output file name $sourceFile = FileSystemUtils::secureTmpname($this->workDir, 'urlfetch', !empty($ext[1]) ? strtolower($ext[1]) : null); file_put_contents($sourceFile, $data); $node->Title = rtrim($v->title); $node->Status = "published"; $node->ActiveDate = $this->DateFactory->newStorageDate(); $node = $this->ImageService->storeMedia($sourceFile, $node, basename($parts['path'])); $this->NodeService->add($node); echo "done\n"; } else { echo "exists\n"; } unset($nodeRef); unset($node); } } catch (Exception $e) { echo "Exception: " . $e->getMessage() . "\n"; } }