|
@@ 359-369 (lines=11) @@
|
| 356 |
|
$file = Injector::inst()->create($fileClass); |
| 357 |
|
|
| 358 |
|
// check canCreate permissions |
| 359 |
|
if (!$file->canCreate(null, $data)) { |
| 360 |
|
$result = ['message' => [ |
| 361 |
|
'type' => 'error', |
| 362 |
|
'value' => _t( |
| 363 |
|
'SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.CreatePermissionDenied', |
| 364 |
|
'You do not have permission to add files' |
| 365 |
|
) |
| 366 |
|
]]; |
| 367 |
|
return (new HTTPResponse(json_encode($result), 403)) |
| 368 |
|
->addHeader('Content-Type', 'application/json'); |
| 369 |
|
} |
| 370 |
|
|
| 371 |
|
$uploadResult = $upload->loadIntoFile($tmpFile, $file, $parentRecord ? $parentRecord->getFilename() : '/'); |
| 372 |
|
if(!$uploadResult) { |
|
@@ 372-382 (lines=11) @@
|
| 369 |
|
} |
| 370 |
|
|
| 371 |
|
$uploadResult = $upload->loadIntoFile($tmpFile, $file, $parentRecord ? $parentRecord->getFilename() : '/'); |
| 372 |
|
if(!$uploadResult) { |
| 373 |
|
$result = ['message' => [ |
| 374 |
|
'type' => 'error', |
| 375 |
|
'value' => _t( |
| 376 |
|
'SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.LoadIntoFileFailed', |
| 377 |
|
'Failed to load file' |
| 378 |
|
) |
| 379 |
|
]]; |
| 380 |
|
return (new HTTPResponse(json_encode($result), 400)) |
| 381 |
|
->addHeader('Content-Type', 'application/json'); |
| 382 |
|
} |
| 383 |
|
|
| 384 |
|
$file->ParentID = $parentRecord ? $parentRecord->ID : 0; |
| 385 |
|
$file->write(); |