Skip to content

Commit 35a3d5a

Browse files
author
roadiz-ci
committed
chore: bumped
1 parent 170ccae commit 35a3d5a

83 files changed

Lines changed: 1331 additions & 1774 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/run-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
runs-on: ubuntu-latest
2020
strategy:
2121
matrix:
22-
php-version: ['8.3', '8.4']
22+
php-version: ['8.2', '8.3']
2323
steps:
2424
- uses: shivammathur/setup-php@v2
2525
with:

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright © 2025 Ambroise Maupate
3+
Copyright © 2024 Ambroise Maupate
44

55
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:
66

composer.json

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
}
1919
],
2020
"require": {
21-
"php": ">=8.3",
21+
"php": ">=8.2",
2222
"ext-json": "*",
2323
"ext-gd": "*",
2424
"ext-dom": "*",
@@ -27,30 +27,28 @@
2727
"ext-fileinfo": "*",
2828
"doctrine/orm": "~2.20.0",
2929
"enshrined/svg-sanitize": "^0.22",
30-
"intervention/image": "^3.11",
30+
"intervention/image": "^2.5",
3131
"league/flysystem": "^3.0",
32-
"monolog/monolog": "^3.9",
33-
"symfony/asset": "7.3.*",
34-
"symfony/console": "7.3.*",
35-
"symfony/event-dispatcher": "7.3.*",
36-
"symfony/filesystem": ">=7.1",
37-
"symfony/finder": "7.3.*",
38-
"symfony/http-foundation": "7.3.*",
32+
"monolog/monolog": "^1.24.0 || ^2.1.1",
33+
"symfony/asset": "6.4.*",
34+
"symfony/console": "6.4.*",
35+
"symfony/event-dispatcher": "6.4.*",
36+
"symfony/filesystem": "6.4.*",
37+
"symfony/finder": "6.4.*",
38+
"symfony/http-foundation": "6.4.*",
3939
"symfony/http-client-contracts": "^3.5",
40-
"symfony/options-resolver": "7.3.*",
41-
"symfony/serializer": "7.3.*",
42-
"twig/twig": "^3.21"
40+
"symfony/options-resolver": "6.4.*",
41+
"symfony/serializer": "6.4.*",
42+
"twig/twig": "^3.16"
4343
},
4444
"require-dev": {
45-
"api-platform/metadata": "^4.1.18",
45+
"api-platform/metadata": "~3.3.11",
4646
"doctrine/doctrine-bundle": "^2.8.1",
4747
"php-coveralls/php-coveralls": "^2.4",
4848
"phpstan/phpstan": "^1.5.3",
4949
"phpstan/phpdoc-parser": "<2",
5050
"phpstan/phpstan-doctrine": "^1.3",
51-
"phpunit/phpunit": "^9.6",
52-
"symfony/http-client": "7.3.*",
53-
"symfony/process": "7.3.*"
51+
"phpunit/phpunit": "^9.5"
5452
},
5553
"autoload": {
5654
"psr-4": {
@@ -70,8 +68,8 @@
7068
},
7169
"extra": {
7270
"branch-alias": {
73-
"dev-master": "2.6.x-dev",
74-
"dev-develop": "2.7.x-dev"
71+
"dev-master": "2.4.x-dev",
72+
"dev-develop": "2.5.x-dev"
7573
}
7674
}
7775
}

src/AbstractDocumentFactory.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use League\Flysystem\FilesystemOperator;
99
use League\Flysystem\MountManager;
1010
use Psr\Log\LoggerInterface;
11+
use Psr\Log\NullLogger;
1112
use RZ\Roadiz\Documents\Models\DocumentInterface;
1213
use RZ\Roadiz\Documents\Models\FileHashInterface;
1314
use RZ\Roadiz\Documents\Models\FolderInterface;
@@ -22,17 +23,23 @@
2223
*/
2324
abstract class AbstractDocumentFactory
2425
{
26+
private LoggerInterface $logger;
2527
private ?File $file = null;
2628
private ?FolderInterface $folder = null;
29+
private FilesystemOperator $documentsStorage;
30+
private DocumentFinderInterface $documentFinder;
2731

2832
public function __construct(
29-
protected readonly FilesystemOperator $documentsStorage,
30-
protected readonly DocumentFinderInterface $documentFinder,
31-
protected readonly LoggerInterface $logger,
33+
FilesystemOperator $documentsStorage,
34+
DocumentFinderInterface $documentFinder,
35+
?LoggerInterface $logger = null,
3236
) {
3337
if (!$documentsStorage instanceof MountManager) {
3438
trigger_error('Document Storage must be a MountManager to address public and private files.', E_USER_WARNING);
3539
}
40+
$this->documentsStorage = $documentsStorage;
41+
$this->documentFinder = $documentFinder;
42+
$this->logger = $logger ?? new NullLogger();
3643
}
3744

3845
public function getFile(): File
@@ -126,10 +133,10 @@ public function getDocument(bool $allowEmpty = false, bool $allowDuplicates = fa
126133
if (false !== $fileHash && !$allowDuplicates) {
127134
$existingDocument = $this->documentFinder->findOneByHashAndAlgorithm($fileHash, $this->getHashAlgorithm());
128135
if (null !== $existingDocument) {
129-
/*
130-
* If existing document is a RAW, serve its downscaled version
131-
*/
132-
if (null !== $existingDownscaledDocument = $existingDocument->getDownscaledDocument()) {
136+
if (
137+
$existingDocument->isRaw()
138+
&& null !== $existingDownscaledDocument = $existingDocument->getDownscaledDocument()
139+
) {
133140
$existingDocument = $existingDownscaledDocument;
134141
}
135142
if (null !== $this->folder) {
@@ -139,10 +146,7 @@ public function getDocument(bool $allowEmpty = false, bool $allowDuplicates = fa
139146
$this->logger->info(sprintf(
140147
'File %s already exists with same checksum, do not upload it twice.',
141148
$existingDocument->getFilename()
142-
), [
143-
'path' => $existingDocument->getMountPath(),
144-
]);
145-
(new Filesystem())->remove($file->getPathname());
149+
));
146150

147151
return $existingDocument;
148152
}
@@ -213,7 +217,7 @@ public function updateDocument(DocumentInterface $document): DocumentInterface
213217
}
214218
}
215219

216-
$document->setFolder(DocumentFolderGenerator::generateFolderName());
220+
$document->setFolder(\mb_substr(hash('crc32b', date('YmdHi')), 0, 12));
217221
}
218222

219223
$document->setFilename($this->getFileName());

src/AbstractDocumentFinder.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
abstract class AbstractDocumentFinder implements DocumentFinderInterface
88
{
9-
#[\Override]
109
public function findVideosWithFilename(string $fileName): iterable
1110
{
1211
$basename = pathinfo($fileName);
@@ -25,7 +24,6 @@ public function findVideosWithFilename(string $fileName): iterable
2524
return $this->findAllByFilenames($sourcesDocsName);
2625
}
2726

28-
#[\Override]
2927
public function findAudiosWithFilename(string $fileName): iterable
3028
{
3129
$basename = pathinfo($fileName);
@@ -42,7 +40,6 @@ public function findAudiosWithFilename(string $fileName): iterable
4240
return $this->findAllByFilenames($sourcesDocsName);
4341
}
4442

45-
#[\Override]
4643
public function findPicturesWithFilename(string $fileName): iterable
4744
{
4845
$pathInfo = pathinfo($fileName);
@@ -63,7 +60,9 @@ public function findPicturesWithFilename(string $fileName): iterable
6360
// remove current extension from list
6461
$extensionsList = array_diff($extensionsList, [$currentExtension]);
6562
// list sources paths for extensions
66-
$sourcesDocsName = array_values(array_map(fn ($extension) => $basename.'.'.$extension, $extensionsList));
63+
$sourcesDocsName = array_values(array_map(function ($extension) use ($basename) {
64+
return $basename.'.'.$extension;
65+
}, $extensionsList));
6766

6867
return $this->findAllByFilenames($sourcesDocsName);
6968
}

src/ArrayDocumentFinder.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ final class ArrayDocumentFinder extends AbstractDocumentFinder
1515
/**
1616
* @var ArrayCollection<int, DocumentInterface>
1717
*/
18-
private readonly ArrayCollection $documents;
18+
private ArrayCollection $documents;
1919

2020
public function __construct()
2121
{
@@ -27,23 +27,24 @@ public function __construct()
2727
*
2828
* @return ArrayCollection<int, DocumentInterface>
2929
*/
30-
#[\Override]
3130
public function findAllByFilenames(array $fileNames): ArrayCollection
3231
{
3332
return $this->documents->filter(
34-
fn (DocumentInterface $document) => in_array($document->getFilename(), $fileNames)
33+
function (DocumentInterface $document) use ($fileNames) {
34+
return in_array($document->getFilename(), $fileNames);
35+
}
3536
);
3637
}
3738

38-
#[\Override]
3939
public function findOneByFilenames(array $fileNames): ?DocumentInterface
4040
{
4141
return $this->documents->filter(
42-
fn (DocumentInterface $document) => in_array($document->getFilename(), $fileNames)
42+
function (DocumentInterface $document) use ($fileNames) {
43+
return in_array($document->getFilename(), $fileNames);
44+
}
4345
)->first() ?: null;
4446
}
4547

46-
#[\Override]
4748
public function findOneByHashAndAlgorithm(string $hash, string $algorithm): ?DocumentInterface
4849
{
4950
return null;

src/AverageColorResolver.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,28 @@
44

55
namespace RZ\Roadiz\Documents;
66

7-
use Intervention\Image\Interfaces\ImageInterface;
7+
use Intervention\Image\Image;
88

9-
final readonly class AverageColorResolver
9+
class AverageColorResolver
1010
{
11-
/**
12-
* Get the average color of an image by resampling the image to 1x1 pixel and pick this pixel color.
13-
* Then only use the RGB channels by picking only the 7 first hex chars to get rid of alpha channel.
14-
*/
15-
public function getAverageColor(ImageInterface $image): string
11+
public function getAverageColor(Image $image): string
1612
{
17-
return substr($image->resize(1, 1)->pickColor(0, 0)->toHex('#'), 0, 7);
13+
$colorArray = $this->getAverageColorAsArray($image);
14+
15+
return sprintf(
16+
'#%02x%02x%02x',
17+
$colorArray[0],
18+
$colorArray[1],
19+
$colorArray[2]
20+
);
21+
}
22+
23+
public function getAverageColorAsArray(Image $image): array
24+
{
25+
$image->resize(1, 1);
26+
/** @var array $array */
27+
$array = $image->pickColor(0, 0);
28+
29+
return $array;
1830
}
1931
}

src/Console/DocumentAverageColorCommand.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
namespace RZ\Roadiz\Documents\Console;
66

7-
use Intervention\Image\Exceptions\DecoderException;
8-
use League\Flysystem\FilesystemException;
7+
use Intervention\Image\Exception\NotReadableException;
98
use RZ\Roadiz\Documents\AverageColorResolver;
109
use RZ\Roadiz\Documents\Models\AdvancedDocumentInterface;
1110
use RZ\Roadiz\Documents\Models\DocumentInterface;
@@ -17,15 +16,13 @@ class DocumentAverageColorCommand extends AbstractDocumentCommand
1716
{
1817
protected SymfonyStyle $io;
1918

20-
#[\Override]
2119
protected function configure(): void
2220
{
2321
$this->setName('documents:color')
2422
->setDescription('Fetch every document medium color and write it in database.')
2523
;
2624
}
2725

28-
#[\Override]
2926
protected function execute(InputInterface $input, OutputInterface $output): int
3027
{
3128
$this->io = new SymfonyStyle($input, $output);
@@ -46,11 +43,11 @@ private function updateDocumentColor(DocumentInterface $document): void
4643
return;
4744
}
4845
try {
49-
$mediumColor = (new AverageColorResolver())->getAverageColor($this->imageManager->read(
46+
$mediumColor = (new AverageColorResolver())->getAverageColor($this->imageManager->make(
5047
$this->documentsStorage->readStream($mountPath)
5148
));
5249
$document->setImageAverageColor($mediumColor);
53-
} catch (DecoderException|FilesystemException) {
50+
} catch (NotReadableException $exception) {
5451
/*
5552
* Do nothing
5653
* just return 0 width and height

src/Console/DocumentClearFolderCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class DocumentClearFolderCommand extends AbstractDocumentCommand
1717
{
1818
protected SymfonyStyle $io;
1919

20-
#[\Override]
2120
protected function configure(): void
2221
{
2322
$this->setName('documents:clear-folder')
@@ -35,7 +34,6 @@ protected function getDocumentQueryBuilder(FolderInterface $folder): QueryBuilde
3534
->setParameter(':folderId', $folder);
3635
}
3736

38-
#[\Override]
3937
protected function execute(InputInterface $input, OutputInterface $output): int
4038
{
4139
$this->io = new SymfonyStyle($input, $output);

src/Console/DocumentDownscaleCommand.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
namespace RZ\Roadiz\Documents\Console;
66

77
use Doctrine\Persistence\ManagerRegistry;
8-
use Intervention\Image\Exceptions\DecoderException;
8+
use Intervention\Image\Exception\NotReadableException;
99
use Intervention\Image\ImageManager;
10-
use League\Flysystem\FilesystemException;
1110
use League\Flysystem\FilesystemOperator;
1211
use RZ\Roadiz\Documents\DownscaleImageManager;
1312
use RZ\Roadiz\Documents\Events\CachePurgeAssetsRequestEvent;
@@ -37,7 +36,6 @@ public function __construct(
3736
parent::__construct($managerRegistry, $imageManager, $documentsStorage, $name);
3837
}
3938

40-
#[\Override]
4139
protected function configure(): void
4240
{
4341
$this->setName('documents:downscale')
@@ -47,7 +45,6 @@ protected function configure(): void
4745
->setDescription('Downscale every document according to max pixel size defined in configuration.');
4846
}
4947

50-
#[\Override]
5148
protected function execute(InputInterface $input, OutputInterface $output): int
5249
{
5350
$io = new SymfonyStyle($input, $output);
@@ -136,7 +133,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
136133
foreach ($documents as $document) {
137134
try {
138135
$this->downscaler->processDocumentFromExistingRaw($document);
139-
} catch (DecoderException|FilesystemException $exception) {
136+
} catch (NotReadableException $exception) {
140137
$io->error($exception->getMessage().' - '.(string) $document);
141138
}
142139
$io->progressAdvance();

0 commit comments

Comments
 (0)