Skip to content

Commit 9f4215d

Browse files
author
roadiz-ci
committed
chore: Bumped
1 parent 45cd03f commit 9f4215d

21 files changed

Lines changed: 439 additions & 336 deletions

composer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
"phpstan/phpstan": "^1.5.3",
4949
"phpstan/phpdoc-parser": "<2",
5050
"phpstan/phpstan-doctrine": "^1.3",
51-
"phpunit/phpunit": "^9.5"
51+
"phpunit/phpunit": "^9.5",
52+
"symfony/http-client": "6.4.*",
53+
"symfony/process": "6.4.*"
5254
},
5355
"autoload": {
5456
"psr-4": {
@@ -68,8 +70,8 @@
6870
},
6971
"extra": {
7072
"branch-alias": {
71-
"dev-master": "2.4.x-dev",
72-
"dev-develop": "2.5.x-dev"
73+
"dev-master": "2.5.x-dev",
74+
"dev-develop": "2.6.x-dev"
7375
}
7476
}
7577
}

src/AbstractDocumentFactory.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use League\Flysystem\FilesystemOperator;
99
use League\Flysystem\MountManager;
1010
use Psr\Log\LoggerInterface;
11-
use Psr\Log\NullLogger;
1211
use RZ\Roadiz\Documents\Models\DocumentInterface;
1312
use RZ\Roadiz\Documents\Models\FileHashInterface;
1413
use RZ\Roadiz\Documents\Models\FolderInterface;
@@ -23,23 +22,17 @@
2322
*/
2423
abstract class AbstractDocumentFactory
2524
{
26-
private LoggerInterface $logger;
2725
private ?File $file = null;
2826
private ?FolderInterface $folder = null;
29-
private FilesystemOperator $documentsStorage;
30-
private DocumentFinderInterface $documentFinder;
3127

3228
public function __construct(
33-
FilesystemOperator $documentsStorage,
34-
DocumentFinderInterface $documentFinder,
35-
?LoggerInterface $logger = null,
29+
protected readonly FilesystemOperator $documentsStorage,
30+
protected readonly DocumentFinderInterface $documentFinder,
31+
protected readonly LoggerInterface $logger,
3632
) {
3733
if (!$documentsStorage instanceof MountManager) {
3834
trigger_error('Document Storage must be a MountManager to address public and private files.', E_USER_WARNING);
3935
}
40-
$this->documentsStorage = $documentsStorage;
41-
$this->documentFinder = $documentFinder;
42-
$this->logger = $logger ?? new NullLogger();
4336
}
4437

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

151147
return $existingDocument;
152148
}
@@ -217,7 +213,7 @@ public function updateDocument(DocumentInterface $document): DocumentInterface
217213
}
218214
}
219215

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

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

src/AverageColorResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Intervention\Image\Image;
88

9-
class AverageColorResolver
9+
final readonly class AverageColorResolver
1010
{
1111
public function getAverageColor(Image $image): string
1212
{

src/DocumentArchiver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
/**
1515
* Easily create and serve ZIP archives from your Roadiz documents.
1616
*/
17-
final class DocumentArchiver
17+
final readonly class DocumentArchiver
1818
{
19-
public function __construct(private readonly FilesystemOperator $documentsStorage)
19+
public function __construct(private FilesystemOperator $documentsStorage)
2020
{
2121
}
2222

src/DocumentFolderGenerator.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace RZ\Roadiz\Documents;
6+
7+
final readonly class DocumentFolderGenerator
8+
{
9+
/**
10+
* Generate a random folder name for documents, 12 characters long.
11+
*/
12+
public static function generateFolderName(): string
13+
{
14+
return \mb_substr(hash('crc32c', microtime()), 0, 12);
15+
}
16+
}

0 commit comments

Comments
 (0)