diff --git a/code/controllers/SilverStripeNavigator.php b/code/controllers/SilverStripeNavigator.php
index 297ea23c..cc0410b8 100644
--- a/code/controllers/SilverStripeNavigator.php
+++ b/code/controllers/SilverStripeNavigator.php
@@ -1,4 +1,6 @@
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', array(
- "\"$baseTable\".\"ID\"" => $this->record->ID
- ));
- $currentLive = Versioned::get_one_by_stage($baseTable, 'Live', array(
- "\"$baseTable\".\"ID\"" => $this->record->ID
- ));
+ $baseClass = $this->record->baseClass();
+ $currentDraft = Versioned::get_by_stage($baseClass, Versioned::DRAFT)->byID($this->record->ID);
+ $currentLive = Versioned::get_by_stage($baseClass, Versioned::LIVE)->byID($this->record->ID);
$this->record->_cached_isArchived = (
(!$currentDraft || ($currentDraft && $this->record->Version != $currentDraft->Version))
@@ -300,10 +298,8 @@ class SilverStripeNavigatorItem_StageLink extends SilverStripeNavigatorItem {
}
protected function getDraftPage() {
- $baseTable = ClassInfo::baseDataClass($this->record->class);
- return Versioned::get_one_by_stage($baseTable, 'Stage', array(
- "\"$baseTable\".\"ID\"" => $this->record->ID
- ));
+ $baseClass = $this->record->baseClass();
+ return Versioned::get_by_stage($baseClass, Versioned::DRAFT)->byID($this->record->ID);
}
}
@@ -352,10 +348,8 @@ class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem {
}
protected function getLivePage() {
- $baseTable = ClassInfo::baseDataClass($this->record->class);
- return Versioned::get_one_by_stage($baseTable, 'Live', array(
- "\"$baseTable\".\"ID\"" => $this->record->ID
- ));
+ $baseClass = $this->record->baseClass();
+ return Versioned::get_by_stage($baseClass, Versioned::LIVE)->byID($this->record->ID);
}
}
@@ -368,8 +362,8 @@ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem {
private static $priority = 40;
public function getHTML() {
- $this->recordLink = $this->record->AbsoluteLink();
- return "isActive() ? ' current' : '') ."\" href=\"$this->recordLink?archiveDate={$this->record->LastEdited}\" target=\"_blank\">". _t('ContentController.ARCHIVEDSITE', 'Preview version') ."";
+ $this->recordLink = $this->record->AbsoluteLink();
+ return "isActive() ? ' current' : '') ."\" href=\"$this->recordLink?archiveDate={$this->record->LastEdited}\" target=\"_blank\">". _t('ContentController.ARCHIVEDSITE', 'Preview version') ."";
}
public function getTitle() {
diff --git a/code/model/SiteTree.php b/code/model/SiteTree.php
index 05606620..fe962e74 100755
--- a/code/model/SiteTree.php
+++ b/code/model/SiteTree.php
@@ -482,7 +482,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
* @return string
*/
public function getAbsoluteLiveLink($includeStageEqualsLive = true) {
- $oldStage = Versioned::get_stage();
+ $oldReadingMode = Versioned::get_reading_mode();
Versioned::set_stage(Versioned::LIVE);
$live = Versioned::get_one_by_stage('SiteTree', Versioned::LIVE, array(
'"SiteTree"."ID"' => $this->ID
@@ -494,7 +494,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$link = null;
}
- Versioned::set_stage($oldStage);
+ Versioned::set_reading_mode($oldReadingMode);
return $link;
}
@@ -2292,7 +2292,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
if(method_exists($conn, 'allowPrimaryKeyEditing')) $conn->allowPrimaryKeyEditing('SiteTree', false);
}
- $oldStage = Versioned::get_stage();
+ $oldReadingMode = Versioned::get_reading_mode();
Versioned::set_stage(Versioned::DRAFT);
$this->forceChange();
$this->write();
@@ -2305,7 +2305,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$page->write();
}
- Versioned::set_stage($oldStage);
+ Versioned::set_reading_mode($oldReadingMode);
$this->invokeWithExtensions('onAfterRestoreToStage', $this);
diff --git a/tasks/RemoveOrphanedPagesTask.php b/tasks/RemoveOrphanedPagesTask.php
index 04b93eef..77705460 100644
--- a/tasks/RemoveOrphanedPagesTask.php
+++ b/tasks/RemoveOrphanedPagesTask.php
@@ -1,4 +1,6 @@
if($orphans) foreach($orphans as $orphan) {
$latestVersion = Versioned::get_latest_version($this->orphanedSearchClass, $orphan->ID);
$latestAuthor = DataObject::get_by_id('Member', $latestVersion->AuthorID);
- $orphanBaseClass = ClassInfo::baseDataClass($this->orphanedSearchClass);
- $stageRecord = Versioned::get_one_by_stage(
- $this->orphanedSearchClass,
- 'Stage',
- array("\"$orphanBaseClass\".\"ID\"" => $orphan->ID)
- );
+ $orphanBaseTable = DataObject::getSchema()->baseDataTable($this->orphanedSearchClass);
$liveRecord = Versioned::get_one_by_stage(
$this->orphanedSearchClass,
'Live',
- array("\"$orphanBaseClass\".\"ID\"" => $orphan->ID)
+ array("\"$orphanBaseTable\".\"ID\"" => $orphan->ID)
);
$label = sprintf(
'%s (#%d, Last Modified Date: %s, Last Modifier: %s, %s)',
$orphan->ID,
$orphan->Title,
$orphan->ID,
- Date::create($orphan->LastEdited)->Nice(),
+ $orphan->dbObject('LastEdited')->Nice(),
($latestAuthor) ? $latestAuthor->Title : 'unknown',
($liveRecord) ? 'is published' : 'not published'
);
@@ -124,7 +121,7 @@ in the other stage:
_t('RemoveOrphanedPagesTask.UNSELECTALL', 'unselect all')
)
));
- $fields->push(new OptionSetField(
+ $fields->push(new OptionsetField(
'OrphanOperation',
_t('RemoveOrphanedPagesTask.CHOOSEOPERATION', 'Choose operation:'),
array(
@@ -183,6 +180,7 @@ in the other stage:
if(!isset($data['OrphanIDs']) || !isset($data['OrphanOperation'])) return false;
+ $successIDs = null;
switch($data['OrphanOperation']) {
case 'remove':
$successIDs = $this->removeOrphans($data['OrphanIDs']);
@@ -213,13 +211,13 @@ in the other stage:
protected function removeOrphans($orphanIDs) {
$removedOrphans = array();
- $orphanBaseClass = ClassInfo::baseDataClass($this->orphanedSearchClass);
+ $orphanBaseTable = DataObject::getSchema()->baseDataTable($this->orphanedSearchClass);
foreach($orphanIDs as $id) {
/** @var SiteTree $stageRecord */
$stageRecord = Versioned::get_one_by_stage(
$this->orphanedSearchClass,
- 'Stage',
- array("\"$orphanBaseClass\".\"ID\"" => $id)
+ Versioned::DRAFT,
+ array("\"$orphanBaseTable\".\"ID\"" => $id)
);
if($stageRecord) {
$removedOrphans[$stageRecord->ID] = sprintf('Removed %s (#%d) from Stage', $stageRecord->Title, $stageRecord->ID);
@@ -230,8 +228,8 @@ in the other stage:
/** @var SiteTree $liveRecord */
$liveRecord = Versioned::get_one_by_stage(
$this->orphanedSearchClass,
- 'Live',
- array("\"$orphanBaseClass\".\"ID\"" => $id)
+ Versioned::LIVE,
+ array("\"$orphanBaseTable\".\"ID\"" => $id)
);
if($liveRecord) {
$removedOrphans[$liveRecord->ID] = sprintf('Removed %s (#%d) from Live', $liveRecord->Title, $liveRecord->ID);
@@ -257,12 +255,12 @@ in the other stage:
$holder->write();
$removedOrphans = array();
- $orphanBaseClass = ClassInfo::baseDataClass($this->orphanedSearchClass);
+ $orphanBaseTable = DataObject::getSchema()->baseDataTable($this->orphanedSearchClass);
foreach($orphanIDs as $id) {
$stageRecord = Versioned::get_one_by_stage(
$this->orphanedSearchClass,
'Stage',
- array("\"$orphanBaseClass\".\"ID\"" => $id)
+ array("\"$orphanBaseTable\".\"ID\"" => $id)
);
if($stageRecord) {
$removedOrphans[$stageRecord->ID] = sprintf('Rebased %s (#%d)', $stageRecord->Title, $stageRecord->ID);
@@ -277,7 +275,7 @@ in the other stage:
$liveRecord = Versioned::get_one_by_stage(
$this->orphanedSearchClass,
'Live',
- array("\"$orphanBaseClass\".\"ID\"" => $id)
+ array("\"$orphanBaseTable\".\"ID\"" => $id)
);
if($liveRecord) {
$removedOrphans[$liveRecord->ID] = sprintf('Rebased %s (#%d)', $liveRecord->Title, $liveRecord->ID);
@@ -318,9 +316,8 @@ in the other stage:
$orphans = new ArrayList();
foreach(array(Versioned::DRAFT, Versioned::LIVE) as $stage) {
- $joinByStage = $join;
- $table = $class;
- $table .= ($stage == 'Live') ? '_Live' : '';
+ $table = DataObject::getSchema()->tableName($class);
+ $table .= ($stage == Versioned::LIVE) ? '_Live' : '';
$stageOrphans = Versioned::get_by_stage(
$class,
$stage,
diff --git a/tests/controller/CMSSiteTreeFilterTest.php b/tests/controller/CMSSiteTreeFilterTest.php
index 3fb395b5..97d7914c 100644
--- a/tests/controller/CMSSiteTreeFilterTest.php
+++ b/tests/controller/CMSSiteTreeFilterTest.php
@@ -168,8 +168,8 @@ class CMSSiteTreeFilterTest extends SapphireTest {
$deletedPageID = $deletedPage->ID;
// Can't use straight $blah->delete() as that blows it away completely and test fails
- $deletedPage->deleteFromStage('Live');
- $deletedPage->deleteFromStage('Draft');
+ $deletedPage->deleteFromStage(Versioned::LIVE);
+ $deletedPage->deleteFromStage(Versioned::DRAFT);
$checkParentExists = Versioned::get_latest_version('SiteTree', $deletedPageID);
// Check deleted page is included