Skip to content

Commit

Permalink
mapper: fix accessing possibly uninitialized storage reflection [closes
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Apr 13, 2020
1 parent 8ac61d4 commit dd9d092
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Mapper/Dbal/DbalMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,12 @@ protected function processMySQLAutoupdate(IEntity $entity, array $args)
{
assert($this instanceof IPersistAutoupdateMapper);
$this->connection->queryArgs($args);
$storageReflection = $this->getStorageReflection();

$primary = [];
$id = (array) ($entity->isPersisted() ? $entity->getPersistedId() : $this->connection->getLastInsertedId());
foreach ($entity->getMetadata()->getPrimaryKey() as $key) {
$key = $this->storageReflection->convertEntityToStorageKey($key);
$key = $storageReflection->convertEntityToStorageKey($key);
$primary[$key] = array_shift($id);
}

Expand All @@ -349,7 +350,7 @@ protected function processMySQLAutoupdate(IEntity $entity, array $args)
if ($row === null) {
$entity->onRefresh(null, true);
} else {
$data = $this->getStorageReflection()->convertStorageToEntity($row->toArray());
$data = $storageReflection->convertStorageToEntity($row->toArray());
$entity->onRefresh($data, true);
}
}
Expand All @@ -358,11 +359,12 @@ protected function processMySQLAutoupdate(IEntity $entity, array $args)
public function remove(IEntity $entity)
{
$this->beginTransaction();
$storageReflection = $this->getStorageReflection();

$primary = [];
$id = (array) $entity->getPersistedId();
foreach ($entity->getMetadata()->getPrimaryKey() as $key) {
$key = $this->storageReflection->convertEntityToStorageKey($key);
$key = $storageReflection->convertEntityToStorageKey($key);
$primary[$key] = array_shift($id);
}

Expand Down

0 comments on commit dd9d092

Please sign in to comment.