table('artworks')->where('id', $this->argument('legacy_artwork_id'))->first(); $legacyEpisode = DB::connection('legacy')->table('episodes')->where('id', $legacyArtwork->episode_id)->first(); dump($legacyEpisode); dump($legacyArtwork); $user = User::where('legacy_id', $legacyArtwork->user_id)->with('artists')->first(); $artist = $user->artists->first(); dump($artist); $podcast = Podcast::find(1); $episode = Episode::where('episode_number', $legacyEpisode->episode_number)->first(); dump($episode); $date = Carbon::parse($legacyArtwork->created_at); $basename = $date->format('Y') . '/' . $date->format('m') . '/' . Str::slug($artist->name) . '_' . Str::slug($legacyArtwork->title) . '_' . Str::random(8) . '.jpg'; $thumbnailName = 'thumbnails/' . $basename; $artworkName = 'artworks/' . $basename; $artworkExists = Artwork::where('artist_id', $artist->id) ->where('episode_id', $episode->id) ->where('title', $legacyArtwork->title) ->count(); $thumbnailExists = false; $artExists = false; dump($artworkExists); dump([$thumbnailName, $artworkName]); if (Storage::disk('static')->exists($thumbnailName)) { $this->line('Thumbnail already exists.'); $thumbnailExists = true; } if (Storage::disk('static')->exists($artworkName)) { $this->line('Artwork already exists.'); $artExists = true; } dump([$thumbnailExists, $artExists]); if (!$artworkExists) { $artwork = Artwork::factory()->state([ 'title' => $legacyArtwork->title, 'artist_id' => $artist->id, 'description' => null, 'overlay_id' => null, 'podcast_id' => $podcast->id, 'episode_id' => $episode->id, 'approved_by' => 4, 'filename' => $basename, 'legacy_filename' => $legacyArtwork->path . '/' . $legacyArtwork->filename, 'legacy_id' => $legacyArtwork->id, 'created_at' => $legacyArtwork->created_at, 'updated_at' => $legacyArtwork->created_at, ])->create(); $img = Image::make('/var/www/html/naartgen/podcastartgenerator/static' . $artwork->legacy_filename) ->resize(3000, null, function($constraint) { $constraint->aspectRatio(); }) ->encode('jpg', 100) ->save(Storage::disk('static')->path('/artworks') . '/' . $artwork->filename); $thumbImg = Image::make('/var/www/html/naartgen/podcastartgenerator/static' . $artwork->legacy_filename) ->resize(512, null, function($constraint) { $constraint->aspectRatio(); }) ->encode('jpg', 100) ->save(Storage::disk('static')->path('/thumbnails') . '/' . $artwork->filename); ImageOptimizer::optimize(Storage::disk('static')->path('/artworks/' . $artwork->filename)); ImageOptimizer::optimize(Storage::disk('static')->path('/thumbnails/' . $artwork->filename)); dump($artwork); } } }