Initial commit

This commit is contained in:
Ronald Huynen
2026-03-23 21:37:59 +01:00
commit 2547717edb
2193 changed files with 972171 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Console\Commands;
use App\Models\Locations\Location;
use Illuminate\Console\Command;
class SyncLocationDataCommand extends Command
{
protected $signature = 'locations:sync-hierarchy {--force : Force sync even if data exists}';
protected $description = 'Sync missing location hierarchy data (i.e. divisions, countries, from cities).';
public function handle()
{
$query = Location::query();
if (!$this->option('force')) {
// Only sync locations that are missing division data
$query->whereNotNull('city_id')->whereNull('division_id');
}
$locations = $query->get();
$syncedCount = 0;
$totalSynced = [];
$this->info("Processing {$locations->count()} locations...");
foreach ($locations as $location) {
try {
$synced = $location->syncAllLocationData();
if (!empty($synced)) {
$syncedCount++;
$totalSynced = array_merge($totalSynced, $synced);
$this->line("Location ID {$location->id}: " . implode(', ', $synced));
}
} catch (\Exception $e) {
$this->error("Failed to sync location ID {$location->id}: " . $e->getMessage());
}
}
$syncStats = array_count_values($totalSynced);
$this->info("\nCompleted syncing {$syncedCount} locations:");
foreach ($syncStats as $type => $count) {
$this->info(" - {$count} locations synced {$type}");
}
}
}