0
0
Fork 0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-05-09 18:40:06 +00: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:
Dan Brown 2022-09-02 12:54:54 +01:00
parent 27ac122502
commit f28ed0ef0b
No known key found for this signature in database
GPG key ID: 46D9F943C24A2EF9
4 changed files with 46 additions and 2 deletions

View file

@ -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']);
}
}