Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Classes/Command/CompressImagesCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function compressImages(QueryResultInterface $files)
foreach ($files as $file) {
if ($file instanceof \Schmitzal\Tinyimg\Domain\Model\File) {
$file = $this->resourceFactory->getFileObject($file->getUid());
if (filesize(GeneralUtility::getFileAbsFileName($file->getPublicUrl())) > 0) {
if (filesize(GeneralUtility::getFileAbsFileName(urldecode($file->getPublicUrl()))) > 0) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, ich weiss nicht ob das so cool ist, ich denke mal $file->getPublicUrl()encoded die url, und dann wird sie hier wieder decoded, gibts da nicht evtl. eine andere Methode, den den Pfad uncodiert zurückgibt?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fand ich auch schön, wenn es da eine gibt. Kennst du eine?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

musst du gucken ...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jo also der macht das ziemlich früh im core. Ich müsste mir halt stattdessen die URL selbst zusammen bauen aus identifier und storage (hier fileadmin). Was meinst du ist besser?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ja, das ist besser

$this->compressImageService->initializeCompression($file);
$fileDeletionAspect->cleanupProcessedFilesPostFileReplace($file, '');
}
Expand Down
30 changes: 27 additions & 3 deletions Classes/Service/CompressImageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
use Aws\S3\S3Client;

use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Resource\Driver\LocalDriver;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Resource\Index\Indexer;
Expand All @@ -15,6 +17,8 @@
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Core\Resource\StorageRepository;
use TYPO3\CMS\Core\Resource\ResourceStorage;

/**
* Class CompressImageService
Expand Down Expand Up @@ -98,6 +102,7 @@ public function initCdn()
*/
public function initializeCompression($file)
{
$fileCreated = false;
$this->initAction();

if ($this->isFileInExcludeFolder($file)) {
Expand All @@ -114,9 +119,26 @@ public function initializeCompression($file)
if ($this->checkForAmazonCdn($file)) {
$fileSize = $this->pushToTinyPngAndStoreToCdn($file);
} else {
$publicUrl = PATH_site . $file->getPublicUrl();
$publicUrl = PATH_site . urldecode($file->getPublicUrl());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s. o.

$source = \Tinify\fromFile($publicUrl);
$source->toFile($publicUrl);

// Sanitize URL in order to check if there are any special characters.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mh, sollte das nicht schon vorher passiert sein? ich finde das gehört hier nicht hier, dass der CompressImageService das file umbennt, das müsste anders gehen

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was schwebt dir da denn vor?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

das kommt ja nur vor, wenn Du das Convert-Command über CLI ausführst, und die Datei, ist noch nicht "richtig" umbenannt, oder? Evtl. kannst Du ein weiteres Command bauen, welches Dateien richtig umbennt? (evtl. auch unabh. von dieser Extension?)

$localDriver = GeneralUtility::makeInstance(LocalDriver::class);
$sanitizedFileName = $localDriver->sanitizeFileName($file->getName());

// Check if file name should be changed due to new file name. If so replace file.
if ($file->getName() != $sanitizedFileName) {
$source->toFile($sanitizedFileName);
/** @var ResourceStorage $storage */
$storage = $file->getStorage();
$newFile = $storage->addFile($sanitizedFileName, $file->getParentFolder());
$storage->deleteFile($file);
$file = $newFile;
$fileCreated = true;
} else {
$source->toFile($publicUrl);
}

$fileSize = $this->setCompressedForCurrentFile($file);
}
if ((int)$fileSize !== 0) {
Expand All @@ -130,7 +152,9 @@ public function initializeCompression($file)
$this->addMessageToFlashMessageQueue('debugMode', [], FlashMessage::INFO);
}

$this->updateFileInformation($file);
if (!$fileCreated) {
$this->updateFileInformation($file);
}
}

/**
Expand Down