Fixed Versioned::get_latest_version when called on live site (parents upgrade issue)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@45104 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2007-11-19 04:50:09 +00:00
parent 0d5b5b36de
commit 0c04f14f37

View File

@ -466,7 +466,7 @@ class Versioned extends DataObjectDecorator {
$fields = array_keys($fromRecord->getAllFields()); $fields = array_keys($fromRecord->getAllFields());
foreach($fields as $field) { foreach($fields as $field) {
if(in_array($field, array("ID","Version","RecordID","AuthorID"))) continue; if(in_array($field, array("ID","Version","RecordID","AuthorID", "ParentID"))) continue;
$fromRecord->$field = Diff::compareHTML($fromRecord->$field, $toRecord->$field); $fromRecord->$field = Diff::compareHTML($fromRecord->$field, $toRecord->$field);
} }
@ -623,6 +623,9 @@ class Versioned extends DataObjectDecorator {
* Return the latest version of the given page * Return the latest version of the given page
*/ */
static function get_latest_version($class, $id) { static function get_latest_version($class, $id) {
$oldStage = Versioned::$reading_stage;
Versioned::$reading_stage = null;
$baseTable = ClassInfo::baseDataClass($class); $baseTable = ClassInfo::baseDataClass($class);
$query = singleton($class)->buildVersionSQL("`{$baseTable}`.RecordID = $id", "`{$baseTable}`.Version DESC"); $query = singleton($class)->buildVersionSQL("`{$baseTable}`.RecordID = $id", "`{$baseTable}`.Version DESC");
$query->limit = 1; $query->limit = 1;
@ -633,6 +636,9 @@ class Versioned extends DataObjectDecorator {
Debug::show($record); Debug::show($record);
user_error("Versioned::get_version: Couldn't get $class.$id, version $version", E_USER_ERROR); user_error("Versioned::get_version: Couldn't get $class.$id, version $version", E_USER_ERROR);
} }
Versioned::$reading_stage = $oldStage;
return new $className($record); return new $className($record);
} }