Merge pull request #5117 from tractorcow/pulls/4.0/soft-errors

BUG Prevent fatal errors during test failure halt tests
This commit is contained in:
Daniel Hensby 2016-03-06 23:32:36 +00:00
commit 08c6aca9a4
2 changed files with 20 additions and 9 deletions

View File

@ -5,6 +5,7 @@ namespace SilverStripe\Filesystem\Flysystem;
use Config; use Config;
use Generator; use Generator;
use Injector; use Injector;
use LogicException;
use Session; use Session;
use Flushable; use Flushable;
use InvalidArgumentException; use InvalidArgumentException;
@ -98,7 +99,7 @@ class FlysystemAssetStore implements AssetStore, AssetStoreRouter, Flushable {
*/ */
public function setPublicFilesystem(Filesystem $filesystem) { public function setPublicFilesystem(Filesystem $filesystem) {
if(!$filesystem->getAdapter() instanceof PublicAdapter) { if(!$filesystem->getAdapter() instanceof PublicAdapter) {
throw new \InvalidArgumentException("Configured adapter must implement PublicAdapter"); throw new InvalidArgumentException("Configured adapter must implement PublicAdapter");
} }
$this->publicFilesystem = $filesystem; $this->publicFilesystem = $filesystem;
return $this; return $this;
@ -108,8 +109,12 @@ class FlysystemAssetStore implements AssetStore, AssetStoreRouter, Flushable {
* Get the currently assigned flysystem backend * Get the currently assigned flysystem backend
* *
* @return Filesystem * @return Filesystem
* @throws LogicException
*/ */
public function getPublicFilesystem() { public function getPublicFilesystem() {
if(!$this->publicFilesystem) {
throw new LogicException("Filesystem misconfiguration error");
}
return $this->publicFilesystem; return $this->publicFilesystem;
} }
@ -121,7 +126,7 @@ class FlysystemAssetStore implements AssetStore, AssetStoreRouter, Flushable {
*/ */
public function setProtectedFilesystem(Filesystem $filesystem) { public function setProtectedFilesystem(Filesystem $filesystem) {
if(!$filesystem->getAdapter() instanceof ProtectedAdapter) { if(!$filesystem->getAdapter() instanceof ProtectedAdapter) {
throw new \InvalidArgumentException("Configured adapter must implement ProtectedAdapter"); throw new InvalidArgumentException("Configured adapter must implement ProtectedAdapter");
} }
$this->protectedFilesystem = $filesystem; $this->protectedFilesystem = $filesystem;
return $this; return $this;
@ -133,6 +138,9 @@ class FlysystemAssetStore implements AssetStore, AssetStoreRouter, Flushable {
* @return Filesystem * @return Filesystem
*/ */
public function getProtectedFilesystem() { public function getProtectedFilesystem() {
if(!$this->protectedFilesystem) {
throw new Exception("Filesystem misconfiguration error");
}
return $this->protectedFilesystem; return $this->protectedFilesystem;
} }
@ -491,7 +499,7 @@ class FlysystemAssetStore implements AssetStore, AssetStoreRouter, Flushable {
} else { } else {
$conflictResolution = $config['conflict']; $conflictResolution = $config['conflict'];
} }
// Validate parameters // Validate parameters
if($variant && $conflictResolution === AssetStore::CONFLICT_RENAME) { if($variant && $conflictResolution === AssetStore::CONFLICT_RENAME) {
// As variants must follow predictable naming rules, they should not be dynamically renamed // As variants must follow predictable naming rules, they should not be dynamically renamed
@ -532,7 +540,7 @@ class FlysystemAssetStore implements AssetStore, AssetStoreRouter, Flushable {
// in case conflict resolution renamed the file, return the renamed // in case conflict resolution renamed the file, return the renamed
$filename = $this->getOriginalFilename($resolvedID); $filename = $this->getOriginalFilename($resolvedID);
} elseif(empty($variant)) { } elseif(empty($variant)) {
// If deferring to the existing file, return the sha of the existing file, // If deferring to the existing file, return the sha of the existing file,
// unless we are writing a variant (which has the same hash value as its original file) // unless we are writing a variant (which has the same hash value as its original file)
@ -562,7 +570,7 @@ class FlysystemAssetStore implements AssetStore, AssetStoreRouter, Flushable {
if(!$legacy || $variant) { if(!$legacy || $variant) {
return AssetStore::CONFLICT_OVERWRITE; return AssetStore::CONFLICT_OVERWRITE;
} }
// Legacy behaviour is to rename // Legacy behaviour is to rename
return AssetStore::CONFLICT_RENAME; return AssetStore::CONFLICT_RENAME;
} }
@ -602,7 +610,7 @@ class FlysystemAssetStore implements AssetStore, AssetStoreRouter, Flushable {
/** /**
* Determine the path that should be written to, given the conflict resolution scheme * Determine the path that should be written to, given the conflict resolution scheme
* *
* @param string $conflictResolution * @param string $conflictResolution
* @param string $fileID * @param string $fileID
* @return string|false Safe filename to write to. If false, then don't write, and use existing file. * @return string|false Safe filename to write to. If false, then don't write, and use existing file.
@ -624,7 +632,7 @@ class FlysystemAssetStore implements AssetStore, AssetStoreRouter, Flushable {
switch($conflictResolution) { switch($conflictResolution) {
// Throw tantrum // Throw tantrum
case static::CONFLICT_EXCEPTION: { case static::CONFLICT_EXCEPTION: {
throw new \InvalidArgumentException("File already exists at path {$fileID}"); throw new InvalidArgumentException("File already exists at path {$fileID}");
} }
// Rename // Rename
@ -635,7 +643,7 @@ class FlysystemAssetStore implements AssetStore, AssetStoreRouter, Flushable {
} }
} }
throw new \InvalidArgumentException("File could not be renamed with path {$fileID}"); throw new InvalidArgumentException("File could not be renamed with path {$fileID}");
} }
// Use existing file // Use existing file

View File

@ -8,7 +8,7 @@ use League\Flysystem\Filesystem;
/** /**
* Simple Flysystem implementation of GeneratedAssetHandler for storing generated content * Simple Flysystem implementation of GeneratedAssetHandler for storing generated content
* *
* @package framework * @package framework
* @subpackage filesystem * @subpackage filesystem
*/ */
@ -38,6 +38,9 @@ class FlysystemGeneratedAssetHandler implements GeneratedAssetHandler {
* @return Filesystem * @return Filesystem
*/ */
public function getFilesystem() { public function getFilesystem() {
if(!$this->assetStore) {
throw new Exception("Filesystem misconfiguration error");
}
return $this->assetStore; return $this->assetStore;
} }