diff --git a/code/controllers/AssetAdmin.php b/code/controllers/AssetAdmin.php index 62facb37..5269c64d 100644 --- a/code/controllers/AssetAdmin.php +++ b/code/controllers/AssetAdmin.php @@ -478,10 +478,12 @@ JS public function currentPage() { $id = $this->currentPageID(); if($id && is_numeric($id) && $id > 0) { - return DataObject::get_by_id('Folder', $id); - } else { - return new Folder(); + $folder = DataObject::get_by_id('Folder', $id); + if($folder && $folder->exists()) { + return $folder; + } } + return new Folder(); } public function getSiteTreeFor($className, $rootID = null, $childrenMethod = null, $numChildrenMethod = null, $filterFunction = null, $minNodeCount = 30) { diff --git a/code/controllers/CMSFileAddController.php b/code/controllers/CMSFileAddController.php index e68916fe..e13cbe44 100644 --- a/code/controllers/CMSFileAddController.php +++ b/code/controllers/CMSFileAddController.php @@ -23,13 +23,13 @@ class CMSFileAddController extends LeftAndMain { */ public function currentPage() { $id = $this->currentPageID(); - if($id && is_numeric($id) && $id > 0) { - return DataObject::get_by_id('Folder', $id); - } else { - // ID is either '0' or 'root' - return singleton('Folder'); + $folder = DataObject::get_by_id('Folder', $id); + if($folder && $folder->exists()) { + return $folder; + } } + return new Folder(); } /** @@ -64,12 +64,12 @@ class CMSFileAddController extends LeftAndMain { $uploadField->removeExtraClass('ss-uploadfield'); $uploadField->setTemplate('AssetUploadField'); - if ($folder->exists() && $folder->getFilename()) { + if($folder->exists() && $folder->getFilename()) { // The Upload class expects a folder relative *within* assets/ $path = preg_replace('/^' . ASSETS_DIR . '\//', '', $folder->getFilename()); $uploadField->setFolderName($path); } else { - $uploadField->setFolderName(ASSETS_DIR); + $uploadField->setFolderName('/'); // root of the assets } $exts = $uploadField->getValidator()->getAllowedExtensions();