BUG Reinstated CMS "History" Preview (fixes ##8089)

This commit is contained in:
Ingo Schommer 2013-01-25 11:35:48 +01:00
parent 6a4387b970
commit 649de6e1bc
2 changed files with 54 additions and 30 deletions

View File

@ -74,6 +74,16 @@ class CMSPageHistoryController extends CMSMain {
return $negotiator->respond($request); return $negotiator->respond($request);
} }
public function getSilverStripeNavigator() {
$record = $this->getRecord($this->currentPageID(), $this->request->param('VersionID'));
if($record) {
$navigator = new SilverStripeNavigator($record);
return $navigator->renderWith($this->getTemplatesWithSuffix('_SilverStripeNavigator'));
} else {
return false;
}
}
/** /**
* Returns the read only version of the edit form. Detaches all {@link FormAction} * Returns the read only version of the edit form. Detaches all {@link FormAction}

View File

@ -182,6 +182,36 @@ class SilverStripeNavigatorItem extends ViewableData {
public function canView($member = null) { public function canView($member = null) {
return true; return true;
} }
/**
* Counts as "archived" if the current record is a different version from both live and draft.
*
* @return boolean
*/
public function isArchived() {
if(!$this->record->hasExtension('Versioned')) return false;
if(!isset($this->record->_cached_isArchived)) {
$baseTable = ClassInfo::baseDataClass($this->record->class);
$currentDraft = Versioned::get_one_by_stage(
$baseTable,
'Stage',
sprintf('"%s"."ID" = %d', $baseTable, $this->record->ID)
);
$currentLive = Versioned::get_one_by_stage(
$baseTable,
'Live',
sprintf('"%s"."ID" = %d', $baseTable, $this->record->ID)
);
$this->record->_cached_isArchived = (
(!$currentDraft || ($currentDraft && $this->record->Version != $currentDraft->Version))
&& (!$currentLive || ($currentLive && $this->record->Version != $currentLive->Version))
);
}
return $this->record->_cached_isArchived;
}
} }
/** /**
@ -246,7 +276,12 @@ class SilverStripeNavigatorItem_StageLink extends SilverStripeNavigatorItem {
} }
public function getLink() { public function getLink() {
return Controller::join_links($this->record->PreviewLink(), '?stage=Stage'); $date = Versioned::current_archived_date();
return Controller::join_links(
$this->record->PreviewLink(),
'?stage=Stage',
$date ? '?archiveDate=' . $date : null
);
} }
public function canView($member = null) { public function canView($member = null) {
@ -262,6 +297,7 @@ class SilverStripeNavigatorItem_StageLink extends SilverStripeNavigatorItem {
return ( return (
Versioned::current_stage() == 'Stage' Versioned::current_stage() == 'Stage'
&& !(ClassInfo::exists('SiteTreeFutureState') && SiteTreeFutureState::get_future_datetime()) && !(ClassInfo::exists('SiteTreeFutureState') && SiteTreeFutureState::get_future_datetime())
&& !$this->isArchived()
); );
} }
@ -312,7 +348,10 @@ class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem {
} }
public function isActive() { public function isActive() {
return (!Versioned::current_stage() || Versioned::current_stage() == 'Live'); return (
(!Versioned::current_stage() || Versioned::current_stage() == 'Live')
&& !$this->isArchived()
);
} }
protected function getLivePage() { protected function getLivePage() {
@ -338,7 +377,7 @@ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem {
} }
public function getTitle() { public function getTitle() {
return _t('ContentController.VERSION', 'Version').': '.$this->record->LastEdited; return _t('SilverStripeNavigator.ARCHIVED', 'Archived');
} }
public function getMessage() { public function getMessage() {
@ -350,7 +389,7 @@ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem {
} }
public function getLink() { public function getLink() {
return $this->record->PreviewLink() . '?archiveDate=' . $this->record->LastEdited; return $this->record->PreviewLink() . '?archiveDate=' . urlencode($this->record->LastEdited);
} }
public function canView($member = null) { public function canView($member = null) {
@ -363,32 +402,7 @@ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem {
} }
public function isActive() { public function isActive() {
return (Versioned::current_archived_date()); return $this->isArchived();
}
/**
* Counts as "archived" if the current record is a different version from both live and draft.
*
* @return boolean
*/
public function isArchived() {
if(!$this->record->hasExtension('Versioned')) return false;
$baseTable = ClassInfo::baseDataClass($this->record->class);
$currentDraft = Versioned::get_one_by_stage(
$baseTable,
'Stage',
sprintf('"%s"."ID" = %d', $baseTable, $this->record->ID)
);
$currentLive = Versioned::get_one_by_stage(
$baseTable,
'Live',
sprintf('"%s"."ID" = %d', $baseTable, $this->record->ID)
);
return (
(!$currentDraft || ($currentDraft && $this->record->Version != $currentDraft->Version))
&& (!$currentLive || ($currentLive && $this->record->Version != $currentLive->Version))
);
} }
} }