mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX Added all columns defined in Versioned extension to decorated or created SELECT statements in "*_versioned" tables. This was necessary because we're now explicitly selecting columns in the ORM, which meant Versioned was missing columns like "WasPublished". See #4050
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@76647 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
d3b95a0009
commit
e6ff8e283c
@ -39,6 +39,36 @@ class Versioned extends DataObjectDecorator {
|
|||||||
*/
|
*/
|
||||||
protected static $cache_versionnumber;
|
protected static $cache_versionnumber;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Additional database columns for the new
|
||||||
|
* "_versions" table. Used in {@link augmentDatabase()}
|
||||||
|
* and all Versioned calls decorating or creating
|
||||||
|
* SELECT statements.
|
||||||
|
*
|
||||||
|
* @var array $db_for_versions_table
|
||||||
|
*/
|
||||||
|
static $db_for_versions_table = array(
|
||||||
|
"RecordID" => "Int",
|
||||||
|
"Version" => "Int",
|
||||||
|
"WasPublished" => "Boolean",
|
||||||
|
"AuthorID" => "Int",
|
||||||
|
"PublisherID" => "Int"
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Additional database indexes for the new
|
||||||
|
* "_versions" table. Used in {@link augmentDatabase()}.
|
||||||
|
*
|
||||||
|
* @var array $indexes_for_versions_table
|
||||||
|
*/
|
||||||
|
static $indexes_for_versions_table = array(
|
||||||
|
'RecordID_Version' => '(RecordID, Version)',
|
||||||
|
'RecordID' => true,
|
||||||
|
'Version' => true,
|
||||||
|
'AuthorID' => true,
|
||||||
|
'PublisherID' => true,
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new Versioned object.
|
* Construct a new Versioned object.
|
||||||
* @var array $stages The different stages the versioned object can be.
|
* @var array $stages The different stages the versioned object can be.
|
||||||
@ -76,7 +106,12 @@ class Versioned extends DataObjectDecorator {
|
|||||||
}
|
}
|
||||||
$query->renameTable($table, $table . '_versions');
|
$query->renameTable($table, $table . '_versions');
|
||||||
$query->replaceText(".\"ID\"", ".\"RecordID\"");
|
$query->replaceText(".\"ID\"", ".\"RecordID\"");
|
||||||
$query->select[] = "\"{$baseTable}_versions\".\"RecordID\" AS \"ID\"";
|
|
||||||
|
// Add all <basetable>_versions columns
|
||||||
|
foreach(self::$db_for_versions_table as $name => $type) {
|
||||||
|
$query->select[] = sprintf('"%s_versions"."%s"', $baseTable, $name);
|
||||||
|
}
|
||||||
|
$query->select[] = sprintf('"%s_versions"."%s" AS "ID"', $baseTable, 'RecordID');
|
||||||
|
|
||||||
if($table != $baseTable) {
|
if($table != $baseTable) {
|
||||||
$query->from[$table] .= " AND \"{$table}_versions\".\"Version\" = \"{$baseTable}_versions\".\"Version\"";
|
$query->from[$table] .= " AND \"{$table}_versions\".\"Version\" = \"{$baseTable}_versions\".\"Version\"";
|
||||||
@ -203,24 +238,12 @@ class Versioned extends DataObjectDecorator {
|
|||||||
|
|
||||||
// Create table for all versions
|
// Create table for all versions
|
||||||
$versionFields = array_merge(
|
$versionFields = array_merge(
|
||||||
array(
|
self::$db_for_versions_table,
|
||||||
"RecordID" => "Int",
|
|
||||||
"Version" => "Int",
|
|
||||||
"WasPublished" => "Boolean",
|
|
||||||
"AuthorID" => "Int",
|
|
||||||
"PublisherID" => "Int"
|
|
||||||
),
|
|
||||||
(array)$fields
|
(array)$fields
|
||||||
);
|
);
|
||||||
|
|
||||||
$versionIndexes = array_merge(
|
$versionIndexes = array_merge(
|
||||||
array(
|
self::$indexes_for_versions_table,
|
||||||
'RecordID_Version' => '(RecordID, Version)',
|
|
||||||
'RecordID' => true,
|
|
||||||
'Version' => true,
|
|
||||||
'AuthorID' => true,
|
|
||||||
'PublisherID' => true,
|
|
||||||
),
|
|
||||||
(array)$indexes
|
(array)$indexes
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -450,7 +473,11 @@ class Versioned extends DataObjectDecorator {
|
|||||||
else if (substr($join,0,5) != 'INNER') $query->from[$table] = "LEFT JOIN \"$table\" ON \"$table\".\"RecordID\" = \"{$baseTable}_versions\".\"RecordID\" AND \"$table\".\"Version\" = \"{$baseTable}_versions\".\"Version\"";
|
else if (substr($join,0,5) != 'INNER') $query->from[$table] = "LEFT JOIN \"$table\" ON \"$table\".\"RecordID\" = \"{$baseTable}_versions\".\"RecordID\" AND \"$table\".\"Version\" = \"{$baseTable}_versions\".\"Version\"";
|
||||||
$query->renameTable($table, $table . '_versions');
|
$query->renameTable($table, $table . '_versions');
|
||||||
}
|
}
|
||||||
$query->select[] = "\"{$baseTable}_versions\".\"AuthorID\", \"{$baseTable}_versions\".\"Version\", \"{$baseTable}_versions\".\"RecordID\"";
|
|
||||||
|
// Add all <basetable>_versions columns
|
||||||
|
foreach(self::$db_for_versions_table as $name => $type) {
|
||||||
|
$query->select[] = sprintf('"%s_versions"."%s"', $baseTable, $name);
|
||||||
|
}
|
||||||
|
|
||||||
$query->where[] = "\"{$baseTable}_versions\".\"RecordID\" = '{$this->owner->ID}'";
|
$query->where[] = "\"{$baseTable}_versions\".\"RecordID\" = '{$this->owner->ID}'";
|
||||||
$query->orderby = "\"{$baseTable}_versions\".\"LastEdited\" DESC, \"{$baseTable}_versions\".\"Version\" DESC";
|
$query->orderby = "\"{$baseTable}_versions\".\"LastEdited\" DESC, \"{$baseTable}_versions\".\"Version\" DESC";
|
||||||
@ -685,7 +712,13 @@ class Versioned extends DataObjectDecorator {
|
|||||||
else $query->from[$table] = "LEFT JOIN \"$table\" ON \"$table\".\"RecordID\" = \"{$baseTable}_versions\".\"RecordID\" AND \"$table\".\"Version\" = \"{$baseTable}_versions\".\"Version\"";
|
else $query->from[$table] = "LEFT JOIN \"$table\" ON \"$table\".\"RecordID\" = \"{$baseTable}_versions\".\"RecordID\" AND \"$table\".\"Version\" = \"{$baseTable}_versions\".\"Version\"";
|
||||||
$query->renameTable($table, $table . '_versions');
|
$query->renameTable($table, $table . '_versions');
|
||||||
}
|
}
|
||||||
$query->select[] = "\"{$baseTable}_versions\".\"AuthorID\", \"{$baseTable}_versions\".\"Version\", \"{$baseTable}_versions\".\"RecordID\" AS \"ID\"";
|
|
||||||
|
// Add all <basetable>_versions columns
|
||||||
|
foreach(self::$db_for_versions_table as $name => $type) {
|
||||||
|
$query->select[] = sprintf('"%s_versions"."%s"', $baseTable, $name);
|
||||||
|
}
|
||||||
|
$query->select[] = sprintf('"%s_versions"."%s" AS "ID"', $baseTable, 'RecordID');
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -696,7 +729,13 @@ class Versioned extends DataObjectDecorator {
|
|||||||
else $query->from[$table] = "LEFT JOIN \"$table\" ON \"$table\".\"RecordID\" = \"{$baseTable}_versions\".\"RecordID\" AND \"$table\".\"Version\" = \"{$baseTable}_versions\".\"Version\"";
|
else $query->from[$table] = "LEFT JOIN \"$table\" ON \"$table\".\"RecordID\" = \"{$baseTable}_versions\".\"RecordID\" AND \"$table\".\"Version\" = \"{$baseTable}_versions\".\"Version\"";
|
||||||
$query->renameTable($table, $table . '_versions');
|
$query->renameTable($table, $table . '_versions');
|
||||||
}
|
}
|
||||||
$query->select[] = "\"{$baseTable}_versions\".\"AuthorID\", \"{$baseTable}_versions\".\"Version\", \"{$baseTable}_versions\".\"RecordID\" AS \"ID\"";
|
|
||||||
|
// Add all <basetable>_versions columns
|
||||||
|
foreach(self::$db_for_versions_table as $name => $type) {
|
||||||
|
$query->select[] = sprintf('"%s_versions"."%s"', $baseTable, $name);
|
||||||
|
}
|
||||||
|
$query->select[] = sprintf('"%s_versions"."%s" AS "ID"', $baseTable, 'RecordID');
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user