mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-06-07 11:24:35 +08:00
Fixed shelf covers being stored as 'cover_book'
Are now stored as 'cover_bookshelf' as expected. Added a migrate to alter existing shelf cover image types.
This commit is contained in:
@ -86,7 +86,7 @@ class Bookshelf extends Entity implements HasCoverImage
|
|||||||
*/
|
*/
|
||||||
public function coverImageTypeKey(): string
|
public function coverImageTypeKey(): string
|
||||||
{
|
{
|
||||||
return 'cover_shelf';
|
return 'cover_bookshelf';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,8 +86,9 @@ class BaseRepo
|
|||||||
public function updateCoverImage($entity, ?UploadedFile $coverImage, bool $removeImage = false)
|
public function updateCoverImage($entity, ?UploadedFile $coverImage, bool $removeImage = false)
|
||||||
{
|
{
|
||||||
if ($coverImage) {
|
if ($coverImage) {
|
||||||
|
$imageType = $entity->coverImageTypeKey();
|
||||||
$this->imageRepo->destroyImage($entity->cover);
|
$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->cover()->associate($image);
|
||||||
$entity->save();
|
$entity->save();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class FixShelfCoverImageTypes extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
// This updates the 'type' field for images, uploaded as shelf cover images,
|
||||||
|
// to be cover_bookshelf instead of cover_book.
|
||||||
|
// This does not fix their paths, since fixing that requires a more complicated operation,
|
||||||
|
// but their path does not affect functionality at time of this fix.
|
||||||
|
|
||||||
|
$shelfImageIds = DB::table('bookshelves')
|
||||||
|
->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']);
|
||||||
|
}
|
||||||
|
}
|
@ -125,6 +125,7 @@ class BookShelfTest extends TestCase
|
|||||||
'image_id' => $lastImage->id,
|
'image_id' => $lastImage->id,
|
||||||
]);
|
]);
|
||||||
$this->assertEquals($lastImage->id, $shelf->cover->id);
|
$this->assertEquals($lastImage->id, $shelf->cover->id);
|
||||||
|
$this->assertEquals('cover_bookshelf', $lastImage->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_shelf_view()
|
public function test_shelf_view()
|
||||||
|
Reference in New Issue
Block a user