mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #5143 from tractorcow/pulls/4.0/fix-versioned-tables
BUG Better filtering of versionable tables during SQL augmentation
This commit is contained in:
commit
01ba7c76a4
@ -264,7 +264,7 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
|
|||||||
case 'archive':
|
case 'archive':
|
||||||
$date = $dataQuery->getQueryParam('Versioned.date');
|
$date = $dataQuery->getQueryParam('Versioned.date');
|
||||||
foreach($query->getFrom() as $table => $dummy) {
|
foreach($query->getFrom() as $table => $dummy) {
|
||||||
if(!DB::get_schema()->hasTable($table . '_versions')) {
|
if(!$this->isTableVersioned($table)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,14 +303,10 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
|
|||||||
$stage = $dataQuery->getQueryParam('Versioned.stage');
|
$stage = $dataQuery->getQueryParam('Versioned.stage');
|
||||||
if($stage && ($stage != $this->defaultStage)) {
|
if($stage && ($stage != $this->defaultStage)) {
|
||||||
foreach($query->getFrom() as $table => $dummy) {
|
foreach($query->getFrom() as $table => $dummy) {
|
||||||
// Only rewrite table names that are actually part of the subclass tree
|
if(!$this->isTableVersioned($table)) {
|
||||||
// This helps prevent rewriting of other tables that get joined in, in
|
continue;
|
||||||
// particular, many_many tables
|
|
||||||
if(class_exists($table) && ($table == $this->owner->class
|
|
||||||
|| is_subclass_of($table, $this->owner->class)
|
|
||||||
|| is_subclass_of($this->owner->class, $table))) {
|
|
||||||
$query->renameTable($table, $table . '_' . $stage);
|
|
||||||
}
|
}
|
||||||
|
$query->renameTable($table, $table . '_' . $stage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -342,6 +338,10 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
|
|||||||
case 'all_versions':
|
case 'all_versions':
|
||||||
case 'latest_versions':
|
case 'latest_versions':
|
||||||
foreach($query->getFrom() as $alias => $join) {
|
foreach($query->getFrom() as $alias => $join) {
|
||||||
|
if(!$this->isTableVersioned($alias)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if($alias != $baseTable) {
|
if($alias != $baseTable) {
|
||||||
// Make sure join includes version as well
|
// Make sure join includes version as well
|
||||||
$query->setJoinFilter(
|
$query->setJoinFilter(
|
||||||
@ -394,6 +394,21 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if the given versioned table is a part of the sub-tree of the current dataobject
|
||||||
|
* This helps prevent rewriting of other tables that get joined in, in particular, many_many tables
|
||||||
|
*
|
||||||
|
* @param string $table
|
||||||
|
* @return bool True if this table should be versioned
|
||||||
|
*/
|
||||||
|
protected function isTableVersioned($table) {
|
||||||
|
if(!class_exists($table)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$baseClass = ClassInfo::baseDataClass($this->owner);
|
||||||
|
return is_a($table, $baseClass, true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For lazy loaded fields requiring extra sql manipulation, ie versioning.
|
* For lazy loaded fields requiring extra sql manipulation, ie versioning.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user