From b31881aa05e1cfe97bfd67955bf8b99eaaaef938 Mon Sep 17 00:00:00 2001 From: Fabien Udriot <fabien.udriot@ecodev.ch> Date: Thu, 2 May 2013 19:50:28 +0200 Subject: [PATCH] [BUGFIX] ProcessedFile is persisted in sys_file as well The problem appears more generally as soon as @getProperties@ is called from a file object. FAL will try, by all means, indexing the file (storing the file into sys_file, in other word) The change set adds a method telling a File not be indexed by the API. This is particularly useful if you want to create objects but don't want them to be persisted. Change-Id: I8cf0c0f6389dc13e8c3855452f1d2519544b69b9 Fixes: #47211 Fixes: #47782 Releases: 6.0, 6.1, 6.2 Reviewed-on: https://review.typo3.org/20437 Reviewed-by: Alexander Opitz Tested-by: Alexander Opitz Reviewed-by: Wouter Wolters Tested-by: Wouter Wolters Reviewed-by: Stefan Neufeind Reviewed-by: Frans Saris Reviewed-by: Philipp Gampe Tested-by: Philipp Gampe --- typo3/sysext/core/Classes/Resource/File.php | 28 ++++++++++++++-- .../core/Classes/Resource/ProcessedFile.php | 10 ++---- .../core/Tests/Unit/Resource/FileTest.php | 32 +++++++++++++++++++ 3 files changed, 60 insertions(+), 10 deletions(-) diff --git a/typo3/sysext/core/Classes/Resource/File.php b/typo3/sysext/core/Classes/Resource/File.php index 2a281e7912b4..e0418a61e6a6 100644 --- a/typo3/sysext/core/Classes/Resource/File.php +++ b/typo3/sysext/core/Classes/Resource/File.php @@ -37,10 +37,18 @@ class File extends AbstractFile { * File indexing status. True, if the file is indexed in the database; * NULL is the default value, this means that the index status is unknown * - * @var boolean + * @var boolean|NULL */ protected $indexed = NULL; + /** + * Tells whether to index a file or not. + * If yes, the file will be persisted into sys_file. + * + * @var boolean + */ + protected $indexable = TRUE; + /** * Set to TRUE while this file is being indexed - used to prevent some endless loops * @@ -139,7 +147,7 @@ class File extends AbstractFile { /** * Returns TRUE if this file is indexed * - * @return boolean + * @return boolean|NULL */ public function isIndexed() { if ($this->indexed === NULL && !$this->indexingInProgress) { @@ -155,7 +163,7 @@ class File extends AbstractFile { * @return void */ protected function loadIndexRecord($indexIfNotIndexed = TRUE) { - if ($this->indexed !== NULL) { + if ($this->indexed !== NULL || !$this->indexable) { return; } /** @var $repo FileRepository */ @@ -319,6 +327,20 @@ class File extends AbstractFile { return $array; } + /** + * @return boolean + */ + public function isIndexable() { + return $this->indexable; + } + + /** + * @param boolean $indexable + */ + public function setIndexable($indexable) { + $this->indexable = $indexable; + } + } diff --git a/typo3/sysext/core/Classes/Resource/ProcessedFile.php b/typo3/sysext/core/Classes/Resource/ProcessedFile.php index 62ed50468605..30208556517e 100644 --- a/typo3/sysext/core/Classes/Resource/ProcessedFile.php +++ b/typo3/sysext/core/Classes/Resource/ProcessedFile.php @@ -192,16 +192,12 @@ class ProcessedFile extends AbstractFile { } // TODO this should be more generic (in fact it only works for local file paths) $addedFile = $this->storage->addFile($filePath, $this->storage->getProcessingFolder(), $this->name, 'replace'); + $addedFile->setIndexable(FALSE); // Update some related properties $this->identifier = $addedFile->getIdentifier(); $this->originalFileSha1 = $this->originalFile->getSha1(); - // The added file is a FileInterface object with own uid - // We have to unset uid otherwise the processed file couldn't be stored in database - // Other non-used fields were removed before database progress - $updateProperties = $addedFile->getProperties(); - unset($updateProperties['uid']); - $this->updateProperties($updateProperties); + $this->updateProperties($addedFile->getProperties()); $this->deleted = FALSE; $this->updated = TRUE; } @@ -524,4 +520,4 @@ class ProcessedFile extends AbstractFile { } -?> \ No newline at end of file +?> diff --git a/typo3/sysext/core/Tests/Unit/Resource/FileTest.php b/typo3/sysext/core/Tests/Unit/Resource/FileTest.php index 0bc5fb6bbd15..d689ce2946f2 100644 --- a/typo3/sysext/core/Tests/Unit/Resource/FileTest.php +++ b/typo3/sysext/core/Tests/Unit/Resource/FileTest.php @@ -392,7 +392,39 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $this->assertSame($expectedExtension, $fixture->getExtension()); } + /** + * @test + */ + public function indexablePropertyIsByDefaultTrue() { + $fixture = new \TYPO3\CMS\Core\Resource\File(array()); + $this->assertAttributeEquals(TRUE, 'indexable', $fixture); + } + /** + * @test + */ + public function indexablePropertyCanBeSetAndGet() { + $fixture = new \TYPO3\CMS\Core\Resource\File(array()); + foreach (array(FALSE, TRUE) as $value) { + $fixture->setIndexable($value); + $this->assertSame($value, $fixture->isIndexable()); + } + } + + /** + * @test + */ + public function callMethodLoadIndexRecordWithPropertyIndexableSetToFalseAndCheckWhetherIsIndexedReturnsNull() { + $method = new \ReflectionMethod( + 'TYPO3\CMS\Core\Resource\File', 'loadIndexRecord' + ); + $method->setAccessible(TRUE); + + $fixture = new \TYPO3\CMS\Core\Resource\File(array()); + $fixture->setIndexable(FALSE); + $method->invoke($fixture); + $this->assertNull($fixture->isIndexed()); + } } ?> \ No newline at end of file -- GitLab