/
delete.php
66 lines (60 loc) · 2.65 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace Concrete\Controller\Dialog\Page;
use Concrete\Controller\Backend\UserInterface\Page as BackendInterfacePageController;
use Concrete\Core\Page\Command\DeletePageCommand;
use Concrete\Core\Workflow\Request\DeletePageRequest as DeletePagePageWorkflowRequest;
use Concrete\Core\Page\EditResponse as PageEditResponse;
use Concrete\Core\Workflow\Progress\Response as WorkflowProgressResponse;
use Concrete\Core\User\User;
use Page;
class Delete extends BackendInterfacePageController
{
protected $viewPath = '/dialogs/page/delete';
protected $controllerActionPath = '/ccm/system/dialogs/page/delete';
protected function canAccess()
{
return $this->permissions->canDeletePage();
}
public function view()
{
$this->set('sitemap', false);
$this->set('numChildren', $this->page->getNumChildren());
}
public function viewFromSitemap()
{
$this->set('numChildren', $this->page->getNumChildren());
$this->set('sitemap', true);
}
public function submit()
{
if ($this->validateAction()) {
$c = $this->page;
$cp = $this->permissions;
if ($cp->canDeletePage() && $c->getCollectionID() != Page::getHomePageID() && (!$c->isMasterCollection())) {
$u = $this->app->make(User::class);
$children = $c->getNumChildren();
if ($children == 0 || $u->isSuperUser()) {
if ($c->isExternalLink()) {
$c->delete();
} else {
$command = new DeletePageCommand($c->getCollectionID(), $u->getUserID());
$response = $this->app->executeCommand($command);
$pr = new PageEditResponse();
$pr->setPage($c);
$parent = Page::getByID($c->getCollectionParentID(), 'ACTIVE');
if ($response instanceof WorkflowProgressResponse) {
// we only get this response if we have skipped workflows and jumped straight in to an approve() step.
$pr->setMessage(t('Page deleted successfully.'));
if (!$this->request->request->get('sitemap')) {
$pr->setRedirectURL($parent->getCollectionLink(true));
}
} else {
$pr->setMessage(t('Page deletion request saved. This action will have to be approved before the page is deleted.'));
}
$pr->outputJSON();
}
}
}
}
}
}