-
Notifications
You must be signed in to change notification settings - Fork 333
/
BrokenFilesReport.php
61 lines (52 loc) · 1.71 KB
/
BrokenFilesReport.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
<?php
namespace SilverStripe\CMS\Reports;
use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\CMS\Model\VirtualPage;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Reports\Report;
use SilverStripe\ORM\DB;
use SilverStripe\Versioned\Versioned;
class BrokenFilesReport extends Report
{
public function title()
{
return _t(__CLASS__.'.BROKENFILES', "Pages with broken files");
}
public function group()
{
return _t(__CLASS__.'.BrokenLinksGroupTitle', "Broken links reports");
}
public function sourceRecords($params = null)
{
// Get class names for page types that are not virtual pages or redirector pages
$classes = array_diff(
ClassInfo::subclassesFor(SiteTree::class) ?? [],
ClassInfo::subclassesFor(VirtualPage::class),
ClassInfo::subclassesFor(RedirectorPage::class)
);
$classParams = DB::placeholders($classes);
$classFilter = [
"\"ClassName\" IN ($classParams) AND \"HasBrokenFile\" = 1" => $classes
];
$stage = isset($params['OnLive']) ? Versioned::LIVE : Versioned::DRAFT;
return Versioned::get_by_stage(SiteTree::class, $stage, $classFilter);
}
public function columns()
{
return [
"Title" => [
"title" => "Title", // todo: use NestedTitle(2)
"link" => true,
],
];
}
public function getParameterFields()
{
return new FieldList(
new CheckboxField('OnLive', _t(__CLASS__.'.ParameterLiveCheckbox', 'Check live site'))
);
}
}