mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
Update use of versioned API and respect table_name
This commit is contained in:
parent
a648c7dc4d
commit
42a383030c
@ -323,7 +323,8 @@ class FixtureContext extends BehatContext
|
|||||||
*/
|
*/
|
||||||
public function stepUpdateRecordState($type, $id, $state) {
|
public function stepUpdateRecordState($type, $id, $state) {
|
||||||
$class = $this->convertTypeToClass($type);
|
$class = $this->convertTypeToClass($type);
|
||||||
$obj = $this->fixtureFactory->get($class, $id);
|
/** @var DataObject|Versioned $obj */
|
||||||
|
$obj = $this->fixtureFactory->get($class, $id);
|
||||||
if(!$obj) {
|
if(!$obj) {
|
||||||
throw new \InvalidArgumentException(sprintf(
|
throw new \InvalidArgumentException(sprintf(
|
||||||
'Can not find record "%s" with identifier "%s"',
|
'Can not find record "%s" with identifier "%s"',
|
||||||
@ -334,7 +335,7 @@ class FixtureContext extends BehatContext
|
|||||||
|
|
||||||
switch($state) {
|
switch($state) {
|
||||||
case 'published':
|
case 'published':
|
||||||
$obj->publish('Stage', 'Live');
|
$obj->copyVersionToStage('Stage', 'Live');
|
||||||
break;
|
break;
|
||||||
case 'not published':
|
case 'not published':
|
||||||
case 'unpublished':
|
case 'unpublished':
|
||||||
@ -521,24 +522,18 @@ class FixtureContext extends BehatContext
|
|||||||
$fields = $this->prepareFixture($class, $id);
|
$fields = $this->prepareFixture($class, $id);
|
||||||
$record = $this->fixtureFactory->createObject($class, $id, $fields);
|
$record = $this->fixtureFactory->createObject($class, $id, $fields);
|
||||||
$date = date("Y-m-d H:i:s",strtotime($time));
|
$date = date("Y-m-d H:i:s",strtotime($time));
|
||||||
$table = \ClassInfo::baseDataClass(get_class($record));
|
$table = $record->baseTable();
|
||||||
$field = ($mod == 'created') ? 'Created' : 'LastEdited';
|
$field = ($mod == 'created') ? 'Created' : 'LastEdited';
|
||||||
DB::query(sprintf(
|
DB::prepared_query(
|
||||||
'UPDATE "%s" SET "%s" = \'%s\' WHERE "ID" = \'%d\'',
|
"UPDATE \"{$table}\" SET \"{$field}\" = ? WHERE \"ID\" = ?",
|
||||||
$table,
|
[$date, $record->ID]
|
||||||
$field,
|
);
|
||||||
$date,
|
|
||||||
$record->ID
|
|
||||||
));
|
|
||||||
// Support for Versioned extension, by checking for a "Live" stage
|
// Support for Versioned extension, by checking for a "Live" stage
|
||||||
if(DB::getConn()->hasTable($table . '_Live')) {
|
if(DB::get_schema()->hasTable($table . '_Live')) {
|
||||||
DB::query(sprintf(
|
DB::prepared_query(
|
||||||
'UPDATE "%s_Live" SET "%s" = \'%s\' WHERE "ID" = \'%d\'',
|
"UPDATE \"{$table}_Live\" SET \"{$field}\" = ? WHERE \"ID\" = ?",
|
||||||
$table,
|
[$date, $record->ID]
|
||||||
$field,
|
);
|
||||||
$date,
|
|
||||||
$record->ID
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user