Skip to content
This repository has been archived by the owner on Sep 1, 2019. It is now read-only.

Commit

Permalink
Merge pull request #2 from kdambekalns/neos3-compatibility
Browse files Browse the repository at this point in the history
TASK: Make compatible with Neos 3.x
  • Loading branch information
Bastian Waidelich authored Oct 17, 2017
2 parents 4421159 + 2ffbd96 commit fddd538
Show file tree
Hide file tree
Showing 17 changed files with 226 additions and 146 deletions.
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
<?php
namespace Wwwision\AssetConstraints\Aspects;


use TYPO3\Eel\FlowQuery\FlowQuery;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Aop\JoinPointInterface;
use TYPO3\Flow\Mvc\ActionRequest;
use TYPO3\Flow\Property\PropertyMapper;
use TYPO3\Flow\Reflection\ObjectAccess;
use TYPO3\Media\Domain\Model\Asset;
use TYPO3\Media\Domain\Model\AssetCollection;
use TYPO3\Media\Domain\Repository\AssetCollectionRepository;
use TYPO3\Neos\Controller\Backend\ContentController;
use TYPO3\TYPO3CR\Domain\Model\NodeInterface;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\Eel\FlowQuery\FlowQuery;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Aop\JoinPointInterface;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Property\PropertyMapper;
use Neos\Media\Domain\Model\Asset;
use Neos\Media\Domain\Model\AssetCollection;
use Neos\Media\Domain\Repository\AssetCollectionRepository;
use Neos\Neos\Controller\Backend\ContentController;
use Neos\Utility\ObjectAccess;

/**
* AOP Aspect that hooks into uploading of assets in order to set the AssetCollection based on the current node
*
* It will look for the closest node matching the "Wwwision.AssetConstraints.nodeLookup.nodeFilter" setting (the closest Document node by default)
* and check whether that node has a property called "assetCollection" to add the uploaded asset to that collection (the name of the property can be changed
* via the "Wwwision.AssetConstraints.nodeLookup.propertyName" setting)
* It will look for the closest node matching the "Wwwision.AssetConstraints.nodeLookup.nodeFilter" setting (the
* closest Document node by default) and check whether that node has a property called "assetCollection" to add the
* uploaded asset to that collection (the name of the property can be changed via the
* "Wwwision.AssetConstraints.nodeLookup.propertyName" setting)
*
* @Flow\Scope("singleton")
* @Flow\Aspect
*/
class ContentControllerAspect
{

/**
* @Flow\Inject
* @var PropertyMapper
Expand All @@ -52,29 +50,29 @@ class ContentControllerAspect
protected $lookupPropertyName;

/**
* @Flow\Before("method(TYPO3\Neos\Controller\Backend\ContentController->uploadAssetAction())")
* @Flow\Before("method(Neos\Neos\Controller\Backend\ContentController->uploadAssetAction())")
* @param JoinPointInterface $joinPoint The current join point
* @return void
*/
public function rewriteSiteAssetCollection(JoinPointInterface $joinPoint)
{
if ($this->lookupNodeFilter === NULL || $this->lookupPropertyName === NULL) {
if ($this->lookupNodeFilter === null || $this->lookupPropertyName === null) {
return;
}

/** @var ContentController $contentController */
$contentController = $joinPoint->getProxy();
/** @var ActionRequest $actionRequest */
$actionRequest = ObjectAccess::getProperty($contentController, 'request', TRUE);
$actionRequest = ObjectAccess::getProperty($contentController, 'request', true);

$nodeContextPath = $actionRequest->getInternalArgument('__node');
if ($nodeContextPath === NULL) {
if ($nodeContextPath === null) {
return;
}

$node = $this->propertyMapper->convert($nodeContextPath, NodeInterface::class);

$flowQuery = new FlowQuery(array($node));
$flowQuery = new FlowQuery([$node]);
/** @var NodeInterface $documentNode */
$documentNode = $flowQuery->closest($this->lookupNodeFilter)->get(0);

Expand All @@ -83,7 +81,7 @@ public function rewriteSiteAssetCollection(JoinPointInterface $joinPoint)
}
/** @var AssetCollection $assetCollection */
$assetCollection = $this->assetCollectionRepository->findByIdentifier($documentNode->getProperty($this->lookupPropertyName));
if ($assetCollection === NULL) {
if ($assetCollection === null) {
return;
}

Expand All @@ -92,5 +90,4 @@ public function rewriteSiteAssetCollection(JoinPointInterface $joinPoint)
$assetCollection->addAsset($asset);
$this->assetCollectionRepository->update($assetCollection);
}

}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
namespace Wwwision\AssetConstraints\DataSource;

use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Persistence\PersistenceManagerInterface;
use TYPO3\Media\Domain\Model\AssetCollection;
use TYPO3\Media\Domain\Repository\AssetCollectionRepository;
use TYPO3\Neos\Service\DataSource\AbstractDataSource;
use TYPO3\TYPO3CR\Domain\Model\NodeInterface;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Persistence\PersistenceManagerInterface;
use Neos\Media\Domain\Model\AssetCollection;
use Neos\Media\Domain\Repository\AssetCollectionRepository;
use Neos\Neos\Service\DataSource\AbstractDataSource;

/**
* A Data source that allows to render a selector for all AssetCollections in the Neos inspector
Expand All @@ -24,7 +24,6 @@
*/
class AssetCollectionDataSource extends AbstractDataSource
{

/**
* @var string
*/
Expand All @@ -49,13 +48,14 @@ class AssetCollectionDataSource extends AbstractDataSource
* @param array $arguments unused
* @return array title of all asset collections
*/
public function getData(NodeInterface $node = NULL, array $arguments)
public function getData(NodeInterface $node = null, array $arguments)
{
$assetCollections = [];
/** @var AssetCollection $assetCollection */
foreach ($this->assetCollectionRepository->findAll() as $assetCollection) {
$assetCollections[] = ['value' => $this->persistenceManager->getIdentifierByObject($assetCollection), 'label' => $assetCollection->getTitle()];
}

return $assetCollections;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\Query\Filter\SQLFilter as DoctrineSqlFilter;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Security\Authorization\Privilege\Entity\Doctrine\PropertyConditionGenerator;
use TYPO3\Flow\Security\Authorization\Privilege\Entity\Doctrine\SqlGeneratorInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Security\Authorization\Privilege\Entity\Doctrine\PropertyConditionGenerator;
use Neos\Flow\Security\Authorization\Privilege\Entity\Doctrine\SqlGeneratorInterface;

/**
* Condition generator covering Asset <-> AssetCollection relations (M:M relations are not supported by the Flow PropertyConditionGenerator yet)
* Condition generator covering Asset <-> AssetCollection relations (M:M relations are not supported by the Flow
* PropertyConditionGenerator yet)
*/
class AssetAssetCollectionConditionGenerator implements SqlGeneratorInterface
{

/**
* @Flow\Inject
* @var ObjectManager
Expand Down Expand Up @@ -44,11 +44,12 @@ public function getSql(DoctrineSqlFilter $sqlFilter, ClassMetadata $targetEntity
$propertyConditionGenerator = new PropertyConditionGenerator('');
$collectionTitle = $propertyConditionGenerator->getValueForOperand($this->collectionTitle);
$quotedCollectionTitle = $this->entityManager->getConnection()->quote($collectionTitle);

return $targetTableAlias . '.persistence_object_identifier IN (
SELECT ' . $targetTableAlias . '_a.persistence_object_identifier
FROM typo3_media_domain_model_asset AS ' . $targetTableAlias . '_a
LEFT JOIN typo3_media_domain_model_assetcollection_assets_join ' . $targetTableAlias . '_acj ON ' . $targetTableAlias . '_a.persistence_object_identifier = ' . $targetTableAlias . '_acj.media_asset
LEFT JOIN typo3_media_domain_model_assetcollection ' . $targetTableAlias . '_ac ON ' . $targetTableAlias . '_ac.persistence_object_identifier = ' . $targetTableAlias . '_acj.media_assetcollection
FROM neos_media_domain_model_asset AS ' . $targetTableAlias . '_a
LEFT JOIN neos_media_domain_model_assetcollection_assets_join ' . $targetTableAlias . '_acj ON ' . $targetTableAlias . '_a.persistence_object_identifier = ' . $targetTableAlias . '_acj.media_asset
LEFT JOIN neos_media_domain_model_assetcollection ' . $targetTableAlias . '_ac ON ' . $targetTableAlias . '_ac.persistence_object_identifier = ' . $targetTableAlias . '_acj.media_assetcollection
WHERE ' . $targetTableAlias . '_ac.title = ' . $quotedCollectionTitle . ')';
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<?php
namespace Wwwision\AssetConstraints\Security\Authorization\Privilege\Doctrine;

use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Security\Authorization\Privilege\Entity\Doctrine\ConditionGenerator as EntityConditionGenerator;
use TYPO3\Flow\Security\Authorization\Privilege\Entity\Doctrine\PropertyConditionGenerator;
use TYPO3\Flow\Security\Exception\InvalidPrivilegeException;
use TYPO3\Media\Domain\Model\AssetCollection;
use Neos\Flow\Security\Authorization\Privilege\Entity\Doctrine\ConditionGenerator as EntityConditionGenerator;
use Neos\Flow\Security\Authorization\Privilege\Entity\Doctrine\PropertyConditionGenerator;
use Neos\Flow\Security\Exception\InvalidPrivilegeException;
use Neos\Media\Domain\Model\AssetCollection;

/**
* A SQL condition generator, supporting special SQL constraints for asset collections
*/
class AssetCollectionConditionGenerator extends EntityConditionGenerator
{

/**
* @var string
*/
Expand All @@ -35,7 +33,7 @@ public function isType($entityType)
public function isTitled($collectionTitle)
{
$propertyConditionGenerator = new PropertyConditionGenerator('title');

return $propertyConditionGenerator->equals($collectionTitle);
}

}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<?php
namespace Wwwision\AssetConstraints\Security\Authorization\Privilege\Doctrine;

use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Security\Authorization\Privilege\Entity\Doctrine\ConditionGenerator as EntityConditionGenerator;
use TYPO3\Flow\Security\Authorization\Privilege\Entity\Doctrine\PropertyConditionGenerator;
use TYPO3\Flow\Security\Exception\InvalidPrivilegeException;
use TYPO3\Media\Domain\Model\Asset;
use Neos\Flow\Security\Authorization\Privilege\Entity\Doctrine\ConditionGenerator as EntityConditionGenerator;
use Neos\Flow\Security\Authorization\Privilege\Entity\Doctrine\PropertyConditionGenerator;
use Neos\Flow\Security\Exception\InvalidPrivilegeException;
use Neos\Media\Domain\Model\Asset;

/**
* A SQL condition generator, supporting special SQL constraints for assets
*/
class AssetConditionGenerator extends EntityConditionGenerator
{

/**
* @var string
*/
Expand All @@ -35,6 +33,7 @@ public function isType($entityType)
public function titleStartsWith($term)
{
$propertyConditionGenerator = new PropertyConditionGenerator('title');

return $propertyConditionGenerator->like($term . '%');
}

Expand All @@ -45,6 +44,7 @@ public function titleStartsWith($term)
public function hasMediaType($mediaType)
{
$propertyConditionGenerator = new PropertyConditionGenerator('resource.mediaType');

return $propertyConditionGenerator->equals($mediaType);
}

Expand Down Expand Up @@ -73,5 +73,4 @@ public function isWithoutCollection()
{
return new AssetWithoutAssetCollectionConditionGenerator();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\Query\Filter\SQLFilter as DoctrineSqlFilter;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Security\Authorization\Privilege\Entity\Doctrine\PropertyConditionGenerator;
use TYPO3\Flow\Security\Authorization\Privilege\Entity\Doctrine\SqlGeneratorInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Security\Authorization\Privilege\Entity\Doctrine\PropertyConditionGenerator;
use Neos\Flow\Security\Authorization\Privilege\Entity\Doctrine\SqlGeneratorInterface;

/**
* Condition generator covering Asset <-> Tag relations (M:M relations are not supported by the Flow PropertyConditionGenerator yet)
* Condition generator covering Asset <-> Tag relations (M:M relations are not supported by the Flow
* PropertyConditionGenerator yet)
*/
class AssetTagConditionGenerator implements SqlGeneratorInterface
{

/**
* @Flow\Inject
* @var ObjectManager
Expand Down Expand Up @@ -44,11 +44,12 @@ public function getSql(DoctrineSqlFilter $sqlFilter, ClassMetadata $targetEntity
$propertyConditionGenerator = new PropertyConditionGenerator('');
$tagLabel = $propertyConditionGenerator->getValueForOperand($this->tagLabel);
$quotedTagLabel = $this->entityManager->getConnection()->quote($tagLabel);

return $targetTableAlias . '.persistence_object_identifier IN (
SELECT ' . $targetTableAlias . '_a.persistence_object_identifier
FROM typo3_media_domain_model_asset AS ' . $targetTableAlias . '_a
LEFT JOIN typo3_media_domain_model_asset_tags_join ' . $targetTableAlias . '_atj ON ' . $targetTableAlias . '_a.persistence_object_identifier = ' . $targetTableAlias . '_atj.media_asset
LEFT JOIN typo3_media_domain_model_tag ' . $targetTableAlias . '_t ON ' . $targetTableAlias . '_t.persistence_object_identifier = ' . $targetTableAlias . '_atj.media_tag
FROM neos_media_domain_model_asset AS ' . $targetTableAlias . '_a
LEFT JOIN neos_media_domain_model_asset_tags_join ' . $targetTableAlias . '_atj ON ' . $targetTableAlias . '_a.persistence_object_identifier = ' . $targetTableAlias . '_atj.media_asset
LEFT JOIN neos_media_domain_model_tag ' . $targetTableAlias . '_t ON ' . $targetTableAlias . '_t.persistence_object_identifier = ' . $targetTableAlias . '_atj.media_tag
WHERE ' . $targetTableAlias . '_t.label = ' . $quotedTagLabel . ')';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\Query\Filter\SQLFilter as DoctrineSqlFilter;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Security\Authorization\Privilege\Entity\Doctrine\SqlGeneratorInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Security\Authorization\Privilege\Entity\Doctrine\SqlGeneratorInterface;

/**
* Condition generator covering Asset >-< AssetCollection relations (M:M relations are not supported by the Flow PropertyConditionGenerator yet)
* Condition generator covering Asset >-< AssetCollection relations (M:M relations are not supported by the Flow
* PropertyConditionGenerator yet)
*/
class AssetWithoutAssetCollectionConditionGenerator implements SqlGeneratorInterface
{

/**
* @Flow\Inject
* @var ObjectManager
Expand All @@ -29,9 +29,10 @@ public function getSql(DoctrineSqlFilter $sqlFilter, ClassMetadata $targetEntity
{
$sql = $targetTableAlias . '.persistence_object_identifier IN (
SELECT ' . $targetTableAlias . '_a.persistence_object_identifier
FROM typo3_media_domain_model_asset AS ' . $targetTableAlias . '_a
LEFT JOIN typo3_media_domain_model_assetcollection_assets_join ' . $targetTableAlias . '_acj ON ' . $targetTableAlias . '_a.persistence_object_identifier = ' . $targetTableAlias . '_acj.media_asset
FROM neos_media_domain_model_asset AS ' . $targetTableAlias . '_a
LEFT JOIN neos_media_domain_model_assetcollection_assets_join ' . $targetTableAlias . '_acj ON ' . $targetTableAlias . '_a.persistence_object_identifier = ' . $targetTableAlias . '_acj.media_asset
WHERE ' . $targetTableAlias . '_acj.media_asset IS NULL)';

return $sql;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<?php
namespace Wwwision\AssetConstraints\Security\Authorization\Privilege\Doctrine;

use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Security\Authorization\Privilege\Entity\Doctrine\ConditionGenerator as EntityConditionGenerator;
use TYPO3\Flow\Security\Authorization\Privilege\Entity\Doctrine\PropertyConditionGenerator;
use TYPO3\Flow\Security\Exception\InvalidPrivilegeException;
use TYPO3\Media\Domain\Model\Tag;
use Neos\Flow\Security\Authorization\Privilege\Entity\Doctrine\ConditionGenerator as EntityConditionGenerator;
use Neos\Flow\Security\Authorization\Privilege\Entity\Doctrine\PropertyConditionGenerator;
use Neos\Flow\Security\Exception\InvalidPrivilegeException;
use Neos\Media\Domain\Model\Tag;

/**
* A SQL condition generator, supporting special SQL constraints for tags
*/
class TagConditionGenerator extends EntityConditionGenerator
{

/**
* @var string
*/
Expand All @@ -35,7 +33,7 @@ public function isType($entityType)
public function isLabeled($tagLabel)
{
$propertyConditionGenerator = new PropertyConditionGenerator('label');

return $propertyConditionGenerator->equals($tagLabel);
}

}
}
Loading

0 comments on commit fddd538

Please sign in to comment.