diff --git a/app/Console/Commands/MigrateMedia.php b/app/Console/Commands/MigrateMedia.php index 008a263f..987da9af 100644 --- a/app/Console/Commands/MigrateMedia.php +++ b/app/Console/Commands/MigrateMedia.php @@ -71,27 +71,18 @@ class MigrateMedia extends Command continue; } + // Copy the file + Storage::disk('public')->writeStream('media'.DIRECTORY_SEPARATOR.$oldMediaItem->file_name, Storage::disk('s3')->readStream($oldMediaItem->id.DIRECTORY_SEPARATOR.$oldMediaItem->file_name)); // Save relationship based on `media.model_id` // I have already checked they are all notes - $noteId = $oldMediaItem->model_id; - $note = Note::find($noteId); - if (! $note) { - $this->warn('Note no longer exists'); - - continue; - } - - // Create media entry in database and attach to note + $note = $oldMediaItem->model_id; $newMediaItem = Media::create([ 'path' => 'media'.DIRECTORY_SEPARATOR.$oldMediaItem->file_name, 'type' => 'image', ]); $note->media()->attach($newMediaItem->id); - // Copy the file - Storage::disk('public')->writeStream('media'.DIRECTORY_SEPARATOR.$oldMediaItem->file_name, Storage::disk('s3')->readStream($oldMediaItem->id.DIRECTORY_SEPARATOR.$oldMediaItem->file_name)); - $this->info('Media item migrated from S3'); }