Skip to content

Commit

Permalink
FIX ListContents no longer called recursively (#415)
Browse files Browse the repository at this point in the history
* ListContents no longer called recursively
* Update FileIDHelpers to support the lookForVariantRecursive method

Co-authored-by: Maxime Rainville <maxime@silverstripe.com>
  • Loading branch information
Adrian Humphreys and maxime-rainville committed Aug 10, 2020
1 parent f700ed6 commit 4c509c1
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/FilenameParsing/FileIDHelper.php
Expand Up @@ -53,4 +53,11 @@ public function isVariantOf($fileID, ParsedFileID $parsedFileID);
* @return string
*/
public function lookForVariantIn(ParsedFileID $parsedFileID);

/**
* Specify if this File ID Helper stores variants in subfolders and require a recursive look up to find all
* variants.
* @return bool
*/
public function lookForVariantRecursive(): bool;
}
2 changes: 1 addition & 1 deletion src/FilenameParsing/FileIDHelperResolutionStrategy.php
Expand Up @@ -436,7 +436,7 @@ public function findVariants($tuple, Filesystem $filesystem)

// Find the correct folder to search for possible variants in
$folder = $helper->lookForVariantIn($parsedFileID);
$possibleVariants = $filesystem->listContents($folder, true);
$possibleVariants = $filesystem->listContents($folder, $helper->lookForVariantRecursive());

// Flysystem returns array of meta data abouch each file, we remove directories and map it down to the path
$possibleVariants = array_filter($possibleVariants, function ($possibleVariant) {
Expand Down
5 changes: 5 additions & 0 deletions src/FilenameParsing/HashFileIDHelper.php
Expand Up @@ -126,4 +126,9 @@ private function truncate($hash)
{
return substr($hash, 0, self::HASH_TRUNCATE_LENGTH);
}

public function lookForVariantRecursive(): bool
{
return false;
}
}
5 changes: 5 additions & 0 deletions src/FilenameParsing/LegacyFileIDHelper.php
Expand Up @@ -238,4 +238,9 @@ public function lookForVariantIn(ParsedFileID $parsedFileID)
}
return $folder . '_resampled';
}

public function lookForVariantRecursive(): bool
{
return true;
}
}
5 changes: 5 additions & 0 deletions src/FilenameParsing/NaturalFileIDHelper.php
Expand Up @@ -99,4 +99,9 @@ public function lookForVariantIn(ParsedFileID $parsedFileID)
$folder = dirname($parsedFileID->getFilename());
return $folder == '.' ? '' : $folder;
}

public function lookForVariantRecursive(): bool
{
return false;
}
}
5 changes: 5 additions & 0 deletions tests/php/FilenameParsing/MockFileIDHelper.php
Expand Up @@ -57,4 +57,9 @@ public function lookForVariantIn(ParsedFileID $parsedFileID)
{
return $this->lookForVariantInVal;
}

public function lookForVariantRecursive(): bool
{
return true;
}
}

0 comments on commit 4c509c1

Please sign in to comment.