mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00:00
Merge pull request #2390 from creative-commoners/pulls/4.4/style-updates
NEW BrokenLinksReport now uses injector for fields, uses short array syntax and single quotes
This commit is contained in:
commit
023248f867
@ -7,13 +7,12 @@ use SilverStripe\CMS\Model\RedirectorPage;
|
|||||||
use SilverStripe\CMS\Model\SiteTree;
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
use SilverStripe\CMS\Model\VirtualPage;
|
use SilverStripe\CMS\Model\VirtualPage;
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Core\ClassInfo;
|
|
||||||
use SilverStripe\Forms\DropdownField;
|
use SilverStripe\Forms\DropdownField;
|
||||||
use SilverStripe\Forms\FieldList;
|
use SilverStripe\Forms\FieldList;
|
||||||
use SilverStripe\Versioned\Versioned;
|
|
||||||
use SilverStripe\ORM\DataObject;
|
|
||||||
use SilverStripe\ORM\ArrayList;
|
use SilverStripe\ORM\ArrayList;
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\Reports\Report;
|
use SilverStripe\Reports\Report;
|
||||||
|
use SilverStripe\Versioned\Versioned;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Content side-report listing pages with broken links
|
* Content side-report listing pages with broken links
|
||||||
@ -23,7 +22,7 @@ class BrokenLinksReport extends Report
|
|||||||
|
|
||||||
public function title()
|
public function title()
|
||||||
{
|
{
|
||||||
return _t(__CLASS__ . '.BROKENLINKS', "Broken links report");
|
return _t(__CLASS__ . '.BROKENLINKS', 'Broken links report');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sourceRecords($params, $sort, $limit)
|
public function sourceRecords($params, $sort, $limit)
|
||||||
@ -35,26 +34,26 @@ class BrokenLinksReport extends Report
|
|||||||
$field = $parts[0];
|
$field = $parts[0];
|
||||||
$direction = $parts[1];
|
$direction = $parts[1];
|
||||||
|
|
||||||
if ($field == 'AbsoluteLink') {
|
if ($field === 'AbsoluteLink') {
|
||||||
$sort = 'URLSegment ' . $direction;
|
$sort = 'URLSegment ' . $direction;
|
||||||
} elseif ($field == 'Subsite.Title') {
|
} elseif ($field === 'Subsite.Title') {
|
||||||
$join = 'LEFT JOIN "Subsite" ON "Subsite"."ID" = "SiteTree"."SubsiteID"';
|
$join = 'LEFT JOIN "Subsite" ON "Subsite"."ID" = "SiteTree"."SubsiteID"';
|
||||||
} elseif ($field == 'BrokenReason') {
|
} elseif ($field === 'BrokenReason') {
|
||||||
$sortBrokenReason = true;
|
$sortBrokenReason = true;
|
||||||
$sort = '';
|
$sort = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$brokenFilter = array(
|
$brokenFilter = [
|
||||||
'"SiteTree"."HasBrokenLink" = ? OR "SiteTree"."HasBrokenFile" = ?' => array(true, true)
|
'"SiteTree"."HasBrokenLink" = ? OR "SiteTree"."HasBrokenFile" = ?' => [true, true]
|
||||||
);
|
];
|
||||||
$isLive = !isset($params['CheckSite']) || $params['CheckSite'] == 'Published';
|
$isLive = !isset($params['CheckSite']) || $params['CheckSite'] === 'Published';
|
||||||
if ($isLive) {
|
if ($isLive) {
|
||||||
$ret = Versioned::get_by_stage(SiteTree::class, 'Live', $brokenFilter, $sort, $join, $limit);
|
$ret = Versioned::get_by_stage(SiteTree::class, Versioned::LIVE, $brokenFilter, $sort, $join, $limit);
|
||||||
} else {
|
} else {
|
||||||
$ret = DataObject::get(SiteTree::class, $brokenFilter, $sort, $join, $limit);
|
$ret = DataObject::get(SiteTree::class, $brokenFilter, $sort, $join, $limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
$returnSet = new ArrayList();
|
$returnSet = ArrayList::create();
|
||||||
if ($ret) {
|
if ($ret) {
|
||||||
foreach ($ret as $record) {
|
foreach ($ret as $record) {
|
||||||
$reason = false;
|
$reason = false;
|
||||||
@ -63,24 +62,24 @@ class BrokenLinksReport extends Report
|
|||||||
$reasonCodes = [];
|
$reasonCodes = [];
|
||||||
if ($isVirtualPage) {
|
if ($isVirtualPage) {
|
||||||
if ($record->HasBrokenLink) {
|
if ($record->HasBrokenLink) {
|
||||||
$reason = _t(__CLASS__ . '.VirtualPageNonExistent', "virtual page pointing to non-existent page");
|
$reason = _t(__CLASS__ . '.VirtualPageNonExistent', 'virtual page pointing to non-existent page');
|
||||||
$reasonCodes = array("VPBROKENLINK");
|
$reasonCodes = ['VPBROKENLINK'];
|
||||||
}
|
}
|
||||||
} elseif ($isRedirectorPage) {
|
} elseif ($isRedirectorPage) {
|
||||||
if ($record->HasBrokenLink) {
|
if ($record->HasBrokenLink) {
|
||||||
$reason = _t(__CLASS__ . '.RedirectorNonExistent', "redirector page pointing to non-existent page");
|
$reason = _t(__CLASS__ . '.RedirectorNonExistent', 'redirector page pointing to non-existent page');
|
||||||
$reasonCodes = array("RPBROKENLINK");
|
$reasonCodes = ['RPBROKENLINK'];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($record->HasBrokenLink && $record->HasBrokenFile) {
|
if ($record->HasBrokenLink && $record->HasBrokenFile) {
|
||||||
$reason = _t(__CLASS__ . '.HasBrokenLinkAndFile', "has broken link and file");
|
$reason = _t(__CLASS__ . '.HasBrokenLinkAndFile', 'has broken link and file');
|
||||||
$reasonCodes = array("BROKENFILE", "BROKENLINK");
|
$reasonCodes = ['BROKENFILE', 'BROKENLINK'];
|
||||||
} elseif ($record->HasBrokenLink && !$record->HasBrokenFile) {
|
} elseif ($record->HasBrokenLink && !$record->HasBrokenFile) {
|
||||||
$reason = _t(__CLASS__ . '.HasBrokenLink', "has broken link");
|
$reason = _t(__CLASS__ . '.HasBrokenLink', 'has broken link');
|
||||||
$reasonCodes = array("BROKENLINK");
|
$reasonCodes = ['BROKENLINK'];
|
||||||
} elseif (!$record->HasBrokenLink && $record->HasBrokenFile) {
|
} elseif (!$record->HasBrokenLink && $record->HasBrokenFile) {
|
||||||
$reason = _t(__CLASS__ . '.HasBrokenFile', "has broken file");
|
$reason = _t(__CLASS__ . '.HasBrokenFile', 'has broken file');
|
||||||
$reasonCodes = array("BROKENFILE");
|
$reasonCodes = ['BROKENFILE'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,9 +108,9 @@ class BrokenLinksReport extends Report
|
|||||||
}
|
}
|
||||||
|
|
||||||
$linkBase = CMSPageEditController::singleton()->Link('show');
|
$linkBase = CMSPageEditController::singleton()->Link('show');
|
||||||
$fields = array(
|
$fields = [
|
||||||
"Title" => array(
|
'Title' => [
|
||||||
"title" => _t(__CLASS__ . '.PageName', 'Page name'),
|
'title' => _t(__CLASS__ . '.PageName', 'Page name'),
|
||||||
'formatting' => function ($value, $item) use ($linkBase) {
|
'formatting' => function ($value, $item) use ($linkBase) {
|
||||||
return sprintf(
|
return sprintf(
|
||||||
'<a href="%s" title="%s">%s</a>',
|
'<a href="%s" title="%s">%s</a>',
|
||||||
@ -120,15 +119,15 @@ class BrokenLinksReport extends Report
|
|||||||
$value
|
$value
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
),
|
],
|
||||||
"LastEdited" => array(
|
'LastEdited' => [
|
||||||
"title" => $dateTitle,
|
'title' => $dateTitle,
|
||||||
'casting' => 'DBDatetime->Full'
|
'casting' => 'DBDatetime->Full'
|
||||||
),
|
],
|
||||||
"BrokenReason" => array(
|
'BrokenReason' => [
|
||||||
"title" => _t(__CLASS__ . '.ColumnProblemType', "Problem type")
|
'title' => _t(__CLASS__ . '.ColumnProblemType', 'Problem type')
|
||||||
),
|
],
|
||||||
'AbsoluteLink' => array(
|
'AbsoluteLink' => [
|
||||||
'title' => _t(__CLASS__ . '.ColumnURL', 'URL'),
|
'title' => _t(__CLASS__ . '.ColumnURL', 'URL'),
|
||||||
'formatting' => function ($value, $item) {
|
'formatting' => function ($value, $item) {
|
||||||
/** @var SiteTree $item */
|
/** @var SiteTree $item */
|
||||||
@ -141,28 +140,28 @@ class BrokenLinksReport extends Report
|
|||||||
$liveLink ? '(live)' : '(draft)'
|
$liveLink ? '(live)' : '(draft)'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
)
|
],
|
||||||
);
|
];
|
||||||
|
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
public function parameterFields()
|
public function parameterFields()
|
||||||
{
|
{
|
||||||
return new FieldList(
|
return FieldList::create(
|
||||||
new DropdownField('CheckSite', _t(__CLASS__ . '.CheckSite', 'Check site'), array(
|
DropdownField::create('CheckSite', _t(__CLASS__ . '.CheckSite', 'Check site'), array(
|
||||||
'Published' => _t(__CLASS__ . '.CheckSiteDropdownPublished', 'Published Site'),
|
'Published' => _t(__CLASS__ . '.CheckSiteDropdownPublished', 'Published Site'),
|
||||||
'Draft' => _t(__CLASS__ . '.CheckSiteDropdownDraft', 'Draft Site')
|
'Draft' => _t(__CLASS__ . '.CheckSiteDropdownDraft', 'Draft Site')
|
||||||
)),
|
)),
|
||||||
new DropdownField(
|
DropdownField::create(
|
||||||
'Reason',
|
'Reason',
|
||||||
_t(__CLASS__ . '.ReasonDropdown', 'Problem to check'),
|
_t(__CLASS__ . '.ReasonDropdown', 'Problem to check'),
|
||||||
array(
|
[
|
||||||
'' => _t(__CLASS__ . '.Any', 'Any'),
|
'' => _t(__CLASS__ . '.Any', 'Any'),
|
||||||
'BROKENFILE' => _t(__CLASS__ . '.ReasonDropdownBROKENFILE', 'Broken file'),
|
'BROKENFILE' => _t(__CLASS__ . '.ReasonDropdownBROKENFILE', 'Broken file'),
|
||||||
'BROKENLINK' => _t(__CLASS__ . '.ReasonDropdownBROKENLINK', 'Broken link'),
|
'BROKENLINK' => _t(__CLASS__ . '.ReasonDropdownBROKENLINK', 'Broken link'),
|
||||||
'VPBROKENLINK' => _t(__CLASS__ . '.ReasonDropdownVPBROKENLINK', 'Virtual page pointing to non-existent page'),
|
'VPBROKENLINK' => _t(__CLASS__ . '.ReasonDropdownVPBROKENLINK', 'Virtual page pointing to non-existent page'),
|
||||||
'RPBROKENLINK' => _t(__CLASS__ . '.ReasonDropdownRPBROKENLINK', 'Redirector page pointing to non-existent page'),
|
'RPBROKENLINK' => _t(__CLASS__ . '.ReasonDropdownRPBROKENLINK', 'Redirector page pointing to non-existent page'),
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user