1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sunnysideup\VersionPruner\Api; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Core\ClassInfo; |
6
|
|
|
use SilverStripe\Core\Config\Config; |
7
|
|
|
use SilverStripe\Core\Injector\Injector; |
8
|
|
|
use SilverStripe\Dev\BuildTask; |
9
|
|
|
use SilverStripe\ORM\DataObject; |
10
|
|
|
use SilverStripe\ORM\DB; |
11
|
|
|
use SilverStripe\Versioned\Versioned; |
|
|
|
|
12
|
|
|
|
13
|
|
|
class PruneAllVersionedRecordsReviewTemplates extends BuildTask |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $title = 'Prune all versioned records - review templates for each dataobject'; |
19
|
|
|
|
20
|
|
|
protected $description = 'Go through all dataobjects and shows the pruning schedule.'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private static $segment = 'prune-all-versioned-records-review-templates'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Prune all published DataObjects which are published according to config. |
29
|
|
|
* |
30
|
|
|
* @param mixed $request |
31
|
|
|
*/ |
32
|
|
|
public function run($request) |
33
|
|
|
{ |
34
|
|
|
$allClasses = ClassInfo::subclassesFor(DataObject::class, false); |
35
|
|
|
$runner = RunForOneObject::inst(); |
36
|
|
|
Versioned::set_stage(Versioned::DRAFT); |
37
|
|
|
foreach ($allClasses as $className) { |
38
|
|
|
$name = Injector::inst()->get($className)->i18n_singular_name(); |
39
|
|
|
$count = $this->getObjectCountPerClassName($className); |
40
|
|
|
$versionCount = $this->getObjectCountPerClassName($className); |
41
|
|
|
if ($count) { |
42
|
|
|
$object = DataObject::get_one($className); |
43
|
|
|
if ($object) { |
44
|
|
|
$array = $runner->getTemplatesDescription($object); |
45
|
|
|
if (count($array)) { |
46
|
|
|
DB::alteration_message('-----------------------------------'); |
47
|
|
|
DB::alteration_message($name . ' (' . $count . ' records, '.$versionCount.' version records) ' . $className); |
48
|
|
|
DB::alteration_message('... ' . $className); |
49
|
|
|
foreach ($array as $string) { |
50
|
|
|
DB::alteration_message('... ... ' . $string); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected function getObjectCountPerClassName(string $className): int |
59
|
|
|
{ |
60
|
|
|
return $className::get()->limit(100000)->count(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
protected function getObjectCountForVersionsPerClassName(string $className): int |
64
|
|
|
{ |
65
|
|
|
$tableName = Config::inst()->get($className, 'table_name'); |
66
|
|
|
return DB::query('SELECT COUNT("ID") FROM "'.$tableName.'_Versions";')->value(); |
|
|
|
|
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths