/**
  * @param NodeInterface $node
  * @param Image $newImage
  * @param string $title
  * @param string|array $tagLabel
  * @param string $propertyName
  * @param boolean $removePreviousProfileImage
  * @return NodeInterface
  */
 public function setImageToNode(NodeInterface $node, Image $newImage, $title, $tagLabel = NULL, $propertyName = 'image', $removePreviousProfileImage = FALSE)
 {
     $newImage->setTitle($title);
     if ($tagLabel !== NULL) {
         if (is_array($tagLabel) && !is_string($tagLabel)) {
             if ($removePreviousProfileImage === TRUE) {
                 $this->removePreviousProfilePictureBasedOnTags($title, $tagLabel);
             }
             foreach ($tagLabel as $key => $label) {
                 $tag = $this->tagRepository->findOneByLabel($label);
                 if (!$tag instanceof Tag) {
                     $tag = new Tag($label);
                     $this->tagRepository->add($tag);
                 }
                 $newImage->addTag($tag);
             }
         } elseif (is_string($tagLabel) && !is_array($tagLabel)) {
             $tag = $this->tagRepository->findOneByLabel($tagLabel);
             if (!$tag instanceof Tag) {
                 $tag = new Tag($tagLabel);
                 $this->tagRepository->add($tag);
             }
             $newImage->addTag($tag);
         }
     }
     /** @var Image $image */
     $image = $this->imageRepository->findByIdentifier($newImage->getIdentifier());
     if ($image !== NULL) {
         try {
             $this->imageRepository->update($image);
             $node->setProperty($propertyName, $image);
         } catch (\Exception $exception) {
             // Image repository might give back an image while not stored for some reason. If so, catch that error and store it anyway
             $image->setTitle($title);
             $this->imageRepository->add($image);
             $node->setProperty($propertyName, $image);
             $this->systemLogger->log('Image with identifier ' . $image->getIdentifier() . ' stored while preceding an error that is not stored yet fetched using ImageRepository', LOG_CRIT);
         }
     } else {
         $this->imageRepository->add($newImage);
         $node->setProperty($propertyName, $newImage);
     }
     return $node;
 }
예제 #2
0
 /**
  * Updates the given news object
  *
  * @param \Lelesys\Plugin\News\Domain\Model\News $news The news to update
  * @param array $media  News media
  * @param array $file News file
  * @param array $tags News tags
  * @param array $relatedLink News related links
  * @return void
  */
 public function update(\Lelesys\Plugin\News\Domain\Model\News $news, $media, $file, $relatedLink, $tags)
 {
     if (!empty($tags['title'])) {
         $tagsArray = array_unique(\TYPO3\Flow\Utility\Arrays::trimExplode(',', strtolower($tags['title'])));
         foreach ($tagsArray as $tag) {
             $existTag = $this->tagService->findTagByName($tag);
             if (!empty($existTag)) {
                 $newsTags = $news->getTags()->toArray();
                 if (!in_array($existTag, $newsTags)) {
                     $news->addTags($existTag);
                 }
             } else {
                 $newTag = new \Lelesys\Plugin\News\Domain\Model\Tag();
                 $newTag->setTitle($tag);
                 $this->tagService->create($newTag);
                 $news->addTags($newTag);
             }
         }
     }
     $news->setUpdatedDate(new \DateTime());
     $mediaPath = $media;
     foreach ($mediaPath as $mediaSource) {
         if (!empty($mediaSource['uuid'])) {
             $updateAsset = $this->propertyMapper->convert($mediaSource['uuid']['__identity'], '\\TYPO3\\Media\\Domain\\Model\\Image');
             $updateAsset->setCaption($mediaSource['caption']);
             $this->imageRepository->update($updateAsset);
         } else {
             if (!empty($mediaSource['resource']['name'])) {
                 $resource = $this->propertyMapper->convert($mediaSource['resource'], 'TYPO3\\Flow\\Resource\\Resource');
                 $media = new \TYPO3\Media\Domain\Model\Image($resource);
                 $media->setCaption($mediaSource['caption']);
                 $this->imageRepository->add($media);
                 $news->addAssets($media);
             }
         }
     }
     $filePath = $file;
     foreach ($filePath as $fileSource) {
         if (isset($fileSource['uuid'])) {
             $updateFile = $this->propertyMapper->convert($fileSource['uuid']['__identity'], '\\TYPO3\\Media\\Domain\\Model\\Document');
             $updateFile->setTitle($fileSource['title']);
             $this->assetRepository->update($updateFile);
         } else {
             if (!empty($fileSource['resource']['name'])) {
                 $resource = $this->propertyMapper->convert($fileSource['resource'], 'TYPO3\\Flow\\Resource\\Resource');
                 $file = new \TYPO3\Media\Domain\Model\Document($resource);
                 $file->setTitle($fileSource['title']);
                 $this->assetRepository->add($file);
                 $news->addFiles($file);
             }
         }
     }
     $related = $relatedLink;
     foreach ($related as $link) {
         if (isset($link['uuid'])) {
             $updateLink = $this->linkService->findById($link['uuid']);
             $updateLink->setUri($link['relatedUri']);
             $updateLink->setTitle($link['relatedUriTitle']);
             $updateLink->setDescription($link['relatedUriDescription']);
             $updateLink->setHidden($link['hidden']);
             $this->linkService->update($updateLink);
         } else {
             if (!empty($link['relatedUri'])) {
                 $newLink = new \Lelesys\Plugin\News\Domain\Model\Link();
                 $newLink->setTitle($link['relatedUriTitle']);
                 $newLink->setUri($link['relatedUri']);
                 $newLink->setDescription($link['relatedUriDescription']);
                 $newLink->setHidden($link['hidden']);
                 $this->linkService->create($newLink);
                 $news->addRelatedLinks($newLink);
             }
         }
     }
     $this->newsRepository->update($news);
     $this->emitNewsUpdated($news);
 }