Tweak error handling of anime collection db calls

This commit is contained in:
Timothy Warren 2020-04-28 12:13:35 -04:00
parent a3d56afef3
commit 0ad4d56663

View File

@ -135,7 +135,6 @@ final class AnimeCollection extends Collection {
$id = $data['id']; $id = $data['id'];
$anime = (object)$this->animeModel->getAnimeById($id); $anime = (object)$this->animeModel->getAnimeById($id);
$this->db->beginTransaction();
$this->db->set([ $this->db->set([
'hummingbird_id' => $id, 'hummingbird_id' => $id,
'slug' => $anime->slug, 'slug' => $anime->slug,
@ -150,10 +149,7 @@ final class AnimeCollection extends Collection {
])->insert('anime_set'); ])->insert('anime_set');
$this->updateMediaLink($id, $data['media_id']); $this->updateMediaLink($id, $data['media_id']);
$this->updateGenres($id); $this->updateGenres($id);
$this->db->commit();
} }
/** /**
@ -197,8 +193,6 @@ final class AnimeCollection extends Collection {
$media = $data['media_id']; $media = $data['media_id'];
unset($data['hummingbird_id'], $data['media_id']); unset($data['hummingbird_id'], $data['media_id']);
$this->db->beginTransaction();
// If updating from the 'add' page, there // If updating from the 'add' page, there
// might be no data to actually update in // might be no data to actually update in
// the anime_set table // the anime_set table
@ -212,8 +206,6 @@ final class AnimeCollection extends Collection {
// Update media and genres // Update media and genres
$this->updateMediaLink($id, $media); $this->updateMediaLink($id, $media);
$this->updateGenres($id); $this->updateGenres($id);
$this->db->commit();
} }
/** /**
@ -235,15 +227,10 @@ final class AnimeCollection extends Collection {
foreach ($data as $key => $value) foreach ($data as $key => $value)
{ {
if (is_array($row[$key])) if (is_array($row[$key]))
{
if ($row[$key] === $value)
{ {
continue; continue;
} }
return FALSE;
}
if ((string)$row[$key] !== (string)$value) if ((string)$row[$key] !== (string)$value)
{ {
return FALSE; return FALSE;
@ -417,6 +404,8 @@ final class AnimeCollection extends Collection {
private function updateMediaLink(string $animeId, array $media): void private function updateMediaLink(string $animeId, array $media): void
{ {
$this->db->beginTransaction();
// Delete the old entries // Delete the old entries
$this->db->where('hummingbird_id', $animeId) $this->db->where('hummingbird_id', $animeId)
->delete('anime_set_media_link'); ->delete('anime_set_media_link');
@ -432,6 +421,8 @@ final class AnimeCollection extends Collection {
} }
$this->db->insertBatch('anime_set_media_link', $entries); $this->db->insertBatch('anime_set_media_link', $entries);
$this->db->commit();
} }
/** /**
@ -477,19 +468,9 @@ final class AnimeCollection extends Collection {
} }
if ( ! empty($linksToInsert)) if ( ! empty($linksToInsert))
{
try
{ {
$this->db->insertBatch('genre_anime_set_link', $linksToInsert); $this->db->insertBatch('genre_anime_set_link', $linksToInsert);
} }
catch (PDOException $e)
{
// This often results in a unique constraint violation
// So swallow this for now
// @TODO Fix properly
}
}
} }
/** /**