BranchActivity: require connection when creating...

...new objects
This commit is contained in:
Thomas Gelf 2022-02-09 14:46:42 +01:00
parent 767329443b
commit 95730fb0aa
2 changed files with 10 additions and 3 deletions

View File

@ -133,14 +133,21 @@ class BranchActivity
return $object;
}
public function createDbObject()
/**
* Hint: $connection is required, because setting groups triggered loading them.
* Should be investigated, as in theory $hostWithoutConnection->groups = 'group'
* is expected to work
* @param Db $connection
* @return DbObject|string
*/
public function createDbObject(Db $connection)
{
if (!$this->isActionCreate()) {
throw new RuntimeException('Only BranchActivity instances with action=create can create objects');
}
$class = DbObjectTypeRegistry::classByType($this->getObjectTable());
$object = $class::create();
$object = $class::create([], $connection);
$object->setUniqueId($this->getObjectUuid());
foreach ($this->getModifiedProperties()->jsonSerialize() as $key => $value) {
$object->set($key, $value);

View File

@ -130,7 +130,7 @@ class BranchMerger
throw new MergeErrorRecreateOnMerge($activity);
}
} else {
$activity->createDbObject()->store($this->connection);
$activity->createDbObject($this->connection)->store($this->connection);
}
} elseif ($activity->isActionDelete()) {
if ($exists) {