diff --git a/database/migrations/2023_02_04_053028_fix_cloud_media_paths.php b/database/migrations/2023_02_04_053028_fix_cloud_media_paths.php new file mode 100644 index 000000000..b45ad7f80 --- /dev/null +++ b/database/migrations/2023_02_04_053028_fix_cloud_media_paths.php @@ -0,0 +1,67 @@ +url('test'); + if(!$startUrl) { + return; + } + $baseUrl = substr($startUrl, 0, -4); + $baseUrlLen = strlen($baseUrl); + + foreach(Media::whereNotNull('cdn_url')->lazyById(200, 'id') as $media) { + if($media->cdn_url == null) { + continue; + } + $cdnPath = substr($media->cdn_url, $baseUrlLen); + if(str_starts_with($cdnPath, '/')) { + continue; + } + if(!str_starts_with($cdnPath, 'public/')) { + continue; + } + if($cdnPath != $media->media_path) { + $media->media_path = $cdnPath; + $media->saveQuietly(); + if($media->status_id) { + MediaService::del($media->status_id); + StatusService::del($media->status_id); + } + } + } + + return; + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +};