Skip to content

Commit

Permalink
ENH Take advantage of new functionality in Versioned (#388)
Browse files Browse the repository at this point in the history
Avoids duplicated code to do what Versioned now lets you do.
  • Loading branch information
GuySartorelli authored Feb 20, 2025
1 parent 4a9cde8 commit f07436c
Showing 1 changed file with 4 additions and 25 deletions.
29 changes: 4 additions & 25 deletions src/ArchiveAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,31 +138,10 @@ public static function createArchiveGridField($title, $class)
$config->addComponent(new GridFieldRestoreAction);
$config->addComponent(new GridField_ActionMenu);

$singleton = singleton($class);
$list = $singleton->get();
$baseTable = $singleton->baseTable();

$list = $list
->setDataQueryParam('Versioned.mode', 'latest_versions');
// Join a temporary alias BaseTable_Draft, renaming this on execution to BaseTable
// See Versioned::augmentSQL() For reference on this alias
$draftTable = $baseTable . '_Draft';
$list = $list
->leftJoin(
$draftTable,
"\"{$baseTable}\".\"ID\" = \"{$draftTable}\".\"ID\""
);

if ($singleton->hasStages()) {
$liveTable = $baseTable . '_Live';
$list = $list->leftJoin(
$liveTable,
"\"{$baseTable}\".\"ID\" = \"{$liveTable}\".\"ID\""
);
}

$list = $list->where("\"{$draftTable}\".\"ID\" IS NULL");
$list = $list->sort('LastEdited DESC');
// Include "on live only" records because they won't appear in GridFields and
// other admin areas - so this may be the only way content authors can know that
// content is in a bad state.
$list = Versioned::getRemovedFromDraft($class)->sort('LastEdited DESC');

$field = GridField::create(
$title,
Expand Down

0 comments on commit f07436c

Please sign in to comment.