Files
jouwdriedee/app/Console/Commands/SyncMakerWorldCollectionsCommand.php
T

78 lines
2.5 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\MakerWorldCollection;
use App\Services\MakerWorldService;
use Illuminate\Console\Command;
class SyncMakerWorldCollectionsCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:sync-makerworld-collections
{--collection= : Specifieke collectie ID (MakerWorld ID of database ID)}
{--all : Synchroniseer alle collecties, ook niet-actieve}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Controleert MakerWorld collecties en haalt nieuwe 3D modellen automatisch binnen als concept.';
/**
* Execute the console command.
*/
public function handle(MakerWorldService $makerWorld): int
{
$this->info('MakerWorld Collecties Synchronisatie gestart...');
$query = MakerWorldCollection::query();
if ($specificId = $this->option('collection')) {
$query->where(function ($q) use ($specificId) {
$q->where('id', $specificId)
->orWhere('makerworld_collection_id', $specificId);
});
} elseif (! $this->option('all')) {
$query->where('is_active_sync', true);
}
$collections = $query->get();
if ($collections->isEmpty()) {
$this->comment('Geen actieve MakerWorld collecties gevonden om te synchroniseren.');
return self::SUCCESS;
}
$this->line("Aantal collecties te synchroniseren: {$collections->count()}");
$totalImported = 0;
$totalUpdated = 0;
foreach ($collections as $collection) {
$this->info("Synchroniseren van '{$collection->name}' (#{$collection->makerworld_collection_id})...");
$result = $makerWorld->syncCollection($collection);
if ($result['error']) {
$this->error("Fout bij '{$collection->name}': {$result['error']}");
} else {
$this->line(" ✓ {$result['imported']} nieuwe modellen binnengehaald als concept.");
$this->line(" ✓ {$result['updated']} bestaande modellen bijgewerkt.");
$totalImported += $result['imported'];
$totalUpdated += $result['updated'];
}
}
$this->info("Klaar! Totaal {$totalImported} nieuwe modellen binnengehaald en {$totalUpdated} bijgewerkt.");
return self::SUCCESS;
}
}