Add semantic token highlighting for 'that' variable and comment file references in VS Code extension Add Phone_Text_Input and Currency_Input components with formatting utilities Implement client widgets, form standardization, and soft delete functionality Add modal scroll lock and update documentation Implement comprehensive modal system with form integration and validation Fix modal component instantiation using jQuery plugin API Implement modal system with responsive sizing, queuing, and validation support Implement form submission with validation, error handling, and loading states Implement country/state selectors with dynamic data loading and Bootstrap styling Revert Rsx::Route() highlighting in Blade/PHP files Target specific PHP scopes for Rsx::Route() highlighting in Blade Expand injection selector for Rsx::Route() highlighting Add custom syntax highlighting for Rsx::Route() and Rsx.Route() calls Update jqhtml packages to v2.2.165 Add bundle path validation for common mistakes (development mode only) Create Ajax_Select_Input widget and Rsx_Reference_Data controller Create Country_Select_Input widget with default country support Initialize Tom Select on Select_Input widgets Add Tom Select bundle for enhanced select dropdowns Implement ISO 3166 geographic data system for country/region selection Implement widget-based form system with disabled state support 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
160 lines
5.1 KiB
PHP
Executable File
160 lines
5.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\RSpade\Commands\Database;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Sokil\IsoCodes\IsoCodesFactory;
|
|
use App\RSpade\Core\Models\Country_Model;
|
|
use App\RSpade\Core\Models\Region_Model;
|
|
|
|
/**
|
|
* Seed geographic data (countries and regions) from ISO 3166 standards
|
|
*
|
|
* Uses sokil/php-isocodes library to populate countries (ISO 3166-1)
|
|
* and regions/subdivisions (ISO 3166-2) tables.
|
|
*/
|
|
#[Instantiatable]
|
|
class Seed_Geographic_Data_Command extends Command
|
|
{
|
|
protected $signature = 'rsx:seed:geographic-data';
|
|
|
|
protected $description = 'Import countries and regions from ISO 3166 standards';
|
|
|
|
public function handle()
|
|
{
|
|
$this->info('Importing geographic data from ISO 3166 standards...');
|
|
$this->newLine();
|
|
|
|
// Initialize ISO codes library
|
|
$isoCodes = new IsoCodesFactory();
|
|
|
|
// Seed countries
|
|
$this->seedCountries($isoCodes);
|
|
|
|
// Seed regions
|
|
$this->seedRegions($isoCodes);
|
|
|
|
$this->newLine();
|
|
$this->info('Geographic data import completed successfully!');
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
|
|
private function seedCountries(IsoCodesFactory $isoCodes)
|
|
{
|
|
$this->info('[Countries] Loading ISO 3166-1 data...');
|
|
|
|
$countries = $isoCodes->getCountries();
|
|
$imported_alpha2_codes = [];
|
|
$added = 0;
|
|
$updated = 0;
|
|
|
|
foreach ($countries as $country) {
|
|
$alpha2 = $country->getAlpha2();
|
|
$imported_alpha2_codes[] = $alpha2;
|
|
|
|
$existing = Country_Model::where('alpha2', $alpha2)->first();
|
|
|
|
if ($existing) {
|
|
$existing->alpha2 = $alpha2;
|
|
$existing->alpha3 = $country->getAlpha3();
|
|
$existing->numeric = $country->getNumericCode();
|
|
$existing->name = $country->getName();
|
|
$existing->common_name = $country->getLocalName() !== $country->getName()
|
|
? $country->getLocalName()
|
|
: null;
|
|
$existing->enabled = true;
|
|
$existing->save();
|
|
$updated++;
|
|
} else {
|
|
$model = new Country_Model();
|
|
$model->alpha2 = $alpha2;
|
|
$model->alpha3 = $country->getAlpha3();
|
|
$model->numeric = $country->getNumericCode();
|
|
$model->name = $country->getName();
|
|
$model->common_name = $country->getLocalName() !== $country->getName()
|
|
? $country->getLocalName()
|
|
: null;
|
|
$model->enabled = true;
|
|
$model->save();
|
|
$added++;
|
|
}
|
|
}
|
|
|
|
// Disable countries not in import
|
|
$disabled = Country_Model::whereNotIn('alpha2', $imported_alpha2_codes)
|
|
->where('enabled', true)
|
|
->update(['enabled' => false]);
|
|
|
|
$this->line("[Countries] Added: {$added}, Updated: {$updated}, Disabled: {$disabled}");
|
|
}
|
|
|
|
private function seedRegions(IsoCodesFactory $isoCodes)
|
|
{
|
|
$this->info('[Regions] Loading ISO 3166-2 subdivisions...');
|
|
|
|
$subdivisions = $isoCodes->getSubdivisions();
|
|
$imported_keys = [];
|
|
$added = 0;
|
|
$updated = 0;
|
|
|
|
foreach ($subdivisions as $subdivision) {
|
|
$code = $subdivision->getCode();
|
|
|
|
// Extract country code from subdivision code (e.g., "US-CA" -> "US")
|
|
$parts = explode('-', $code);
|
|
if (count($parts) < 2) {
|
|
// Skip malformed codes
|
|
continue;
|
|
}
|
|
|
|
$country_alpha2 = $parts[0];
|
|
|
|
// Only import if country exists
|
|
if (!Country_Model::where('alpha2', $country_alpha2)->exists()) {
|
|
continue;
|
|
}
|
|
|
|
$imported_keys[] = $country_alpha2 . '|' . $code;
|
|
|
|
$existing = Region_Model::where('country_alpha2', $country_alpha2)
|
|
->where('code', $code)
|
|
->first();
|
|
|
|
if ($existing) {
|
|
$existing->code = $code;
|
|
$existing->country_alpha2 = $country_alpha2;
|
|
$existing->name = $subdivision->getName();
|
|
$existing->type = $subdivision->getType();
|
|
$existing->enabled = true;
|
|
$existing->save();
|
|
$updated++;
|
|
} else {
|
|
$model = new Region_Model();
|
|
$model->code = $code;
|
|
$model->country_alpha2 = $country_alpha2;
|
|
$model->name = $subdivision->getName();
|
|
$model->type = $subdivision->getType();
|
|
$model->enabled = true;
|
|
$model->save();
|
|
$added++;
|
|
}
|
|
}
|
|
|
|
// Disable regions not in import
|
|
$disabled = 0;
|
|
$all_regions = Region_Model::where('enabled', true)->get();
|
|
|
|
foreach ($all_regions as $region) {
|
|
$key = $region->country_alpha2 . '|' . $region->code;
|
|
if (!in_array($key, $imported_keys)) {
|
|
$region->enabled = false;
|
|
$region->save();
|
|
$disabled++;
|
|
}
|
|
}
|
|
|
|
$this->line("[Regions] Added: {$added}, Updated: {$updated}, Disabled: {$disabled}");
|
|
}
|
|
}
|