From c293db1d59ad93972bdccceaa761e73924c48aa2 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 4 Feb 2023 05:14:58 -0700 Subject: [PATCH] Add migration --- ...023_02_04_053028_fix_cloud_media_paths.php | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 database/migrations/2023_02_04_053028_fix_cloud_media_paths.php 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 00000000..b45ad7f8 --- /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() + { + // + } +};