Merge pull request 'MTM Fix issue with migrating old S3 media' (#70) from develop into main
Reviewed-on: #70
This commit is contained in:
commit
c1f2066b07
1 changed files with 12 additions and 3 deletions
|
|
@ -71,18 +71,27 @@ class MigrateMedia extends Command
|
||||||
|
|
||||||
continue;
|
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`
|
// Save relationship based on `media.model_id`
|
||||||
// I have already checked they are all notes
|
// I have already checked they are all notes
|
||||||
$note = $oldMediaItem->model_id;
|
$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
|
||||||
$newMediaItem = Media::create([
|
$newMediaItem = Media::create([
|
||||||
'path' => 'media'.DIRECTORY_SEPARATOR.$oldMediaItem->file_name,
|
'path' => 'media'.DIRECTORY_SEPARATOR.$oldMediaItem->file_name,
|
||||||
'type' => 'image',
|
'type' => 'image',
|
||||||
]);
|
]);
|
||||||
$note->media()->attach($newMediaItem->id);
|
$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');
|
$this->info('Media item migrated from S3');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue