Skip to content

Commit 3cf9860

Browse files
authored
Merge pull request #176 from andersundsehr/bugfix/clear-transient-file
Fix growing var/transient folder contents to get (image) sizes
2 parents f5354e9 + 1885d45 commit 3cf9860

4 files changed

Lines changed: 45 additions & 8 deletions

File tree

Classes/Index/Extractor.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
namespace AUS\AusDriverAmazonS3\Index;
1616

1717
use AUS\AusDriverAmazonS3\Driver\AmazonS3Driver;
18+
use TYPO3\CMS\Core\Cache\CacheManager;
19+
use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException;
20+
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
1821
use TYPO3\CMS\Core\Resource\File;
1922
use TYPO3\CMS\Core\Resource\FileInterface;
2023
use TYPO3\CMS\Core\Resource\Index\ExtractorInterface;
@@ -30,6 +33,16 @@
3033
*/
3134
class Extractor implements ExtractorInterface
3235
{
36+
private ?FrontendInterface $cache = null;
37+
38+
public function __construct()
39+
{
40+
try {
41+
$this->cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('runtime');
42+
} catch (NoSuchCacheException) {
43+
}
44+
}
45+
3346
/**
3447
* Returns an array of supported file types;
3548
* An empty array indicates all filetypes
@@ -122,11 +135,23 @@ public function extractMetaData(File $file, array $previousExtractedData = [])
122135
*/
123136
public function getImageDimensionsOfRemoteFile(FileInterface $file): array
124137
{
138+
$identifier = 'andersundsehr_aus_driver_amazon_s3_' . sha1($file->getIdentifier());
139+
if ($this->cache?->has($identifier)) {
140+
$sizes = $this->cache->get($identifier);
141+
if (is_array($sizes) && count($sizes) === 2) {
142+
return $sizes;
143+
}
144+
}
145+
125146
$fileNameAndPath = $file->getForLocalProcessing(false);
126147
$imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $fileNameAndPath);
127-
return [
148+
$sizes = [
128149
$imageInfo->getWidth(),
129150
$imageInfo->getHeight(),
130151
];
152+
153+
$this->cache?->set($identifier, $sizes);
154+
GeneralUtility::unlink_tempfile($fileNameAndPath);
155+
return $sizes;
131156
}
132157
}

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,12 @@ If you wish other hooks - don’t be shy: [GitHub issue tracking: Amazon S3 FAL
177177
## Running tests
178178
179179
Run `make tests` to run both unit and functional tests.
180+
181+
To switch TYPO3 test version to 11:
182+
```bash
183+
composer update --with typo3/cms-core:^11.5.6
184+
```
185+
To switch TYPO3 test version to 12:
186+
```bash
187+
composer update --with typo3/cms-core:^12.4.0 --ignore-platform-req=ext-intl
188+
```

Tests/Unit/S3Adapter/MetaInfoDownloadAdapterTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use PHPUnit\Framework\TestCase;
2020
use Prophecy\PhpUnit\ProphecyTrait;
2121
use Prophecy\Prophecy\ObjectProphecy;
22+
use TYPO3\CMS\Core\Information\Typo3Version;
2223
use TYPO3\CMS\Core\Resource\MimeTypeCompatibilityTypeGuesser;
2324
use TYPO3\CMS\Core\Type\File\FileInfo;
2425
use TYPO3\CMS\Core\Utility\PathUtility;
@@ -52,7 +53,9 @@ public function setUp(): void
5253
parent::setUp();
5354
$this->metaInfoDownloadAdapter = new MetaInfoDownloadAdapter();
5455
$this->driver = $this->prophesize(AmazonS3Driver::class);
55-
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][FileInfo::class]['mimeTypeGuessers'][MimeTypeCompatibilityTypeGuesser::class] = MimeTypeCompatibilityTypeGuesser::class . '->guessMimeType';
56+
if ((new Typo3Version())->getMajorVersion() > 11) {
57+
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][FileInfo::class]['mimeTypeGuessers'][MimeTypeCompatibilityTypeGuesser::class] = MimeTypeCompatibilityTypeGuesser::class . '->guessMimeType';
58+
}
5659
}
5760

5861
/**

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
},
1010
"license": "LGPL-3.0-or-later",
1111
"require": {
12-
"php": ">=7.4",
13-
"typo3/cms-core": "^11.5.6 || ^12.4.5",
12+
"php": ">=8.2.0 <8.5.0",
13+
"typo3/cms-core": "~v11.5.41 || ~v12.4.36",
1414
"aws/aws-sdk-php": "^3.288"
1515
},
1616
"require-dev": {
1717
"pluswerk/grumphp-config": "^5.0",
18-
"typo3/testing-framework": "^8.0",
19-
"phpspec/prophecy": "dev-master",
20-
"phpspec/prophecy-phpunit": "dev-master",
21-
"saschaegerer/phpstan-typo3": "^1.8.9",
18+
"typo3/testing-framework": "^7.1.1 || ^8.2.7",
19+
"phpspec/prophecy": "^1.22.0",
20+
"phpspec/prophecy-phpunit": "^2.4.0",
21+
"saschaegerer/phpstan-typo3": "^1.10.2",
2222
"ssch/typo3-rector": "^1.3.5"
2323
},
2424
"autoload": {

0 commit comments

Comments
 (0)