BUG Prevent top-level files being created with incorrect parent folder

This commit is contained in:
Damian Mooyman 2017-02-24 15:07:25 +13:00
parent 9fca2e9306
commit 9610a0a284
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A

View File

@ -615,6 +615,8 @@ class FixtureContext extends BehatContext
if (!$data) {
$data = array();
}
$relativeTargetPath = (isset($data['Filename'])) ? $data['Filename'] : $identifier;
$relativeTargetPath = preg_replace('/^' . ASSETS_DIR . '\/?/', '', $relativeTargetPath);
$sourcePath = $this->joinPaths($this->getFilesPath(), basename($relativeTargetPath));
@ -624,7 +626,7 @@ class FixtureContext extends BehatContext
$parent = Folder::find_or_make($relativeTargetPath);
$data['ID'] = $parent->ID;
} else {
$parent = Folder::find_or_make(dirname($relativeTargetPath));
// Check file exists
if (!file_exists($sourcePath)) {
throw new \InvalidArgumentException(sprintf(
'Source file for "%s" cannot be found in "%s"',
@ -632,7 +634,17 @@ class FixtureContext extends BehatContext
$sourcePath
));
}
$data['ParentID'] = $parent->ID;
// Get parent
$parentID = 0;
if (strstr($relativeTargetPath, '/')) {
$folderName = dirname($relativeTargetPath);
$parent = Folder::find_or_make($folderName);
if ($parent) {
$parentID = $parent->ID;
}
}
$data['ParentID'] = $parentID;
// Load file into APL and retrieve tuple
$asset = $this->getAssetStore()->setFromLocalFile(