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>
This commit was merged in pull request #1.
This commit is contained in:
51
site/app/Console/Commands/AddMissingArtworkIdsToEpisodes.php
Normal file
51
site/app/Console/Commands/AddMissingArtworkIdsToEpisodes.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Artwork;
|
||||
use App\Models\Episode;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AddMissingArtworkIdsToEpisodes extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'naart:artwork-to-episodes';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$oldEpisodes = DB::connection('legacy')->select('SELECT * FROM episodes WHERE artwork_id IS NOT NULL AND published = 1');
|
||||
foreach($oldEpisodes as $oldEpisode) {
|
||||
$this->info('Checking old episode ' . $oldEpisode->show_date);
|
||||
$episode = Episode::where('legacy_id', $oldEpisode->id)->first();
|
||||
$artwork = Artwork::where('legacy_id', $oldEpisode->artwork_id)->first();
|
||||
if ($episode && $artwork) {
|
||||
$this->line('Have artwork ' . $artwork->title . ' for episode ' . $episode->title);
|
||||
$episode->artwork_id = $artwork->id;
|
||||
$episode->timestamps = false;
|
||||
if ($episode->isDirty()) {
|
||||
$this->info('I need to update this.');
|
||||
//$episode->save();
|
||||
} else {
|
||||
$this->line('No Change Needed.');
|
||||
}
|
||||
} else {
|
||||
$this->error('I am lost.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
125
site/app/Console/Commands/GetMissingArtworkMovedCommand.php
Normal file
125
site/app/Console/Commands/GetMissingArtworkMovedCommand.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Intervention\Image\Facades\Image;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\User;
|
||||
use App\Models\Artist;
|
||||
use App\Models\Podcast;
|
||||
use App\Models\Episode;
|
||||
use App\Models\Artwork;
|
||||
use ImageOptimizer;
|
||||
|
||||
class GetMissingArtworkMovedCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'naart:wrapup';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$missingArtworks = DB::connection('legacy')->select('SELECT * FROM artworks WHERE id > 30835 AND approved_by IS NOT NULL');
|
||||
foreach ($missingArtworks as $missingArtwork) {
|
||||
$localPath = '/legacypublic' . $missingArtwork->path . '/' . $missingArtwork->filename;
|
||||
$user = User::where('legacy_id', $missingArtwork->user_id)->with('artists')->first();
|
||||
$artwork = Artwork::where('legacy_id', $missingArtwork->id)->first();
|
||||
$episode = Episode::where('legacy_id', $missingArtwork->episode_id)->first();
|
||||
$approver = User::where('legacy_id', $missingArtwork->approved_by)->with('artists')->first();
|
||||
if ($artwork) {
|
||||
$this->line('Artwork ID: ' . $artwork->id);
|
||||
}
|
||||
if ($episode) {
|
||||
$this->line('Episode: ' . $episode->episode_number . ' "' . $episode->title . '"');
|
||||
}
|
||||
if (!$artwork) {
|
||||
$newFilename = $this->uniqueName($episode, $user, $missingArtwork);
|
||||
$state = [
|
||||
'title' => $missingArtwork->title,
|
||||
'description' => '',
|
||||
'artist_id' => $user->artists->first()->id,
|
||||
'episode_id' => $episode->id,
|
||||
'podcast_id' => 1,
|
||||
'overlay_id' => null,
|
||||
'filename' => $newFilename . '.jpg',
|
||||
'created_at' => Carbon::parse($missingArtwork->created_at),
|
||||
'updated_at' => Carbon::parse($missingArtwork->updated_at),
|
||||
'legacy_id' => $missingArtwork->id,
|
||||
'approved_by' => $approver->artists->first()->id,
|
||||
];
|
||||
$artwork = Artwork::factory()->state($state)->create();
|
||||
}
|
||||
$this->line('Artist: ' . $user->artists->first()->name);
|
||||
$this->line($localPath);
|
||||
$filename = 'artworks/' . $artwork->filename;
|
||||
$thumbnailName = 'thumbnails/' . $artwork->filename;
|
||||
if (Storage::disk('static')->exists($filename)) {
|
||||
$this->error($filename . ' already exists. ' . Storage::disk('static')->size($filename));
|
||||
}
|
||||
if (Storage::disk('static')->exists($thumbnailName)) {
|
||||
$this->error($thumbnailName . ' already exists. ' . Storage::disk('static')->size($thumbnailName));
|
||||
}
|
||||
$img = Image::make($localPath)
|
||||
->resize(3000, null, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
})
|
||||
->encode('jpg', 100);
|
||||
$thumbImg = Image::make($localPath)
|
||||
->resize(512, null, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
})
|
||||
->encode('jpg', 100);
|
||||
$imgLocation = Storage::disk('static')->put($filename, $img);
|
||||
$thumbLocation = Storage::disk('static')->put($thumbnailName, $thumbImg);
|
||||
$size_before = Storage::disk('static')->size($filename);
|
||||
$thumb_size_before = Storage::disk('static')->size($thumbnailName);
|
||||
ImageOptimizer::optimize(Storage::disk('static')->path($filename));
|
||||
ImageOptimizer::optimize(Storage::disk('static')->path($thumbnailName));
|
||||
$size_after = Storage::disk('static')->size($filename);
|
||||
$thumb_size_after = Storage::disk('static')->size($thumbnailName);
|
||||
$diff = $size_before - $size_after;
|
||||
$thumbDiff = $thumb_size_before - $thumb_size_after;
|
||||
$this->line('Filesize before: ' . $size_before);
|
||||
$this->line('Filesize after: ' . $size_after);
|
||||
$this->line('Thumb Filesize before: ' . $thumb_size_before);
|
||||
$this->line('Thumb Filesize after: ' . $thumb_size_after);
|
||||
}
|
||||
}
|
||||
|
||||
private function checkExistingFilename($name) {
|
||||
$checkArtwork = Artwork::where('filename', $name . '.jpg')->count();
|
||||
return $checkArtwork;
|
||||
}
|
||||
|
||||
private function uniqueName($episode, $user, $missingArtwork) {
|
||||
$i = 0;
|
||||
$uniqueFilename = $episode->episode_date->format('Y/m/') . Str::slug($user->artists->first()->name . '-' . $missingArtwork->title) . '_' . $missingArtwork->id;
|
||||
$exists = $this->checkExistingFilename($uniqueFilename);
|
||||
if (!$exists) {
|
||||
return $uniqueFilename;
|
||||
}
|
||||
while(!$exists) {
|
||||
$i++;
|
||||
$uniqueFilename = $uniqueFilename . '_v' . $i;
|
||||
$exists = $this->checkExistingFilename($uniqueFilename);
|
||||
}
|
||||
return $uniqueFilename;
|
||||
}
|
||||
}
|
||||
46
site/app/Console/Commands/LegacyNginxMappingCommand.php
Normal file
46
site/app/Console/Commands/LegacyNginxMappingCommand.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Artwork;
|
||||
|
||||
class LegacyNginxMappingCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'naart:legacy-nginx-mapping';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$oldLocations = [];
|
||||
$newLocations = [];
|
||||
$this->line('# legacy_mappings.conf');
|
||||
$this->line('');
|
||||
$this->line('map $uri $new_location {');
|
||||
$artworks = Artwork::whereNotNull('legacy_filename')->get();
|
||||
foreach ($artworks as $artwork) {
|
||||
if (!in_array($artwork->legacy_filename, $oldLocations) && !in_array($artwork->legacy_filename, $newLocations)) {
|
||||
$oldLocations[] = $artwork->legacy_filename;
|
||||
$newLocations[] = $artwork->legacy_filename;
|
||||
$this->line(' "' . $artwork->legacy_filename . '" "/legacy-asset/?legacy_filename=' . urlencode($artwork->legacy_filename) . '";');
|
||||
}
|
||||
}
|
||||
$this->line(' default $uri;');
|
||||
$this->line('}');
|
||||
$this->line('');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Models\Artwork;
|
||||
use App\Models\Episode;
|
||||
|
||||
class MapLegacyArtworkToLegacyEpisodeCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'naart:map-legacy';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Maps legacy artwork to the legacy episode it related to.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$artworks = Artwork::whereNotNull('legacy_id')->get();
|
||||
foreach ($artworks as $artwork) {
|
||||
if ($artwork->id > 76200) {
|
||||
$legacyDetailResponse = $this->getArtworkInfoFromApi($artwork->legacy_id);
|
||||
$response = $legacyDetailResponse->object();
|
||||
if ($response->artwork->episode_id) {
|
||||
$episode = Episode::where('legacy_id', $response->artwork->episode_id)->first();
|
||||
if ($episode) {
|
||||
$artwork->episode_id = $episode->id;
|
||||
$this->line('Artwork ID ' . $artwork->id . ' is mapped to Episode ID ' . $episode->id);
|
||||
if ($artwork->isDirty()) {
|
||||
$this->line('This is a new mapping.');
|
||||
$artwork->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getArtworkInfoFromApi($artwork_legacy_id) {
|
||||
$response = Http::timeout(180)
|
||||
->get('https://noagendaartgenerator.com/artworkapi/' . $artwork_legacy_id,
|
||||
[
|
||||
'p' => '7476',
|
||||
]
|
||||
);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Models\Artwork;
|
||||
use App\Models\Episode;
|
||||
|
||||
class MapSelectedLegacyArtworkToEpisode extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'naart:map-selected';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Maps the correct artwork selected to the legacy episodes';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$episodes = Episode::all();
|
||||
foreach ($episodes as $episode) {
|
||||
$this->line('Checking episode ' . $episode->episode_number);
|
||||
$legacyEpisodeResponse = $this->getEpisodeFromApi($episode->episode_number);
|
||||
$response = $legacyEpisodeResponse->object();
|
||||
if ($response->episode->artwork_id && $response->episode->artwork_id + 0 > 0) {
|
||||
$selectedArtwork = Artwork::where('legacy_id', $response->episode->artwork_id)->first();
|
||||
if ($selectedArtwork) {
|
||||
$episode->artwork_id = $selectedArtwork->id;
|
||||
$this->line('Artwork ID ' . $selectedArtwork->id . ' marked as episode artwork for episode ' . $episode->episode_number);
|
||||
if ($episode->isDirty()) {
|
||||
$this->line('This is a new mapping.');
|
||||
$episode->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getEpisodeFromApi($episode_legacy_id) {
|
||||
$response = Http::timeout(180)
|
||||
->get('https://noagendaartgenerator.com/episodeapi/' . $episode_legacy_id,
|
||||
[
|
||||
'p' => '7476',
|
||||
]
|
||||
);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user