Fix error on attempt to insert a duplicate series

This commit is contained in:
Timothy Warren 2019-01-22 10:21:58 -05:00
parent 27c7f08d7f
commit 4e2437f2bc
3 changed files with 16 additions and 23 deletions

View File

@ -14,13 +14,13 @@
<tr> <tr>
<td class="align-right"><label for="title">Title</label></td> <td class="align-right"><label for="title">Title</label></td>
<td class="align-left"> <td class="align-left">
<input type="text" name="title" value="<?= $item['title'] ?>" /> <input type="text" id="title" name="title" value="<?= $item['title'] ?>" />
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="align-right"><label for="title">Alternate Title</label></td> <td class="align-right"><label for="alternate_title">Alternate Title</label></td>
<td class="align-left"> <td class="align-left">
<input type="text" name="alternate_title" value="<?= $item['alternate_title'] ?>"/> <input type="text" id="alternate_title" name="alternate_title" value="<?= $item['alternate_title'] ?>"/>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -28,7 +28,7 @@
<td class="align-left"> <td class="align-left">
<select name="media_id" id="media_id"> <select name="media_id" id="media_id">
<?php foreach($media_items as $id => $name): ?> <?php foreach($media_items as $id => $name): ?>
<option <?= $item['media_id'] === $id ? 'selected="selected"' : '' ?> value="<?= $id ?>"><?= $name ?></option> <option <?= $item['media_id'] === (string)$id ? 'selected="selected"' : '' ?> value="<?= $id ?>"><?= $name ?></option>
<?php endforeach ?> <?php endforeach ?>
</select> </select>
</td> </td>

View File

@ -89,21 +89,6 @@ final class AnimeCollection extends Collection {
return $output; return $output;
} }
/**
* Get item from collection for editing
*
* @param string $id
* @return array
*/
public function getCollectionEntry($id): array
{
$query = $this->db->from('anime_set')
->where('hummingbird_id', $id)
->get();
return $query->fetch(PDO::FETCH_ASSOC);
}
/** /**
* Get full collection from the database * Get full collection from the database
* *
@ -151,7 +136,16 @@ final class AnimeCollection extends Collection {
*/ */
public function add($data): void public function add($data): void
{ {
$anime = (object)$this->animeModel->getAnimeById($data['id']); $id = $data['id'];
// Check that the anime doesn't already exist
$existing = $this->get($id);
if ($existing === FALSE)
{
return;
}
$anime = (object)$this->animeModel->getAnimeById($id);
$this->db->set([ $this->db->set([
'hummingbird_id' => $data['id'], 'hummingbird_id' => $data['id'],
'slug' => $anime->slug, 'slug' => $anime->slug,
@ -216,9 +210,9 @@ final class AnimeCollection extends Collection {
* Get the details of a collection item * Get the details of a collection item
* *
* @param int $kitsuId * @param int $kitsuId
* @return array * @return array | false
*/ */
public function get($kitsuId): array public function get($kitsuId)
{ {
$query = $this->db->from('anime_set') $query = $this->db->from('anime_set')
->where('hummingbird_id', $kitsuId) ->where('hummingbird_id', $kitsuId)

View File

@ -17,7 +17,6 @@
namespace Aviat\AnimeClient\Model; namespace Aviat\AnimeClient\Model;
use Aviat\Ion\Di\ContainerInterface; use Aviat\Ion\Di\ContainerInterface;
use PDO;
use PDOException; use PDOException;
/** /**