blob: 89549170191b2c4d93cd35f97fcc515c89f3db2e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
<?php
namespace JsonApi\Routes\Courseware;
use Courseware\StructuralElement;
use JsonApi\Errors\AuthorizationFailedException;
use JsonApi\Errors\RecordNotFoundException;
use JsonApi\NonJsonApiController;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
class StructuralElementsImageDelete extends NonJsonApiController
{
public function invoke(Request $request, Response $response, array $args): Response
{
if (!($structuralElement = StructuralElement::find($args['id']))) {
throw new RecordNotFoundException();
}
if (!Authority::canDeleteStructuralElementsImage($this->getUser($request), $structuralElement)) {
throw new AuthorizationFailedException();
}
// remove existing image
if (is_a($structuralElement->image, \FileRef::class)) {
$structuralElement->image->getFileType()->delete();
}
$structuralElement->image_id = null;
$structuralElement->image_type = \FileRef::class;
$structuralElement->store();
return $response->withStatus(204);
}
}
|