Skip to content

Commit

Permalink
Merge pull request #140 from prooph/fix_projection_managers
Browse files Browse the repository at this point in the history
fix multiple calls to reset/stop/delete projection
  • Loading branch information
prolic authored Mar 26, 2018
2 parents b89aad8 + 84826f2 commit 4431fa6
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 6 deletions.
54 changes: 51 additions & 3 deletions src/Projection/MariaDbProjectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,23 @@ public function deleteProjection(string $name, bool $deleteEmittedEvents): void
}

if (0 === $statement->rowCount()) {
throw ProjectionNotFound::withName($name);
$sql = <<<EOT
SELECT * FROM `$this->projectionsTable` WHERE name = ? LIMIT 1;
EOT;
$statement = $this->connection->prepare($sql);
try {
$statement->execute([$name]);
} catch (PDOException $exception) {
// ignore and check error code
}

if ($statement->errorCode() !== '00000') {
throw Exception\RuntimeException::fromStatementErrorInfo($statement->errorInfo());
}

if (0 === $statement->rowCount()) {
throw ProjectionNotFound::withName($name);
}
}
}

Expand All @@ -163,7 +179,23 @@ public function resetProjection(string $name): void
}

if (0 === $statement->rowCount()) {
throw ProjectionNotFound::withName($name);
$sql = <<<EOT
SELECT * FROM `$this->projectionsTable` WHERE name = ? LIMIT 1;
EOT;
$statement = $this->connection->prepare($sql);
try {
$statement->execute([$name]);
} catch (PDOException $exception) {
// ignore and check error code
}

if ($statement->errorCode() !== '00000') {
throw Exception\RuntimeException::fromStatementErrorInfo($statement->errorInfo());
}

if (0 === $statement->rowCount()) {
throw ProjectionNotFound::withName($name);
}
}
}

Expand All @@ -188,7 +220,23 @@ public function stopProjection(string $name): void
}

if (0 === $statement->rowCount()) {
throw ProjectionNotFound::withName($name);
$sql = <<<EOT
SELECT * FROM `$this->projectionsTable` WHERE name = ? LIMIT 1;
EOT;
$statement = $this->connection->prepare($sql);
try {
$statement->execute([$name]);
} catch (PDOException $exception) {
// ignore and check error code
}

if ($statement->errorCode() !== '00000') {
throw Exception\RuntimeException::fromStatementErrorInfo($statement->errorInfo());
}

if (0 === $statement->rowCount()) {
throw ProjectionNotFound::withName($name);
}
}
}

Expand Down
54 changes: 51 additions & 3 deletions src/Projection/MySqlProjectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,23 @@ public function deleteProjection(string $name, bool $deleteEmittedEvents): void
}

if (0 === $statement->rowCount()) {
throw ProjectionNotFound::withName($name);
$sql = <<<EOT
SELECT * FROM `$this->projectionsTable` WHERE name = ? LIMIT 1;
EOT;
$statement = $this->connection->prepare($sql);
try {
$statement->execute([$name]);
} catch (PDOException $exception) {
// ignore and check error code
}

if ($statement->errorCode() !== '00000') {
throw Exception\RuntimeException::fromStatementErrorInfo($statement->errorInfo());
}

if (0 === $statement->rowCount()) {
throw ProjectionNotFound::withName($name);
}
}
}

Expand All @@ -163,7 +179,23 @@ public function resetProjection(string $name): void
}

if (0 === $statement->rowCount()) {
throw ProjectionNotFound::withName($name);
$sql = <<<EOT
SELECT * FROM `$this->projectionsTable` WHERE name = ? LIMIT 1;
EOT;
$statement = $this->connection->prepare($sql);
try {
$statement->execute([$name]);
} catch (PDOException $exception) {
// ignore and check error code
}

if ($statement->errorCode() !== '00000') {
throw Exception\RuntimeException::fromStatementErrorInfo($statement->errorInfo());
}

if (0 === $statement->rowCount()) {
throw ProjectionNotFound::withName($name);
}
}
}

Expand All @@ -188,7 +220,23 @@ public function stopProjection(string $name): void
}

if (0 === $statement->rowCount()) {
throw ProjectionNotFound::withName($name);
$sql = <<<EOT
SELECT * FROM `$this->projectionsTable` WHERE name = ? LIMIT 1;
EOT;
$statement = $this->connection->prepare($sql);
try {
$statement->execute([$name]);
} catch (PDOException $exception) {
// ignore and check error code
}

if ($statement->errorCode() !== '00000') {
throw Exception\RuntimeException::fromStatementErrorInfo($statement->errorInfo());
}

if (0 === $statement->rowCount()) {
throw ProjectionNotFound::withName($name);
}
}
}

Expand Down

0 comments on commit 4431fa6

Please sign in to comment.