1 | <?php |
||
2 | |||
3 | namespace Sunnysideup\VersionPruner\PruningTemplates; |
||
4 | |||
5 | use SilverStripe\ORM\DB; |
||
6 | use Sunnysideup\VersionPruner\PruningTemplatesTemplate; |
||
7 | |||
8 | class UserChanged extends PruningTemplatesTemplate |
||
9 | { |
||
10 | protected $keepVersions = 3; |
||
11 | |||
12 | public function setKeepVersions(int $keepVersions): self |
||
13 | { |
||
14 | $this->keepVersions = $keepVersions; |
||
15 | |||
16 | return $this; |
||
17 | } |
||
18 | |||
19 | public function getTitle(): string |
||
20 | { |
||
21 | return 'Prune automated saves'; |
||
22 | } |
||
23 | |||
24 | public function getDescription(): string |
||
25 | { |
||
26 | return 'Delete versions that are not edited by a logged-in user.'; |
||
27 | } |
||
28 | |||
29 | public function run(?bool $verbose = false) |
||
30 | { |
||
31 | DB::query('SELECT * FROM SiteTree_Versions WHERE AuthorID > 0 AND RecordID = ' . $this->object->ID); |
||
32 | $this->markOlderItemsWithoutAuthor(); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * these can be deleted. |
||
37 | */ |
||
38 | protected function markOlderItemsWithoutAuthor() |
||
39 | { |
||
40 | $filter['"AuthorID" = ?'] = 0; |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
![]() |
|||
41 | $query = $this->getBaseQuery(['AuthorID']) |
||
42 | ->addWhere($this->normaliseWhere($filter)) |
||
43 | ->setLimit($this->normaliseLimit(), $this->normaliseOffset($this->keepVersions)) |
||
44 | ; |
||
45 | $this->toDelete[$this->getUniqueKey()] += $this->addVersionNumberToArray( |
||
46 | $this->toDelete[$this->getUniqueKey()], |
||
47 | $query->execute() |
||
48 | ); |
||
49 | } |
||
50 | } |
||
51 |