/
RemoveOldPageVersionsController.php
68 lines (53 loc) · 2.04 KB
/
RemoveOldPageVersionsController.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
67
68
<?php
namespace Concrete\Core\Command\Task\Controller;
use Concrete\Core\Command\Batch\Batch;
use Concrete\Core\Command\Task\Input\Definition\Definition;
use Concrete\Core\Command\Task\Input\Definition\Field;
use Concrete\Core\Command\Task\Input\InputInterface;
use Concrete\Core\Command\Task\Runner\BatchProcessTaskRunner;
use Concrete\Core\Command\Task\Runner\TaskRunnerInterface;
use Concrete\Core\Command\Task\TaskInterface;
use Concrete\Core\Database\Connection\Connection;
use Concrete\Core\Page\Command\RemoveOldPageVersionsTaskCommand;
defined('C5_EXECUTE') or die("Access Denied.");
class RemoveOldPageVersionsController extends AbstractController
{
/**
* @var Connection
*/
protected $db;
public function __construct(Connection $db)
{
$this->db = $db;
}
public function getName(): string
{
return t('Remove Old Page Versions');
}
public function getDescription(): string
{
return t('Removes all except the 10 most recent page versions for each page.');
}
public function getInputDefinition(): ?Definition
{
$definition = new Definition();
$definition->addField(new Field('after', t('After Page ID'), t('Scan pages for versions to remove after a particular page ID.')));
return $definition;
}
public function getTaskRunner(TaskInterface $task, InputInterface $input): TaskRunnerInterface
{
$query = $this->db->createQueryBuilder();
$query->select('cID')->from('Pages', 'p');
if ($input->hasField('after')) {
$after = $input->getField('after');
$query->andWhere('p.cID > :after');
$query->setParameter('after', $after->getValue());
}
$query->orderBy('p.cID', 'asc');
$batch = Batch::create();
foreach($query->execute()->fetchAll() as $result) {
$batch->add(new RemoveOldPageVersionsTaskCommand($result['cID']));
}
return new BatchProcessTaskRunner($task, $batch, $input, t('Page version removal beginning...'));
}
}