diff --git a/DataStorage/Database/Mapper/UpdateMapper.php b/DataStorage/Database/Mapper/UpdateMapper.php index 9407d2006..db0dc76ca 100755 --- a/DataStorage/Database/Mapper/UpdateMapper.php +++ b/DataStorage/Database/Mapper/UpdateMapper.php @@ -163,9 +163,25 @@ final class UpdateMapper extends DataMapperAbstract } $sth = $this->db->con->prepare($query->toSql()); - if ($sth !== false) { - $sth->execute(); + if ($sth === false) { + throw new \Exception(); } + + $deadlock = 0; + do { + $repeat = false; + try { + ++$deadlock; + $sth->execute(); + } catch (\Throwable $t) { + if ($deadlock > 3 || $t->errorInfo[1] !== 1213) { + throw $t; + } + + \usleep(10000); + $repeat = true; + } + } while($repeat); } catch (\Throwable $t) { // @codeCoverageIgnoreStart \phpOMS\Log\FileLogger::getInstance()->error( diff --git a/DataStorage/Database/Mapper/WriteMapper.php b/DataStorage/Database/Mapper/WriteMapper.php index fbb45bead..a171b397a 100755 --- a/DataStorage/Database/Mapper/WriteMapper.php +++ b/DataStorage/Database/Mapper/WriteMapper.php @@ -159,7 +159,25 @@ final class WriteMapper extends DataMapperAbstract } $sth = $this->db->con->prepare($query->toSql()); - $sth->execute(); + if ($sth === false) { + throw new \Exception(); + } + + $deadlock = 0; + do { + $repeat = false; + try { + ++$deadlock; + $sth->execute(); + } catch (\Throwable $t) { + if ($deadlock > 3 || $t->errorInfo[1] !== 1213) { + throw $t; + } + + \usleep(10000); + $repeat = true; + } + } while($repeat); $objId = empty($id = $this->mapper::getObjectId($obj)) ? $this->db->con->lastInsertId() : $id; \settype($objId, $this->mapper::COLUMNS[$this->mapper::PRIMARYFIELD]['type']); @@ -399,9 +417,25 @@ final class WriteMapper extends DataMapperAbstract } $sth = $this->db->con->prepare($relQuery->toSql()); - if ($sth !== false) { - $sth->execute(); + if ($sth === false) { + throw new \Exception(); } + + $deadlock = 0; + do { + $repeat = false; + try { + ++$deadlock; + $sth->execute(); + } catch (\Throwable $t) { + if ($deadlock > 3 || $t->errorInfo[1] !== 1213) { + throw $t; + } + + \usleep(10000); + $repeat = true; + } + } while($repeat); } catch (\Throwable $t) { // @codeCoverageIgnoreStart \phpOMS\Log\FileLogger::getInstance()->error(