|
@@ 263-273 (lines=11) @@
|
| 260 |
|
$file = Injector::inst()->create($fileClass); |
| 261 |
|
|
| 262 |
|
// check canCreate permissions |
| 263 |
|
if (!$file->canCreate(null, $data)) { |
| 264 |
|
$result = ['message' => [ |
| 265 |
|
'type' => 'error', |
| 266 |
|
'value' => _t( |
| 267 |
|
'SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.CreatePermissionDenied', |
| 268 |
|
'You do not have permission to add files' |
| 269 |
|
) |
| 270 |
|
]]; |
| 271 |
|
return (new HTTPResponse(json_encode($result), 403)) |
| 272 |
|
->addHeader('Content-Type', 'application/json'); |
| 273 |
|
} |
| 274 |
|
|
| 275 |
|
$uploadResult = $upload->loadIntoFile($tmpFile, $file, $parentRecord ? $parentRecord->getFilename() : '/'); |
| 276 |
|
if (!$uploadResult) { |
|
@@ 276-286 (lines=11) @@
|
| 273 |
|
} |
| 274 |
|
|
| 275 |
|
$uploadResult = $upload->loadIntoFile($tmpFile, $file, $parentRecord ? $parentRecord->getFilename() : '/'); |
| 276 |
|
if (!$uploadResult) { |
| 277 |
|
$result = ['message' => [ |
| 278 |
|
'type' => 'error', |
| 279 |
|
'value' => _t( |
| 280 |
|
'SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.LoadIntoFileFailed', |
| 281 |
|
'Failed to load file' |
| 282 |
|
) |
| 283 |
|
]]; |
| 284 |
|
return (new HTTPResponse(json_encode($result), 400)) |
| 285 |
|
->addHeader('Content-Type', 'application/json'); |
| 286 |
|
} |
| 287 |
|
|
| 288 |
|
$file->ParentID = $parentRecord ? $parentRecord->ID : 0; |
| 289 |
|
$file->write(); |