|
@@ 232-242 (lines=11) @@
|
| 229 |
|
$file = Injector::inst()->create($fileClass); |
| 230 |
|
|
| 231 |
|
// check canCreate permissions |
| 232 |
|
if (!$file->canCreate(null, $data)) { |
| 233 |
|
$result = ['message' => [ |
| 234 |
|
'type' => 'error', |
| 235 |
|
'value' => _t( |
| 236 |
|
'SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.CreatePermissionDenied', |
| 237 |
|
'You do not have permission to add files' |
| 238 |
|
) |
| 239 |
|
]]; |
| 240 |
|
return (new HTTPResponse(json_encode($result), 403)) |
| 241 |
|
->addHeader('Content-Type', 'application/json'); |
| 242 |
|
} |
| 243 |
|
|
| 244 |
|
$uploadResult = $upload->loadIntoFile($tmpFile, $file, $parentRecord ? $parentRecord->getFilename() : '/'); |
| 245 |
|
if (!$uploadResult) { |
|
@@ 245-255 (lines=11) @@
|
| 242 |
|
} |
| 243 |
|
|
| 244 |
|
$uploadResult = $upload->loadIntoFile($tmpFile, $file, $parentRecord ? $parentRecord->getFilename() : '/'); |
| 245 |
|
if (!$uploadResult) { |
| 246 |
|
$result = ['message' => [ |
| 247 |
|
'type' => 'error', |
| 248 |
|
'value' => _t( |
| 249 |
|
'SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.LoadIntoFileFailed', |
| 250 |
|
'Failed to load file' |
| 251 |
|
) |
| 252 |
|
]]; |
| 253 |
|
return (new HTTPResponse(json_encode($result), 400)) |
| 254 |
|
->addHeader('Content-Type', 'application/json'); |
| 255 |
|
} |
| 256 |
|
|
| 257 |
|
$file->ParentID = $parentRecord ? $parentRecord->ID : 0; |
| 258 |
|
$file->write(); |