Skip to content

Commit

Permalink
Merge pull request #184 from Flowpack/feature/hierarchical-asset-coll…
Browse files Browse the repository at this point in the history
…ections

FEATURE: Hierarchical asset collections
  • Loading branch information
Sebobo authored Jun 29, 2023
2 parents 87c1622 + 3b5be95 commit 6beb20b
Show file tree
Hide file tree
Showing 413 changed files with 14,493 additions and 16,196 deletions.
2 changes: 0 additions & 2 deletions .babelrc

This file was deleted.

3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@ module.exports = {
es2020: true,
node: true,
},
ignorePatterns: ['.cache', '.parcel-cache', 'dist'],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{
args: 'none', // FIXME: Eslint shows warnings for used interfaces
},
],
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/ban-ts-ignore': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'no-unused-vars': 'off',
'prettier/prettier': ['error'],
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': [
Expand Down
17 changes: 17 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,20 @@
*.map binary
Plugin.js binary
Plugin.css binary

/Resources/Private/JavaScript export-ignore
/Tests export-ignore
/.yarn export-ignore
/.env export-ignore
/.github export-ignore
/.eslintrc.js export-ignore
/.eslintrc.js export-ignore
/.mocharc export-ignore
/.nvmrc export-ignore
/.testcaferc.json export-ignore
/.yarn.yml export-ignore
/.apollo.config.js export-ignore
/package.json export-ignore
/phpstan.neon export-ignore
/tsconfig.json export-ignore
/yarn.lock export-ignore
55 changes: 41 additions & 14 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
node-version-file: '.nvmrc'
cache: 'yarn'

- name: Install dependencies
Expand Down Expand Up @@ -53,40 +53,67 @@ jobs:
command: analyse

php-unit-tests:
env:
FLOW_CONTEXT: Testing
FLOW_FOLDER: ../flow-base-distribution

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php-versions: ['7.4']
flow-versions: ['7.3']

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: ${{ matrix.php-versions }}
extensions: mbstring, xml, json, zlib, iconv, intl, pdo_sqlite, mysql
coverage: xdebug #optional
ini-values: opcache.fast_shutdown=0

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.composer/cache
key: dependencies-composer-${{ hashFiles('composer.json') }}

- name: Install dependencies
uses: php-actions/composer@v6
with:
php_version: 7.4
version: 2

- name: Run PHPUnit tests
run: composer test
- name: Prepare Flow distribution
run: |
git clone https://github.com/neos/flow-base-distribution.git -b ${{ matrix.flow-versions }} ${FLOW_FOLDER}
cd ${FLOW_FOLDER}
composer require --no-update --no-interaction flowpack/media-ui
- name: Install distribution
run: |
cd ${FLOW_FOLDER}
composer install --no-interaction --no-progress
rm -rf Packages/Application/Flowpack.Media.Ui
cp -r ../media-ui Packages/Application/Flowpack.Media.Ui
- name: Run Unit tests
run: |
cd ${FLOW_FOLDER}
bin/phpunit --colors -c Build/BuildEssentials/PhpUnit/UnitTests.xml Packages/Application/Flowpack.Media.Ui/Tests/Unit/
- name: Run Functional tests
run: |
cd ${FLOW_FOLDER}
bin/phpunit --colors -c Build/BuildEssentials/PhpUnit/FunctionalTests.xml Packages/Application/Flowpack.Media.Ui/Tests/Functional/
js-unit-tests:
runs-on: ubuntu-latest

steps:
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
node-version-file: '.nvmrc'
cache: 'yarn'
- uses: actions/checkout@v2

- name: Install dependencies
run: yarn
Expand All @@ -105,7 +132,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
node-version-file: '.nvmrc'
cache: 'yarn'

- name: Install dependencies
Expand Down
11 changes: 8 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,23 @@
# Application & development dependencies.
#
node_modules
.yarn/cache
.yarn/install-state.gz
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
Packages
vendor
composer.lock
/.parcel-cache

#
# Compiled assets.
#
.cache
Resources/Private/JavaScript/dev-server/dist
Resources/Public
yarn-error.log

#
Expand Down
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/scripts/helpers/webpack.config.js b/scripts/helpers/webpack.config.js
index 25930d442a5aec4d22f1e890bd061ea3256570af..9f94a69f2892c156c5b2da64ba56363ffdaa1dfc 100644
--- a/scripts/helpers/webpack.config.js
+++ b/scripts/helpers/webpack.config.js
@@ -135,6 +135,11 @@ module.exports = function (neosPackageJson) {
}
],
},
+ performance: {
+ hints : false,
+ maxEntrypointSize: 1000000,
+ maxAssetSize: 1000000
+ },
entry: {
Plugin: './src/index.js'
},
121 changes: 121 additions & 0 deletions Classes/Aspect/HierarchicalAssetCollectionAspect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php

declare(strict_types=1);

namespace Flowpack\Media\Ui\Aspect;

/*
* This file is part of the Flowpack.Media.Ui package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Flowpack\Media\Ui\Domain\Model\HierarchicalAssetCollectionInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Aop\JoinPointInterface;
use Neos\Media\Domain\Model\AssetCollection;
use Neos\Utility\ObjectAccess;

/**
* An aspect for adding hierarchical relations to the Neos.Media AssetCollection entity
* This is a AOP patch until the same functionality is merged into the Neos core
*
* @Flow\Introduce("class(Neos\Media\Domain\Model\AssetCollection)", interfaceName="Flowpack\Media\Ui\Domain\Model\HierarchicalAssetCollectionInterface")
* @Flow\Aspect
*/
class HierarchicalAssetCollectionAspect
{

/**
* @var AssetCollection
* @ORM\ManyToOne(cascade={"persist"})
* @ORM\JoinColumn(onDelete="SET NULL")
* @Flow\Lazy
* @Flow\Introduce("class(Neos\Media\Domain\Model\AssetCollection)")
*/
protected $parent;

/**
* @Flow\Around("method(Neos\Media\Domain\Model\AssetCollection->getParent())")
*/
public function getParent(JoinPointInterface $joinPoint): ?HierarchicalAssetCollectionInterface
{
/** @var HierarchicalAssetCollectionInterface $assetCollection */
$assetCollection = $joinPoint->getProxy();
return ObjectAccess::getProperty($assetCollection, 'parent', true);
}

/**
* @Flow\Around("method(Neos\Media\Domain\Model\AssetCollection->setParent())")
*/
public function setParent(JoinPointInterface $joinPoint): void
{
/** @var HierarchicalAssetCollectionInterface $assetCollection */
$assetCollection = $joinPoint->getProxy();
/** @var HierarchicalAssetCollectionInterface $parentAssetCollection */
$parentAssetCollection = $joinPoint->getMethodArgument('parent');
if (!$parentAssetCollection instanceof AssetCollection && $parentAssetCollection !== null) {
throw new \InvalidArgumentException('Parent must be an AssetCollection', 1678330583);
}
ObjectAccess::setProperty($assetCollection, 'parent', $parentAssetCollection, true);

// Throws an error if a circular dependency has been detected
$parent = $assetCollection->getParent();
while ($parent !== null) {
$parent = $parent->getParent();
if ($parent === $assetCollection->getParent()) {
throw new \InvalidArgumentException(sprintf(
'Circular reference detected, parent AssetCollection "%s" appeared twice in the hierarchy',
$parent->getTitle()
), 1678330856);
}
}
}

/**
* @Flow\Around("method(Neos\Media\Domain\Model\AssetCollection->unsetParent())")
*/
public function unsetParent(JoinPointInterface $joinPoint): void
{
/** @var HierarchicalAssetCollectionInterface $assetCollection */
$assetCollection = $joinPoint->getProxy();
ObjectAccess::setProperty($assetCollection, 'parent', null, true);
}

/**
* @Flow\Around("method(Neos\Media\Domain\Model\AssetCollection->hasParent())")
*/
public function hasParent(JoinPointInterface $joinPoint): bool
{
/** @var HierarchicalAssetCollectionInterface $assetCollection */
$assetCollection = $joinPoint->getProxy();
return ObjectAccess::getProperty($assetCollection, 'parent', true) !== null;
}

/**
* @Flow\Around("method(Neos\Media\Domain\Model\AssetCollection->getTitle())")
*/
public function getTitle(JoinPointInterface $joinPoint): string
{
/** @var AssetCollection $assetCollection */
$assetCollection = $joinPoint->getProxy();
return $assetCollection->getTitle();
}

/**
* @Flow\Around("method(Neos\Media\Domain\Model\AssetCollection->getTags())")
*/
public function getTags(JoinPointInterface $joinPoint): Collection
{
/** @var AssetCollection $assetCollection */
$assetCollection = $joinPoint->getProxy();
return $assetCollection->getTags();
}
}
58 changes: 58 additions & 0 deletions Classes/Aspect/HierarchicalAssetCollectionRepositoryAspect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace Flowpack\Media\Ui\Aspect;

/*
* This file is part of the Flowpack.Media.Ui package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Flowpack\Media\Ui\Domain\Model\HierarchicalAssetCollectionInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Aop\JoinPointInterface;
use Neos\Flow\Persistence\QueryResultInterface;
use Neos\Media\Domain\Model\AssetCollection;
use Neos\Media\Domain\Repository\AssetCollectionRepository;
use Neos\Utility\ObjectAccess;

/**
* An aspect for adding hierarchical relations to the Neos.Media AssetCollection entity
* This is a AOP patch until the same functionality is merged into the Neos core
*
* @Flow\Aspect
*/
class HierarchicalAssetCollectionRepositoryAspect
{
/**
* Remove all child collections recursively to prevent orphaned collections
*
* @Flow\Around("method(Neos\Media\Domain\Repository\AssetCollectionRepository->remove())")
*/
public function remove(JoinPointInterface $joinPoint): void
{
/** @var AssetCollectionRepository $assetCollectionRepository */
$assetCollectionRepository = $joinPoint->getProxy();
/** @var AssetCollection $assetCollection */
$assetCollection = $joinPoint->getMethodArgument('object');
$persistenceManager = ObjectAccess::getProperty($assetCollectionRepository, 'persistenceManager', true);

$deleteRecursively = static function (AssetCollection $collection) use (&$deleteRecursively, $persistenceManager, $assetCollectionRepository) {
$childCollections = $assetCollectionRepository->findByParent($collection);
foreach ($childCollections as $childCollection) {
$deleteRecursively($childCollection);
}
$persistenceManager->remove($collection);
};
$deleteRecursively($assetCollection);
}
}
Loading

0 comments on commit 6beb20b

Please sign in to comment.