/
sitemap_delete_forever.php
53 lines (46 loc) · 1.9 KB
/
sitemap_delete_forever.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
<?php
namespace Concrete\Controller\Backend\Page;
use Concrete\Core\Command\Batch\Batch;
use Concrete\Core\Controller\AbstractController;
use Concrete\Core\Error\UserMessageException;
use Concrete\Core\Page\Command\DeletePageForeverCommand;
use Concrete\Core\Page\Page;
use Concrete\Core\Permission\Checker;
class SitemapDeleteForever extends AbstractController
{
public function canAccess()
{
$checker = new Checker();
return $checker->canEmptyTrash();
}
public function fillQueue()
{
if ($this->canAccess()) {
$c = Page::getByID($_REQUEST['cID']);
if (is_object($c) && !$c->isError()) {
$cp = new \Permissions($c);
if ($cp->canDeletePage()) {
$includeThisPage = true;
if ($c->getCollectionPath() == $this->app->make('config')->get('concrete.paths.trash')) {
// we're in the trash. we can't delete the trash. we're skipping over the trash node.
$includeThisPage = false;
}
$pages = $c->populateRecursivePages([], ['cID' => $c->getCollectionID()], $c->getCollectionParentID(), 0, $includeThisPage);
// business if the queue dies.
usort($pages, ['\Concrete\Core\Page\Page', 'queueForDeletionSort']);
foreach ($pages as $page) {
$ids[] = $page['cID'];
}
$batch = Batch::create(t('Delete Pages'), function() use ($pages) {
foreach ($pages as $page) {
yield new DeletePageForeverCommand($page['cID']);
}
});
return $this->dispatchBatch($batch);
}
}
} else {
throw new UserMessageException(t('Access Denied.'));
}
}
}