Skip to content

Commit

Permalink
ENH: Respect sort and limit arguments
Browse files Browse the repository at this point in the history
These parameters are defined in the PHPDocs for `Report` and are technically part of the method signature. They should be respected and in the case of the new default limit in silverstripe/silverstripe-reports#139 this could have performance ramifications for large datasets.
  • Loading branch information
GuySartorelli committed Mar 7, 2022
1 parent 46a637a commit 9bdd084
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
10 changes: 9 additions & 1 deletion src/Reports/PagesDueForReviewReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,21 @@ public function columns()
*
* @return SS_List
*/
public function sourceRecords($params = [])
public function sourceRecords($params = [], $sort = null, $limit = null)
{
Versioned::set_stage(Versioned::DRAFT);

$records = SiteTree::get();
$compatibility = ContentReviewCompatability::start();

// Apply sort and limit if appropriate.
if ($sort !== null) {
$records = $records->sort($sort);
}
if ($limit !== null) {
$records = $records->limit($limit);
}

if (empty($params['ReviewDateBefore']) && empty($params['ReviewDateAfter'])) {
// If there's no review dates set, default to all pages due for review now
$records = $records->where(
Expand Down
19 changes: 11 additions & 8 deletions src/Reports/PagesWithoutReviewScheduleReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function columns()
*
* @return SS_List
*/
public function sourceRecords($params = [])
public function sourceRecords($params = [], $sort = null, $limit = null)
{
Versioned::set_stage(Versioned::DRAFT);

Expand All @@ -125,16 +125,19 @@ public function sourceRecords($params = [])
));
}

$records->sort("ParentID");
if ($sort !== null) {
$sort = 'ParentID';
}
$records = $records->sort($sort);
if ($limit !== null) {
$records = $records->limit($limit);
}
$records = $records->toArray();

// Trim out calculated values
$list = ArrayList::create();
foreach ($records as $record) {
if (!$this->hasReviewSchedule($record)) {
$list->push($record);
}
}
$list = $records->filterByCallback(function($record) {
return !$this->hasReviewSchedule($record);
});

ContentReviewCompatability::done($compatibility);

Expand Down

0 comments on commit 9bdd084

Please sign in to comment.