mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUG Fix incorrect use of baseClass as baseTable
This commit is contained in:
parent
f79c11f7f8
commit
01a13dcba9
@ -1705,6 +1705,7 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
|
||||
$owner->invokeWithExtensions('onBeforeVersionedPublish', $fromStage, $toStage, $createNewVersion);
|
||||
|
||||
$baseClass = $owner->baseClass();
|
||||
$baseTable = $owner->baseTable();
|
||||
|
||||
/** @var Versioned|DataObject $from */
|
||||
if(is_numeric($fromStage)) {
|
||||
@ -1712,7 +1713,7 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
|
||||
} else {
|
||||
$owner->flushCache();
|
||||
$from = Versioned::get_one_by_stage($baseClass, $fromStage, array(
|
||||
"\"{$baseClass}\".\"ID\" = ?" => $owner->ID
|
||||
"\"{$baseTable}\".\"ID\" = ?" => $owner->ID
|
||||
));
|
||||
}
|
||||
if(!$from) {
|
||||
@ -1728,7 +1729,7 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
|
||||
|
||||
// Mark this version as having been published at some stage
|
||||
$publisherID = isset(Member::currentUser()->ID) ? Member::currentUser()->ID : 0;
|
||||
$extTable = $this->extendWithSuffix($baseClass);
|
||||
$extTable = $this->extendWithSuffix($baseTable);
|
||||
DB::prepared_query("UPDATE \"{$extTable}_versions\"
|
||||
SET \"WasPublished\" = ?, \"PublisherID\" = ?
|
||||
WHERE \"RecordID\" = ? AND \"Version\" = ?",
|
||||
@ -1746,9 +1747,9 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
|
||||
|
||||
$conn = DB::get_conn();
|
||||
if(method_exists($conn, 'allowPrimaryKeyEditing')) {
|
||||
$conn->allowPrimaryKeyEditing($baseClass, true);
|
||||
$conn->allowPrimaryKeyEditing($baseTable, true);
|
||||
$from->write();
|
||||
$conn->allowPrimaryKeyEditing($baseClass, false);
|
||||
$conn->allowPrimaryKeyEditing($baseTable, false);
|
||||
} else {
|
||||
$from->write();
|
||||
}
|
||||
|
@ -162,7 +162,8 @@ class AssetControlExtension extends DataExtension
|
||||
|
||||
// Unauthenticated member to use for checking visibility
|
||||
$baseClass = $this->owner->baseClass();
|
||||
$filter = array("\"{$baseClass}\".\"ID\"" => $this->owner->ID);
|
||||
$baseTable = $this->owner->baseTable();
|
||||
$filter = array("\"{$baseTable}\".\"ID\"" => $this->owner->ID);
|
||||
$stages = $this->owner->getVersionedStages(); // {@see Versioned::getVersionedStages}
|
||||
foreach ($stages as $stage) {
|
||||
// Skip current stage; These should be handled explicitly
|
||||
|
@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
use SilverStripe\ORM\DB;
|
||||
use SilverStripe\ORM\Versioning\Versioned;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
@ -25,6 +24,7 @@ class VersionedTest extends SapphireTest {
|
||||
'VersionedTest_WithIndexes',
|
||||
'VersionedTest_PublicStage',
|
||||
'VersionedTest_PublicViaExtension',
|
||||
'VersionedTest_CustomTable',
|
||||
);
|
||||
|
||||
protected $requiredExtensions = array(
|
||||
@ -110,6 +110,22 @@ class VersionedTest extends SapphireTest {
|
||||
$this->assertEquals($count, $count2);
|
||||
}
|
||||
|
||||
public function testCustomTable() {
|
||||
$obj = new VersionedTest_CustomTable();
|
||||
$obj->Title = 'my object';
|
||||
$obj->write();
|
||||
$id = $obj->ID;
|
||||
$obj->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
$obj->Title = 'new title';
|
||||
$obj->write();
|
||||
|
||||
$liveRecord = Versioned::get_by_stage('VersionedTest_CustomTable', Versioned::LIVE)->byID($id);
|
||||
$draftRecord = Versioned::get_by_stage('VersionedTest_CustomTable', Versioned::DRAFT)->byID($id);
|
||||
|
||||
$this->assertEquals('my object', $liveRecord->Title);
|
||||
$this->assertEquals('new title', $draftRecord->Title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that publishing from invalid stage will throw exception
|
||||
*/
|
||||
@ -1242,3 +1258,18 @@ class VersionedTest_PublicExtension extends DataExtension implements TestOnly {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @mixin Versioned
|
||||
*/
|
||||
class VersionedTest_CustomTable extends DataObject implements TestOnly {
|
||||
private static $db = [
|
||||
'Title' => 'Varchar'
|
||||
];
|
||||
|
||||
private static $table_name = 'VTCustomTable';
|
||||
|
||||
private static $extensions = [
|
||||
"SilverStripe\\ORM\\Versioning\\Versioned",
|
||||
];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user