/
delete.php
47 lines (38 loc) · 1.24 KB
/
delete.php
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
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace Concrete\Controller\Dialog\File;
use Concrete\Controller\Backend\UserInterface;
use Concrete\Core\Error\UserMessageException;
use Concrete\Core\File\EditResponse;
use Concrete\Core\File\File;
use Concrete\Core\Permission\Checker;
use Symfony\Component\HttpFoundation\JsonResponse;
class Delete extends UserInterface
{
protected $viewPath = '/dialogs/file/delete';
protected function canAccess()
{
$file = File::getByID($this->request->attributes->get('fID'));
if (!$file) {
throw new UserMessageException(t('Invalid file object.'));
}
$checker = new Checker($file);
return $checker->canDeleteFile();
}
public function view($fID)
{
$file = File::getByID($this->request->attributes->get('fID'));
$this->set('file', $file);
}
public function submit($fID)
{
if ($this->canAccess()) {
$file = File::getByID($this->request->attributes->get('fID'));
$file->delete();
$this->flash('success', t('File deleted successfully.'));
$response = new EditResponse();
$response->setFile($file);
return new JsonResponse($response);
}
$this->view($fID);
}
}