Skip to content
Permalink
Browse files

BUG Fix GeneratedAssetHandler crashing on expired resources

  • Loading branch information...
Damian Mooyman
Damian Mooyman committed Oct 22, 2015
1 parent f9892c6 commit fe3d23f0d4c381040f47d24c4dcc9b27768a06b8
Showing with 29 additions and 10 deletions.
  1. +18 −10 filesystem/storage/CacheGeneratedAssetHandler.php
  2. +11 −0 tests/filesystem/AssetStoreTest.php
@@ -105,7 +105,10 @@ protected function getGeneratedFile($filename, $entropy = 0, $callback = null) {
$data = $cache->load($cacheID);
if($data) {
$result = unserialize($data);
return $this->validateResult($result, $filename);
$valid = $this->validateResult($result, $filename);
if($valid) {
return $result;
}
}
// Regenerate
@@ -127,8 +130,14 @@ public function updateContent($filename, $entropy, $content) {
if($result) {
$cache->save(serialize($result), $cacheID);
}
return $this->validateResult($result, $filename);
// Ensure this result is successfully saved
$valid = $this->validateResult($result, $filename);
if($valid) {
return $result;
}
throw new Exception("Error regenerating file \"{$filename}\"");
}
/**
@@ -151,17 +160,16 @@ protected function getCacheKey($filename, $entropy = 0) {
*
* @param mixed $result
* @param string $filename
* @return array The result
* @throws Exception
* @return bool True if this $result is valid
*/
protected function validateResult($result, $filename) {
if(!$result) {
return false;
}
// Retrieve URL from tuple
$store = $this->getAssetStore();
if($result && $store->exists($result['Filename'], $result['Hash'], $result['Variant'])) {
return $result;
}
throw new Exception("Error regenerating file \"{$filename}\"");
return $store->exists($result['Filename'], $result['Hash'], $result['Variant']);
}
}
@@ -7,6 +7,7 @@
use SilverStripe\Filesystem\Flysystem\FlysystemUrlPlugin;
use SilverStripe\Filesystem\Storage\AssetContainer;
use SilverStripe\Filesystem\Storage\AssetStore;
use SilverStripe\Filesystem\Storage\CacheGeneratedAssetHandler;
class AssetStoreTest extends SapphireTest {
@@ -450,6 +451,10 @@ public static function base_path() {
* Reset defaults for this store
*/
public static function reset() {
// Need flushing since it won't have any files left
CacheGeneratedAssetHandler::flush();
// Remove all files in this store
if(self::$basedir) {
$path = self::base_path();
if(file_exists($path)) {
@@ -469,6 +474,12 @@ public static function getLocalPath(AssetContainer $asset) {
if($asset instanceof Folder) {
return self::base_path() . '/' . $asset->getFilename();
}
if($asset instanceof File) {
$asset = $asset->File;
}
if($asset instanceof DBFile) {
return BASE_PATH . $asset->getSourceURL();
}
return BASE_PATH . $asset->getUrl();
}

0 comments on commit fe3d23f

Please sign in to comment.
You can’t perform that action at this time.