podcastartgenerator/site/database/seeders/FixLegacyEpisodeSeeder.php
Paul Couture c4398c641e feat/factory_creation (#1)
Prepping for launch.

Reviewed-on: #1
Co-authored-by: Paul Couture <paul@paulcouture.com>
Co-committed-by: Paul Couture <paul@paulcouture.com>
2023-12-14 11:33:03 -06:00

32 lines
795 B
PHP

<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\Episode;
use App\Models\Podcast;
use App\Models\Artwork;
use Illuminate\Support\Str;
use Illuminate\Support\Facade\Log;
class FixLegacyEpisodeSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$episodes = Episode::all();
foreach ($episodes as $episode) {
if (is_null($episode->episode_number) || $episode->episode_number == 0) {
$ep_num_arr = explode('_', $episode->slug);
$episode->episode_number = $ep_num_arr[0];
}
if ($episode->isDirty()) {
$episode->save();
}
}
}
}