Skip to content

Commit

Permalink
Merge branch hotfix/v2.3.28
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Sep 24, 2024
1 parent c6b0956 commit 1e9501d
Show file tree
Hide file tree
Showing 39 changed files with 1,440 additions and 2,085 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.0', '8.1']
php-version: ['8.1', '8.2', '8.3']
steps:
- uses: shivammathur/setup-php@v2
with:
Expand All @@ -35,8 +35,8 @@ jobs:
${{ runner.os }}-php-${{ matrix.php-version }}-
- name: Install Dependencies
run: composer install --no-scripts --no-ansi --no-interaction --no-progress
- name: Run atoum unit tests
run: vendor/bin/atoum -d tests
- name: Run Unit tests
run: vendor/bin/phpunit -v --whitelist ./src tests
- name: Run PHP Code Sniffer
run: vendor/bin/phpcs -p ./src
- name: Run PHPStan
Expand Down
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#
# Roadiz
#
/pimple.json

# Ignore Google webmaster tool verification
/google*.html
Expand Down
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright © 2023 Ambroise Maupate
Copyright © 2024 Ambroise Maupate

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
13 changes: 0 additions & 13 deletions Makefile

This file was deleted.

32 changes: 19 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,34 @@
}
],
"require": {
"php": ">=8.0",
"php": ">=8.1",
"ext-json": "*",
"ext-gd": "*",
"ext-dom": "*",
"ext-zip": "*",
"ext-simplexml": "*",
"ext-fileinfo": "*",
"doctrine/orm": "<2.17",
"doctrine/orm": "~2.19.0",
"enshrined/svg-sanitize": "^0.15",
"guzzlehttp/guzzle": "^7.2.0",
"guzzlehttp/psr7": "^2.0",
"intervention/image": "^2.5",
"league/flysystem": "^3.0",
"monolog/monolog": "^1.24.0 || ^2.1.1",
"symfony/asset": "5.4.*",
"symfony/console": "5.4.*",
"symfony/event-dispatcher": "5.4.*",
"symfony/filesystem": "5.4.*",
"symfony/finder": "5.4.*",
"symfony/http-foundation": "5.4.*",
"symfony/options-resolver": "5.4.*",
"symfony/serializer": "5.4.*",
"symfony/asset": "6.4.*",
"symfony/console": "6.4.*",
"symfony/event-dispatcher": "6.4.*",
"symfony/filesystem": "6.4.*",
"symfony/finder": "6.4.*",
"symfony/http-foundation": "6.4.*",
"symfony/options-resolver": "6.4.*",
"symfony/serializer": "6.4.*",
"twig/twig": "^3.1"
},
"require-dev": {
"php-coveralls/php-coveralls": "^2.4",
"atoum/atoum": "^4.0.0",
"phpunit/phpunit": "^9.5",
"api-platform/metadata": "^3.2.12",
"squizlabs/php_codesniffer": "^3.5",
"phpstan/phpstan": "^1.5.3",
"phpstan/phpstan-doctrine": "^1.3"
Expand All @@ -54,6 +55,11 @@
"RZ\\Roadiz\\Documents\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"RZ\\Roadiz\\Documents\\Tests\\": "tests/"
}
},
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": true,
Expand All @@ -62,8 +68,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.1.x-dev",
"dev-develop": "2.2.x-dev"
"dev-master": "2.3.x-dev",
"dev-develop": "2.4.x-dev"
}
}
}
11 changes: 0 additions & 11 deletions docker-compose.yml

This file was deleted.

8 changes: 5 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
parameters:
level: max
level: 7
paths:
- src
excludePaths:
- */node_modules/*
- */bower_components/*
- */static/*
ignoreErrors:
- identifier: missingType.iterableValue
- identifier: missingType.generics
- '#Call to an undefined method Doctrine\\Persistence\\ObjectRepository#'
- '#Call to an undefined method Doctrine\\Persistence\\ObjectManager#'
- '#Call to an undefined method Doctrine\\ORM\\EntityRepository#'
Expand All @@ -17,9 +19,9 @@ parameters:
- '#Doctrine\\ORM\\Mapping\\GeneratedValue constructor expects#'
- '#type mapping mismatch: property can contain Doctrine\\Common\\Collections\\Collection<int, [^\>]+> but database expects Doctrine\\Common\\Collections\\Collection&iterable<[^\>]+>#'
- '#should return Doctrine\\Common\\Collections\\Collection<int, [^\>]+Interface> but returns Doctrine\\Common\\Collections\\Collection<int, [^\>]+>#'
- '#but returns Doctrine\\Common\\Collections\\ReadableCollection<int, [^\>]+>#'
- '#does not accept Doctrine\\Common\\Collections\\ReadableCollection<int, [^\>]+>#'
reportUnmatchedIgnoredErrors: false
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false

includes:
- vendor/phpstan/phpstan-doctrine/extension.neon
Expand Down
5 changes: 4 additions & 1 deletion src/AbstractDocumentFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ public function findPicturesWithFilename(string $fileName): iterable
{
$pathInfo = pathinfo($fileName);
$basename = $pathInfo['filename'];
$currentExtension = $pathInfo['extension'];
$currentExtension = $pathInfo['extension'] ?? null;
if (null === $currentExtension) {
return [];
}
$extensionsList = [
'jpg',
'gif',
Expand Down
4 changes: 2 additions & 2 deletions src/Console/DocumentClearFolderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ protected function getDocumentQueryBuilder(FolderInterface $folder): QueryBuilde
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->io = new SymfonyStyle($input, $output);
$folderId = $input->getArgument('folderId');

$folderId = intval($input->getArgument('folderId'));
if ($folderId <= 0) {
if (!\is_numeric($folderId) || $folderId <= 0) {
throw new \InvalidArgumentException('Folder ID must be a valid ID');
}
$em = $this->getManager();
Expand Down
19 changes: 12 additions & 7 deletions src/DocumentArchiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,18 @@
*/
final class DocumentArchiver
{
private FilesystemOperator $documentsStorage;

public function __construct(FilesystemOperator $documentsStorage)
public function __construct(private readonly FilesystemOperator $documentsStorage)
{
$this->documentsStorage = $documentsStorage;
}

/**
* @param array $documents
* @param iterable<DocumentInterface> $documents
* @param string $name
* @param bool $keepFolders
* @return string Zip file path
* @throws FilesystemException
*/
public function archive(array $documents, string $name, bool $keepFolders = true): string
public function archive(iterable $documents, string $name, bool $keepFolders = true): string
{
$filename = (new AsciiSlugger())->slug($name . ' ' . date('YmdHis'), '_') . '.zip';
$tmpFileName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $filename;
Expand Down Expand Up @@ -60,8 +57,16 @@ public function archive(array $documents, string $name, bool $keepFolders = true
return $tmpFileName;
}

/**
* @param iterable<DocumentInterface> $documents
* @param string $name
* @param bool $keepFolders
* @param bool $unlink
* @return BinaryFileResponse
* @throws FilesystemException
*/
public function archiveAndServe(
array $documents,
iterable $documents,
string $name,
bool $keepFolders = true,
bool $unlink = true
Expand Down
27 changes: 7 additions & 20 deletions src/DownscaleImageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,14 @@

final class DownscaleImageManager
{
protected EntityManagerInterface $em;
protected ?LoggerInterface $logger;
protected int $maxPixelSize = 0;
protected string $rawImageSuffix = ".raw";
protected ImageManager $imageManager;
private FilesystemOperator $documentsStorage;

public function __construct(
EntityManagerInterface $em,
FilesystemOperator $documentsStorage,
ImageManager $imageManager,
?LoggerInterface $logger = null,
int $maxPixelSize = 0,
string $rawImageSuffix = ".raw"
private readonly EntityManagerInterface $em,
private readonly FilesystemOperator $documentsStorage,
private readonly ImageManager $imageManager,
private readonly ?LoggerInterface $logger = null,
private readonly int $maxPixelSize = 0,
private readonly string $rawImageSuffix = ".raw"
) {
$this->maxPixelSize = $maxPixelSize;
$this->rawImageSuffix = $rawImageSuffix;
$this->em = $em;
$this->logger = $logger;
$this->imageManager = $imageManager;
$this->documentsStorage = $documentsStorage;
}

/**
Expand Down Expand Up @@ -97,7 +84,7 @@ public function processDocumentFromExistingRaw(?DocumentInterface $document = nu
null !== $this->createDocumentFromImage($document, $processImage, true)
&& null !== $this->logger
) {
$this->logger->info('Document has been downscaled.', ['path' => $documentPath]);
$this->logger->info('Document has been downscaled.', ['path' => $documentPath, 'entity' => $document]);
}
}
}
Expand Down
40 changes: 26 additions & 14 deletions src/Events/DocumentLifeCycleSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Doctrine\Persistence\Event\LifecycleEventArgs;
use League\Flysystem\FilesystemException;
use League\Flysystem\FilesystemOperator;
use League\Flysystem\UnableToMoveFile;
use League\Flysystem\Visibility;
use RZ\Roadiz\Documents\Exceptions\DocumentWithoutFileException;
use RZ\Roadiz\Documents\Models\DocumentInterface;
Expand Down Expand Up @@ -52,19 +51,9 @@ public function preUpdate(PreUpdateEventArgs $args): void
&& is_string($args->getNewValue('filename'))
&& $args->getOldValue('filename') !== ''
) {
$oldPath = $this->getDocumentMountPathForFilename($document, $args->getOldValue('filename'));
$newPath = $this->getDocumentMountPathForFilename($document, $args->getNewValue('filename'));

if ($oldPath !== $newPath) {
if ($this->documentsStorage->fileExists($oldPath) && !$this->documentsStorage->fileExists($newPath)) {
/*
* Only perform IO rename if old file exists and new path is free.
*/
$this->documentsStorage->move($oldPath, $newPath);
} else {
throw new UnableToMoveFile('Cannot rename file from ' . $oldPath . ' to ' . $newPath);
}
}
// This method must not throw any exception
// because filename WILL change if document file is updated too.
$this->renameDocumentFilename($document, $args);
}
if ($document instanceof DocumentInterface && $args->hasChangedField('private')) {
if ($document->isPrivate() === true) {
Expand All @@ -75,6 +64,29 @@ public function preUpdate(PreUpdateEventArgs $args): void
}
}

private function renameDocumentFilename(DocumentInterface $document, PreUpdateEventArgs $args): void
{
$oldPath = $this->getDocumentMountPathForFilename($document, $args->getOldValue('filename'));
$newPath = $this->getDocumentMountPathForFilename($document, $args->getNewValue('filename'));

if ($oldPath === $newPath) {
return;
}

if (!$this->documentsStorage->fileExists($oldPath)) {
// Do not throw, just return
return;
}
if ($this->documentsStorage->fileExists($newPath)) {
// Do not throw, just return
return;
}
/*
* Only perform IO rename if old file exists and new path is free.
*/
$this->documentsStorage->move($oldPath, $newPath);
}

/**
* @param DocumentInterface $document
* @param PreUpdateEventArgs $args
Expand Down
8 changes: 1 addition & 7 deletions src/Exceptions/DocumentWithoutFileException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,11 @@

final class DocumentWithoutFileException extends \RuntimeException
{
private DocumentInterface $document;

public function __construct(DocumentInterface $document)
public function __construct(private readonly DocumentInterface $document)
{
$this->document = $document;
parent::__construct(sprintf('Document (%s) does not have a file on system.', (string) $document));
}

/**
* @return DocumentInterface
*/
public function getDocument(): DocumentInterface
{
return $this->document;
Expand Down
13 changes: 1 addition & 12 deletions src/Models/AdvancedDocumentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,8 @@

namespace RZ\Roadiz\Documents\Models;

interface AdvancedDocumentInterface extends DocumentInterface, SizeableInterface
interface AdvancedDocumentInterface extends DocumentInterface, SizeableInterface, DisplayableInterface
{
/**
* @return string|null
*/
public function getImageAverageColor(): ?string;

/**
* @param string|null $imageAverageColor
* @return $this
*/
public function setImageAverageColor(?string $imageAverageColor): static;

/**
* @return int|null
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Models/DocumentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function setRawDocument(?DocumentInterface $rawDocument = null): static;
public function isRaw(): bool;

/**
* @param boolean $raw the raw
* @param bool $raw the raw
* @return $this
*/
public function setRaw(bool $raw): static;
Expand Down
Loading

0 comments on commit 1e9501d

Please sign in to comment.