Skip to content

Commit

Permalink
Fix race condition when updating a removed resource would break entit…
Browse files Browse the repository at this point in the history
…y hydrate
  • Loading branch information
flavioheleno committed May 18, 2023
1 parent ddd4448 commit 92043a2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,12 @@ public function update(Dependency $dependency): Dependency {
]
);

$dependency = $this->hydrate($stmt->fetch(PDO::FETCH_ASSOC));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($row === false) {
throw new DependencyNotFoundException('Dependency "' . $dependency->getId() . '" not found');
}

$dependency = $this->hydrate($row);

$this->producer->sendEvent(
new DependencyUpdatedEvent($dependency)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,12 @@ public function update(Package $package): Package {
]
);

$package = $this->hydrate($stmt->fetch(PDO::FETCH_ASSOC));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($row === false) {
throw new PackageNotFoundException('Package "' . $package->getId() . '" not found');
}

$package = $this->hydrate($row);

$this->producer->sendEvent(
new PackageUpdatedEvent($package)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,12 @@ public function update(Preference $preference): Preference {
]
);

$preference = $this->hydrate($stmt->fetch(PDO::FETCH_ASSOC));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($row === false) {
throw new PreferenceNotFoundException('Preference "' . $preference->getId() . '" not found');
}

$preference = $this->hydrate($row);

$this->producer->sendEvent(
new PreferenceUpdatedEvent($preference)
Expand Down
9 changes: 7 additions & 2 deletions src/Infrastructure/Persistence/Stats/PdoStatsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function get(string $packageName): Stats {
$stmt->execute(['package_name' => $packageName]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($row === false) {
throw new StatsNotFoundException("Stats '{$packageName}' not found");
throw new StatsNotFoundException("Stats for '{$packageName}' not found");
}

return $this->hydrate($row);
Expand Down Expand Up @@ -321,7 +321,12 @@ public function update(Stats $stats): Stats {
]
);

$stats = $this->hydrate($stmt->fetch(PDO::FETCH_ASSOC));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($row === false) {
throw new StatsNotFoundException('Stats for package "' . $stats->getPackageName() . '" not found');
}

$stats = $this->hydrate($row);

$this->producer->sendEvent(
new StatsUpdatedEvent($stats)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,12 @@ public function update(Version $version): Version {
]
);

$version = $this->hydrate($stmt->fetch(PDO::FETCH_ASSOC));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($row === false) {
throw new VersionNotFoundException('Version "' . $version->getId() . '" not found');
}

$version = $this->hydrate($row);

$this->producer->sendEvent(
new VersionUpdatedEvent($version)
Expand Down

0 comments on commit 92043a2

Please sign in to comment.