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

ENH Take advantage of new functionality in Versioned #388

Open
wants to merge 1 commit into
base: 3.0
Choose a base branch
from
Open
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
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::getRemovedOnDraft($class)->sort('LastEdited DESC');

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