Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: NEW Add Title, Last Edited and Last Editor as default columns in all CMS reports #2234

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions code/Reports/AbstractCMSReport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace SilverStripe\CMS\Reports;

use SilverStripe\CMS\Controllers\CMSPageEditController;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
use SilverStripe\Reports\Report;
use SilverStripe\Security\Member;
use SilverStripe\Versioned\Versioned;

/**
* Provides some common functionality for all CMS module reports
*/
abstract class AbstractCMSReport extends Report
{
/**
* By default we provide the page title with a clickable link, the last edited date and the member's name
* who last edited the page.
*
* @return array[]
*/
public function columns()
{
// @todo remove coupling to global state
$isDraft = isset($_REQUEST['filters']['CheckSite']) && $_REQUEST['filters']['CheckSite'] === 'Draft';
if ($isDraft) {
$dateTitle = _t(__CLASS__ . '.ColumnDateLastModified', 'Date last modified');
} else {
$dateTitle = _t(__CLASS__ . '.ColumnDateLastPublished', 'Date last published');
}
$linkBase = CMSPageEditController::singleton()->Link('show');

return [
'Title' => [
'title' => _t(__CLASS__ . '.PageName', 'Page name'),
'formatting' => function ($value, $item) use ($linkBase) {
return sprintf(
'<a href="%s" title="%s">%s</a>',
Controller::join_links($linkBase, $item->ID),
_t(__CLASS__ . '.HoverTitleEditPage', 'Edit page'),
$value
);
},
],
'LastEdited' => [
'title' => $dateTitle,
'casting' => 'DBDatetime->Full',
],
'AuthorID' => [
'title' => _t(__CLASS__ . '.LastEditor', 'Last Editor'),
'formatting' => function ($value, SiteTree $item) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you added this as a getter to SiteTree, would that make it exportable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it would, but it's also couple it a bit more to versioned. I'm sure I can customise the export fields with callbacks, I just haven't looked at it enough yet 😆

$latestVersion = Versioned::get_latest_version(SiteTree::class, $item->ID);
if (!$latestVersion) {
return '';
}

/** @var Member $member */
$member = Member::get()->byID($latestVersion->AuthorID);
if ($member) {
return sprintf('%s %s', $member->FirstName, $member->Surname);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return sprintf('%s %s', $member->FirstName, $member->Surname);
return $member->Title;

}
return '';
},
],
];
}
}
14 changes: 1 addition & 13 deletions code/Reports/BrokenFilesReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
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
class BrokenFilesReport extends AbstractCMSReport
{

public function title()
{
return _t(__CLASS__.'.BROKENFILES', "Pages with broken files");
Expand Down Expand Up @@ -42,16 +40,6 @@ public function sourceRecords($params = null)
return Versioned::get_by_stage(SiteTree::class, $stage, $classFilter);
}

public function columns()
{
return array(
"Title" => array(
"title" => "Title", // todo: use NestedTitle(2)
"link" => true,
),
);
}

public function getParameterFields()
{
return new FieldList(
Expand Down
40 changes: 8 additions & 32 deletions code/Reports/BrokenLinksReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,21 @@

namespace SilverStripe\CMS\Reports;

use SilverStripe\CMS\Controllers\CMSPageEditController;
use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\CMS\Model\VirtualPage;
use SilverStripe\Control\Controller;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Versioned\Versioned;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\ArrayList;
use SilverStripe\Reports\Report;
use SilverStripe\ORM\DataObject;
use SilverStripe\Versioned\Versioned;

/**
* Content side-report listing pages with broken links
*/
class BrokenLinksReport extends Report
class BrokenLinksReport extends AbstractCMSReport
{

public function title()
{
return _t(__CLASS__ . '.BROKENLINKS', "Broken links report");
Expand Down Expand Up @@ -49,7 +45,7 @@ public function sourceRecords($params, $sort, $limit)
);
$isLive = !isset($params['CheckSite']) || $params['CheckSite'] == 'Published';
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 {
$ret = DataObject::get(SiteTree::class, $brokenFilter, $sort, $join, $limit);
}
Expand Down Expand Up @@ -102,29 +98,9 @@ public function sourceRecords($params, $sort, $limit)
}
public function columns()
{
if (isset($_REQUEST['filters']['CheckSite']) && $_REQUEST['filters']['CheckSite'] == 'Draft') {
$dateTitle = _t(__CLASS__ . '.ColumnDateLastModified', 'Date last modified');
} else {
$dateTitle = _t(__CLASS__ . '.ColumnDateLastPublished', 'Date last published');
}
$columns = parent::columns();

$linkBase = CMSPageEditController::singleton()->Link('show');
$fields = array(
"Title" => array(
"title" => _t(__CLASS__ . '.PageName', 'Page name'),
'formatting' => function ($value, $item) use ($linkBase) {
return sprintf(
'<a href="%s" title="%s">%s</a>',
Controller::join_links($linkBase, $item->ID),
_t(__CLASS__ . '.HoverTitleEditPage', 'Edit page'),
$value
);
}
),
"LastEdited" => array(
"title" => $dateTitle,
'casting' => 'DBDatetime->Full'
),
$columns += [
"BrokenReason" => array(
"title" => _t(__CLASS__ . '.ColumnProblemType', "Problem type")
),
Expand All @@ -142,9 +118,9 @@ public function columns()
);
}
)
);
];

return $fields;
return $columns;
}
public function parameterFields()
{
Expand Down
16 changes: 2 additions & 14 deletions code/Reports/BrokenRedirectorPagesReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
use SilverStripe\Forms\FieldList;
use SilverStripe\ORM\DB;
use SilverStripe\Versioned\Versioned;
use SilverStripe\Reports\Report;

class BrokenRedirectorPagesReport extends Report
class BrokenRedirectorPagesReport extends AbstractCMSReport
{

public function title()
{
return _t(__CLASS__.'.BROKENREDIRECTORPAGES', 'RedirectorPages pointing to deleted pages');
Expand All @@ -31,20 +29,10 @@ public function sourceRecords($params = null)
$classFilter = array(
"\"ClassName\" IN ($classParams) AND \"HasBrokenLink\" = 1" => $classes
);
$stage = isset($params['OnLive']) ? 'Live' : 'Stage';
$stage = isset($params['OnLive']) ? Versioned::LIVE : Versioned::DRAFT;
return Versioned::get_by_stage(SiteTree::class, $stage, $classFilter);
}

public function columns()
{
return array(
"Title" => array(
"title" => "Title", // todo: use NestedTitle(2)
"link" => true,
),
);
}

public function getParameterFields()
{
return new FieldList(
Expand Down
14 changes: 1 addition & 13 deletions code/Reports/BrokenVirtualPagesReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
use SilverStripe\Forms\FieldList;
use SilverStripe\ORM\DB;
use SilverStripe\Versioned\Versioned;
use SilverStripe\Reports\Report;

class BrokenVirtualPagesReport extends Report
class BrokenVirtualPagesReport extends AbstractCMSReport
{

public function title()
{
return _t(__CLASS__.'.BROKENVIRTUALPAGES', 'VirtualPages pointing to deleted pages');
Expand All @@ -35,16 +33,6 @@ public function sourceRecords($params = null)
return Versioned::get_by_stage(SiteTree::class, $stage, $classFilter);
}

public function columns()
{
return array(
"Title" => array(
"title" => "Title", // todo: use NestedTitle(2)
"link" => true,
),
);
}

public function getParameterFields()
{
return new FieldList(
Expand Down
14 changes: 1 addition & 13 deletions code/Reports/EmptyPagesReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\ORM\DataList;
use SilverStripe\Reports\Report;

class EmptyPagesReport extends Report
class EmptyPagesReport extends AbstractCMSReport
{

public function title()
{
return _t(__CLASS__.'.EMPTYPAGES', "Pages with no content");
Expand Down Expand Up @@ -38,14 +36,4 @@ public function sourceRecords($params = null)
->filter('Content', [null, '', '<p></p>', '<p>&nbsp;</p>'])
->sort('Title');
}

public function columns()
{
return array(
"Title" => array(
"title" => "Title", // todo: use NestedTitle(2)
"link" => true,
),
);
}
}
15 changes: 1 addition & 14 deletions code/Reports/RecentlyEditedReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@

use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\DataObject;
use SilverStripe\Reports\Report;

class RecentlyEditedReport extends Report
class RecentlyEditedReport extends AbstractCMSReport
{

public function title()
{
return _t(__CLASS__.'.LAST2WEEKS', "Pages edited in the last 2 weeks");
Expand All @@ -32,14 +29,4 @@ public function sourceRecords($params = null)
->filter('LastEdited:GreaterThan', date("Y-m-d H:i:s", $threshold))
->sort("\"SiteTree\".\"LastEdited\" DESC");
}

public function columns()
{
return array(
"Title" => array(
"title" => "Title", // todo: use NestedTitle(2)
"link" => true,
),
);
}
}