From 2a41801b774945bff7c46021a842a750b5fa0293 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 10 Mar 2024 02:24:57 +0000 Subject: [PATCH] bump --- DataStorage/Database/Mapper/UpdateMapper.php | 20 +++++++++- DataStorage/Database/Mapper/WriteMapper.php | 40 ++++++++++++++++++-- 2 files changed, 55 insertions(+), 5 deletions(-) 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(