/** * @param Asset $asset * @param MetaDataCollection $metaDataCollection */ public function mapMetaData(Asset $asset, MetaDataCollection $metaDataCollection) { $contextVariables = array_merge($this->defaultContextVariables, $metaDataCollection->toArray()); if (isset($this->metaDataMappingConfiguration['title'])) { $asset->setTitle(substr((string) EelUtility::evaluateEelExpression($this->metaDataMappingConfiguration['title'], $this->eelEvaluator, $contextVariables), 0, 255)); } if (isset($this->metaDataMappingConfiguration['caption'])) { $asset->setCaption((string) EelUtility::evaluateEelExpression($this->metaDataMappingConfiguration['caption'], $this->eelEvaluator, $contextVariables)); } if (isset($this->metaDataMappingConfiguration['tags'])) { $tagLabels = EelUtility::evaluateEelExpression($this->metaDataMappingConfiguration['tags'], $this->eelEvaluator, $contextVariables); $tagLabels = array_unique($tagLabels); $tags = new ArrayCollection(); foreach ($tagLabels as $tagLabel) { if (trim($tagLabel) !== '') { $tags->add($this->getOrCreateTag(trim($tagLabel))); } } $asset->setTags($tags); } if (isset($this->metaDataMappingConfiguration['collections'])) { $collectionTitles = EelUtility::evaluateEelExpression($this->metaDataMappingConfiguration['collections'], $this->eelEvaluator, $contextVariables); $collectionTitles = array_unique($collectionTitles); $collections = new ArrayCollection(); foreach ($collectionTitles as $collectionTitle) { if (trim($collectionTitle) !== '') { $collections->add($this->getOrCreateCollection(trim($collectionTitle))); } } $asset->setAssetCollections($collections); } if (!$this->persistenceManager->isNewObject($asset)) { $this->assetRepository->update($asset); } }
/** * @param Tag $tag * @return void */ public function deleteTagAction(Tag $tag) { $taggedAssets = $this->assetRepository->findByTag($tag); foreach ($taggedAssets as $asset) { $asset->removeTag($tag); $this->assetRepository->update($asset); } $this->tagRepository->remove($tag); $this->addFlashMessage('tagHasBeenDeleted', '', Message::SEVERITY_OK, [htmlspecialchars($tag->getLabel())]); $this->redirect('index'); }
/** * @param Tag $tag * @return void */ public function deleteTagAction(Tag $tag) { $taggedAssets = $this->assetRepository->findByTag($tag); foreach ($taggedAssets as $asset) { $asset->removeTag($tag); $this->assetRepository->update($asset); } $this->tagRepository->remove($tag); $this->addFlashMessage(sprintf('Tag "%s" has been deleted.', $tag->getLabel())); $this->redirect('index'); }
/** * Change the property on the given node. * * @param NodeData $node * @return void */ public function execute(NodeData $node) { foreach ($node->getNodeType()->getProperties() as $propertyName => $propertyConfiguration) { if (isset($propertyConfiguration['type']) && ($propertyConfiguration['type'] === 'TYPO3\\Media\\Domain\\Model\\ImageInterface' || preg_match('/array\\<.*\\>/', $propertyConfiguration['type']))) { if (!isset($nodeProperties)) { $nodeRecordQuery = $this->entityManager->getConnection()->prepare('SELECT properties FROM typo3_typo3cr_domain_model_nodedata WHERE persistence_object_identifier=?'); $nodeRecordQuery->execute([$this->persistenceManager->getIdentifierByObject($node)]); $nodeRecord = $nodeRecordQuery->fetch(\PDO::FETCH_ASSOC); $nodeProperties = unserialize($nodeRecord['properties']); } if (!isset($nodeProperties[$propertyName]) || empty($nodeProperties[$propertyName])) { continue; } if ($propertyConfiguration['type'] === 'TYPO3\\Media\\Domain\\Model\\ImageInterface') { $adjustments = array(); $oldVariantConfiguration = $nodeProperties[$propertyName]; if (is_array($oldVariantConfiguration)) { foreach ($oldVariantConfiguration as $variantPropertyName => $property) { switch (substr($variantPropertyName, 3)) { case 'originalImage': /** * @var $originalAsset \TYPO3\Media\Domain\Model\Image */ $originalAsset = $this->assetRepository->findByIdentifier($this->persistenceManager->getIdentifierByObject($property)); break; case 'processingInstructions': $adjustments = $this->processingInstructionsConverter->convertFrom($property, 'array'); break; } } $nodeProperties[$propertyName] = NULL; if (isset($originalAsset)) { $stream = $originalAsset->getResource()->getStream(); if ($stream === FALSE) { continue; } fclose($stream); $newImageVariant = new \TYPO3\Media\Domain\Model\ImageVariant($originalAsset); foreach ($adjustments as $adjustment) { $newImageVariant->addAdjustment($adjustment); } $originalAsset->addVariant($newImageVariant); $this->assetRepository->update($originalAsset); $nodeProperties[$propertyName] = $this->persistenceManager->getIdentifierByObject($newImageVariant); } } } elseif (preg_match('/array\\<.*\\>/', $propertyConfiguration['type'])) { if (is_array($nodeProperties[$propertyName])) { $convertedValue = []; foreach ($nodeProperties[$propertyName] as $entryValue) { if (!is_object($entryValue)) { continue; } $stream = $entryValue->getResource()->getStream(); if ($stream === FALSE) { continue; } fclose($stream); $existingObjectIdentifier = NULL; try { $existingObjectIdentifier = $this->persistenceManager->getIdentifierByObject($entryValue); if ($existingObjectIdentifier !== NULL) { $convertedValue[] = $existingObjectIdentifier; } } catch (\Exception $exception) { } } $nodeProperties[$propertyName] = $convertedValue; } } } } if (isset($nodeProperties)) { $nodeUpdateQuery = $this->entityManager->getConnection()->prepare('UPDATE typo3_typo3cr_domain_model_nodedata SET properties=? WHERE persistence_object_identifier=?'); $nodeUpdateQuery->execute([serialize($nodeProperties), $this->persistenceManager->getIdentifierByObject($node)]); } }
/** * 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); }