Skip to content
Merged
57 changes: 50 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.2

- name: Add additional dependencies
run: |
composer require --no-update --no-interaction neos/contentgraph-doctrinedbaladapter:"~9.0.0"

- name: Cache dependencies
uses: actions/cache@v3
Expand All @@ -47,13 +51,13 @@ jobs:
- name: Install dependencies
uses: php-actions/composer@v6
with:
php_version: 8.1
php_version: 8.2
version: 2

- name: PHPStan
uses: php-actions/phpstan@v3
with:
php_version: 8.1
php_version: 8.2
version: 2.1.17
command: analyse
path: 'Classes/'
Expand All @@ -68,8 +72,22 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: ['8.1']
flow-versions: ['8.3']
php-versions: ['8.2']
flow-versions: ['9.0']

services:
mariadb:
# see https://mariadb.com/kb/en/mariadb-server-release-dates/
# this should be a current release, e.g. the LTS version
image: mariadb:10.8
env:
MYSQL_USER: neos
MYSQL_PASSWORD: neos
MYSQL_DATABASE: neos_functional_testing
MYSQL_ROOT_PASSWORD: neos
ports:
- "3306:3306"
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- uses: actions/checkout@v3
Expand All @@ -96,12 +114,11 @@ jobs:
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/entity-usage:"^1.1"
composer require --no-update --no-interaction flowpack/entity-usage-databasestorage:"^0.1"

git -C ../${{ env.PACKAGE_FOLDER }} checkout -b build
composer config repositories.package '{ "type": "path", "url": "../${{ env.PACKAGE_FOLDER }}", "options": { "symlink": false } }'
composer require --no-update --no-interaction flowpack/media-ui:"dev-build as dev-${PACKAGE_TARGET_VERSION}"
composer require --no-update --no-interaction neos/contentgraph-doctrinedbaladapter:"~9.0.0"

- name: Composer Install
run: |
Expand All @@ -113,11 +130,37 @@ jobs:
cd ${FLOW_FOLDER}
bin/phpunit --colors -c Build/BuildEssentials/PhpUnit/UnitTests.xml Packages/Application/Flowpack.Media.Ui/Tests/Unit/

- name: Setup Flow configuration
run: |
cd ${FLOW_FOLDER}
rm -f Configuration/Testing/Settings.yaml
cat <<EOF >> Configuration/Testing/Settings.yaml
Neos:
Flow:
persistence:
backendOptions:
host: '127.0.0.1'
driver: pdo_mysql
user: 'neos'
password: 'neos'
dbname: 'neos_functional_testing'
EOF

- name: Run Functional tests
run: |
cd ${FLOW_FOLDER}
bin/phpunit --colors -c Build/BuildEssentials/PhpUnit/FunctionalTests.xml Packages/Application/Flowpack.Media.Ui/Tests/Functional/

- name: Show log on failure
if: ${{ failure() }}
run: |
cd ${FLOW_PATH_ROOT}
cat Data/Logs/System_Testing.log
for file in Data/Logs/Exceptions/*; do
echo $file
cat $file
done

js-unit-tests:
runs-on: ubuntu-latest

Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Model/AssetSource/NeosAssetProxyRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function orderBy(array $orderings): void
$this->assetRepository->setDefaultOrderings($orderings);
}

public function filterByType(AssetTypeFilter $assetType = null): void
public function filterByType(?AssetTypeFilter $assetType = null): void
{
$this->assetTypeFilter = (string)$assetType ?: 'All';
$this->initializeObject();
Expand All @@ -126,7 +126,7 @@ public function filterByMediaType(string $mediaType): void
* NOTE: This needs to be refactored to use an asset collection identifier instead of Media's domain model before
* it can become a public API for other asset sources.
*/
public function filterByCollection(AssetCollection $assetCollection = null): void
public function filterByCollection(?AssetCollection $assetCollection = null): void
{
$this->activeAssetCollection = $assetCollection;
}
Expand Down
5 changes: 2 additions & 3 deletions Classes/GraphQL/MediaApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,12 @@ public function assetUsageCount(Types\AssetId $id, Types\AssetSourceId $assetSou
#[Query]
public function unusedAssets(int $limit = 20, int $offset = 0): Types\Assets
{
$assets = [];
try {
$assets = $this->usageDetailsService->getUnusedAssets($limit, $offset, Types\AssetSourceId::default());
return $this->usageDetailsService->getUnusedAssets($limit, $offset, Types\AssetSourceId::default());
} catch (MediaUiException $e) {
$this->logger->error('Could not retrieve unused assets', ['exception' => $e]);
}
return Types\Assets::fromAssets($assets);
return Types\Assets::empty();
}

#[Description('Provides a list of changes to assets since a given timestamp')]
Expand Down
5 changes: 5 additions & 0 deletions Classes/GraphQL/Types/AssetCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ private function __construct(
public readonly ?AssetCollectionPath $path = null,
) {
}

public function equals(?AssetCollection $assetCollection): bool
{
return $assetCollection !== null && $this->id->equals($assetCollection->id);
}
}
5 changes: 5 additions & 0 deletions Classes/GraphQL/Types/AssetCollectionId.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ public function isUnassigned(): bool
{
return $this->value === self::UNASSIGNED;
}

public function equals(?AssetCollectionId $id): bool
{
return $this->value === $id?->value;
}
}
3 changes: 3 additions & 0 deletions Classes/GraphQL/Types/AssetCollections.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#[ListBased(itemClassName: AssetCollection::class)]
final class AssetCollections implements \IteratorAggregate
{
/**
* @param AssetCollection[] $collections
*/
private function __construct(public readonly array $collections)
{
}
Expand Down
12 changes: 11 additions & 1 deletion Classes/GraphQL/Types/AssetSourceId.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#[Description('Unique identifier of an Asset source (e.g. "neos")')]
#[Flow\Proxy(false)]
#[StringBased]
final class AssetSourceId implements \JsonSerializable
final class AssetSourceId implements \JsonSerializable, \Stringable
{
private function __construct(public readonly string $value)
{
Expand All @@ -26,4 +26,14 @@ public static function default(): self
{
return new self('neos');
}

public static function fromString(string $value): self
{
return new self($value);
}

public function __toString(): string
{
return $this->value;
}
}
18 changes: 7 additions & 11 deletions Classes/Service/AssetCollectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
use Flowpack\Media\Ui\Domain\Model\HierarchicalAssetCollectionInterface;
use Flowpack\Media\Ui\GraphQL\Types;
use Flowpack\Media\Ui\Utility\AssetCollectionUtility;
use Neos\ContentRepository\Domain\Service\ContextFactoryInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
use Neos\Media\Domain\Model\AssetCollection;
use Neos\Media\Domain\Repository\AssetCollectionRepository;
use Neos\Neos\Domain\Service\ContentContext;
use Neos\Neos\Domain\Repository\DomainRepository;

#[Flow\Scope('singleton')]
class AssetCollectionService
Expand All @@ -37,11 +36,8 @@ class AssetCollectionService
#[Flow\Inject]
protected AssetCollectionRepository $assetCollectionRepository;

/**
* @var ContextFactoryInterface
*/
#[Flow\Inject]
protected $contextFactory;
protected DomainRepository $domainRepository;

/**
* Queries the asset count for all asset collections once and caches the result.
Expand Down Expand Up @@ -98,11 +94,11 @@ public function updatePathForNestedAssetCollections(HierarchicalAssetCollectionI
*/
public function getDefaultCollectionForCurrentSite(): ?AssetCollection
{
/** @var ContentContext $context */
$context = $this->contextFactory->create([
'workspaceName' => 'live',
]);
$domain = $this->domainRepository->findOneByActiveRequest();
if ($domain !== null) {
return $domain->getSite()->getAssetCollection();
}

return $context->getCurrentSite()?->getAssetCollection();
return null;
}
}
Loading
Loading