mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUG Fix DataObject::loadLazyFields discarding original query parameters
BUG Fix Versioned::writeToStage failing to write object with unchanged fields
This commit is contained in:
parent
ccb791995e
commit
23f5f08eda
@ -2166,6 +2166,11 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
}
|
}
|
||||||
|
|
||||||
$dataQuery = new DataQuery($tableClass);
|
$dataQuery = new DataQuery($tableClass);
|
||||||
|
|
||||||
|
// Reset query parameter context to that of this DataObject
|
||||||
|
if($params = $this->getSourceQueryParams()) {
|
||||||
|
foreach($params as $key => $value) $dataQuery->setQueryParam($key, $value);
|
||||||
|
}
|
||||||
|
|
||||||
// TableField sets the record ID to "new" on new row data, so don't try doing anything in that case
|
// TableField sets the record ID to "new" on new row data, so don't try doing anything in that case
|
||||||
if(!is_numeric($this->record['ID'])) return false;
|
if(!is_numeric($this->record['ID'])) return false;
|
||||||
|
@ -1184,6 +1184,7 @@ class Versioned extends DataExtension {
|
|||||||
$oldMode = Versioned::get_reading_mode();
|
$oldMode = Versioned::get_reading_mode();
|
||||||
Versioned::reading_stage($stage);
|
Versioned::reading_stage($stage);
|
||||||
|
|
||||||
|
$this->owner->forceChange();
|
||||||
$result = $this->owner->write(false, $forceInsert);
|
$result = $this->owner->write(false, $forceInsert);
|
||||||
Versioned::set_reading_mode($oldMode);
|
Versioned::set_reading_mode($oldMode);
|
||||||
|
|
||||||
|
@ -492,6 +492,47 @@ class VersionedTest extends SapphireTest {
|
|||||||
'Writes to and reads from default stage even if a non-matching stage is set'
|
'Writes to and reads from default stage even if a non-matching stage is set'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that publishing processes respects lazy loaded fields
|
||||||
|
*/
|
||||||
|
public function testLazyLoadFields() {
|
||||||
|
$originalMode = Versioned::get_reading_mode();
|
||||||
|
|
||||||
|
// Generate staging record and retrieve it from stage in live mode
|
||||||
|
Versioned::reading_stage('Stage');
|
||||||
|
$obj = new VersionedTest_Subclass();
|
||||||
|
$obj->Name = 'bob';
|
||||||
|
$obj->ExtraField = 'Field Value';
|
||||||
|
$obj->write();
|
||||||
|
$objID = $obj->ID;
|
||||||
|
$filter = sprintf('"VersionedTest_DataObject"."ID" = \'%d\'', Convert::raw2sql($objID));
|
||||||
|
Versioned::reading_stage('Live');
|
||||||
|
|
||||||
|
// Check fields are unloaded prior to access
|
||||||
|
$objLazy = Versioned::get_one_by_stage('VersionedTest_DataObject', 'Stage', $filter, false);
|
||||||
|
$lazyFields = $objLazy->getQueriedDatabaseFields();
|
||||||
|
$this->assertTrue(isset($lazyFields['ExtraField_Lazy']));
|
||||||
|
$this->assertEquals('VersionedTest_Subclass', $lazyFields['ExtraField_Lazy']);
|
||||||
|
|
||||||
|
// Check lazy loading works when viewing a Stage object in Live mode
|
||||||
|
$this->assertEquals('Field Value', $objLazy->ExtraField);
|
||||||
|
|
||||||
|
// Test that writeToStage respects lazy loaded fields
|
||||||
|
$objLazy = Versioned::get_one_by_stage('VersionedTest_DataObject', 'Stage', $filter, false);
|
||||||
|
$objLazy->writeToStage('Live');
|
||||||
|
$objLive = Versioned::get_one_by_stage('VersionedTest_DataObject', 'Live', $filter, false);
|
||||||
|
$liveLazyFields = $objLive->getQueriedDatabaseFields();
|
||||||
|
|
||||||
|
// Check fields are unloaded prior to access
|
||||||
|
$this->assertTrue(isset($liveLazyFields['ExtraField_Lazy']));
|
||||||
|
$this->assertEquals('VersionedTest_Subclass', $liveLazyFields['ExtraField_Lazy']);
|
||||||
|
|
||||||
|
// Check that live record has original value
|
||||||
|
$this->assertEquals('Field Value', $objLive->ExtraField);
|
||||||
|
|
||||||
|
Versioned::set_reading_mode($originalMode);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user