diff --git a/app/Entities/Models/Bookshelf.php b/app/Entities/Models/Bookshelf.php index b2dab252a..cdc6648f9 100644 --- a/app/Entities/Models/Bookshelf.php +++ b/app/Entities/Models/Bookshelf.php @@ -86,7 +86,7 @@ class Bookshelf extends Entity implements HasCoverImage */ public function coverImageTypeKey(): string { - return 'cover_shelf'; + return 'cover_bookshelf'; } /** diff --git a/app/Entities/Repos/BaseRepo.php b/app/Entities/Repos/BaseRepo.php index 747d1b176..da939e102 100644 --- a/app/Entities/Repos/BaseRepo.php +++ b/app/Entities/Repos/BaseRepo.php @@ -86,8 +86,9 @@ class BaseRepo public function updateCoverImage($entity, ?UploadedFile $coverImage, bool $removeImage = false) { if ($coverImage) { + $imageType = $entity->coverImageTypeKey(); $this->imageRepo->destroyImage($entity->cover); - $image = $this->imageRepo->saveNew($coverImage, 'cover_book', $entity->id, 512, 512, true); + $image = $this->imageRepo->saveNew($coverImage, $imageType, $entity->id, 512, 512, true); $entity->cover()->associate($image); $entity->save(); } diff --git a/database/migrations/2022_09_02_082910_fix_shelf_cover_image_types.php b/database/migrations/2022_09_02_082910_fix_shelf_cover_image_types.php new file mode 100644 index 000000000..837bdfe24 --- /dev/null +++ b/database/migrations/2022_09_02_082910_fix_shelf_cover_image_types.php @@ -0,0 +1,42 @@ +whereNotNull('image_id') + ->pluck('image_id') + ->values()->all(); + + DB::table('images') + ->where('type', '=', 'cover_book') + ->whereIn('id', $shelfImageIds) + ->update(['type' => 'cover_bookshelf']); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + DB::table('images') + ->where('type', '=', 'cover_bookshelf') + ->update(['type' => 'cover_book']); + } +} diff --git a/tests/Entity/BookShelfTest.php b/tests/Entity/BookShelfTest.php index 5a7107ff0..44d30a548 100644 --- a/tests/Entity/BookShelfTest.php +++ b/tests/Entity/BookShelfTest.php @@ -125,6 +125,7 @@ class BookShelfTest extends TestCase 'image_id' => $lastImage->id, ]); $this->assertEquals($lastImage->id, $shelf->cover->id); + $this->assertEquals('cover_bookshelf', $lastImage->type); } public function test_shelf_view()