First Commit
This commit is contained in:
+57
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
/**
|
||||
* Migration for creating the lists_countries table and seeding Brazil.
|
||||
*/
|
||||
class CreateListsCountriesTable
|
||||
{
|
||||
/**
|
||||
* Run the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (!Capsule::schema()->hasTable('lists_countries')) {
|
||||
Capsule::schema()->create('lists_countries', function (Blueprint $table) {
|
||||
$table->increments('countries_id');
|
||||
$table->string('countries_name', 100);
|
||||
$table->char('countries_iso_code', 2)->default('BR');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
// Insert Brazil as default country
|
||||
Capsule::table('lists_countries')->insert([
|
||||
'countries_name' => 'Brasil',
|
||||
'countries_iso_code' => 'BR',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
} else {
|
||||
// Se a tabela já existe, removemos os campos idbus e iduser caso ainda existam
|
||||
if (Capsule::schema()->hasColumn('lists_countries', 'idbus')) {
|
||||
Capsule::schema()->table('lists_countries', function (Blueprint $table) {
|
||||
$table->dropColumn('idbus');
|
||||
});
|
||||
}
|
||||
if (Capsule::schema()->hasColumn('lists_countries', 'iduser')) {
|
||||
Capsule::schema()->table('lists_countries', function (Blueprint $table) {
|
||||
$table->dropColumn('iduser');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Capsule::schema()->dropIfExists('lists_countries');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
/**
|
||||
* Migration for creating the lists_states table.
|
||||
*/
|
||||
class CreateListsStatesTable
|
||||
{
|
||||
/**
|
||||
* Run the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (!Capsule::schema()->hasTable('lists_states')) {
|
||||
Capsule::schema()->create('lists_states', function (Blueprint $table) {
|
||||
$table->increments('states_id');
|
||||
$table->integer('states_country_id')->unsigned();
|
||||
$table->string('states_name', 100);
|
||||
$table->char('states_uf', 2);
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('states_country_id')->references('countries_id')->on('lists_countries')->onDelete('cascade');
|
||||
});
|
||||
} else {
|
||||
// Se a tabela já existe, removemos os campos idbus e iduser caso ainda existam
|
||||
if (Capsule::schema()->hasColumn('lists_states', 'idbus')) {
|
||||
Capsule::schema()->table('lists_states', function (Blueprint $table) {
|
||||
$table->dropColumn('idbus');
|
||||
});
|
||||
}
|
||||
if (Capsule::schema()->hasColumn('lists_states', 'iduser')) {
|
||||
Capsule::schema()->table('lists_states', function (Blueprint $table) {
|
||||
$table->dropColumn('iduser');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Capsule::schema()->dropIfExists('lists_states');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
/**
|
||||
* Migration for creating the lists_cities table.
|
||||
*/
|
||||
class CreateListsCitiesTable
|
||||
{
|
||||
/**
|
||||
* Run the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (!Capsule::schema()->hasTable('lists_cities')) {
|
||||
Capsule::schema()->create('lists_cities', function (Blueprint $table) {
|
||||
$table->increments('cities_id');
|
||||
$table->integer('cities_state_id')->unsigned();
|
||||
$table->string('cities_name', 150);
|
||||
$table->string('cities_slug', 150)->nullable();
|
||||
$table->string('cities_ibge_code', 10)->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('cities_state_id')->references('states_id')->on('lists_states')->onDelete('cascade');
|
||||
});
|
||||
} else {
|
||||
// Se a tabela já existe, removemos os campos idbus e iduser caso ainda existam
|
||||
if (Capsule::schema()->hasColumn('lists_cities', 'idbus')) {
|
||||
Capsule::schema()->table('lists_cities', function (Blueprint $table) {
|
||||
$table->dropColumn('idbus');
|
||||
});
|
||||
}
|
||||
if (Capsule::schema()->hasColumn('lists_cities', 'iduser')) {
|
||||
Capsule::schema()->table('lists_cities', function (Blueprint $table) {
|
||||
$table->dropColumn('iduser');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Capsule::schema()->dropIfExists('lists_cities');
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
/**
|
||||
* Migration for creating the lists_activities table.
|
||||
*/
|
||||
class CreateListsActivitiesTable
|
||||
{
|
||||
/**
|
||||
* Run the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (!Capsule::schema()->hasTable('lists_activities')) {
|
||||
Capsule::schema()->create('lists_activities', function (Blueprint $table) {
|
||||
$table->increments('activities_id');
|
||||
$table->string('activities_name', 150);
|
||||
$table->string('activities_slug', 150);
|
||||
$table->string('activities_type', 50)->default('activity'); // 'activity' or 'service'
|
||||
$table->timestamps();
|
||||
});
|
||||
} else {
|
||||
// Se a tabela já existe, removemos os campos idbus e iduser caso ainda existam
|
||||
if (Capsule::schema()->hasColumn('lists_activities', 'idbus')) {
|
||||
Capsule::schema()->table('lists_activities', function (Blueprint $table) {
|
||||
$table->dropColumn('idbus');
|
||||
});
|
||||
}
|
||||
if (Capsule::schema()->hasColumn('lists_activities', 'iduser')) {
|
||||
Capsule::schema()->table('lists_activities', function (Blueprint $table) {
|
||||
$table->dropColumn('iduser');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Capsule::schema()->dropIfExists('lists_activities');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Modules\GlobalLists\Models\State;
|
||||
use Modules\GlobalLists\Models\City;
|
||||
|
||||
/**
|
||||
* Migration for importing data from municipios.csv.
|
||||
*/
|
||||
class ImportMunicipiosData
|
||||
{
|
||||
/**
|
||||
* Run the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$csvFile = dirname(__DIR__, 2) . '/municipios.csv';
|
||||
|
||||
if (!file_exists($csvFile)) {
|
||||
// Try to find it in the root if not in module
|
||||
$csvFile = dirname(__DIR__, 4) . '/municipios.csv';
|
||||
}
|
||||
|
||||
if (!file_exists($csvFile)) {
|
||||
throw new \Exception("Arquivo municipios.csv não encontrado em: " . $csvFile);
|
||||
}
|
||||
|
||||
$handle = fopen($csvFile, 'r');
|
||||
if ($handle === false) {
|
||||
throw new \Exception("Não foi possível abrir o arquivo municipios.csv");
|
||||
}
|
||||
|
||||
// Skip header
|
||||
fgets($handle);
|
||||
|
||||
$states = [];
|
||||
$batchSize = 500;
|
||||
$citiesBatch = [];
|
||||
|
||||
// Check if we already have data to avoid re-importing and potential tablespace issues
|
||||
$citiesCount = Capsule::table('lists_cities')->count();
|
||||
if ($citiesCount > 0) {
|
||||
echo "Tabela lists_cities já contém dados ($citiesCount registros). Verificando colunas...\n";
|
||||
|
||||
// Removemos os campos idbus e iduser caso ainda existam
|
||||
if (Capsule::schema()->hasColumn('lists_cities', 'idbus')) {
|
||||
Capsule::schema()->table('lists_cities', function ($table) {
|
||||
$table->dropColumn('idbus');
|
||||
});
|
||||
}
|
||||
if (Capsule::schema()->hasColumn('lists_cities', 'iduser')) {
|
||||
Capsule::schema()->table('lists_cities', function ($table) {
|
||||
$table->dropColumn('iduser');
|
||||
});
|
||||
}
|
||||
if (Capsule::schema()->hasColumn('lists_states', 'idbus')) {
|
||||
Capsule::schema()->table('lists_states', function ($table) {
|
||||
$table->dropColumn('idbus');
|
||||
});
|
||||
}
|
||||
if (Capsule::schema()->hasColumn('lists_states', 'iduser')) {
|
||||
Capsule::schema()->table('lists_states', function ($table) {
|
||||
$table->dropColumn('iduser');
|
||||
});
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Capsule::statement('SET FOREIGN_KEY_CHECKS=0;');
|
||||
|
||||
// Use DELETE instead of TRUNCATE to avoid tablespace issues with InnoDB
|
||||
// Only delete if there is something, to be safe
|
||||
Capsule::table('lists_cities')->delete();
|
||||
Capsule::table('lists_states')->delete();
|
||||
|
||||
Capsule::statement('SET FOREIGN_KEY_CHECKS=1;');
|
||||
|
||||
while (($line = fgets($handle)) !== false) {
|
||||
$data = str_getcsv($line, ';');
|
||||
if (count($data) < 5) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$uf = trim($data[4]);
|
||||
$cityName = trim($data[3]);
|
||||
$ibgeCode = trim($data[1]);
|
||||
|
||||
// Convert encoding from ISO-8859-1 to UTF-8
|
||||
if (!mb_check_encoding($cityName, 'UTF-8')) {
|
||||
$cityName = mb_convert_encoding($cityName, 'UTF-8', 'ISO-8859-1');
|
||||
}
|
||||
|
||||
if (!isset($states[$uf])) {
|
||||
$stateId = Capsule::table('lists_states')->insertGetId([
|
||||
'states_uf' => $uf,
|
||||
'states_name' => $this->getStateName($uf),
|
||||
'states_country_id' => 1, // Brasil
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
$states[$uf] = $stateId;
|
||||
}
|
||||
|
||||
$citiesBatch[] = [
|
||||
'cities_state_id' => $states[$uf],
|
||||
'cities_name' => $cityName,
|
||||
'cities_slug' => $this->slugify($cityName),
|
||||
'cities_ibge_code' => $ibgeCode,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
];
|
||||
|
||||
if (count($citiesBatch) >= $batchSize) {
|
||||
Capsule::table('lists_cities')->insert($citiesBatch);
|
||||
$citiesBatch = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($citiesBatch)) {
|
||||
Capsule::table('lists_cities')->insert($citiesBatch);
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get state name by UF.
|
||||
*/
|
||||
private function getStateName($uf)
|
||||
{
|
||||
$names = [
|
||||
'AC' => 'Acre', 'AL' => 'Alagoas', 'AP' => 'Amapá', 'AM' => 'Amazonas',
|
||||
'BA' => 'Bahia', 'CE' => 'Ceará', 'DF' => 'Distrito Federal', 'ES' => 'Espírito Santo',
|
||||
'GO' => 'Goiás', 'MA' => 'Maranhão', 'MT' => 'Mato Grosso', 'MS' => 'Mato Grosso do Sul',
|
||||
'MG' => 'Minas Gerais', 'PA' => 'Pará', 'PB' => 'Paraíba', 'PR' => 'Paraná',
|
||||
'PE' => 'Pernambuco', 'PI' => 'Piauí', 'RJ' => 'Rio de Janeiro', 'RN' => 'Rio Grande do Norte',
|
||||
'RS' => 'Rio Grande do Sul', 'RO' => 'Rondônia', 'RR' => 'Roraima', 'SC' => 'Santa Catarina',
|
||||
'SP' => 'São Paulo', 'SE' => 'Sergipe', 'TO' => 'Tocantins'
|
||||
];
|
||||
return $names[$uf] ?? $uf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple slugify function.
|
||||
*/
|
||||
private function slugify($text)
|
||||
{
|
||||
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
|
||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
$text = preg_replace('~[^-\w]+~', '', $text);
|
||||
$text = trim($text, '-');
|
||||
$text = preg_replace('~-+~', '-', $text);
|
||||
$text = strtolower($text);
|
||||
if (empty($text)) {
|
||||
return 'n-a';
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
// No down migration for data import usually
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
/**
|
||||
* Migration for seeding initial activities.
|
||||
*/
|
||||
class SeedActivitiesData
|
||||
{
|
||||
/**
|
||||
* Run the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// Se a tabela já existe, removemos os campos idbus e iduser caso ainda existam
|
||||
if (Capsule::schema()->hasTable('lists_activities')) {
|
||||
if (Capsule::schema()->hasColumn('lists_activities', 'idbus')) {
|
||||
Capsule::schema()->table('lists_activities', function ($table) {
|
||||
$table->dropColumn('idbus');
|
||||
});
|
||||
}
|
||||
if (Capsule::schema()->hasColumn('lists_activities', 'iduser')) {
|
||||
Capsule::schema()->table('lists_activities', function ($table) {
|
||||
$table->dropColumn('iduser');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Verificar se já existem dados para evitar duplicidade
|
||||
if (Capsule::table('lists_activities')->count() > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$activities = [
|
||||
['name' => 'Restaurante', 'type' => 'service'],
|
||||
['name' => 'Oficina Mecânica', 'type' => 'service'],
|
||||
['name' => 'Padaria', 'type' => 'commercial'],
|
||||
['name' => 'Supermercado', 'type' => 'commercial'],
|
||||
['name' => 'Farmácia', 'type' => 'commercial'],
|
||||
['name' => 'Loja de Roupas', 'type' => 'commercial'],
|
||||
['name' => 'Salão de Beleza', 'type' => 'service'],
|
||||
['name' => 'Academia', 'type' => 'service'],
|
||||
['name' => 'Escola', 'type' => 'service'],
|
||||
['name' => 'Clínica Médica', 'type' => 'service'],
|
||||
['name' => 'Indústria Metalúrgica', 'type' => 'industrial'],
|
||||
['name' => 'Indústria Têxtil', 'type' => 'industrial'],
|
||||
['name' => 'Contabilidade', 'type' => 'service'],
|
||||
['name' => 'Advocacia', 'type' => 'service'],
|
||||
['name' => 'Imobiliária', 'type' => 'service'],
|
||||
['name' => 'Pet Shop', 'type' => 'service'],
|
||||
['name' => 'Livraria', 'type' => 'commercial'],
|
||||
['name' => 'Ótica', 'type' => 'commercial'],
|
||||
['name' => 'Joalheria', 'type' => 'commercial'],
|
||||
['name' => 'Hotelaria', 'type' => 'service'],
|
||||
];
|
||||
|
||||
foreach ($activities as $activity) {
|
||||
Capsule::table('lists_activities')->insert([
|
||||
'activities_name' => $activity['name'],
|
||||
'activities_type' => $activity['type'],
|
||||
'activities_slug' => $this->slugify($activity['name']),
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple slugify function.
|
||||
*/
|
||||
private function slugify($text)
|
||||
{
|
||||
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
|
||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
$text = preg_replace('~[^-\w]+~', '', $text);
|
||||
$text = trim($text, '-');
|
||||
$text = preg_replace('~-+~', '-', $text);
|
||||
$text = strtolower($text);
|
||||
if (empty($text)) {
|
||||
return 'n-a';
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Capsule::table('lists_activities')->delete();
|
||||
}
|
||||
}
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
/**
|
||||
* Migration for importing activities from sis_atividades.csv with encoding correction.
|
||||
*/
|
||||
class ImportActivitiesFromSis
|
||||
{
|
||||
/**
|
||||
* Run the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// Se a tabela já existe, removemos os campos idbus e iduser caso ainda existam
|
||||
if (Capsule::schema()->hasTable('lists_activities')) {
|
||||
if (Capsule::schema()->hasColumn('lists_activities', 'idbus')) {
|
||||
Capsule::schema()->table('lists_activities', function ($table) {
|
||||
$table->dropColumn('idbus');
|
||||
});
|
||||
}
|
||||
if (Capsule::schema()->hasColumn('lists_activities', 'iduser')) {
|
||||
Capsule::schema()->table('lists_activities', function ($table) {
|
||||
$table->dropColumn('iduser');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$filePath = __DIR__ . '/../../sis_atividades.csv';
|
||||
|
||||
// If not in module dir, check root
|
||||
if (!file_exists($filePath)) {
|
||||
$filePath = dirname(__DIR__, 4) . '/sis_atividades.csv';
|
||||
}
|
||||
|
||||
if (!file_exists($filePath)) {
|
||||
throw new \Exception("Arquivo sis_atividades.csv não encontrado em: " . $filePath);
|
||||
}
|
||||
|
||||
// Check if data already exists to avoid re-importing and to avoid the InnoDB tablespace error with TRUNCATE
|
||||
$count = Capsule::table('lists_activities')->count();
|
||||
if ($count > 0) {
|
||||
echo "A tabela lists_activities já possui $count registros. Pulando importação do CSV para evitar erros de tablespace.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
$file = fopen($filePath, 'r');
|
||||
if ($file) {
|
||||
while (($line = fgetcsv($file, 0, ';')) !== false || ($line = fgetcsv($file, 0, ',')) !== false) {
|
||||
if (empty($line) || empty($line[0])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$name = $line[0];
|
||||
|
||||
// Fix encoding: Detect if it's not UTF-8 and convert from ISO-8859-1 (common for Brazilian CSVs)
|
||||
if (!mb_check_encoding($name, 'UTF-8')) {
|
||||
$name = mb_convert_encoding($name, 'UTF-8', 'ISO-8859-1');
|
||||
}
|
||||
|
||||
// Additional cleanup for common issues
|
||||
$name = trim($name, '" '); // Remove quotes and spaces
|
||||
$name = str_replace("'água", "água", $name); // Fix specific typo found: "Bombas de 'água"
|
||||
$name = str_replace("Cabeileireiros", "Cabeleireiros", $name); // Fix typo: "Cabeileireiros"
|
||||
|
||||
if (empty($name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Capsule::table('lists_activities')->insert([
|
||||
'activities_name' => $name,
|
||||
'activities_type' => $this->determineType($name),
|
||||
'activities_slug' => $this->slugify($name),
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
fclose($file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine activity type based on name keywords.
|
||||
*/
|
||||
private function determineType($name)
|
||||
{
|
||||
$name = mb_strtolower($name);
|
||||
|
||||
$industrialKeywords = ['indústria', 'fábrica', 'produção', 'metalúrgica', 'têxtil', 'usinagem'];
|
||||
$serviceKeywords = ['serviço', 'conserto', 'manutenção', 'assistência', 'aula', 'consultoria', 'advogado', 'médico', 'clínica', 'hospital', 'escola', 'academia', 'hotel', 'restaurante', 'bar', 'oficina'];
|
||||
|
||||
foreach ($industrialKeywords as $key) {
|
||||
if (str_contains($name, $key)) {
|
||||
return 'industrial';
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($serviceKeywords as $key) {
|
||||
if (str_contains($name, $key)) {
|
||||
return 'service';
|
||||
}
|
||||
}
|
||||
|
||||
return 'commercial'; // Default
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple slugify function.
|
||||
*/
|
||||
private function slugify($text)
|
||||
{
|
||||
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
|
||||
// Fallback for iconv if not available or failing
|
||||
if (function_exists('iconv')) {
|
||||
$text = @iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
}
|
||||
$text = preg_replace('~[^-\w]+~', '', $text);
|
||||
$text = trim($text, '-');
|
||||
$text = preg_replace('~-+~', '-', $text);
|
||||
$text = strtolower($text);
|
||||
if (empty($text)) {
|
||||
return 'n-a';
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
// Re-seed original data if needed, or just leave it empty
|
||||
// Capsule::table('lists_activities')->truncate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* Migration to add locale support (JSON) to countries and activities.
|
||||
*/
|
||||
class UpdateListsForLocales
|
||||
{
|
||||
/**
|
||||
* Run the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Capsule::statement('SET FOREIGN_KEY_CHECKS=0;');
|
||||
|
||||
// 1. Process lists_countries
|
||||
if (Capsule::schema()->hasTable('lists_countries')) {
|
||||
// Save data
|
||||
$countries = Capsule::table('lists_countries')->get();
|
||||
$newCountries = [];
|
||||
foreach ($countries as $country) {
|
||||
$name = $country->countries_name;
|
||||
// Prepare JSON name
|
||||
if ($name && strpos($name, '{') !== 0) {
|
||||
if ($name === 'Brasil' || $country->countries_iso_code === 'BR') {
|
||||
$jsonName = json_encode([
|
||||
'pt_BR' => 'Brasil', 'en_US' => 'Brazil', 'es_ES' => 'Brasil',
|
||||
'de_DE' => 'Brasilien', 'fr_FR' => 'Brésil'
|
||||
]);
|
||||
} else {
|
||||
$jsonName = json_encode(['pt_BR' => $name]);
|
||||
}
|
||||
} else {
|
||||
$jsonName = $name;
|
||||
}
|
||||
|
||||
$newCountries[] = [
|
||||
'countries_id' => $country->countries_id,
|
||||
'countries_name' => $jsonName,
|
||||
'countries_iso_code' => $country->countries_iso_code,
|
||||
'created_at' => $country->created_at,
|
||||
'updated_at' => $country->updated_at
|
||||
];
|
||||
}
|
||||
|
||||
// Recreate table to fix tablespace error
|
||||
Capsule::schema()->dropIfExists('lists_countries');
|
||||
Capsule::schema()->create('lists_countries', function (Blueprint $table) {
|
||||
$table->increments('countries_id');
|
||||
$table->json('countries_name')->nullable();
|
||||
$table->string('countries_iso_code', 2)->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
// Restore data
|
||||
foreach ($newCountries as $cData) {
|
||||
Capsule::table('lists_countries')->insert($cData);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Process lists_activities
|
||||
if (Capsule::schema()->hasTable('lists_activities')) {
|
||||
// Save data
|
||||
$activities = Capsule::table('lists_activities')->get();
|
||||
$newActivities = [];
|
||||
|
||||
// Initial translations for reference
|
||||
$translations = $this->getInitialActivityTranslations();
|
||||
|
||||
foreach ($activities as $activity) {
|
||||
$name = $activity->activities_name;
|
||||
$jsonName = $name;
|
||||
|
||||
if ($name && strpos($name, '{') !== 0) {
|
||||
if (isset($translations[$name])) {
|
||||
$jsonName = json_encode($translations[$name]);
|
||||
} else {
|
||||
$jsonName = json_encode(['pt_BR' => $name]);
|
||||
}
|
||||
}
|
||||
|
||||
$newActivities[] = [
|
||||
'activities_id' => $activity->activities_id,
|
||||
'activities_name' => $jsonName,
|
||||
'activities_type' => $activity->activities_type,
|
||||
'activities_slug' => $activity->activities_slug,
|
||||
'created_at' => $activity->created_at,
|
||||
'updated_at' => $activity->updated_at
|
||||
];
|
||||
}
|
||||
|
||||
// Recreate table to fix tablespace error
|
||||
Capsule::schema()->dropIfExists('lists_activities');
|
||||
Capsule::schema()->create('lists_activities', function (Blueprint $table) {
|
||||
$table->increments('activities_id');
|
||||
$table->json('activities_name')->nullable();
|
||||
$table->string('activities_type', 50)->nullable();
|
||||
$table->string('activities_slug', 150)->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
// Restore data
|
||||
foreach ($newActivities as $aData) {
|
||||
Capsule::table('lists_activities')->insert($aData);
|
||||
}
|
||||
}
|
||||
|
||||
Capsule::statement('SET FOREIGN_KEY_CHECKS=1;');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get initial activity translations.
|
||||
*/
|
||||
private function getInitialActivityTranslations()
|
||||
{
|
||||
return [
|
||||
'Restaurante' => [
|
||||
'pt_BR' => 'Restaurante', 'en_US' => 'Restaurant', 'es_ES' => 'Restaurante', 'de_DE' => 'Restaurant', 'fr_FR' => 'Restaurant'
|
||||
],
|
||||
'Oficina Mecânica' => [
|
||||
'pt_BR' => 'Oficina Mecânica', 'en_US' => 'Mechanical Workshop', 'es_ES' => 'Taller mecánico', 'de_DE' => 'Kfz-Werkstatt', 'fr_FR' => 'Atelier de mécanique'
|
||||
],
|
||||
'Padaria' => [
|
||||
'pt_BR' => 'Padaria', 'en_US' => 'Bakery', 'es_ES' => 'Panadería', 'de_DE' => 'Bäckerei', 'fr_FR' => 'Boulangerie'
|
||||
],
|
||||
'Supermercado' => [
|
||||
'pt_BR' => 'Supermercado', 'en_US' => 'Supermarket', 'es_ES' => 'Supermercado', 'de_DE' => 'Supermarkt', 'fr_FR' => 'Supermarché'
|
||||
],
|
||||
'Farmácia' => [
|
||||
'pt_BR' => 'Farmácia', 'en_US' => 'Pharmacy', 'es_ES' => 'Farmacia', 'de_DE' => 'Apotheke', 'fr_FR' => 'Pharmacie'
|
||||
],
|
||||
'Loja de Roupas' => [
|
||||
'pt_BR' => 'Loja de Roupas', 'en_US' => 'Clothing Store', 'es_ES' => 'Tienda de ropa', 'de_DE' => 'Bekleidungsgeschäft', 'fr_FR' => 'Magasin de vêtements'
|
||||
],
|
||||
'Salão de Beleza' => [
|
||||
'pt_BR' => 'Salão de Beleza', 'en_US' => 'Beauty Salon', 'es_ES' => 'Salón de beleza', 'de_DE' => 'Schönheitssalon', 'fr_FR' => 'Salon de beauté'
|
||||
],
|
||||
'Academia' => [
|
||||
'pt_BR' => 'Academia', 'en_US' => 'Gym', 'es_ES' => 'Gimnasio', 'de_DE' => 'Fitnessstudio', 'fr_FR' => 'Salle de sport'
|
||||
],
|
||||
'Escola' => [
|
||||
'pt_BR' => 'Escola', 'en_US' => 'School', 'es_ES' => 'Escuela', 'de_DE' => 'Schule', 'fr_FR' => 'École'
|
||||
],
|
||||
'Clínica Médica' => [
|
||||
'pt_BR' => 'Clínica Médica', 'en_US' => 'Medical Clinic', 'es_ES' => 'Clínica médica', 'de_DE' => 'Medizinische Klinik', 'fr_FR' => 'Clinique médicale'
|
||||
],
|
||||
'Indústria Metalúrgica' => [
|
||||
'pt_BR' => 'Indústria Metalúrgica', 'en_US' => 'Metallurgical Industry', 'es_ES' => 'Industria metalúrgica', 'de_DE' => 'Metallurgische Industrie', 'fr_FR' => 'Industrie métallurgique'
|
||||
],
|
||||
'Indústria Têxtil' => [
|
||||
'pt_BR' => 'Indústria Têxtil', 'en_US' => 'Textile Industry', 'es_ES' => 'Industria textil', 'de_DE' => 'Textilindustrie', 'fr_FR' => 'Industrie textile'
|
||||
],
|
||||
'Contabilidade' => [
|
||||
'pt_BR' => 'Contabilidade', 'en_US' => 'Accounting', 'es_ES' => 'Contabilidad', 'de_DE' => 'Buchhaltung', 'fr_FR' => 'Comptabilidade'
|
||||
],
|
||||
'Advocacia' => [
|
||||
'pt_BR' => 'Advocacia', 'en_US' => 'Law Firm', 'es_ES' => 'Abogacía', 'de_DE' => 'Anwaltskanzlei', 'fr_FR' => 'Cabinet d\'avocats'
|
||||
],
|
||||
'Imobiliária' => [
|
||||
'pt_BR' => 'Imobiliária', 'en_US' => 'Real Estate', 'es_ES' => 'Inmobiliaria', 'de_DE' => 'Immobilienagentur', 'fr_FR' => 'Agence immobilière'
|
||||
],
|
||||
'Pet Shop' => [
|
||||
'pt_BR' => 'Pet Shop', 'en_US' => 'Pet Shop', 'es_ES' => 'Tienda de mascotas', 'de_DE' => 'Zoofachgeschäft', 'fr_FR' => 'Animalerie'
|
||||
],
|
||||
'Livraria' => [
|
||||
'pt_BR' => 'Livraria', 'en_US' => 'Bookstore', 'es_ES' => 'Librería', 'de_DE' => 'Buchhandlung', 'fr_FR' => 'Librairie'
|
||||
],
|
||||
'Ótica' => [
|
||||
'pt_BR' => 'Ótica', 'en_US' => 'Optician', 'es_ES' => 'Óptica', 'de_DE' => 'Optiker', 'fr_FR' => 'Opticien'
|
||||
],
|
||||
'Joalheria' => [
|
||||
'pt_BR' => 'Joalheria', 'en_US' => 'Jewelry Store', 'es_ES' => 'Joyería', 'de_DE' => 'Juweliergeschäft', 'fr_FR' => 'Bijouterie'
|
||||
],
|
||||
'Hotelaria' => [
|
||||
'pt_BR' => 'Hotelaria', 'en_US' => 'Hospitality', 'es_ES' => 'Hostelería', 'de_DE' => 'Hotellerie', 'fr_FR' => 'Hôtellerie'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
if (Capsule::schema()->hasTable('lists_countries')) {
|
||||
Capsule::schema()->table('lists_countries', function (Blueprint $table) {
|
||||
$table->string('countries_name', 100)->nullable()->change();
|
||||
});
|
||||
}
|
||||
|
||||
if (Capsule::schema()->hasTable('lists_activities')) {
|
||||
Capsule::schema()->table('lists_activities', function (Blueprint $table) {
|
||||
$table->string('activities_name', 150)->nullable()->change();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use App\Models\Module;
|
||||
use Modules\Company\Models\Company;
|
||||
|
||||
/**
|
||||
* Migration to register the Lists module in the system.
|
||||
*/
|
||||
class InsertListsModuleRecord
|
||||
{
|
||||
/**
|
||||
* Run the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$moduleData = [
|
||||
'modules_name' => 'globallists',
|
||||
'modules_display_name' => 'Listas Globais',
|
||||
'modules_description' => 'Módulo para gerenciamento de listas globais do sistema, como países, estados, cidades e atividades.',
|
||||
'modules_version' => '1.0.0',
|
||||
'modules_author' => 'SysCMS',
|
||||
'modules_ative' => true,
|
||||
'modules_public' => false,
|
||||
'modules_blocked' => false,
|
||||
'modules_dependencies' => [],
|
||||
'modules_permissions' => [
|
||||
'globallists.view',
|
||||
'globallists.create',
|
||||
'globallists.edit',
|
||||
'globallists.delete',
|
||||
'globallists.admin'
|
||||
],
|
||||
'modules_settings' => [
|
||||
'menu' => [
|
||||
[
|
||||
'label' => 'Listas Globais',
|
||||
'icon' => 'bi-list-ul',
|
||||
'url' => '/admin/globallists',
|
||||
'permission' => 'globallists.view',
|
||||
'submenu' => [
|
||||
[
|
||||
'label' => 'Atividades',
|
||||
'url' => '/admin/globallists/activities',
|
||||
'permission' => 'globallists.view'
|
||||
],
|
||||
[
|
||||
'label' => 'Países',
|
||||
'url' => '/admin/globallists/countries',
|
||||
'permission' => 'globallists.view'
|
||||
],
|
||||
[
|
||||
'label' => 'Estados',
|
||||
'url' => '/admin/globallists/states',
|
||||
'permission' => 'globallists.view'
|
||||
],
|
||||
[
|
||||
'label' => 'Cidades',
|
||||
'url' => '/admin/globallists/cities',
|
||||
'permission' => 'globallists.view'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'modules_path' => 'modules/globallists',
|
||||
'modules_namespace' => 'Modules\\GlobalLists',
|
||||
'modules_icon' => 'bi-list-ul',
|
||||
'menu_side_bar' => true,
|
||||
'menu_nav_bar' => false,
|
||||
'modules_order' => 10,
|
||||
'modules_install_date' => date('Y-m-d H:i:s'),
|
||||
'modules_update_date' => date('Y-m-d H:i:s')
|
||||
];
|
||||
|
||||
// Check if module already exists
|
||||
$existingModule = Module::where('modules_name', 'globallists')->first();
|
||||
|
||||
if (!$existingModule) {
|
||||
$module = Module::create($moduleData);
|
||||
|
||||
// Associate with all existing companies (bus_modules)
|
||||
if (Capsule::schema()->hasTable('bus')) {
|
||||
$companies = Company::all();
|
||||
foreach ($companies as $company) {
|
||||
// Check if already associated
|
||||
$exists = Capsule::table('bus_modules')
|
||||
->where('bus_modules_bus_id', $company->bus_id)
|
||||
->where('bus_modules_module_id', $module->modules_id)
|
||||
->exists();
|
||||
|
||||
if (!$exists) {
|
||||
Capsule::table('bus_modules')->insert([
|
||||
'bus_modules_bus_id' => $company->bus_id,
|
||||
'bus_modules_module_id' => $module->modules_id,
|
||||
'bus_modules_is_enabled' => true,
|
||||
'bus_modules_settings' => json_encode([]),
|
||||
'bus_modules_enabled_by' => 1, // System
|
||||
'bus_modules_enabled_at' => date('Y-m-d H:i:s'),
|
||||
'bus_modules_show_public_nav' => false,
|
||||
'bus_modules_show_dashboard_nav' => true,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Update existing record
|
||||
$existingModule->update([
|
||||
'modules_display_name' => 'Listas do Sistema',
|
||||
'modules_description' => 'Módulo para gerenciamento de listas globais do sistema, como países, estados, cidades e atividades.',
|
||||
'modules_permissions' => $moduleData['modules_permissions'],
|
||||
'modules_settings' => $moduleData['modules_settings'],
|
||||
'modules_icon' => 'bi-list-ul',
|
||||
'modules_update_date' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$module = Module::where('modules_name', 'lists')->first();
|
||||
if ($module) {
|
||||
// Remove associations
|
||||
Capsule::table('bus_modules')->where('bus_modules_module_id', $module->modules_id)->delete();
|
||||
// Remove module
|
||||
$module->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
/**
|
||||
* Migration to import Paraguay countries, states and cities from CSV.
|
||||
*/
|
||||
class ImportParaguayData
|
||||
{
|
||||
/**
|
||||
* Run the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// 1. Ensure Paraguay exists in lists_countries
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'PY')->value('countries_id');
|
||||
|
||||
if (!$countryId) {
|
||||
$countryId = Capsule::table('lists_countries')->insertGetId([
|
||||
'countries_name' => json_encode([
|
||||
'pt_BR' => 'Paraguai',
|
||||
'en_US' => 'Paraguay',
|
||||
'es_ES' => 'Paraguay',
|
||||
'de_DE' => 'Paraguay',
|
||||
'fr_FR' => 'Paraguay'
|
||||
]),
|
||||
'countries_iso_code' => 'PY',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
// 2. Path to CSV file
|
||||
$csvFile = __DIR__ . '/../../../../Distritos_Paraguay_Codigos_DGEEC.csv';
|
||||
|
||||
if (!file_exists($csvFile)) {
|
||||
// Fallback for different execution contexts
|
||||
$csvFile = 'Distritos_Paraguay_Codigos_DGEEC.csv';
|
||||
}
|
||||
|
||||
if (file_exists($csvFile)) {
|
||||
$handle = fopen($csvFile, 'r');
|
||||
if ($handle !== false) {
|
||||
// Skip header
|
||||
fgetcsv($handle, 0, ';');
|
||||
|
||||
$states = []; // Cache for state IDs
|
||||
|
||||
while (($row = fgetcsv($handle, 0, ';')) !== false) {
|
||||
if (count($row) < 5) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Clean and encode data
|
||||
$deptCode = trim($row[1]);
|
||||
$deptName = $this->cleanString($row[2]);
|
||||
$distCode = trim($row[3]);
|
||||
$distName = $this->cleanString($row[4]);
|
||||
|
||||
if (empty($deptName) || empty($distName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 3. Ensure State (Department) exists
|
||||
$stateKey = 'PY-' . $deptCode;
|
||||
if (!isset($states[$stateKey])) {
|
||||
$stateId = Capsule::table('lists_states')
|
||||
->where('states_country_id', $countryId)
|
||||
->where('states_uf', str_pad($deptCode, 2, '0', STR_PAD_LEFT))
|
||||
->value('states_id');
|
||||
|
||||
if (!$stateId) {
|
||||
$stateId = Capsule::table('lists_states')->insertGetId([
|
||||
'states_country_id' => $countryId,
|
||||
'states_name' => $deptName,
|
||||
'states_uf' => str_pad($deptCode, 2, '0', STR_PAD_LEFT),
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
$states[$stateKey] = $stateId;
|
||||
}
|
||||
|
||||
$stateId = $states[$stateKey];
|
||||
|
||||
// 4. Ensure City (District) exists
|
||||
$cityExists = Capsule::table('lists_cities')
|
||||
->where('cities_state_id', $stateId)
|
||||
->where('cities_name', $distName)
|
||||
->exists();
|
||||
|
||||
if (!$cityExists) {
|
||||
Capsule::table('lists_cities')->insert([
|
||||
'cities_state_id' => $stateId,
|
||||
'cities_name' => $distName,
|
||||
'cities_slug' => $this->slugify($distName),
|
||||
'cities_ibge_code' => $deptCode . str_pad($distCode, 3, '0', STR_PAD_LEFT),
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
fclose($handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean and convert string encoding if needed.
|
||||
*
|
||||
* @param string $str
|
||||
* @return string
|
||||
*/
|
||||
private function cleanString($str)
|
||||
{
|
||||
$str = trim($str);
|
||||
if (empty($str)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Detect if it's not UTF-8 and convert from ISO-8859-1
|
||||
if (!mb_check_encoding($str, 'UTF-8')) {
|
||||
$str = mb_convert_encoding($str, 'UTF-8', 'ISO-8859-1');
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple slugify helper.
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
private function slugify($text)
|
||||
{
|
||||
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
|
||||
if (function_exists('iconv')) {
|
||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
}
|
||||
$text = preg_replace('~[^-\w]+~', '', $text);
|
||||
$text = trim($text, '-');
|
||||
$text = preg_replace('~-+~', '-', $text);
|
||||
$text = strtolower($text);
|
||||
return empty($text) ? 'n-a' : $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'PY')->value('countries_id');
|
||||
if ($countryId) {
|
||||
// This will cascade delete states and cities due to foreign key constraints
|
||||
Capsule::table('lists_countries')->where('countries_id', $countryId)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
/**
|
||||
* Migration to import Argentina countries, states and cities.
|
||||
*/
|
||||
class ImportArgentinaData
|
||||
{
|
||||
/**
|
||||
* Run the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// 1. Ensure Argentina exists in lists_countries
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'AR')->value('countries_id');
|
||||
|
||||
if (!$countryId) {
|
||||
$countryId = Capsule::table('lists_countries')->insertGetId([
|
||||
'countries_name' => json_encode([
|
||||
'pt_BR' => 'Argentina',
|
||||
'en_US' => 'Argentina',
|
||||
'es_ES' => 'Argentina',
|
||||
'de_DE' => 'Argentinien',
|
||||
'fr_FR' => 'Argentine'
|
||||
]),
|
||||
'countries_iso_code' => 'AR',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
// 2. Argentina Provinces (States)
|
||||
$provinces = [
|
||||
['name' => 'Buenos Aires', 'uf' => 'BA'],
|
||||
['name' => 'Ciudad Autónoma de Buenos Aires', 'uf' => 'CABA'],
|
||||
['name' => 'Catamarca', 'uf' => 'CT'],
|
||||
['name' => 'Chaco', 'uf' => 'CH'],
|
||||
['name' => 'Chubut', 'uf' => 'CB'],
|
||||
['name' => 'Córdoba', 'uf' => 'CD'],
|
||||
['name' => 'Corrientes', 'uf' => 'CR'],
|
||||
['name' => 'Entre Ríos', 'uf' => 'ER'],
|
||||
['name' => 'Formosa', 'uf' => 'FO'],
|
||||
['name' => 'Jujuy', 'uf' => 'JY'],
|
||||
['name' => 'La Pampa', 'uf' => 'LP'],
|
||||
['name' => 'La Rioja', 'uf' => 'LR'],
|
||||
['name' => 'Mendoza', 'uf' => 'MZ'],
|
||||
['name' => 'Misiones', 'uf' => 'MN'],
|
||||
['name' => 'Neuquén', 'uf' => 'NQ'],
|
||||
['name' => 'Río Negro', 'uf' => 'RN'],
|
||||
['name' => 'Salta', 'uf' => 'SA'],
|
||||
['name' => 'San Juan', 'uf' => 'SJ'],
|
||||
['name' => 'San Luis', 'uf' => 'SL'],
|
||||
['name' => 'Santa Cruz', 'uf' => 'SC'],
|
||||
['name' => 'Santa Fe', 'uf' => 'SF'],
|
||||
['name' => 'Santiago del Estero', 'uf' => 'SE'],
|
||||
['name' => 'Tierra del Fuego', 'uf' => 'TF'],
|
||||
['name' => 'Tucumán', 'uf' => 'TM'],
|
||||
];
|
||||
|
||||
$stateIds = [];
|
||||
foreach ($provinces as $prov) {
|
||||
$stateId = Capsule::table('lists_states')
|
||||
->where('states_country_id', $countryId)
|
||||
->where('states_uf', $prov['uf'])
|
||||
->value('states_id');
|
||||
|
||||
if (!$stateId) {
|
||||
$stateId = Capsule::table('lists_states')->insertGetId([
|
||||
'states_country_id' => $countryId,
|
||||
'states_name' => $prov['name'],
|
||||
'states_uf' => $prov['uf'],
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
$stateIds[$prov['name']] = $stateId;
|
||||
}
|
||||
|
||||
// 3. Principal Cities by Province
|
||||
$cities = [
|
||||
'Buenos Aires' => ['La Plata', 'Mar del Plata', 'Bahía Blanca', 'Lanús', 'Quilmes', 'Pilar', 'Luján', 'Tandil', 'San Nicolás', 'Zárate'],
|
||||
'Ciudad Autónoma de Buenos Aires' => ['Buenos Aires'],
|
||||
'Catamarca' => ['San Fernando del Valle de Catamarca', 'Andalgalá', 'Belén'],
|
||||
'Chaco' => ['Resistencia', 'Presidencia Roque Sáenz Peña', 'Villa Ángela'],
|
||||
'Chubut' => ['Rawson', 'Comodoro Rivadavia', 'Trelew', 'Puerto Madryn', 'Esquel'],
|
||||
'Córdoba' => ['Córdoba', 'Río Cuarto', 'Villa María', 'Villa Carlos Paz', 'San Francisco', 'Alta Gracia'],
|
||||
'Corrientes' => ['Corrientes', 'Goya', 'Paso de los Libres', 'Curuzú Cuatiá'],
|
||||
'Entre Ríos' => ['Paraná', 'Concordia', 'Gualeguaychú', 'Concepción del Uruguay'],
|
||||
'Formosa' => ['Formosa', 'Clorinda', 'Pirané'],
|
||||
'Jujuy' => ['San Salvador de Jujuy', 'San Pedro de Jujuy', 'Palpalá'],
|
||||
'La Pampa' => ['Santa Rosa', 'General Pico'],
|
||||
'La Rioja' => ['La Rioja', 'Chilecito'],
|
||||
'Mendoza' => ['Mendoza', 'San Rafael', 'Godoy Cruz', 'Guaymallén', 'Luján de Cuyo', 'Maipú'],
|
||||
'Misiones' => ['Posadas', 'Eldorado', 'Oberá', 'Puerto Iguazú'],
|
||||
'Neuquén' => ['Neuquén', 'Cutral Có', 'Centenario', 'Plottier', 'San Martín de los Andes'],
|
||||
'Río Negro' => ['Viedma', 'San Carlos de Bariloche', 'General Roca', 'Cipolletti'],
|
||||
'Salta' => ['Salta', 'San Ramón de la Nueva Orán', 'Tartagal', 'General Güemes'],
|
||||
'San Juan' => ['San Juan', 'Rawson', 'Rivadavia', 'Chimbas'],
|
||||
'San Luis' => ['San Luis', 'Villa Mercedes', 'Merlo'],
|
||||
'Santa Cruz' => ['Río Gallegos', 'Caleta Olivia', 'El Calafate'],
|
||||
'Santa Fe' => ['Santa Fe', 'Rosario', 'Rafaela', 'Venado Tuerto', 'Reconquista', 'Santo Tomé'],
|
||||
'Santiago del Estero' => ['Santiago del Estero', 'La Banda', 'Termas de Río Hondo'],
|
||||
'Tierra del Fuego' => ['Ushuaia', 'Río Grande', 'Tolhuin'],
|
||||
'Tucumán' => ['San Miguel de Tucumán', 'Yerba Buena', 'Tafí Viejo', 'Concepción'],
|
||||
];
|
||||
|
||||
foreach ($cities as $provinceName => $provinceCities) {
|
||||
if (!isset($stateIds[$provinceName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$stateId = $stateIds[$provinceName];
|
||||
|
||||
foreach ($provinceCities as $cityName) {
|
||||
$cityExists = Capsule::table('lists_cities')
|
||||
->where('cities_state_id', $stateId)
|
||||
->where('cities_name', $cityName)
|
||||
->exists();
|
||||
|
||||
if (!$cityExists) {
|
||||
Capsule::table('lists_cities')->insert([
|
||||
'cities_state_id' => $stateId,
|
||||
'cities_name' => $cityName,
|
||||
'cities_slug' => $this->slugify($cityName),
|
||||
'cities_ibge_code' => null, // Argentina uses different codes, leaving null for now
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple slugify helper.
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
private function slugify($text)
|
||||
{
|
||||
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
|
||||
if (function_exists('iconv')) {
|
||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
}
|
||||
$text = preg_replace('~[^-\w]+~', '', $text);
|
||||
$text = trim($text, '-');
|
||||
$text = preg_replace('~-+~', '-', $text);
|
||||
$text = strtolower($text);
|
||||
return empty($text) ? 'n-a' : $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'AR')->value('countries_id');
|
||||
if ($countryId) {
|
||||
// This will cascade delete states and cities due to foreign key constraints
|
||||
Capsule::table('lists_countries')->where('countries_id', $countryId)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
/**
|
||||
* Migration to import all South American countries, states and cities.
|
||||
*/
|
||||
class ImportSouthAmericaData
|
||||
{
|
||||
/**
|
||||
* Run the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$countries = [
|
||||
'BO' => [
|
||||
'names' => ['pt_BR' => 'Bolívia', 'en_US' => 'Bolivia', 'es_ES' => 'Bolivia', 'de_DE' => 'Bolivien', 'fr_FR' => 'Bolivie'],
|
||||
'states' => [
|
||||
['name' => 'Beni', 'uf' => 'BN', 'cities' => ['Trinidad', 'Riberalta', 'Guayaramerín']],
|
||||
['name' => 'Chuquisaca', 'uf' => 'CH', 'cities' => ['Sucre', 'Camargo', 'Monteagudo']],
|
||||
['name' => 'Cochabamba', 'uf' => 'CB', 'cities' => ['Cochabamba', 'Quillacollo', 'Sacaba']],
|
||||
['name' => 'La Paz', 'uf' => 'LP', 'cities' => ['La Paz', 'El Alto', 'Viacha']],
|
||||
['name' => 'Oruro', 'uf' => 'OR', 'cities' => ['Oruro', 'Huanuni', 'Challapata']],
|
||||
['name' => 'Pando', 'uf' => 'PN', 'cities' => ['Cobija', 'Porvenir']],
|
||||
['name' => 'Potosí', 'uf' => 'PT', 'cities' => ['Potosí', 'Uyuni', 'Tupiza']],
|
||||
['name' => 'Santa Cruz', 'uf' => 'SC', 'cities' => ['Santa Cruz de la Sierra', 'Montero', 'Warnes']],
|
||||
['name' => 'Tarija', 'uf' => 'TJ', 'cities' => ['Tarija', 'Yacuiba', 'Bermejo']],
|
||||
]
|
||||
],
|
||||
'CL' => [
|
||||
'names' => ['pt_BR' => 'Chile', 'en_US' => 'Chile', 'es_ES' => 'Chile', 'de_DE' => 'Chile', 'fr_FR' => 'Chili'],
|
||||
'states' => [
|
||||
['name' => 'Metropolitana de Santiago', 'uf' => 'RM', 'cities' => ['Santiago', 'Puente Alto', 'Maipú']],
|
||||
['name' => 'Valparaíso', 'uf' => 'VS', 'cities' => ['Valparaíso', 'Viña del Mar', 'Quilpué']],
|
||||
['name' => 'Biobío', 'uf' => 'BI', 'cities' => ['Concepción', 'Talcahuano', 'Los Ángeles']],
|
||||
['name' => 'Antofagasta', 'uf' => 'AN', 'cities' => ['Antofagasta', 'Calama', 'Tocopilla']],
|
||||
['name' => 'Coquimbo', 'uf' => 'CO', 'cities' => ['La Serena', 'Coquimbo', 'Ovalle']],
|
||||
['name' => 'Araucanía', 'uf' => 'AR', 'cities' => ['Temuco', 'Villarrica', 'Angol']],
|
||||
['name' => 'Tarapacá', 'uf' => 'TA', 'cities' => ['Iquique', 'Alto Hospicio']],
|
||||
['name' => 'Maule', 'uf' => 'MA', 'cities' => ['Talca', 'Curicó', 'Linares']],
|
||||
['name' => 'Los Lagos', 'uf' => 'LL', 'cities' => ['Puerto Montt', 'Osorno', 'Castro']],
|
||||
]
|
||||
],
|
||||
'CO' => [
|
||||
'names' => ['pt_BR' => 'Colômbia', 'en_US' => 'Colombia', 'es_ES' => 'Colombia', 'de_DE' => 'Kolumbien', 'fr_FR' => 'Colombie'],
|
||||
'states' => [
|
||||
['name' => 'Cundinamarca', 'uf' => 'CU', 'cities' => ['Bogotá', 'Soacha', 'Facatativá']],
|
||||
['name' => 'Antioquia', 'uf' => 'AN', 'cities' => ['Medellín', 'Bello', 'Itagüí']],
|
||||
['name' => 'Valle del Cauca', 'uf' => 'VC', 'cities' => ['Cali', 'Buenaventura', 'Palmira']],
|
||||
['name' => 'Atlántico', 'uf' => 'AT', 'cities' => ['Barranquilla', 'Soledad', 'Malambo']],
|
||||
['name' => 'Bolívar', 'uf' => 'BL', 'cities' => ['Cartagena', 'Magangué', 'Turbaco']],
|
||||
['name' => 'Santander', 'uf' => 'ST', 'cities' => ['Bucaramanga', 'Floridablanca', 'Barrancabermeja']],
|
||||
['name' => 'Magdalena', 'uf' => 'MG', 'cities' => ['Santa Marta', 'Ciénaga']],
|
||||
['name' => 'Risaralda', 'uf' => 'RI', 'cities' => ['Pereira', 'Dosquebradas']],
|
||||
['name' => 'Tolima', 'uf' => 'TO', 'cities' => ['Ibagué', 'Espinal']],
|
||||
]
|
||||
],
|
||||
'EC' => [
|
||||
'names' => ['pt_BR' => 'Equador', 'en_US' => 'Ecuador', 'es_ES' => 'Ecuador', 'de_DE' => 'Ecuador', 'fr_FR' => 'Équateur'],
|
||||
'states' => [
|
||||
['name' => 'Pichincha', 'uf' => 'PI', 'cities' => ['Quito', 'Sangolquí', 'Machachi']],
|
||||
['name' => 'Guayas', 'uf' => 'GU', 'cities' => ['Guayaquil', 'Durán', 'Milagro']],
|
||||
['name' => 'Azuay', 'uf' => 'AZ', 'cities' => ['Cuenca', 'Gualaceo']],
|
||||
['name' => 'Manabí', 'uf' => 'MA', 'cities' => ['Portoviejo', 'Manta', 'Chone']],
|
||||
['name' => 'Tungurahua', 'uf' => 'TU', 'cities' => ['Ambato', 'Baños']],
|
||||
['name' => 'El Oro', 'uf' => 'EO', 'cities' => ['Machala', 'Pasaje', 'Santa Rosa']],
|
||||
['name' => 'Loja', 'uf' => 'LO', 'cities' => ['Loja', 'Catamayo']],
|
||||
['name' => 'Santo Domingo', 'uf' => 'SD', 'cities' => ['Santo Domingo']],
|
||||
['name' => 'Esmeraldas', 'uf' => 'ES', 'cities' => ['Esmeraldas', 'Quinindé']],
|
||||
]
|
||||
],
|
||||
'PE' => [
|
||||
'names' => ['pt_BR' => 'Peru', 'en_US' => 'Peru', 'es_ES' => 'Perú', 'de_DE' => 'Peru', 'fr_FR' => 'Pérou'],
|
||||
'states' => [
|
||||
['name' => 'Lima', 'uf' => 'LM', 'cities' => ['Lima', 'Callao', 'Huacho']],
|
||||
['name' => 'Arequipa', 'uf' => 'AR', 'cities' => ['Arequipa', 'Mollendo', 'Camaná']],
|
||||
['name' => 'La Libertad', 'uf' => 'LL', 'cities' => ['Trujillo', 'Chimbote', 'Huamachuco']],
|
||||
['name' => 'Lambayeque', 'uf' => 'LB', 'cities' => ['Chiclayo', 'Lambayeque']],
|
||||
['name' => 'Piura', 'uf' => 'PI', 'cities' => ['Piura', 'Sullana', 'Paita']],
|
||||
['name' => 'Loreto', 'uf' => 'LO', 'cities' => ['Iquitos', 'Yurimaguas']],
|
||||
['name' => 'Cusco', 'uf' => 'CU', 'cities' => ['Cusco', 'Sicuani', 'Quillabamba']],
|
||||
['name' => 'Junín', 'uf' => 'JU', 'cities' => ['Huancayo', 'Tarma', 'Jauja']],
|
||||
['name' => 'Puno', 'uf' => 'PU', 'cities' => ['Puno', 'Juliaca']],
|
||||
]
|
||||
],
|
||||
'UY' => [
|
||||
'names' => ['pt_BR' => 'Uruguai', 'en_US' => 'Uruguay', 'es_ES' => 'Uruguay', 'de_DE' => 'Uruguay', 'fr_FR' => 'Uruguay'],
|
||||
'states' => [
|
||||
['name' => 'Montevideo', 'uf' => 'MO', 'cities' => ['Montevideo']],
|
||||
['name' => 'Canelones', 'uf' => 'CA', 'cities' => ['Canelones', 'Las Piedras', 'Ciudad de la Costa']],
|
||||
['name' => 'Maldonado', 'uf' => 'MA', 'cities' => ['Maldonado', 'Punta del Este', 'San Carlos']],
|
||||
['name' => 'Salto', 'uf' => 'SA', 'cities' => ['Salto']],
|
||||
['name' => 'Paysandú', 'uf' => 'PA', 'cities' => ['Paysandú']],
|
||||
['name' => 'Rivera', 'uf' => 'RI', 'cities' => ['Rivera']],
|
||||
['name' => 'Tacuarembó', 'uf' => 'TA', 'cities' => ['Tacuarembó']],
|
||||
['name' => 'Colonia', 'uf' => 'CO', 'cities' => ['Colonia del Sacramento', 'Carmelo']],
|
||||
['name' => 'Rocha', 'uf' => 'RO', 'cities' => ['Rocha', 'Chuy']],
|
||||
]
|
||||
],
|
||||
'VE' => [
|
||||
'names' => ['pt_BR' => 'Venezuela', 'en_US' => 'Venezuela', 'es_ES' => 'Venezuela', 'de_DE' => 'Venezuela', 'fr_FR' => 'Venezuela'],
|
||||
'states' => [
|
||||
['name' => 'Distrito Capital', 'uf' => 'DC', 'cities' => ['Caracas']],
|
||||
['name' => 'Zulia', 'uf' => 'ZU', 'cities' => ['Maracaibo', 'Cabimas', 'Ciudad Ojeda']],
|
||||
['name' => 'Carabobo', 'uf' => 'CA', 'cities' => ['Valencia', 'Puerto Cabello', 'Guacara']],
|
||||
['name' => 'Lara', 'uf' => 'LA', 'cities' => ['Barquisimeto', 'Cabudare', 'Carora']],
|
||||
['name' => 'Aragua', 'uf' => 'AR', 'cities' => ['Maracay', 'Turmero', 'La Victoria']],
|
||||
['name' => 'Bolívar', 'uf' => 'BO', 'cities' => ['Ciudad Guayana', 'Ciudad Bolívar']],
|
||||
['name' => 'Anzoátegui', 'uf' => 'AN', 'cities' => ['Barcelona', 'Puerto La Cruz', 'El Tigre']],
|
||||
['name' => 'Miranda', 'uf' => 'MI', 'cities' => ['Los Teques', 'Santa Teresa del Tuy']],
|
||||
['name' => 'Táchira', 'uf' => 'TA', 'cities' => ['San Cristóbal', 'Táriba']],
|
||||
]
|
||||
],
|
||||
'GY' => [
|
||||
'names' => ['pt_BR' => 'Guiana', 'en_US' => 'Guyana', 'es_ES' => 'Guyana', 'de_DE' => 'Guyana', 'fr_FR' => 'Guyana'],
|
||||
'states' => [
|
||||
['name' => 'Demerara-Mahaica', 'uf' => '04', 'cities' => ['Georgetown']],
|
||||
['name' => 'Upper Demerara-Berbice', 'uf' => '10', 'cities' => ['Linden']],
|
||||
['name' => 'East Berbice-Corentyne', 'uf' => '06', 'cities' => ['New Amsterdam']],
|
||||
]
|
||||
],
|
||||
'SR' => [
|
||||
'names' => ['pt_BR' => 'Suriname', 'en_US' => 'Suriname', 'es_ES' => 'Suriname', 'de_DE' => 'Suriname', 'fr_FR' => 'Suriname'],
|
||||
'states' => [
|
||||
['name' => 'Paramaribo', 'uf' => 'PM', 'cities' => ['Paramaribo']],
|
||||
['name' => 'Wanica', 'uf' => 'WA', 'cities' => ['Lelydorp']],
|
||||
['name' => 'Nickerie', 'uf' => 'NI', 'cities' => ['Nieuw Nickerie']],
|
||||
]
|
||||
],
|
||||
'GF' => [
|
||||
'names' => ['pt_BR' => 'Guiana Francesa', 'en_US' => 'French Guiana', 'es_ES' => 'Guayana Francesa', 'de_DE' => 'Französisch-Guayana', 'fr_FR' => 'Guyane française'],
|
||||
'states' => [
|
||||
['name' => 'Cayenne', 'uf' => 'CY', 'cities' => ['Cayenne', 'Matoury', 'Remire-Montjoly']],
|
||||
['name' => 'Saint-Laurent-du-Maroni', 'uf' => 'SL', 'cities' => ['Saint-Laurent-du-Maroni', 'Kourou']],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
foreach ($countries as $iso => $data) {
|
||||
// 1. Ensure Country exists
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', $iso)->value('countries_id');
|
||||
|
||||
if (!$countryId) {
|
||||
$countryId = Capsule::table('lists_countries')->insertGetId([
|
||||
'countries_name' => json_encode($data['names']),
|
||||
'countries_iso_code' => $iso,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
// 2. States and Cities
|
||||
foreach ($data['states'] as $stateData) {
|
||||
$stateId = Capsule::table('lists_states')
|
||||
->where('states_country_id', $countryId)
|
||||
->where('states_uf', $stateData['uf'])
|
||||
->value('states_id');
|
||||
|
||||
if (!$stateId) {
|
||||
$stateId = Capsule::table('lists_states')->insertGetId([
|
||||
'states_country_id' => $countryId,
|
||||
'states_name' => $stateData['name'],
|
||||
'states_uf' => $stateData['uf'],
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($stateData['cities'] as $cityName) {
|
||||
$cityExists = Capsule::table('lists_cities')
|
||||
->where('cities_state_id', $stateId)
|
||||
->where('cities_name', $cityName)
|
||||
->exists();
|
||||
|
||||
if (!$cityExists) {
|
||||
Capsule::table('lists_cities')->insert([
|
||||
'cities_state_id' => $stateId,
|
||||
'cities_name' => $cityName,
|
||||
'cities_slug' => $this->slugify($cityName),
|
||||
'cities_ibge_code' => null,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple slugify helper.
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
private function slugify($text)
|
||||
{
|
||||
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
|
||||
if (function_exists('iconv')) {
|
||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
}
|
||||
$text = preg_replace('~[^-\w]+~', '', $text);
|
||||
$text = trim($text, '-');
|
||||
$text = preg_replace('~-+~', '-', $text);
|
||||
$text = strtolower($text);
|
||||
return empty($text) ? 'n-a' : $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$isos = ['BO', 'CL', 'CO', 'EC', 'PE', 'UY', 'VE', 'GY', 'SR', 'GF'];
|
||||
Capsule::table('lists_countries')->whereIn('countries_iso_code', $isos)->delete();
|
||||
}
|
||||
}
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
/**
|
||||
* Migration to import detailed Bolivia departments and municipalities.
|
||||
*/
|
||||
class ImportBoliviaDetailedData
|
||||
{
|
||||
/**
|
||||
* Run the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// 1. Ensure Bolivia exists in lists_countries
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'BO')->value('countries_id');
|
||||
|
||||
if (!$countryId) {
|
||||
$countryId = Capsule::table('lists_countries')->insertGetId([
|
||||
'countries_name' => json_encode([
|
||||
'pt_BR' => 'Bolívia',
|
||||
'en_US' => 'Bolivia',
|
||||
'es_ES' => 'Bolivia',
|
||||
'de_DE' => 'Bolivien',
|
||||
'fr_FR' => 'Bolivie'
|
||||
]),
|
||||
'countries_iso_code' => 'BO',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
// 2. Bolivia Departments (States) with their Municipalities (Cities)
|
||||
$departments = [
|
||||
'Beni' => [
|
||||
'uf' => 'BN',
|
||||
'cities' => ['Trinidad', 'Riberalta', 'Guayaramerín', 'Reyes', 'San Borja', 'Santa Ana del Yacuma', 'San Ignacio de Moxos', 'Loreto', 'San Javier', 'Baures', 'Huacaraje', 'Magdalena', 'Exaltación', 'San Ramón', 'San Joaquín', 'Puerto Siles', 'Santa Rosa', 'Rurrenabaque', 'San Andrés']
|
||||
],
|
||||
'Chuquisaca' => [
|
||||
'uf' => 'CH',
|
||||
'cities' => ['Sucre', 'Yotala', 'Yamparáez', 'Tarabuco', 'Icla', 'Presto', 'Mojocoya', 'Zudáñez', 'Sopachuy', 'Tomina', 'Padilla', 'El Villar', 'Serrano', 'Camargo', 'San Lucas', 'Incahuasi', 'Las Carreras', 'Culpina', 'Villa Abecia', 'Monteagudo', 'Huacareta', 'Muyupampa', 'Huacaya', 'Macharetí']
|
||||
],
|
||||
'Cochabamba' => [
|
||||
'uf' => 'CB',
|
||||
'cities' => ['Cochabamba', 'Quillacollo', 'Sacaba', 'Vinto', 'Colcapirhua', 'Tiquipaya', 'Sipe Sipe', 'Colomi', 'Villa Tunari', 'Puerto Villarroel', 'Entre Ríos', 'Chimoré', 'Shinahota', 'Punata', 'Cliza', 'Tarata', 'Arani', 'Toco', 'Anzaldo', 'Arbieto', 'Tolata', 'Capinuta', 'Santiváñez', 'Sicaya', 'Mizque', 'Aiquile', 'Pasorapa', 'Omereque', 'Totora', 'Pojo', 'Pocona', 'Vacas', 'Tiraque', 'Bolívar', 'Arque', 'Tacopaya', 'Tapacarí', 'Independencia', 'Morochata', 'Cocapata']
|
||||
],
|
||||
'La Paz' => [
|
||||
'uf' => 'LP',
|
||||
'cities' => ['La Paz', 'El Alto', 'Viacha', 'Achocalla', 'Laja', 'Mecapaca', 'Palca', 'Pucarani', 'Batallas', 'Puerto Pérez', 'Guaqui', 'Tiwanaku', 'Desaguadero', 'San Andrés de Machaca', 'Jesús de Machaca', 'Copacabana', 'San Pedro de Tiquina', 'Tito Yupanqui', 'Achacachi', 'Ancoraimes', 'Santiago de Huata', 'Huatajata', 'Chua Cocani', 'Puerto Carabuco', 'Escoma', 'Sorata', 'Guanay', 'Tipuani', 'Mapiri', 'Teoponte', 'Caranavi', 'Coroico', 'Coripata', 'Chulumani', 'Irupana', 'Yanacachi', 'Palos Blancos', 'La Asunta', 'Ixiamas', 'San Buenaventura', 'Apollo', 'Pelechuco']
|
||||
],
|
||||
'Oruro' => [
|
||||
'uf' => 'OR',
|
||||
'cities' => ['Oruro', 'Caracollo', 'El Choro', 'Machacamarca', 'Huanuni', 'Poopó', 'Pazña', 'Antequera', 'Challapata', 'Quillacas', 'Santiago de Huari', 'Salinas de Garci Mendoza', 'Pampa Aullagas', 'Toledo', 'Eucaliptus', 'Sabaya', 'Coipasa', 'Chipaya', 'Corque', 'Choquecota', 'Curahuara de Carangas', 'Turco', 'Huayllamarca', 'Totora', 'Santiago de Andamarca', 'Belén de Andamarca', 'Escara', 'Cruz de Machacamarca', 'Yunguyo del Litoral', 'Esmeralda']
|
||||
],
|
||||
'Pando' => [
|
||||
'uf' => 'PN',
|
||||
'cities' => ['Cobija', 'Porvenir', 'Bolpebra', 'Bella Flor', 'Puerto Rico', 'San Pedro', 'Sena', 'Santa Rosa del Abuná', 'Ingavi', 'Nueva Esperanza', 'Villa Nueva', 'Santos Mercado', 'San Lorenzo', 'El Porvenir', 'Filadelfia']
|
||||
],
|
||||
'Potosí' => [
|
||||
'uf' => 'PT',
|
||||
'cities' => ['Potosí', 'Tinguipaya', 'Yocalla', 'Belén de Urmiri', 'Uncía', 'Chayanta', 'Llallagua', 'Chuquihuta', 'Uyuni', 'Tomave', 'Porco', 'Tupiza', 'Atocha', 'Villazón', 'Cotagaita', 'Vitichi', 'Colcha K', 'San Agustín', 'San Pablo de Lípez', 'San Antonio de Esmoruco', 'Mojinete', 'Betanzos', 'Chaquí', 'Tacobamba', 'Puna', 'Caiza D', 'Ckochas', 'Sacaca', 'Caripuyo', 'Colquechaca', 'Ravelo', 'Pocoata', 'Ocurí', 'San Pedro de Buena Vista', 'Toro Toro']
|
||||
],
|
||||
'Santa Cruz' => [
|
||||
'uf' => 'SC',
|
||||
'cities' => ['Santa Cruz de la Sierra', 'Cotoca', 'Porongo', 'La Guardia', 'El Torno', 'Montero', 'Saavedra', 'Mineros', 'Fernández Alonso', 'San Pedro', 'Warnes', 'Okinawa Uno', 'Buena Vista', 'San Carlos', 'Yapacaní', 'San Juan', 'Portachuelo', 'Santa Rosa del Sara', 'Pailón', 'Roboré', 'San José de Chiquitos', 'San Ignacio de Velasco', 'San Miguel de Velasco', 'San Rafael de Velasco', 'Puerto Suárez', 'Puerto Quijarro', 'El Carmen Rivero Tórrez', 'Ascensión de Guarayos', 'Urubichá', 'El Puente', 'San Julián', 'Cuatro Cañadas', 'San Ramón', 'San Javier', 'Concepción', 'San Antonio de Lomerío', 'San Matías', 'Comarapa', 'Saipina', 'Vallegrande', 'Trigal', 'Moro Moro', 'Postrervalle', 'Pucará', 'Samaipata', 'Quirusillas', 'Mairana', 'Pampa Grande', 'Cabezas', 'Gutiérrez', 'Camiri', 'Boyuibe', 'Cuevo', 'Lagunillas', 'Charagua']
|
||||
],
|
||||
'Tarija' => [
|
||||
'uf' => 'TJ',
|
||||
'cities' => ['Tarija', 'Padcaya', 'Bermejo', 'Yacuiba', 'Caraparí', 'Villamontes', 'Uriondo', 'Yunchará', 'San Lorenzo', 'El Puente', 'Entre Ríos']
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($departments as $deptName => $deptData) {
|
||||
$stateId = Capsule::table('lists_states')
|
||||
->where('states_country_id', $countryId)
|
||||
->where('states_name', $deptName)
|
||||
->value('states_id');
|
||||
|
||||
if (!$stateId) {
|
||||
$stateId = Capsule::table('lists_states')->insertGetId([
|
||||
'states_country_id' => $countryId,
|
||||
'states_name' => $deptName,
|
||||
'states_uf' => $deptData['uf'],
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($deptData['cities'] as $cityName) {
|
||||
$cityExists = Capsule::table('lists_cities')
|
||||
->where('cities_state_id', $stateId)
|
||||
->where('cities_name', $cityName)
|
||||
->exists();
|
||||
|
||||
if (!$cityExists) {
|
||||
Capsule::table('lists_cities')->insert([
|
||||
'cities_state_id' => $stateId,
|
||||
'cities_name' => $cityName,
|
||||
'cities_slug' => $this->slugify($cityName),
|
||||
'cities_ibge_code' => null,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple slugify helper.
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
private function slugify($text)
|
||||
{
|
||||
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
|
||||
if (function_exists('iconv')) {
|
||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
}
|
||||
$text = preg_replace('~[^-\w]+~', '', $text);
|
||||
$text = trim($text, '-');
|
||||
$text = preg_replace('~-+~', '-', $text);
|
||||
$text = strtolower($text);
|
||||
return empty($text) ? 'n-a' : $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'BO')->value('countries_id');
|
||||
if ($countryId) {
|
||||
Capsule::table('lists_countries')->where('countries_id', $countryId)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
/**
|
||||
* Migration to import detailed Chile regions and communes.
|
||||
*/
|
||||
class ImportChileDetailedData
|
||||
{
|
||||
/**
|
||||
* Run the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// 1. Ensure Chile exists in lists_countries
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'CL')->value('countries_id');
|
||||
|
||||
if (!$countryId) {
|
||||
$countryId = Capsule::table('lists_countries')->insertGetId([
|
||||
'countries_name' => json_encode([
|
||||
'pt_BR' => 'Chile',
|
||||
'en_US' => 'Chile',
|
||||
'es_ES' => 'Chile',
|
||||
'de_DE' => 'Chile',
|
||||
'fr_FR' => 'Chili'
|
||||
]),
|
||||
'countries_iso_code' => 'CL',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
// 2. Chile Regions (States) with their Communes (Cities)
|
||||
$regions = [
|
||||
'Arica y Parinacota' => [
|
||||
'uf' => 'AP',
|
||||
'cities' => ['Arica', 'Camarones', 'Putre', 'General Lagos']
|
||||
],
|
||||
'Tarapacá' => [
|
||||
'uf' => 'TA',
|
||||
'cities' => ['Iquique', 'Alto Hospicio', 'Pozo Almonte', 'Camiña', 'Colchane', 'Huara', 'Pica']
|
||||
],
|
||||
'Antofagasta' => [
|
||||
'uf' => 'AN',
|
||||
'cities' => ['Antofagasta', 'Mejillones', 'Sierra Gorda', 'Taltal', 'Calama', 'Ollagüe', 'San Pedro de Atacama', 'Tocopilla', 'María Elena']
|
||||
],
|
||||
'Atacama' => [
|
||||
'uf' => 'AT',
|
||||
'cities' => ['Copiapó', 'Caldera', 'Tierra Amarilla', 'Chañaral', 'Diego de Almagro', 'Vallenar', 'Alto del Carmen', 'Freirina', 'Huasco']
|
||||
],
|
||||
'Coquimbo' => [
|
||||
'uf' => 'CO',
|
||||
'cities' => ['La Serena', 'Coquimbo', 'Andacollo', 'La Higuera', 'Paiguano', 'Vicuña', 'Illapel', 'Canela', 'Los Vilos', 'Salamanca', 'Ovalle', 'Combarbalá', 'Monte Patria', 'Punitaqui', 'Río Hurtado']
|
||||
],
|
||||
'Valparaíso' => [
|
||||
'uf' => 'VS',
|
||||
'cities' => ['Valparaíso', 'Casablanca', 'Concón', 'Juan Fernández', 'Puchuncaví', 'Quintero', 'Viña del Mar', 'Isla de Pascua', 'Los Andes', 'Calle Larga', 'Rinconada', 'San Esteban', 'La Ligua', 'Cabildo', 'Papudo', 'Petorca', 'Zapallar', 'Quillota', 'Calera', 'Hijuelas', 'La Cruz', 'Nogales', 'San Antonio', 'Algarrobo', 'Cartagena', 'El Quisco', 'El Tabo', 'Santo Domingo', 'San Felipe', 'Catemu', 'Llaillay', 'Panquehue', 'Putaendo', 'Santa María', 'Quilpué', 'Villa Alemana', 'Limache', 'Olmué']
|
||||
],
|
||||
'Región Metropolitana de Santiago' => [
|
||||
'uf' => 'RM',
|
||||
'cities' => ['Santiago', 'Cerrillos', 'Cerro Navia', 'Conchalí', 'El Bosque', 'Estación Central', 'Huechuraba', 'Independencia', 'La Cisterna', 'La Florida', 'La Granja', 'La Pintana', 'La Reina', 'Las Condes', 'Lo Barnechea', 'Lo Espejo', 'Lo Prado', 'Macul', 'Maipú', 'Ñuñoa', 'Pedro Aguirre Cerda', 'Peñalolén', 'Providencia', 'Pudahuel', 'Quilicura', 'Quinta Normal', 'Recoleta', 'Renca', 'San Joaquín', 'San Miguel', 'San Ramón', 'Vitacura', 'Puente Alto', 'Pirque', 'San José de Maipo', 'Colina', 'Lampa', 'Tiltil', 'San Bernardo', 'Buin', 'Calera de Tango', 'Paine', 'Melipilla', 'Alhué', 'Curacaví', 'María Pinto', 'San Pedro', 'Talagante', 'El Monte', 'Isla de Maipo', 'Padre Hurtado', 'Peñaflor']
|
||||
],
|
||||
'Libertador General Bernardo O’Higgins' => [
|
||||
'uf' => 'LI',
|
||||
'cities' => ['Rancagua', 'Codegua', 'Coinco', 'Coltauco', 'Doñihue', 'Graneros', 'Las Cabras', 'Machalí', 'Malloa', 'Mostazal', 'Olivar', 'Peumo', 'Pichidegua', 'Quinta de Tilcoco', 'Rengo', 'Requínoa', 'San Vicente', 'Pichilemu', 'La Estrella', 'Litueche', 'Marchihue', 'Navidad', 'Paredones', 'San Fernando', 'Chépica', 'Chimbarongo', 'Lolol', 'Nancagua', 'Palmilla', 'Peralillo', 'Placilla', 'Pumanque', 'Santa Cruz']
|
||||
],
|
||||
'Maule' => [
|
||||
'uf' => 'MA',
|
||||
'cities' => ['Talca', 'Constitución', 'Curepto', 'Empedrado', 'Maule', 'Pelarco', 'Pencahue', 'Río Claro', 'San Clemente', 'San Rafael', 'Cauquenes', 'Chanco', 'Pelluhue', 'Curicó', 'Hualañé', 'Licantén', 'Molina', 'Rauco', 'Romeral', 'Sagrada Familia', 'Teno', 'Vichuquén', 'Linares', 'Colbún', 'Longaví', 'Parral', 'Retiro', 'San Javier', 'Villa Alegre', 'Yerbas Buenas']
|
||||
],
|
||||
'Ñuble' => [
|
||||
'uf' => 'NB',
|
||||
'cities' => ['Chillán', 'Bulnes', 'Chillán Viejo', 'El Carmen', 'Pemuco', 'Pinto', 'Quillón', 'San Ignacio', 'Yungay', 'Quirihue', 'Cobquecura', 'Coelemu', 'Ninhue', 'Portezuelo', 'Ránquil', 'Treguaco', 'San Carlos', 'Coihueco', 'Ñiquén', 'San Fabián', 'San Nicolás']
|
||||
],
|
||||
'Biobío' => [
|
||||
'uf' => 'BI',
|
||||
'cities' => ['Concepción', 'Coronel', 'Chiguayante', 'Florida', 'Hualpén', 'Hualqui', 'Lota', 'Penco', 'San Pedro de la Paz', 'Santa Juana', 'Talcahuano', 'Tomé', 'Lebu', 'Arauco', 'Cañete', 'Contulmo', 'Curanilahue', 'Los Álamos', 'Tirúa', 'Los Ángeles', 'Antuco', 'Cabrero', 'Laja', 'Mulchén', 'Nacimiento', 'Negrete', 'Quilaco', 'Quilleco', 'San Rosendo', 'Santa Bárbara', 'Tucapel', 'Yumbel', 'Alto Biobío']
|
||||
],
|
||||
'Araucanía' => [
|
||||
'uf' => 'AR',
|
||||
'cities' => ['Temuco', 'Carahue', 'Cunco', 'Curarrehue', 'Freire', 'Galvarino', 'Gorbea', 'Lautaro', 'Loncoche', 'Melipeuco', 'Nueva Imperial', 'Padre Las Casas', 'Perquenco', 'Pitrufquén', 'Pucón', 'Saavedra', 'Teodoro Schmidt', 'Toltén', 'Vilún', 'Villarrica', 'Cholchol', 'Angol', 'Collipulli', 'Curacautín', 'Ercilla', 'Lonquimay', 'Los Sauces', 'Lumaco', 'Purén', 'Renaico', 'Traiguén', 'Victoria']
|
||||
],
|
||||
'Los Ríos' => [
|
||||
'uf' => 'LR',
|
||||
'cities' => ['Valdivia', 'Corral', 'Lanco', 'Los Lagos', 'Máfil', 'Mariquina', 'Paillaco', 'Panguipulli', 'La Unión', 'Futrono', 'Lago Ranco', 'Río Bueno']
|
||||
],
|
||||
'Los Lagos' => [
|
||||
'uf' => 'LL',
|
||||
'cities' => ['Puerto Montt', 'Calbuco', 'Cochamó', 'Fresia', 'Frutillar', 'Los Muermos', 'Llanquihue', 'Maullín', 'Puerto Varas', 'Castro', 'Ancud', 'Chonchi', 'Curaco de Vélez', 'Dalcahue', 'Puqueldón', 'Queilén', 'Quellón', 'Quemchi', 'Quinchao', 'Osorno', 'Puerto Octay', 'Purranque', 'Puyehue', 'Río Negro', 'San Juan de la Costa', 'San Pablo', 'Chaitén', 'Futaleufú', 'Hualaihué', 'Palena']
|
||||
],
|
||||
'Aysén del General Carlos Ibáñez del Campo' => [
|
||||
'uf' => 'AI',
|
||||
'cities' => ['Coyhaique', 'Lago Verde', 'Aysén', 'Cisnes', 'Guaitecas', 'Cochrane', 'O’Higgins', 'Tortel', 'Chile Chico', 'Río Ibáñez']
|
||||
],
|
||||
'Magallanes y de la Antártica Chilena' => [
|
||||
'uf' => 'MG',
|
||||
'cities' => ['Punta Arenas', 'Laguna Blanca', 'Río Verde', 'San Gregorio', 'Cabo de Hornos', 'Antártica', 'Porvenir', 'Primavera', 'Timaukel', 'Natales', 'Torres del Paine']
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($regions as $regionName => $regionData) {
|
||||
$stateId = Capsule::table('lists_states')
|
||||
->where('states_country_id', $countryId)
|
||||
->where('states_name', $regionName)
|
||||
->value('states_id');
|
||||
|
||||
if (!$stateId) {
|
||||
$stateId = Capsule::table('lists_states')->insertGetId([
|
||||
'states_country_id' => $countryId,
|
||||
'states_name' => $regionName,
|
||||
'states_uf' => $regionData['uf'],
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($regionData['cities'] as $cityName) {
|
||||
$cityExists = Capsule::table('lists_cities')
|
||||
->where('cities_state_id', $stateId)
|
||||
->where('cities_name', $cityName)
|
||||
->exists();
|
||||
|
||||
if (!$cityExists) {
|
||||
Capsule::table('lists_cities')->insert([
|
||||
'cities_state_id' => $stateId,
|
||||
'cities_name' => $cityName,
|
||||
'cities_slug' => $this->slugify($cityName),
|
||||
'cities_ibge_code' => null,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple slugify helper.
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
private function slugify($text)
|
||||
{
|
||||
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
|
||||
if (function_exists('iconv')) {
|
||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
}
|
||||
$text = preg_replace('~[^-\w]+~', '', $text);
|
||||
$text = trim($text, '-');
|
||||
$text = preg_replace('~-+~', '-', $text);
|
||||
$text = strtolower($text);
|
||||
return empty($text) ? 'n-a' : $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'CL')->value('countries_id');
|
||||
if ($countryId) {
|
||||
Capsule::table('lists_countries')->where('countries_id', $countryId)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
/**
|
||||
* Migration to import detailed Uruguay departments and municipalities.
|
||||
*/
|
||||
class ImportUruguayDetailedData
|
||||
{
|
||||
/**
|
||||
* Run the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// 1. Ensure Uruguay exists in lists_countries
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'UY')->value('countries_id');
|
||||
|
||||
if (!$countryId) {
|
||||
$countryId = Capsule::table('lists_countries')->insertGetId([
|
||||
'countries_name' => json_encode([
|
||||
'pt_BR' => 'Uruguai',
|
||||
'en_US' => 'Uruguay',
|
||||
'es_ES' => 'Uruguay',
|
||||
'de_DE' => 'Uruguay',
|
||||
'fr_FR' => 'Uruguay'
|
||||
]),
|
||||
'countries_iso_code' => 'UY',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
// 2. Uruguay Departments with their Municipalities
|
||||
$departments = [
|
||||
'Artigas' => ['uf' => 'AR', 'cities' => ['Artigas', 'Bella Unión', 'Tomás Gomensoro', 'Baltasar Brum']],
|
||||
'Canelones' => ['uf' => 'CA', 'cities' => ['Canelones', 'Santa Lucía', 'Pando', 'Las Piedras', 'La Paz', 'Progreso', 'Sauce', 'Tala', 'San Jacinto', 'San Bautista', 'San Ramón', 'Migues', 'Montes', 'Santa Rosa', 'Atlántida', 'Parque del Plata', 'La Floresta', 'Ciudad de la Costa', 'Paso Carrasco', 'Nicolich', '18 de Mayo']],
|
||||
'Cerro Largo' => ['uf' => 'CL', 'cities' => ['Melo', 'Río Branco', 'Fraile Muerto', 'Isidoro Noblía', 'Aceguá', 'Tupambaé', 'Plácido Rosas', 'Arévalo', 'Arbolito', 'Bañado de Medina']],
|
||||
'Colonia' => ['uf' => 'CO', 'cities' => ['Colonia del Sacramento', 'Carmelo', 'Juan Lacaze', 'Nueva Helvecia', 'Rosario', 'Nueva Palmira', 'Tarariras', 'Florencio Sánchez', 'Ombúes de Lavalle', 'Colonia Valdense']],
|
||||
'Durazno' => ['uf' => 'DU', 'cities' => ['Durazno', 'Sarandí del Yí', 'Villa del Carmen', 'La Paloma', 'Santa Bernardina', 'Centenario']],
|
||||
'Flores' => ['uf' => 'FS', 'cities' => ['Trinidad', 'Ismael Cortinas']],
|
||||
'Florida' => ['uf' => 'FD', 'cities' => ['Florida', 'Sarandí Grande', 'Casupá', 'Fray Marcos', '25 de Mayo', 'Cardal', '25 de Agosto']],
|
||||
'Lavalleja' => ['uf' => 'LA', 'cities' => ['Minas', 'José Pedro Varela', 'Solís de Mataojo', 'José Batlle y Ordóñez', 'Mariscala', 'Pirarajá']],
|
||||
'Maldonado' => ['uf' => 'MA', 'cities' => ['Maldonado', 'San Carlos', 'Punta del Este', 'Piriápolis', 'Pan de Azúcar', 'Aiguá', 'Solís Grande', 'Garzón']],
|
||||
'Montevideo' => ['uf' => 'MO', 'cities' => ['Montevideo']],
|
||||
'Paysandú' => ['uf' => 'PA', 'cities' => ['Paysandú', 'Guichón', 'Quebracho', 'Lorenzo Geyres', 'Piedras Coloradas', 'Chapicuy', 'Tambores']],
|
||||
'Río Negro' => ['uf' => 'RN', 'cities' => ['Fray Bentos', 'Young', 'Nuevo Berlín', 'San Javier']],
|
||||
'Rivera' => ['uf' => 'RV', 'cities' => ['Rivera', 'Tranqueras', 'Vichadero', 'Minas de Corrales']],
|
||||
'Rocha' => ['uf' => 'RO', 'cities' => ['Rocha', 'Chuy', 'Castillos', 'Lascano', 'La Paloma', 'Velázquez', 'Cebollatí']],
|
||||
'Salto' => ['uf' => 'SA', 'cities' => ['Salto', 'Constitución', 'Belén', 'Colonia Lavalleja', 'Mataojo', 'Rincón de Valentín']],
|
||||
'San José' => ['uf' => 'SJ', 'cities' => ['San José de Mayo', 'Libertad', 'Ciudad del Plata', 'Rodríguez', 'Ecilda Paullier']],
|
||||
'Soriano' => ['uf' => 'SO', 'cities' => ['Mercedes', 'Dolores', 'Cardona', 'Palmitas', 'José Enrique Rodó']],
|
||||
'Tacuarembó' => ['uf' => 'TA', 'cities' => ['Tacuarembó', 'Paso de los Toros', 'San Gregorio de Polanco', 'Ansina']],
|
||||
'Treinta y Tres' => ['uf' => 'TT', 'cities' => ['Treinta y Tres', 'Santa Clara de Olimar', 'Vergara', 'Cerro Chato']],
|
||||
];
|
||||
|
||||
foreach ($departments as $deptName => $deptData) {
|
||||
$stateId = Capsule::table('lists_states')
|
||||
->where('states_country_id', $countryId)
|
||||
->where('states_name', $deptName)
|
||||
->value('states_id');
|
||||
|
||||
if (!$stateId) {
|
||||
$stateId = Capsule::table('lists_states')->insertGetId([
|
||||
'states_country_id' => $countryId,
|
||||
'states_name' => $deptName,
|
||||
'states_uf' => $deptData['uf'],
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($deptData['cities'] as $cityName) {
|
||||
$cityExists = Capsule::table('lists_cities')
|
||||
->where('cities_state_id', $stateId)
|
||||
->where('cities_name', $cityName)
|
||||
->exists();
|
||||
|
||||
if (!$cityExists) {
|
||||
Capsule::table('lists_cities')->insert([
|
||||
'cities_state_id' => $stateId,
|
||||
'cities_name' => $cityName,
|
||||
'cities_slug' => $this->slugify($cityName),
|
||||
'cities_ibge_code' => null,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple slugify helper.
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
private function slugify($text)
|
||||
{
|
||||
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
|
||||
if (function_exists('iconv')) {
|
||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
}
|
||||
$text = preg_replace('~[^-\w]+~', '', $text);
|
||||
$text = trim($text, '-');
|
||||
$text = preg_replace('~-+~', '-', $text);
|
||||
$text = strtolower($text);
|
||||
return empty($text) ? 'n-a' : $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'UY')->value('countries_id');
|
||||
if ($countryId) {
|
||||
Capsule::table('lists_countries')->where('countries_id', $countryId)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
/**
|
||||
* Migration to import detailed Ecuador provinces and cantons.
|
||||
*/
|
||||
class ImportEcuadorDetailedData
|
||||
{
|
||||
/**
|
||||
* Run the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// 1. Ensure Ecuador exists in lists_countries
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'EC')->value('countries_id');
|
||||
|
||||
if (!$countryId) {
|
||||
$countryId = Capsule::table('lists_countries')->insertGetId([
|
||||
'countries_name' => json_encode([
|
||||
'pt_BR' => 'Equador',
|
||||
'en_US' => 'Ecuador',
|
||||
'es_ES' => 'Ecuador',
|
||||
'de_DE' => 'Ecuador',
|
||||
'fr_FR' => 'Équateur'
|
||||
]),
|
||||
'countries_iso_code' => 'EC',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
// 2. Ecuador Provinces with their Cantons (Cities)
|
||||
$provinces = [
|
||||
'Azuay' => ['uf' => 'AZ', 'cities' => ['Cuenca', 'Girón', 'Gualaceo', 'Nabón', 'Paute', 'Pucará', 'San Fernando', 'Santa Isabel', 'Sigsig', 'Oña', 'Chordeleg', 'El Pan', 'Sevilla de Oro', 'Guachapala', 'Camilo Ponce Enríquez']],
|
||||
'Bolívar' => ['uf' => 'BO', 'cities' => ['Guaranda', 'Chillanes', 'Chimbo', 'Echeandía', 'San Miguel', 'Caluma', 'Las Naves']],
|
||||
'Cañar' => ['uf' => 'CN', 'cities' => ['Azogues', 'Biblián', 'Cañar', 'La Troncal', 'El Tambo', 'Deleg', 'Suscal']],
|
||||
'Carchi' => ['uf' => 'CR', 'cities' => ['Tulcán', 'Bolívar', 'Espejo', 'Mira', 'Montúfar', 'San Pedro de Huaca']],
|
||||
'Cotopaxi' => ['uf' => 'CT', 'cities' => ['Latacunga', 'La Maná', 'Pangua', 'Pujilí', 'Salcedo', 'Saquisilí', 'Sigchos']],
|
||||
'Chimborazo' => ['uf' => 'CH', 'cities' => ['Riobamba', 'Alausí', 'Colta', 'Chambo', 'Chunchi', 'Guamote', 'Guano', 'Pallatanga', 'Penipe', 'Cumandá']],
|
||||
'El Oro' => ['uf' => 'EO', 'cities' => ['Machala', 'Arenillas', 'Atahualpa', 'Balsas', 'Chilla', 'El Guabo', 'Huaquillas', 'Marcabelí', 'Pasaje', 'Piñas', 'Santa Rosa', 'Zaruma', 'Las Lajas', 'Chordeleg']],
|
||||
'Esmeraldas' => ['uf' => 'ES', 'cities' => ['Esmeraldas', 'Eloy Alfaro', 'Muisne', 'Quinindé', 'San Lorenzo', 'Atacames', 'Rioverde', 'La Concordia']],
|
||||
'Guayas' => ['uf' => 'GY', 'cities' => ['Guayaquil', 'Alfredo Baquerizo Moreno', 'Balao', 'Balzar', 'Colimes', 'Daule', 'Durán', 'Empalme', 'El Triunfo', 'Milagro', 'Naranjal', 'Naranjito', 'Palestina', 'Pedro Carbo', 'Samborondón', 'Santa Lucía', 'Salitre', 'San Jacinto de Yaguachi', 'Playas', 'Simón Bolívar', 'Marcelino Maridueña', 'Lomas de Sargentillo', 'Nobol', 'General Antonio Elizalde', 'Isidro Ayora']],
|
||||
'Imbabura' => ['uf' => 'IM', 'cities' => ['Ibarra', 'Antonio Ante', 'Cotacachi', 'Otavalo', 'Pimampiro', 'San Miguel de Urcuquí']],
|
||||
'Loja' => ['uf' => 'LO', 'cities' => ['Loja', 'Calvas', 'Catamayo', 'Celica', 'Chaguarpamba', 'Espíndola', 'Gonzanamá', 'Macará', 'Paltas', 'Puyango', 'Saraguro', 'Sozoranga', 'Zapotillo', 'Pindal', 'Quilanga', 'Olmedo']],
|
||||
'Los Ríos' => ['uf' => 'LR', 'cities' => ['Babahoyo', 'Baba', 'Montalvo', 'Puebloviejo', 'Quevedo', 'Urdaneta', 'Ventanas', 'Vinces', 'Palenque', 'Buena Fé', 'Valencia', 'Mocache', 'Quinsaloma']],
|
||||
'Manabí' => ['uf' => 'MN', 'cities' => ['Portoviejo', 'Bolívar', 'Chone', 'El Carmen', 'Flavio Alfaro', 'Jipijapa', 'Junín', 'Manta', 'Montecristi', 'Paján', 'Pichincha', 'Rocafuerte', 'Santa Ana', 'Sucre', 'Tosagua', '24 de Mayo', 'Pedernales', 'Olmedo', 'Puerto López', 'Jama', 'Jaramijó']],
|
||||
'Morona Santiago' => ['uf' => 'MS', 'cities' => ['Morona', 'Gualaquiza', 'Limón Indanza', 'Palora', 'Santiago', 'Sucúa', 'Huamboya', 'San Juan Bosco', 'Taisha', 'Logroño', 'Pablo Sexto', 'Tiwintza']],
|
||||
'Napo' => ['uf' => 'NA', 'cities' => ['Tena', 'Archidona', 'Quijos', 'Carlos Julio Arosemena Tola', 'El Chaco']],
|
||||
'Pastaza' => ['uf' => 'PA', 'cities' => ['Pastaza', 'Mera', 'Santa Clara', 'Arajuno']],
|
||||
'Pichincha' => ['uf' => 'PI', 'cities' => ['Quito', 'Cayambe', 'Mejía', 'Pedro Moncayo', 'Rumiñahui', 'San Miguel de los Bancos', 'Pedro Vicente Maldonado', 'Puerto Quito']],
|
||||
'Tungurahua' => ['uf' => 'TU', 'cities' => ['Ambato', 'Baños de Agua Santa', 'Cevallos', 'Mocha', 'Patate', 'Quero', 'San Pedro de Pelileo', 'Santiago de Píllaro', 'Tisaleo']],
|
||||
'Zamora Chinchipe' => ['uf' => 'ZC', 'cities' => ['Zamora', 'Chinchipe', 'Nangaritza', 'Yacuambi', 'Yantzaza', 'El Pangui', 'Centinela del Cóndor', 'Palanda', 'Paquisha']],
|
||||
'Galápagos' => ['uf' => 'GA', 'cities' => ['San Cristóbal', 'Isabela', 'Santa Cruz']],
|
||||
'Sucumbíos' => ['uf' => 'SU', 'cities' => ['Lago Agrio', 'Cascales', 'Cuyabeno', 'Gonzalo Pizarro', 'Putumayo', 'Shushufindi', 'Sucumbíos']],
|
||||
'Orellana' => ['uf' => 'OR', 'cities' => ['Orellana', 'Aguarico', 'La Joya de los Sachas', 'Loreto']],
|
||||
'Santo Domingo de los Tsáchilas' => ['uf' => 'SD', 'cities' => ['Santo Domingo']],
|
||||
'Santa Elena' => ['uf' => 'SE', 'cities' => ['Santa Elena', 'La Libertad', 'Salinas']],
|
||||
];
|
||||
|
||||
foreach ($provinces as $provName => $provData) {
|
||||
$stateId = Capsule::table('lists_states')
|
||||
->where('states_country_id', $countryId)
|
||||
->where('states_name', $provName)
|
||||
->value('states_id');
|
||||
|
||||
if (!$stateId) {
|
||||
$stateId = Capsule::table('lists_states')->insertGetId([
|
||||
'states_country_id' => $countryId,
|
||||
'states_name' => $provName,
|
||||
'states_uf' => $provData['uf'],
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($provData['cities'] as $cityName) {
|
||||
$cityExists = Capsule::table('lists_cities')
|
||||
->where('cities_state_id', $stateId)
|
||||
->where('cities_name', $cityName)
|
||||
->exists();
|
||||
|
||||
if (!$cityExists) {
|
||||
Capsule::table('lists_cities')->insert([
|
||||
'cities_state_id' => $stateId,
|
||||
'cities_name' => $cityName,
|
||||
'cities_slug' => $this->slugify($cityName),
|
||||
'cities_ibge_code' => null,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple slugify helper.
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
private function slugify($text)
|
||||
{
|
||||
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
|
||||
if (function_exists('iconv')) {
|
||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
}
|
||||
$text = preg_replace('~[^-\w]+~', '', $text);
|
||||
$text = trim($text, '-');
|
||||
$text = preg_replace('~-+~', '-', $text);
|
||||
$text = strtolower($text);
|
||||
return empty($text) ? 'n-a' : $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'EC')->value('countries_id');
|
||||
if ($countryId) {
|
||||
Capsule::table('lists_countries')->where('countries_id', $countryId)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
/**
|
||||
* Migration to import detailed Venezuela states and municipalities.
|
||||
*/
|
||||
class ImportVenezuelaDetailedData
|
||||
{
|
||||
/**
|
||||
* Run the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// 1. Ensure Venezuela exists in lists_countries
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'VE')->value('countries_id');
|
||||
|
||||
if (!$countryId) {
|
||||
$countryId = Capsule::table('lists_countries')->insertGetId([
|
||||
'countries_name' => json_encode([
|
||||
'pt_BR' => 'Venezuela',
|
||||
'en_US' => 'Venezuela',
|
||||
'es_ES' => 'Venezuela',
|
||||
'de_DE' => 'Venezuela',
|
||||
'fr_FR' => 'Venezuela'
|
||||
]),
|
||||
'countries_iso_code' => 'VE',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
// 2. Venezuela States with their Municipalities (Cities)
|
||||
$states = [
|
||||
'Amazonas' => ['uf' => 'AM', 'cities' => ['Puerto Ayacucho', 'Alto Orinoco', 'Atabapo', 'Atures', 'Autana', 'Manapiare', 'Maroa', 'Río Negro']],
|
||||
'Anzoátegui' => ['uf' => 'AN', 'cities' => ['Barcelona', 'Anaco', 'Aragua', 'Diego Bautista Urbaneja', 'Fernando de Peñalver', 'Francisco del Carmen Carvajal', 'Francisco de Miranda', 'Guanta', 'Independencia', 'José Gregorio Monagas', 'Juan Antonio Sotillo', 'Juan Manuel Cajigal', 'Libertad', 'Manuel Ezequiel Bruzual', 'Pedro María Freites', 'Píritu', 'San José de Guanipa', 'San Juan de Capistrano', 'Santa Ana', 'Simón Bolívar', 'Simón Rodríguez']],
|
||||
'Apure' => ['uf' => 'AP', 'cities' => ['San Fernando de Apure', 'Achaguas', 'Biruaca', 'Muñoz', 'Páez', 'Pedro Camejo', 'Rómulo Gallegos']],
|
||||
'Aragua' => ['uf' => 'AR', 'cities' => ['Maracay', 'Bolívar', 'Camatagua', 'Francisco Linares Alcántara', 'Girardot', 'José Ángel Lamas', 'José Casanova Godoy', 'José Félix Ribas', 'José Rafael Revenga', 'Libertador', 'Mario Briceño Iragorry', 'Ocumare de la Costa de Oro', 'San Casimiro', 'San Sebastián', 'Santiago Mariño', 'Santos Michelena', 'Sucre', 'Tovar', 'Urdaneta', 'Zamora']],
|
||||
'Barinas' => ['uf' => 'BA', 'cities' => ['Barinas', 'Alberto Arvelo Torrealba', 'Andrés Eloy Blanco', 'Antonio José de Sucre', 'Arismendi', 'Bolívar', 'Cruz Paredes', 'Ezequiel Zamora', 'Obispos', 'Pedraza', 'Rojas', 'Sosa']],
|
||||
'Bolívar' => ['uf' => 'BO', 'cities' => ['Ciudad Bolívar', 'Caroní', 'Cedeño', 'El Callao', 'Gran Sabana', 'Heres', 'Padre Pedro Chien', 'Piar', 'Raúl Leoni', 'Roscio', 'Sifontes', 'Sucre']],
|
||||
'Carabobo' => ['uf' => 'CA', 'cities' => ['Valencia', 'Bejuma', 'Carlos Arvelo', 'Diego Ibarra', 'Guacara', 'Juan José Mora', 'Libertador', 'Los Guayos', 'Miranda', 'Montalbán', 'Naguanagua', 'Puerto Cabello', 'San Diego', 'San Joaquín']],
|
||||
'Cojedes' => ['uf' => 'CO', 'cities' => ['San Carlos', 'Anzoátegui', 'Falcon', 'Girardot', 'Lima Blanco', 'Pao de San Juan Bautista', 'Ricaurte', 'Rómulo Gallegos', 'Tinaco']],
|
||||
'Delta Amacuro' => ['uf' => 'DA', 'cities' => ['Tucupita', 'Antonio Díaz', 'Casacoima', 'Pedernales']],
|
||||
'Distrito Capital' => ['uf' => 'DC', 'cities' => ['Caracas', 'Libertador']],
|
||||
'Falcón' => ['uf' => 'FA', 'cities' => ['Coro', 'Acosta', 'Bolívar', 'Buchivacoa', 'Cacique Manaure', 'Carirubana', 'Colina', 'Dabajuro', 'Democracia', 'Falcón', 'Federación', 'Jacura', 'Los Taques', 'Mauroa', 'Miranda', 'Monseñor Iturriza', 'Palmasola', 'Petit', 'Píritu', 'San Francisco', 'Silva', 'Sucre', 'Tocópero', 'Unión', 'Urumaco', 'Zamura']],
|
||||
'Guárico' => ['uf' => 'GU', 'cities' => ['San Juan de los Morros', 'Camaguán', 'Chaguaramas', 'El Socorro', 'Francisco de Miranda', 'José Félix Ribas', 'José Tadeo Monagas', 'Juan Germán Roscio', 'Julián Mellado', 'Las Mercedes', 'Leonardo Infante', 'Ortiz', 'Pedro Zaraza', 'San Gerónimo de Guayabal', 'Santa María de Ipire']],
|
||||
'Lara' => ['uf' => 'LA', 'cities' => ['Barquisimeto', 'Andrés Eloy Blanco', 'Crespo', 'Iribarren', 'Jiménez', 'Morán', 'Palavecino', 'Simón Planas', 'Torres', 'Urdaneta']],
|
||||
'Mérida' => ['uf' => 'ME', 'cities' => ['Mérida', 'Alberto Adriani', 'Andrés Eloy Blanco', 'Aricagua', 'Arzobispo Chacón', 'Campo Elías', 'Caracciolo Parra Olmedo', 'Cardenal Quintero', 'Guaraque', 'Julio César Salas', 'Justo Briceño', 'Libertador', 'Miranda', 'Obispo Ramos de Lora', 'Padre Noguera', 'Pueblo Llano', 'Rangel', 'Rivas Dávila', 'Santos Marquina', 'Sucre', 'Tovar', 'Tulio Febres Cordero', 'Zea']],
|
||||
'Miranda' => ['uf' => 'MI', 'cities' => ['Los Teques', 'Acevedo', 'Andrés Bello', 'Baruta', 'Brión', 'Buroz', 'Carrizal', 'Chacao', 'Cristóbal Rojas', 'El Hatillo', 'Guaicaipuro', 'Independencia', 'Lander', 'Los Salias', 'Páez', 'Paz Castillo', 'Pedro Gual', 'Plaza', 'Simón Bolívar', 'Sucre', 'Urdaneta', 'Zamora']],
|
||||
'Monagas' => ['uf' => 'MO', 'cities' => ['Maturín', 'Acosta', 'Aguasay', 'Bolívar', 'Caripe', 'Cedeño', 'Ezequiel Zamora', 'Libertador', 'Piar', 'Punceres', 'Santa Bárbara', 'Sotillo', 'Uracoa']],
|
||||
'Nueva Esparta' => ['uf' => 'NE', 'cities' => ['La Asunción', 'Antolín del Campo', 'Arismendi', 'Díaz', 'García', 'Gómez', 'Maneiro', 'Marcano', 'Mariño', 'Península de Macanao', 'Tubores', 'Villalba']],
|
||||
'Portuguesa' => ['uf' => 'PO', 'cities' => ['Guanare', 'Agua Blanca', 'Araure', 'Esteller', 'Guanarito', 'Monseñor José Vicente de Unda', 'Ospino', 'Páez', 'Papelón', 'San Genaro de Boconoíto', 'San Rafael de Onoto', 'Santa Rosalía', 'Sucre', 'Turén']],
|
||||
'Sucre' => ['uf' => 'SU', 'cities' => ['Cumaná', 'Andrés Eloy Blanco', 'Andrés Mata', 'Arismendi', 'Benítez', 'Bermúdez', 'Bolívar', 'Cajigal', 'Cruz Salmerón Acosta', 'Libertador', 'Mariño', 'Mejía', 'Montes', 'Ribero', 'Valdez']],
|
||||
'Táchira' => ['uf' => 'TA', 'cities' => ['San Cristóbal', 'Andrés Bello', 'Antonio Rómulo Costa', 'Ayacucho', 'Bolívar', 'Cárdenas', 'Córdoba', 'Fernández Feo', 'Francisco de Miranda', 'García de Hevia', 'Guásimos', 'Independencia', 'Jáuregui', 'José María Vargas', 'Junín', 'Libertad', 'Libertador', 'Lobatera', 'Michelena', 'Panamericano', 'Pedro María Ureña', 'Rafael Urdaneta', 'Samuel Darío Maldonado', 'San Judas Tadeo', 'Sébaco', 'Simón Rodríguez', 'Sucre', 'Torbes', 'Uribante']],
|
||||
'Trujillo' => ['uf' => 'TR', 'cities' => ['Trujillo', 'Andrés Bello', 'Boconó', 'Bolívar', 'Candelaria', 'Carache', 'Escuque', 'José Felipe Márquez Cañizalez', 'José Vicente Campo Elías', 'La Ceiba', 'Miranda', 'Monte Carmelo', 'Motatán', 'Pampán', 'Pampanito', 'Rafael Rangel', 'San Rafael de Carvajal', 'Sucre', 'Urdaneta', 'Valera']],
|
||||
'Yaracuy' => ['uf' => 'YA', 'cities' => ['San Felipe', 'Arístides Bastidas', 'Bruzual', 'Cocorote', 'Independencia', 'José Antonio Páez', 'La Trinidad', 'Manuel Monge', 'Nirgua', 'Peña', 'San Felipe', 'Sucre', 'Urachiche', 'Veroes']],
|
||||
'Zulia' => ['uf' => 'ZU', 'cities' => ['Maracaibo', 'Almirante Padilla', 'Baralt', 'Cabimas', 'Catatumbo', 'Colón', 'Francisco Javier Pulgar', 'Jesús Enrique Lossada', 'Jesús María Semprún', 'La Cañada de Urdaneta', 'Lagunillas', 'Machiques de Perijá', 'Mara', 'Miranda', 'Páez', 'Rosario de Perijá', 'San Francisco', 'Santa Rita', 'Simón Bolívar', 'Sucre', 'Valmore Rodríguez']],
|
||||
'Vargas' => ['uf' => 'VA', 'cities' => ['La Guaira', 'Vargas']],
|
||||
];
|
||||
|
||||
foreach ($states as $stateName => $stateData) {
|
||||
$stateId = Capsule::table('lists_states')
|
||||
->where('states_country_id', $countryId)
|
||||
->where('states_name', $stateName)
|
||||
->value('states_id');
|
||||
|
||||
if (!$stateId) {
|
||||
$stateId = Capsule::table('lists_states')->insertGetId([
|
||||
'states_country_id' => $countryId,
|
||||
'states_name' => $stateName,
|
||||
'states_uf' => $stateData['uf'],
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($stateData['cities'] as $cityName) {
|
||||
$cityExists = Capsule::table('lists_cities')
|
||||
->where('cities_state_id', $stateId)
|
||||
->where('cities_name', $cityName)
|
||||
->exists();
|
||||
|
||||
if (!$cityExists) {
|
||||
Capsule::table('lists_cities')->insert([
|
||||
'cities_state_id' => $stateId,
|
||||
'cities_name' => $cityName,
|
||||
'cities_slug' => $this->slugify($cityName),
|
||||
'cities_ibge_code' => null,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple slugify helper.
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
private function slugify($text)
|
||||
{
|
||||
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
|
||||
if (function_exists('iconv')) {
|
||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
}
|
||||
$text = preg_replace('~[^-\w]+~', '', $text);
|
||||
$text = trim($text, '-');
|
||||
$text = preg_replace('~-+~', '-', $text);
|
||||
$text = strtolower($text);
|
||||
return empty($text) ? 'n-a' : $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'VE')->value('countries_id');
|
||||
if ($countryId) {
|
||||
Capsule::table('lists_countries')->where('countries_id', $countryId)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
/**
|
||||
* Migration to import detailed Peru departments and provinces/districts.
|
||||
*/
|
||||
class ImportPeruDetailedData
|
||||
{
|
||||
/**
|
||||
* Run the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// 1. Ensure Peru exists in lists_countries
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'PE')->value('countries_id');
|
||||
|
||||
if (!$countryId) {
|
||||
$countryId = Capsule::table('lists_countries')->insertGetId([
|
||||
'countries_name' => json_encode([
|
||||
'pt_BR' => 'Peru',
|
||||
'en_US' => 'Peru',
|
||||
'es_ES' => 'Perú',
|
||||
'de_DE' => 'Peru',
|
||||
'fr_FR' => 'Pérou'
|
||||
]),
|
||||
'countries_iso_code' => 'PE',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
// 2. Peru Departments with their principal Cities (Districts/Provinces)
|
||||
$departments = [
|
||||
'Amazonas' => ['uf' => 'AM', 'cities' => ['Chachapoyas', 'Bagua', 'Bongará', 'Condorcanqui', 'Luya', 'Rodríguez de Mendoza', 'Utcubamba']],
|
||||
'Áncash' => ['uf' => 'AN', 'cities' => ['Huaraz', 'Aija', 'Antonio Raymondi', 'Asunción', 'Bolognesi', 'Carhuaz', 'Carlos Fermín Fitzcarrald', 'Casma', 'Corongo', 'Huari', 'Huarmey', 'Huaylas', 'Mariscal Luzuriaga', 'Ocros', 'Pallasca', 'Pomabamba', 'Recuay', 'Santa', 'Sihuas', 'Yungay']],
|
||||
'Apurímac' => ['uf' => 'AP', 'cities' => ['Abancay', 'Andahuaylas', 'Antabamba', 'Aymaraes', 'Cotabambas', 'Chincheros', 'Grau']],
|
||||
'Arequipa' => ['uf' => 'AR', 'cities' => ['Arequipa', 'Camaná', 'Caravelí', 'Castilla', 'Caylloma', 'Condesuyos', 'Islay', 'La Unión']],
|
||||
'Ayacucho' => ['uf' => 'AY', 'cities' => ['Ayacucho', 'Cangallo', 'Huanca Sancos', 'Huanta', 'La Mar', 'Lucanas', 'Parinacochas', 'Páucar del Sara Sara', 'Sucre', 'Víctor Fajardo', 'Vilcas Huamán']],
|
||||
'Cajamarca' => ['uf' => 'CA', 'cities' => ['Cajamarca', 'Cajabamba', 'Celendín', 'Chota', 'Contumazá', 'Cutervo', 'Hualgayoc', 'Jaén', 'San Ignacio', 'San Marcos', 'San Miguel', 'San Pablo', 'Santa Cruz']],
|
||||
'Callao' => ['uf' => 'CL', 'cities' => ['Callao', 'Bellavista', 'Carmen de la Legua', 'La Perla', 'La Punta', 'Ventanilla', 'Mi Perú']],
|
||||
'Cusco' => ['uf' => 'CU', 'cities' => ['Cusco', 'Acomayo', 'Anta', 'Calca', 'Canas', 'Canchis', 'Chumbivilcas', 'Espinar', 'La Convención', 'Paruro', 'Paucartambo', 'Quispicanchi', 'Urubamba']],
|
||||
'Huancavelica' => ['uf' => 'HV', 'cities' => ['Huancavelica', 'Acobamba', 'Angaraes', 'Castrovirreyna', 'Churcampa', 'Huaytará', 'Tayacaja']],
|
||||
'Huánuco' => ['uf' => 'HU', 'cities' => ['Huánuco', 'Ambo', 'Dos de Mayo', 'Huacaybamba', 'Huamalíes', 'Leoncio Prado', 'Marañón', 'Pachitea', 'Puerto Inca', 'Lauricocha', 'Yarowilca']],
|
||||
'Ica' => ['uf' => 'IC', 'cities' => ['Ica', 'Chincha', 'Nasca', 'Palpa', 'Pisco']],
|
||||
'Junín' => ['uf' => 'JU', 'cities' => ['Huancayo', 'Concepción', 'Chanchamayo', 'Jauja', 'Junín', 'Satipo', 'Tarma', 'Yauli', 'Chupaca']],
|
||||
'La Libertad' => ['uf' => 'LL', 'cities' => ['Trujillo', 'Ascope', 'Bolívar', 'Chepén', 'Julcán', 'Otuzco', 'Pacasmayo', 'Pataz', 'Sánchez Carrión', 'Santiago de Chuco', 'Gran Chimú', 'Virú']],
|
||||
'Lambayeque' => ['uf' => 'LA', 'cities' => ['Chiclayo', 'Ferreñafe', 'Lambayeque']],
|
||||
'Lima' => ['uf' => 'LM', 'cities' => ['Lima', 'Barranca', 'Cajatambo', 'Canta', 'Cañete', 'Huaral', 'Huarochirí', 'Huaura', 'Oyón', 'Yauyos']],
|
||||
'Loreto' => ['uf' => 'LO', 'cities' => ['Iquitos', 'Alto Amazonas', 'Loreto', 'Mariscal Ramón Castilla', 'Maynas', 'Requena', 'Ucayali', 'Datem del Marañón', 'Putumayo']],
|
||||
'Madre de Dios' => ['uf' => 'MD', 'cities' => ['Puerto Maldonado', 'Manu', 'Tahuamanu', 'Tambopata']],
|
||||
'Moquegua' => ['uf' => 'MO', 'cities' => ['Moquegua', 'General Sánchez Cerro', 'Ilo', 'Mariscal Nieto']],
|
||||
'Pasco' => ['uf' => 'PA', 'cities' => ['Cerro de Pasco', 'Daniel Alcides Carrión', 'Oxapampa', 'Pasco']],
|
||||
'Piura' => ['uf' => 'PI', 'cities' => ['Piura', 'Ayabaca', 'Huancabamba', 'Morropón', 'Paita', 'Sullana', 'Talara', 'Sechura']],
|
||||
'Puno' => ['uf' => 'PU', 'cities' => ['Puno', 'Azángaro', 'Carabaya', 'Chucuito', 'El Collao', 'Huancané', 'Lampa', 'Melgar', 'Moho', 'San Antonio de Putina', 'San Román', 'Sandia', 'Yunguyo']],
|
||||
'San Martín' => ['uf' => 'SM', 'cities' => ['Moyobamba', 'Bellavista', 'El Dorado', 'Huallaga', 'Lamas', 'Mariscal Cáceres', 'Picota', 'Rioja', 'San Martín', 'Tocache']],
|
||||
'Tacna' => ['uf' => 'TA', 'cities' => ['Tacna', 'Candarave', 'Jorge Basadre', 'Tarata']],
|
||||
'Tumbes' => ['uf' => 'TU', 'cities' => ['Tumbes', 'Contralmirante Villar', 'Zarumilla']],
|
||||
'Ucayali' => ['uf' => 'UC', 'cities' => ['Pucallpa', 'Atalaya', 'Coronel Portillo', 'Padre Abad', 'Purús']],
|
||||
];
|
||||
|
||||
foreach ($departments as $deptName => $deptData) {
|
||||
$stateId = Capsule::table('lists_states')
|
||||
->where('states_country_id', $countryId)
|
||||
->where('states_name', $deptName)
|
||||
->value('states_id');
|
||||
|
||||
if (!$stateId) {
|
||||
$stateId = Capsule::table('lists_states')->insertGetId([
|
||||
'states_country_id' => $countryId,
|
||||
'states_name' => $deptName,
|
||||
'states_uf' => $deptData['uf'],
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($deptData['cities'] as $cityName) {
|
||||
$cityExists = Capsule::table('lists_cities')
|
||||
->where('cities_state_id', $stateId)
|
||||
->where('cities_name', $cityName)
|
||||
->exists();
|
||||
|
||||
if (!$cityExists) {
|
||||
Capsule::table('lists_cities')->insert([
|
||||
'cities_state_id' => $stateId,
|
||||
'cities_name' => $cityName,
|
||||
'cities_slug' => $this->slugify($cityName),
|
||||
'cities_ibge_code' => null,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple slugify helper.
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
private function slugify($text)
|
||||
{
|
||||
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
|
||||
if (function_exists('iconv')) {
|
||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
}
|
||||
$text = preg_replace('~[^-\w]+~', '', $text);
|
||||
$text = trim($text, '-');
|
||||
$text = preg_replace('~-+~', '-', $text);
|
||||
$text = strtolower($text);
|
||||
return empty($text) ? 'n-a' : $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'PE')->value('countries_id');
|
||||
if ($countryId) {
|
||||
Capsule::table('lists_countries')->where('countries_id', $countryId)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
/**
|
||||
* Migration to import detailed Colombia departments and municipalities.
|
||||
*/
|
||||
class ImportColombiaDetailedData
|
||||
{
|
||||
/**
|
||||
* Run the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// 1. Ensure Colombia exists in lists_countries
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'CO')->value('countries_id');
|
||||
|
||||
if (!$countryId) {
|
||||
$countryId = Capsule::table('lists_countries')->insertGetId([
|
||||
'countries_name' => json_encode([
|
||||
'pt_BR' => 'Colômbia',
|
||||
'en_US' => 'Colombia',
|
||||
'es_ES' => 'Colombia',
|
||||
'de_DE' => 'Kolumbien',
|
||||
'fr_FR' => 'Colombie'
|
||||
]),
|
||||
'countries_iso_code' => 'CO',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
// 2. Colombia Departments with their principal Municipalities
|
||||
$departments = [
|
||||
'Amazonas' => ['uf' => 'AM', 'cities' => ['Leticia', 'Puerto Nariño']],
|
||||
'Antioquia' => ['uf' => 'AN', 'cities' => ['Medellín', 'Bello', 'Itagüí', 'Envigado', 'Apartadó', 'Rionegro', 'Turbo', 'Caucasia', 'Chigorodó', 'Sabaneta', 'Caldas', 'La Estrella', 'Carepa', 'Copacabana', 'Girardota', 'Marinilla', 'Guarne', 'El Carmen de Viboral', 'Santa Rosa de Osos', 'Yarumal', 'Urrao', 'Sonsón']],
|
||||
'Arauca' => ['uf' => 'AR', 'cities' => ['Arauca', 'Arauquita', 'Saravena', 'Tame', 'Fortul', 'Puerto Rondón']],
|
||||
'Atlántico' => ['uf' => 'AT', 'cities' => ['Barranquilla', 'Soledad', 'Malambo', 'Sabanalarga', 'Baranoa', 'Galapa', 'Puerto Colombia', 'Santo Tomás', 'Palmar de Varela', 'Ponedera']],
|
||||
'Bolívar' => ['uf' => 'BL', 'cities' => ['Cartagena', 'Magangué', 'Turbaco', 'Arjona', 'El Carmen de Bolívar', 'María La Baja', 'Mompós', 'San Juan Nepomuceno', 'Turbaná', 'Santa Rosa de Lima', 'Calamar']],
|
||||
'Boyacá' => ['uf' => 'BY', 'cities' => ['Tunja', 'Duitama', 'Sogamoso', 'Chiquinquirá', 'Puerto Boyacá', 'Paipa', 'Moniquirá', 'Samacá', 'Garagoa', 'Villa de Leyva', 'Guateque']],
|
||||
'Caldas' => ['uf' => 'CL', 'cities' => ['Manizales', 'La Dorada', 'Chinchiná', 'Villamaría', 'Anserma', 'Riosucio', 'Aguadas', 'Supía', 'Salamina', 'Neira', 'Pensilvania']],
|
||||
'Caquetá' => ['uf' => 'CQ', 'cities' => ['Florencia', 'San Vicente del Caguán', 'Cartagena del Chairá', 'Puerto Rico', 'Curillo', 'El Doncello', 'Paujil', 'Belén de los Andaquíes']],
|
||||
'Casanare' => ['uf' => 'CS', 'cities' => ['Yopal', 'Aguazul', 'Villanueva', 'Paz de Ariporo', 'Monterrey', 'Tauramena', 'Hato Corozal', 'Orocué']],
|
||||
'Cauca' => ['uf' => 'CU', 'cities' => ['Popayán', 'Santander de Quilichao', 'Puerto Tejada', 'Miranda', 'Corinto', 'Caldono', 'El Tambo', 'Silvia', 'Piendamó', 'Patía', 'Guapi', 'Bolívar']],
|
||||
'Cesar' => ['uf' => 'CE', 'cities' => ['Valledupar', 'Aguachica', 'Agustín Codazzi', 'Bosconia', 'Curumaní', 'El Paso', 'La Paz', 'San Alberto', 'San Diego', 'Chiriguaná', 'Pailitas']],
|
||||
'Chocó' => ['uf' => 'CH', 'cities' => ['Quibdó', 'Istmina', 'Condoto', 'Tadó', 'Bahía Solano', 'Nuquí', 'Riosucio', 'Acandí']],
|
||||
'Córdoba' => ['uf' => 'CO', 'cities' => ['Montería', 'Cereté', 'Sahagún', 'Lorica', 'Planeta Rica', 'Montelíbano', 'Tierralta', 'Ciénaga de Oro', 'Chinu', 'Ayapel', 'Tuchín', 'San Andrés de Sotavento']],
|
||||
'Cundinamarca' => ['uf' => 'CN', 'cities' => ['Bogotá', 'Soacha', 'Fusagasugá', 'Facatativá', 'Chía', 'Zipaquirá', 'Girardot', 'Mosquera', 'Madrid', 'Funza', 'Cajicá', 'Sibaté', 'Tocancipá', 'Villeta', 'Ubaté', 'Pacho', 'La Mesa']],
|
||||
'Guainía' => ['uf' => 'GN', 'cities' => ['Inírida']],
|
||||
'Guaviare' => ['uf' => 'GV', 'cities' => ['San José del Guaviare', 'Calamar', 'El Retorno']],
|
||||
'Huila' => ['uf' => 'HU', 'cities' => ['Neiva', 'Pitalito', 'Garzón', 'La Plata', 'Campoalegre', 'Gigante', 'San Agustín', 'Isnos', 'Rivera']],
|
||||
'La Guajira' => ['uf' => 'LG', 'cities' => ['Riohacha', 'Maicao', 'Uribia', 'Manaure', 'San Juan del Cesar', 'Fonseca', 'Barrancas', 'Villanueva', 'Dibulla']],
|
||||
'Magdalena' => ['uf' => 'MG', 'cities' => ['Santa Marta', 'Ciénaga', 'Fundación', 'El Banco', 'Plato', 'Aracataca', 'Pivijay', 'Santa Ana', 'Ariguaní']],
|
||||
'Meta' => ['uf' => 'ME', 'cities' => ['Villavicencio', 'Acacías', 'Granada', 'Puerto López', 'Puerto Gaitán', 'Cumaral', 'San Martín', 'Vista Hermosa', 'Mesetas']],
|
||||
'Nariño' => ['uf' => 'NA', 'cities' => ['Pasto', 'Tumaco', 'Ipiales', 'Túquerres', 'Samaniego', 'La Unión', 'Barbacoas', 'Cumbal', 'Guachucal', 'El Charco']],
|
||||
'Norte de Santander' => ['uf' => 'NS', 'cities' => ['Cúcuta', 'Ocaña', 'Villa del Rosario', 'Los Patios', 'Pamplona', 'Tibú', 'Abrego', 'Chinacota', 'Sardinata', 'El Zulia']],
|
||||
'Putumayo' => ['uf' => 'PU', 'cities' => ['Mocoa', 'Puerto Asís', 'Orito', 'Valle del Guamuez', 'Puerto Guzmán', 'Puerto Leguízamo', 'Sibundoy']],
|
||||
'Quindío' => ['uf' => 'QD', 'cities' => ['Armenia', 'Calarcá', 'La Tebaida', 'Montenegro', 'Quimbaya', 'Circasia', 'Filandia']],
|
||||
'Risaralda' => ['uf' => 'RI', 'cities' => ['Pereira', 'Dosquebradas', 'Santa Rosa de Cabal', 'La Virginia', 'Belén de Umbría', 'Quinchía', 'Marsella']],
|
||||
'San Andrés y Providencia' => ['uf' => 'SA', 'cities' => ['San Andrés', 'Providencia']],
|
||||
'Santander' => ['uf' => 'ST', 'cities' => ['Bucaramanga', 'Floridablanca', 'Barrancabermeja', 'Girón', 'Piedecuesta', 'San Gil', 'Socorro', 'Barbosa', 'Rionegro', 'Sabana de Torres', 'Lebrija']],
|
||||
'Sucre' => ['uf' => 'SU', 'cities' => ['Sincelejo', 'Corozal', 'San Marcos', 'Sampués', 'Tolú', 'Majagual', 'San Onofre', 'Los Palmitos', 'Ovejas']],
|
||||
'Tolima' => ['uf' => 'TO', 'cities' => ['Ibagué', 'Espinal', 'Chaparral', 'Líbano', 'Melgar', 'Mariquita', 'Honda', 'Flandes', 'Cajamarca', 'Guamo', 'Purificación', 'Ortega']],
|
||||
'Valle del Cauca' => ['uf' => 'VC', 'cities' => ['Cali', 'Buenaventura', 'Palmira', 'Tuluá', 'Cartago', 'Buga', 'Jamundí', 'Yumbo', 'Candelaria', 'Florida', 'Pradera', 'Guacarí', 'Zarzal', 'Caicedonia', 'Sevilla', 'Roldanillo', 'La Unión']],
|
||||
'Vaupés' => ['uf' => 'VP', 'cities' => ['Mitú', 'Caruru', 'Taraira']],
|
||||
'Vichada' => ['uf' => 'VD', 'cities' => ['Puerto Carreño', 'La Primavera', 'Santa Rosalía', 'Cumaribo']],
|
||||
];
|
||||
|
||||
foreach ($departments as $deptName => $deptData) {
|
||||
$stateId = Capsule::table('lists_states')
|
||||
->where('states_country_id', $countryId)
|
||||
->where('states_name', $deptName)
|
||||
->value('states_id');
|
||||
|
||||
if (!$stateId) {
|
||||
$stateId = Capsule::table('lists_states')->insertGetId([
|
||||
'states_country_id' => $countryId,
|
||||
'states_name' => $deptName,
|
||||
'states_uf' => $deptData['uf'],
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($deptData['cities'] as $cityName) {
|
||||
$cityExists = Capsule::table('lists_cities')
|
||||
->where('cities_state_id', $stateId)
|
||||
->where('cities_name', $cityName)
|
||||
->exists();
|
||||
|
||||
if (!$cityExists) {
|
||||
Capsule::table('lists_cities')->insert([
|
||||
'cities_state_id' => $stateId,
|
||||
'cities_name' => $cityName,
|
||||
'cities_slug' => $this->slugify($cityName),
|
||||
'cities_ibge_code' => null,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple slugify helper.
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
private function slugify($text)
|
||||
{
|
||||
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
|
||||
if (function_exists('iconv')) {
|
||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
}
|
||||
$text = preg_replace('~[^-\w]+~', '', $text);
|
||||
$text = trim($text, '-');
|
||||
$text = preg_replace('~-+~', '-', $text);
|
||||
$text = strtolower($text);
|
||||
return empty($text) ? 'n-a' : $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'CO')->value('countries_id');
|
||||
if ($countryId) {
|
||||
Capsule::table('lists_countries')->where('countries_id', $countryId)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
/**
|
||||
* Migration to import detailed Guiana, Suriname and French Guiana.
|
||||
*/
|
||||
class ImportGuianasDetailedData
|
||||
{
|
||||
/**
|
||||
* Run the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$countries = [
|
||||
'GY' => [
|
||||
'names' => ['pt_BR' => 'Guiana', 'en_US' => 'Guyana', 'es_ES' => 'Guyana', 'de_DE' => 'Guyana', 'fr_FR' => 'Guyana'],
|
||||
'states' => [
|
||||
'Barima-Waini' => ['uf' => '01', 'cities' => ['Mabaruma', 'Port Kaituma', 'Matthews Ridge']],
|
||||
'Pomeroon-Supenaam' => ['uf' => '02', 'cities' => ['Anna Regina', 'Charity', 'Suddie']],
|
||||
'Essequibo Islands-West Demerara' => ['uf' => '03', 'cities' => ['Vreed-en-Hoop', 'Parika', 'Leonora']],
|
||||
'Demerara-Mahaica' => ['uf' => '04', 'cities' => ['Georgetown', 'Enmore', 'Buxton', 'Lusignan']],
|
||||
'Mahaica-Berbice' => ['uf' => '05', 'cities' => ['Rosignol', 'Mahaicony', 'Fort Wellington']],
|
||||
'East Berbice-Corentyne' => ['uf' => '06', 'cities' => ['New Amsterdam', 'Rose Hall', 'Skeldon', 'Corriverton']],
|
||||
'Cuyuni-Mazaruni' => ['uf' => '07', 'cities' => ['Bartica', 'Issano', 'Kamarang']],
|
||||
'Potaro-Siparuni' => ['uf' => '08', 'cities' => ['Mahdia', 'Kangaruma']],
|
||||
'Upper Takutu-Upper Essequibo' => ['uf' => '09', 'cities' => ['Lethem', 'Annai', 'Aishalton']],
|
||||
'Upper Demerara-Berbice' => ['uf' => '10', 'cities' => ['Linden', 'Ituni', 'Kwakwani']],
|
||||
]
|
||||
],
|
||||
'SR' => [
|
||||
'names' => ['pt_BR' => 'Suriname', 'en_US' => 'Suriname', 'es_ES' => 'Suriname', 'de_DE' => 'Suriname', 'fr_FR' => 'Suriname'],
|
||||
'states' => [
|
||||
'Brokopondo' => ['uf' => 'BR', 'cities' => ['Brokopondo', 'Brownsweg']],
|
||||
'Commewijne' => ['uf' => 'CM', 'cities' => ['Nieuw Amsterdam', 'Mariënburg']],
|
||||
'Coronie' => ['uf' => 'CR', 'cities' => ['Totness', 'Friendship']],
|
||||
'Marowijne' => ['uf' => 'MA', 'cities' => ['Albina', 'Moengo']],
|
||||
'Nickerie' => ['uf' => 'NI', 'cities' => ['Nieuw Nickerie', 'Wageningen']],
|
||||
'Para' => ['uf' => 'PR', 'cities' => ['Onverwacht', 'Zanderij']],
|
||||
'Paramaribo' => ['uf' => 'PM', 'cities' => ['Paramaribo']],
|
||||
'Saramacca' => ['uf' => 'SA', 'cities' => ['Groningen', 'Boskamp']],
|
||||
'Sipaliwini' => ['uf' => 'SI', 'cities' => ['Kwamelasemoetoe', 'Pontoetoe']],
|
||||
'Wanica' => ['uf' => 'WA', 'cities' => ['Lelydorp', 'Kwatta']],
|
||||
]
|
||||
],
|
||||
'GF' => [
|
||||
'names' => ['pt_BR' => 'Guiana Francesa', 'en_US' => 'French Guiana', 'es_ES' => 'Guayana Francesa', 'de_DE' => 'Französisch-Guayana', 'fr_FR' => 'Guyane française'],
|
||||
'states' => [
|
||||
'Cayenne' => ['uf' => 'CY', 'cities' => ['Cayenne', 'Matoury', 'Remire-Montjoly', 'Roura', 'Saint-Georges', 'Sinnamary']],
|
||||
'Saint-Laurent-du-Maroni' => ['uf' => 'SL', 'cities' => ['Saint-Laurent-du-Maroni', 'Mana', 'Maripasoula', 'Kourou', 'Iracoubo']],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
foreach ($countries as $iso => $countryData) {
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', $iso)->value('countries_id');
|
||||
|
||||
if (!$countryId) {
|
||||
$countryId = Capsule::table('lists_countries')->insertGetId([
|
||||
'countries_name' => json_encode($countryData['names']),
|
||||
'countries_iso_code' => $iso,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($countryData['states'] as $stateName => $stateData) {
|
||||
$stateId = Capsule::table('lists_states')
|
||||
->where('states_country_id', $countryId)
|
||||
->where('states_name', $stateName)
|
||||
->value('states_id');
|
||||
|
||||
if (!$stateId) {
|
||||
$stateId = Capsule::table('lists_states')->insertGetId([
|
||||
'states_country_id' => $countryId,
|
||||
'states_name' => $stateName,
|
||||
'states_uf' => $stateData['uf'],
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($stateData['cities'] as $cityName) {
|
||||
$cityExists = Capsule::table('lists_cities')
|
||||
->where('cities_state_id', $stateId)
|
||||
->where('cities_name', $cityName)
|
||||
->exists();
|
||||
|
||||
if (!$cityExists) {
|
||||
Capsule::table('lists_cities')->insert([
|
||||
'cities_state_id' => $stateId,
|
||||
'cities_name' => $cityName,
|
||||
'cities_slug' => $this->slugify($cityName),
|
||||
'cities_ibge_code' => null,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple slugify helper.
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
private function slugify($text)
|
||||
{
|
||||
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
|
||||
if (function_exists('iconv')) {
|
||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
}
|
||||
$text = preg_replace('~[^-\w]+~', '', $text);
|
||||
$text = trim($text, '-');
|
||||
$text = preg_replace('~-+~', '-', $text);
|
||||
$text = strtolower($text);
|
||||
return empty($text) ? 'n-a' : $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$isos = ['GY', 'SR', 'GF'];
|
||||
Capsule::table('lists_countries')->whereIn('countries_iso_code', $isos)->delete();
|
||||
}
|
||||
}
|
||||
+181
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
/**
|
||||
* Migration to import detailed France regions and cities.
|
||||
* Following SysCMS architecture for global lists.
|
||||
*/
|
||||
class ImportFranceDetailedData
|
||||
{
|
||||
/**
|
||||
* Run the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// 1. Ensure France exists in lists_countries
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'FR')->value('countries_id');
|
||||
|
||||
if (!$countryId) {
|
||||
$countryId = Capsule::table('lists_countries')->insertGetId([
|
||||
'countries_name' => json_encode([
|
||||
'pt_BR' => 'França',
|
||||
'en_US' => 'France',
|
||||
'es_ES' => 'Francia',
|
||||
'de_DE' => 'Frankreich',
|
||||
'fr_FR' => 'France'
|
||||
]),
|
||||
'countries_iso_code' => 'FR',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
// 2. France Regions (States) with their principal Cities (Communes)
|
||||
$regions = [
|
||||
'Auvergne-Rhône-Alpes' => [
|
||||
'uf' => 'ARA',
|
||||
'cities' => ['Lyon', 'Saint-Étienne', 'Grenoble', 'Villeurbanne', 'Clermont-Ferrand', 'Annecy', 'Vénissieux', 'Valence', 'Chambéry', 'Vaulx-en-Velin']
|
||||
],
|
||||
'Bourgogne-Franche-Comté' => [
|
||||
'uf' => 'BFC',
|
||||
'cities' => ['Dijon', 'Besançon', 'Belfort', 'Chalon-sur-Saône', 'Nevers', 'Auxerre', 'Mâcon', 'Sens']
|
||||
],
|
||||
'Bretagne' => [
|
||||
'uf' => 'BRE',
|
||||
'cities' => ['Rennes', 'Brest', 'Quimper', 'Lorient', 'Vannes', 'Saint-Malo', 'Saint-Brieuc']
|
||||
],
|
||||
'Centre-Val de Loire' => [
|
||||
'uf' => 'CVL',
|
||||
'cities' => ['Orléans', 'Tours', 'Bourges', 'Blois', 'Châteauroux', 'Chartres']
|
||||
],
|
||||
'Corse' => [
|
||||
'uf' => 'COR',
|
||||
'cities' => ['Ajaccio', 'Bastia', 'Porto-Vecchio', 'Borgo']
|
||||
],
|
||||
'Grand Est' => [
|
||||
'uf' => 'GES',
|
||||
'cities' => ['Strasbourg', 'Reims', 'Metz', 'Mulhouse', 'Nancy', 'Colmar', 'Troyes', 'Charleville-Mézières', 'Châlons-en-Champagne']
|
||||
],
|
||||
'Hauts-de-France' => [
|
||||
'uf' => 'HDF',
|
||||
'cities' => ['Lille', 'Amiens', 'Roubaix', 'Tourcoing', 'Dunkerque', 'Calais', 'Villeneuve-d' . "'" . 'Ascq', 'Saint-Quentin', 'Beauvais']
|
||||
],
|
||||
'Île-de-France' => [
|
||||
'uf' => 'IDF',
|
||||
'cities' => ['Paris', 'Boulogne-Billancourt', 'Saint-Denis', 'Argenteuil', 'Montreuil', 'Nanterre', 'Vitry-sur-Seine', 'Créteil', 'Asnières-sur-Seine', 'Versailles', 'Courbevoie', 'Colombes', 'Aulnay-sous-Bois']
|
||||
],
|
||||
'Normandie' => [
|
||||
'uf' => 'NOR',
|
||||
'cities' => ['Le Havre', 'Rouen', 'Caen', 'Cherbourg-en-Cotentin', 'Évreux', 'Dieppe']
|
||||
],
|
||||
'Nouvelle-Aquitaine' => [
|
||||
'uf' => 'NAQ',
|
||||
'cities' => ['Bordeaux', 'Limoges', 'Poitiers', 'Pau', 'La Rochelle', 'Mérignac', 'Pessac', 'Niort', 'Bayonne']
|
||||
],
|
||||
'Occitanie' => [
|
||||
'uf' => 'OCC',
|
||||
'cities' => ['Toulouse', 'Montpellier', 'Nîmes', 'Perpignan', 'Béziers', 'Montauban', 'Narbonne', 'Albi', 'Carcassonne']
|
||||
],
|
||||
'Pays de la Loire' => [
|
||||
'uf' => 'PDL',
|
||||
'cities' => ['Nantes', 'Angers', 'Le Mans', 'Saint-Nazaire', 'La Roche-sur-Yon', 'Cholet']
|
||||
],
|
||||
'Provence-Alpes-Côte d' . "'" . 'Azur' => [
|
||||
'uf' => 'PAC',
|
||||
'cities' => ['Marseille', 'Nice', 'Toulon', 'Aix-en-Provence', 'Avignon', 'Antibes', 'Cannes', 'La Seyne-sur-Mer', 'Hyères', 'Arles']
|
||||
],
|
||||
// Overseas Regions
|
||||
'Guadeloupe' => [
|
||||
'uf' => 'GUA',
|
||||
'cities' => ['Les Abymes', 'Baie-Mahault', 'Le Gosier', 'Sainte-Anne', 'Petit-Bourg', 'Basse-Terre']
|
||||
],
|
||||
'Martinique' => [
|
||||
'uf' => 'MAR',
|
||||
'cities' => ['Fort-de-France', 'Le Lamentin', 'Le Robert', 'Schœlcher', 'Sainte-Marie']
|
||||
],
|
||||
'Guyane française' => [
|
||||
'uf' => 'GUY',
|
||||
'cities' => ['Cayenne', 'Saint-Laurent-du-Maroni', 'Matoury', 'Remire-Montjoly', 'Kourou']
|
||||
],
|
||||
'La Réunion' => [
|
||||
'uf' => 'REU',
|
||||
'cities' => ['Saint-Denis', 'Saint-Paul', 'Saint-Pierre', 'Le Tampon', 'Saint-André', 'Saint-Louis']
|
||||
],
|
||||
'Mayotte' => [
|
||||
'uf' => 'MAY',
|
||||
'cities' => ['Mamoudzou', 'Koungou', 'Dzaoudzi', 'Dembeni']
|
||||
]
|
||||
];
|
||||
|
||||
foreach ($regions as $regionName => $regionData) {
|
||||
$stateId = Capsule::table('lists_states')
|
||||
->where('states_country_id', $countryId)
|
||||
->where('states_name', $regionName)
|
||||
->value('states_id');
|
||||
|
||||
if (!$stateId) {
|
||||
$stateId = Capsule::table('lists_states')->insertGetId([
|
||||
'states_country_id' => $countryId,
|
||||
'states_name' => $regionName,
|
||||
'states_uf' => $regionData['uf'],
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($regionData['cities'] as $cityName) {
|
||||
$cityExists = Capsule::table('lists_cities')
|
||||
->where('cities_state_id', $stateId)
|
||||
->where('cities_name', $cityName)
|
||||
->exists();
|
||||
|
||||
if (!$cityExists) {
|
||||
Capsule::table('lists_cities')->insert([
|
||||
'cities_state_id' => $stateId,
|
||||
'cities_name' => $cityName,
|
||||
'cities_slug' => $this->slugify($cityName),
|
||||
'cities_ibge_code' => null,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple slugify helper to generate consistent URL-friendly names.
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
private function slugify($text)
|
||||
{
|
||||
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
|
||||
if (function_exists('iconv')) {
|
||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
}
|
||||
$text = preg_replace('~[^-\w]+~', '', $text);
|
||||
$text = trim($text, '-');
|
||||
$text = preg_replace('~-+~', '-', $text);
|
||||
$text = strtolower($text);
|
||||
return empty($text) ? 'n-a' : $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'FR')->value('countries_id');
|
||||
if ($countryId) {
|
||||
// Foreign key constraints will handle states and cities deletion
|
||||
Capsule::table('lists_countries')->where('countries_id', $countryId)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
/**
|
||||
* Migration to import detailed data for Portugal (Districts and Cities)
|
||||
*
|
||||
* This migration adds Portugal to the lists_countries table and populates
|
||||
* its 18 districts and 2 autonomous regions into the lists_states table,
|
||||
* along with their respective main municipalities into lists_cities.
|
||||
*/
|
||||
class ImportPortugalDetailedData extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// Check if Portugal already exists
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'PT')->value('countries_id');
|
||||
|
||||
if (!$countryId) {
|
||||
$countryId = Capsule::table('lists_countries')->insertGetId([
|
||||
'countries_name' => json_encode([
|
||||
'pt_BR' => 'Portugal',
|
||||
'en_US' => 'Portugal',
|
||||
'es_ES' => 'Portugal',
|
||||
'de_DE' => 'Portugal',
|
||||
'fr_FR' => 'Portugal'
|
||||
]),
|
||||
'countries_iso_code' => 'PT',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
// Districts and Autonomous Regions of Portugal with main cities
|
||||
$districts = [
|
||||
'Aveiro' => ['uf' => 'AV', 'cities' => ['Aveiro', 'Águeda', 'Albergaria-a-Velha', 'Anadia', 'Arouca', 'Castelo de Paiva', 'Espinho', 'Estarreja', 'Ílhavo', 'Mealhada', 'Murtosa', 'Oliveira de Azeméis', 'Oliveira do Bairro', 'Ovar', 'Santa Maria da Feira', 'São João da Madeira', 'Sever do Vouga', 'Vagos', 'Vale de Cambra']],
|
||||
'Beja' => ['uf' => 'BE', 'cities' => ['Beja', 'Aljustrel', 'Almodôvar', 'Alvito', 'Barrancos', 'Castro Verde', 'Cuba', 'Ferreira do Alentejo', 'Mértola', 'Moura', 'Odemira', 'Ourique', 'Serpa', 'Vidigueira']],
|
||||
'Braga' => ['uf' => 'BR', 'cities' => ['Braga', 'Amares', 'Barcelos', 'Cabeceiras de Basto', 'Celorico de Basto', 'Esposende', 'Fafe', 'Guimarães', 'Póvoa de Lanhoso', 'Terras de Bouro', 'Vieira do Minho', 'Vila Nova de Famalicão', 'Vila Verde', 'Vizela']],
|
||||
'Bragança' => ['uf' => 'BA', 'cities' => ['Bragança', 'Alfândega da Fé', 'Carrazeda de Ansiães', 'Fornos de Algodres', 'Macedo de Cavaleiros', 'Miranda do Douro', 'Mirandela', 'Mogadouro', 'Torre de Moncorvo', 'Vila Flor', 'Vimioso', 'Vinhais']],
|
||||
'Castelo Branco' => ['uf' => 'CB', 'cities' => ['Castelo Branco', 'Belmonte', 'Covilhã', 'Fundão', 'Idanha-a-Nova', 'Oleiros', 'Penamacor', 'Proença-a-Nova', 'Sertã', 'Vila de Rei', 'Vila Velha de Ródão']],
|
||||
'Coimbra' => ['uf' => 'CO', 'cities' => ['Coimbra', 'Arganil', 'Cantanhede', 'Condeixa-a-Nova', 'Figueira da Foz', 'Góis', 'Lousã', 'Mira', 'Miranda do Corvo', 'Montemor-o-Velho', 'Oliveira do Hospital', 'Pampilhosa da Serra', 'Penacova', 'Penela', 'Soure', 'Tábua', 'Vila Nova de Poiares']],
|
||||
'Évora' => ['uf' => 'EV', 'cities' => ['Évora', 'Alandroal', 'Arraiolos', 'Borba', 'Estremoz', 'Montemor-o-Novo', 'Mora', 'Mourão', 'Portel', 'Redondo', 'Reguengos de Monsaraz', 'Vendas Novas', 'Viana do Alentejo', 'Vila Viçosa']],
|
||||
'Faro' => ['uf' => 'FA', 'cities' => ['Faro', 'Albufeira', 'Alcoutim', 'Aljezur', 'Castro Marim', 'Lagoa', 'Lagos', 'Loulé', 'Monchique', 'Olhão', 'Portimão', 'São Brás de Alportel', 'Silves', 'Tavira', 'Vila do Bispo', 'Vila Real de Santo António']],
|
||||
'Guarda' => ['uf' => 'GU', 'cities' => ['Guarda', 'Aguiar da Beira', 'Almeida', 'Celorico da Beira', 'Figueira de Castelo Rodrigo', 'Fornos de Algodres', 'Gouveia', 'Manteigas', 'Mêda', 'Pinhel', 'Sabugal', 'Seia', 'Trancoso', 'Vila Nova de Foz Côa']],
|
||||
'Leiria' => ['uf' => 'LE', 'cities' => ['Leiria', 'Alcobaça', 'Alvaiázere', 'Ansião', 'Batalha', 'Bombarral', 'Caldas da Rainha', 'Castanheira de Pera', 'Figueiró dos Vinhos', 'Marinha Grande', 'Nazaré', 'Óbidos', 'Pedrógão Grande', 'Peniche', 'Pombal', 'Porto de Mós']],
|
||||
'Lisboa' => ['uf' => 'LI', 'cities' => ['Lisboa', 'Alenquer', 'Arruda dos Vinhos', 'Azambuja', 'Cadaval', 'Cascais', 'Loures', 'Lourinhã', 'Mafra', 'Odivelas', 'Oeiras', 'Sintra', 'Sobral de Monte Agraço', 'Torres Vedras', 'Vila Franca de Xira', 'Amadora']],
|
||||
'Portalegre' => ['uf' => 'PO', 'cities' => ['Portalegre', 'Alter do Chão', 'Arronches', 'Avis', 'Campo Maior', 'Castelo de Vide', 'Crato', 'Elvas', 'Fronteira', 'Gavião', 'Marvão', 'Monforte', 'Nisa', 'Ponte de Sor', 'Sousel']],
|
||||
'Porto' => ['uf' => 'PR', 'cities' => ['Porto', 'Amarante', 'Baião', 'Felgueiras', 'Gondomar', 'Lousada', 'Maia', 'Marco de Canaveses', 'Matosinhos', 'Paços de Ferreira', 'Paredes', 'Penafiel', 'Póvoa de Varzim', 'Santo Tirso', 'Trofa', 'Valongo', 'Vila do Conde', 'Vila Nova de Gaia']],
|
||||
'Santarém' => ['uf' => 'SA', 'cities' => ['Santarém', 'Abrantes', 'Alcanena', 'Almeirim', 'Alpiarça', 'Benavente', 'Cartaxo', 'Chamusca', 'Constância', 'Coruche', 'Entroncamento', 'Ferreira do Zêzere', 'Golegã', 'Mação', 'Ourém', 'Rio Maior', 'Salvaterra de Magos', 'Sardoal', 'Tomar', 'Torres Novas', 'Vila Nova da Barquinha']],
|
||||
'Setúbal' => ['uf' => 'SE', 'cities' => ['Setúbal', 'Alcácer do Sal', 'Alcochete', 'Almada', 'Barreiro', 'Grândola', 'Moita', 'Montijo', 'Palmela', 'Santiago do Cacém', 'Seixal', 'Sesimbra', 'Sines']],
|
||||
'Viana do Castelo' => ['uf' => 'VC', 'cities' => ['Viana do Castelo', 'Arcos de Valdevez', 'Caminha', 'Melgaço', 'Monção', 'Paredes de Coura', 'Ponte da Barca', 'Ponte de Lima', 'Valença', 'Vila Nova de Cerveira']],
|
||||
'Vila Real' => ['uf' => 'VR', 'cities' => ['Vila Real', 'Alijó', 'Boticas', 'Chaves', 'Mesão Frio', 'Mondim de Basto', 'Montalegre', 'Murça', 'Peso da Régua', 'Ribeira de Pena', 'Sabrosa', 'Santa Marta de Penaguião', 'Valpaços', 'Vila Pouca de Aguiar']],
|
||||
'Viseu' => ['uf' => 'VI', 'cities' => ['Viseu', 'Armamar', 'Carregal do Sal', 'Castro Daire', 'Cinfães', 'Lamego', 'Mangualde', 'Moimenta da Beira', 'Mortágua', 'Nelas', 'Oliveira de Frades', 'Penalva do Castelo', 'Penedono', 'Resende', 'Santa Comba Dão', 'São João da Pesqueira', 'São Pedro do Sul', 'Sátão', 'Sernancelhe', 'Tabuaço', 'Tarouca', 'Tondela', 'Vila Nova de Paiva', 'Vouzela']],
|
||||
'Açores' => ['uf' => 'AC', 'cities' => ['Ponta Delgada', 'Angra do Heroísmo', 'Horta', 'Ribeira Grande', 'Lagoa', 'Vila Franca do Campo', 'Povoação', 'Nordeste', 'Vila do Porto', 'Santa Cruz da Graciosa', 'Velas', 'Calheta', 'São Roque do Pico', 'Madalena', 'Lajes do Pico', 'Santa Cruz das Flores', 'Lajes das Flores', 'Corvo']],
|
||||
'Madeira' => ['uf' => 'MA', 'cities' => ['Funchal', 'Santa Cruz', 'Câmara de Lobos', 'Machico', 'Ribeira Brava', 'Calheta', 'Ponta do Sol', 'Santana', 'São Vicente', 'Porto Moniz', 'Porto Santo']]
|
||||
];
|
||||
|
||||
foreach ($districts as $stateName => $stateData) {
|
||||
// Check if state exists
|
||||
$stateId = Capsule::table('lists_states')->where('states_country_id', $countryId)->where('states_name', $stateName)->value('states_id');
|
||||
|
||||
if (!$stateId) {
|
||||
$stateId = Capsule::table('lists_states')->insertGetId([
|
||||
'states_country_id' => $countryId,
|
||||
'states_name' => $stateName,
|
||||
'states_uf' => $stateData['uf'],
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($stateData['cities'] as $cityName) {
|
||||
// Check if city exists
|
||||
$cityExists = Capsule::table('lists_cities')->where('cities_state_id', $stateId)->where('cities_name', $cityName)->exists();
|
||||
|
||||
if (!$cityExists) {
|
||||
Capsule::table('lists_cities')->insert([
|
||||
'cities_state_id' => $stateId,
|
||||
'cities_name' => $cityName,
|
||||
'cities_slug' => $this->slugify($cityName),
|
||||
'cities_ibge_code' => null, // Not applicable for Portugal
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal slugify helper
|
||||
*/
|
||||
private function slugify($text)
|
||||
{
|
||||
// Replace non letter or digits by -
|
||||
$text = preg_replace('~[^\\pL\\d]+~u', '-', $text);
|
||||
// Transliterate
|
||||
if (function_exists('iconv')) {
|
||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
}
|
||||
// Remove unwanted characters
|
||||
$text = preg_replace('~[^-\\w]+~', '', $text);
|
||||
// Trim
|
||||
$text = trim($text, '-');
|
||||
// Remove duplicate -
|
||||
$text = preg_replace('~-+~', '-', $text);
|
||||
// Lowercase
|
||||
$text = strtolower($text);
|
||||
|
||||
if (empty($text)) {
|
||||
return 'n-a';
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'PT')->value('countries_id');
|
||||
if ($countryId) {
|
||||
// Cascading delete should handle states and cities if foreign keys are set,
|
||||
// but we'll focus on the country to trigger it.
|
||||
Capsule::table('lists_countries')->where('countries_id', $countryId)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
/**
|
||||
* Migration to import detailed data for Spain (Autonomous Communities and Cities)
|
||||
*
|
||||
* This migration adds Spain to the lists_countries table and populates
|
||||
* its 17 Autonomous Communities and 2 Autonomous Cities into the lists_states table,
|
||||
* along with their respective main cities/provinces into lists_cities.
|
||||
*/
|
||||
class ImportSpainDetailedData extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// Check if Spain already exists
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'ES')->value('countries_id');
|
||||
|
||||
if (!$countryId) {
|
||||
$countryId = Capsule::table('lists_countries')->insertGetId([
|
||||
'countries_name' => json_encode([
|
||||
'pt_BR' => 'Espanha',
|
||||
'en_US' => 'Spain',
|
||||
'es_ES' => 'España',
|
||||
'de_DE' => 'Spanien',
|
||||
'fr_FR' => 'Espagne'
|
||||
]),
|
||||
'countries_iso_code' => 'ES',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
// Autonomous Communities and Cities of Spain with main cities/provinces
|
||||
$communities = [
|
||||
'Andalucía' => ['uf' => 'AN', 'cities' => ['Sevilla', 'Málaga', 'Córdoba', 'Granada', 'Jerez de la Frontera', 'Almería', 'Huelva', 'Marbella', 'Dos Hermanas', 'Cádiz', 'Jaén', 'Algeciras', 'San Fernando', 'El Puerto de Santa María', 'Roquetas de Mar', 'Chiclana de la Frontera', 'El Ejido']],
|
||||
'Aragón' => ['uf' => 'AR', 'cities' => ['Zaragoza', 'Huesca', 'Teruel', 'Calatayud', 'Utebo', 'Monzón', 'Barbastro', 'Ejea de los Caballeros']],
|
||||
'Asturias' => ['uf' => 'AS', 'cities' => ['Gijón', 'Oviedo', 'Avilés', 'Siero', 'Langreo', 'Mieres', 'Castrillón']],
|
||||
'Islas Baleares' => ['uf' => 'IB', 'cities' => ['Palma de Mallorca', 'Ibiza', 'Manacor', 'Mahón', 'Santa Eulalia del Río', 'Inca', 'Ciudadela']],
|
||||
'Canarias' => ['uf' => 'CN', 'cities' => ['Las Palmas de Gran Canaria', 'Santa Cruz de Tenerife', 'San Cristóbal de La Laguna', 'Telde', 'Arona', 'Santa Lucía de Tirajana', 'Arrecife', 'San Bartolomé de Tirajana', 'Puerto del Rosario', 'Adeje', 'La Orotava']],
|
||||
'Cantabria' => ['uf' => 'CB', 'cities' => ['Santander', 'Torrelavega', 'Castro-Urdiales', 'Camargo', 'Piélagos', 'El Astillero', 'Laredo']],
|
||||
'Castilla y León' => ['uf' => 'CL', 'cities' => ['Valladolid', 'Burgos', 'Salamanca', 'León', 'Palencia', 'Ponferrada', 'Zamora', 'Segovia', 'Ávila', 'Miranda de Ebro', 'Aranda de Duero', 'Soria']],
|
||||
'Castilla-La Mancha' => ['uf' => 'CM', 'cities' => ['Albacete', 'Guadalajara', 'Toledo', 'Talavera de la Reina', 'Ciudad Real', 'Cuenca', 'Puertollano', 'Tomelloso', 'Azuqueca de Henares', 'Alcázar de San Juan']],
|
||||
'Catalunya' => ['uf' => 'CT', 'cities' => ['Barcelona', 'L\'Hospitalet de Llobregat', 'Terrassa', 'Badalona', 'Sabadell', 'Lleida', 'Tarragona', 'Mataró', 'Santa Coloma de Gramenet', 'Reus', 'Girona', 'Sant Cugat del Vallès', 'Cornellà de Llobregat', 'Sant Boi de Llobregat', 'Rubí', 'Manresa', 'Vilanova i la Geltrú', 'Castelldefels', 'Viladecans', 'El Prat de Llobregat']],
|
||||
'Comunitat Valenciana' => ['uf' => 'VC', 'cities' => ['Valencia', 'Alicante', 'Elche', 'Castellón de la Plana', 'Torrevieja', 'Torrente', 'Orihuela', 'Gandía', 'Paterna', 'Benidorm', 'Sagunto', 'San Vicente del Raspeig', 'Elda', 'Vila-real', 'Alcoy']],
|
||||
'Extremadura' => ['uf' => 'EX', 'cities' => ['Badajoz', 'Cáceres', 'Mérida', 'Plasencia', 'Don Benito', 'Almendralejo', 'Villanueva de la Serena']],
|
||||
'Galicia' => ['uf' => 'GA', 'cities' => ['Vigo', 'A Coruña', 'Ourense', 'Lugo', 'Santiago de Compostela', 'Pontevedra', 'Ferrol', 'Narón', 'Vilagarcía de Arousa', 'Oleiros', 'Carballo', 'Arteixo']],
|
||||
'Madrid' => ['uf' => 'MD', 'cities' => ['Madrid', 'Móstoles', 'Alcalá de Henares', 'Fuenlabrada', 'Leganés', 'Getafe', 'Alcorcón', 'Torrejón de Ardoz', 'Parla', 'Alcobendas', 'Las Rozas de Madrid', 'San Sebastián de los Reyes', 'Pozuelo de Alarcón', 'Rivas-Vaciamadrid', 'Coslada', 'Valdemoro', 'Majadahonda', 'Collado Villalba', 'Aranjuez', 'Boadilla del Monte']],
|
||||
'Murcia' => ['uf' => 'MC', 'cities' => ['Murcia', 'Cartagena', 'Lorca', 'Molina de Segura', 'Alcantarilla', 'Mazarrón', 'Cieza', 'Águilas', 'Yecla', 'Torre-Pacheco', 'San Javier']],
|
||||
'Navarra' => ['uf' => 'NC', 'cities' => ['Pamplona', 'Tudela', 'Barañáin', 'Valle de Egüés', 'Burlada', 'Zizur Mayor', 'Estella', 'Tafalla']],
|
||||
'País Vasco' => ['uf' => 'PV', 'cities' => ['Bilbao', 'Vitoria-Gasteiz', 'San Sebastián', 'Barakaldo', 'Getxo', 'Irún', 'Portugalete', 'Santurtzi', 'Basauri', 'Errenteria', 'Leioa']],
|
||||
'La Rioja' => ['uf' => 'RI', 'cities' => ['Logroño', 'Calahorra', 'Arnedo', 'Haro', 'Alfaro', 'Lardero', 'Nájera']],
|
||||
'Ceuta' => ['uf' => 'CE', 'cities' => ['Ceuta']],
|
||||
'Melilla' => ['uf' => 'ML', 'cities' => ['Melilla']]
|
||||
];
|
||||
|
||||
foreach ($communities as $stateName => $stateData) {
|
||||
// Check if state exists
|
||||
$stateId = Capsule::table('lists_states')->where('states_country_id', $countryId)->where('states_name', $stateName)->value('states_id');
|
||||
|
||||
if (!$stateId) {
|
||||
$stateId = Capsule::table('lists_states')->insertGetId([
|
||||
'states_country_id' => $countryId,
|
||||
'states_name' => $stateName,
|
||||
'states_uf' => $stateData['uf'],
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($stateData['cities'] as $cityName) {
|
||||
// Check if city exists
|
||||
$cityExists = Capsule::table('lists_cities')->where('cities_state_id', $stateId)->where('cities_name', $cityName)->exists();
|
||||
|
||||
if (!$cityExists) {
|
||||
Capsule::table('lists_cities')->insert([
|
||||
'cities_state_id' => $stateId,
|
||||
'cities_name' => $cityName,
|
||||
'cities_slug' => $this->slugify($cityName),
|
||||
'cities_ibge_code' => null, // Not applicable for Spain
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal slugify helper
|
||||
*/
|
||||
private function slugify($text)
|
||||
{
|
||||
// Replace non letter or digits by -
|
||||
$text = preg_replace('~[^\\pL\\d]+~u', '-', $text);
|
||||
// Transliterate
|
||||
if (function_exists('iconv')) {
|
||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
}
|
||||
// Remove unwanted characters
|
||||
$text = preg_replace('~[^-\\w]+~', '', $text);
|
||||
// Trim
|
||||
$text = trim($text, '-');
|
||||
// Remove duplicate -
|
||||
$text = preg_replace('~-+~', '-', $text);
|
||||
// Lowercase
|
||||
$text = strtolower($text);
|
||||
|
||||
if (empty($text)) {
|
||||
return 'n-a';
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'ES')->value('countries_id');
|
||||
if ($countryId) {
|
||||
// Cascading delete should handle states and cities if foreign keys are set
|
||||
Capsule::table('lists_countries')->where('countries_id', $countryId)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
/**
|
||||
* Migration to import detailed data for Germany (States and Cities)
|
||||
*
|
||||
* This migration adds Germany to the lists_countries table and populates
|
||||
* its 16 Federal States (Bundesländer) into the lists_states table,
|
||||
* along with their respective main cities into lists_cities.
|
||||
*/
|
||||
class ImportGermanyDetailedData extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// Check if Germany already exists
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'DE')->value('countries_id');
|
||||
|
||||
if (!$countryId) {
|
||||
$countryId = Capsule::table('lists_countries')->insertGetId([
|
||||
'countries_name' => json_encode([
|
||||
'pt_BR' => 'Alemanha',
|
||||
'en_US' => 'Germany',
|
||||
'es_ES' => 'Alemania',
|
||||
'de_DE' => 'Deutschland',
|
||||
'fr_FR' => 'Allemagne'
|
||||
]),
|
||||
'countries_iso_code' => 'DE',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
// Federal States of Germany with main cities
|
||||
$states = [
|
||||
'Baden-Württemberg' => ['uf' => 'BW', 'cities' => ['Stuttgart', 'Mannheim', 'Karlsruhe', 'Freiburg im Breisgau', 'Heidelberg', 'Heilbronn', 'Ulm', 'Pforzheim', 'Reutlingen', 'Ludwigsburg', 'Esslingen am Neckar', 'Tübingen', 'Villingen-Schwenningen', 'Konstanz']],
|
||||
'Bayern' => ['uf' => 'BY', 'cities' => ['München', 'Nürnberg', 'Augsburg', 'Regensburg', 'Ingolstadt', 'Fürth', 'Würzburg', 'Erlangen', 'Bamberg', 'Bayreuth', 'Landshut', 'Aschaffenburg', 'Kempten (Allgäu)', 'Rosenheim', 'Neu-Ulm']],
|
||||
'Berlin' => ['uf' => 'BE', 'cities' => ['Berlin']],
|
||||
'Brandenburg' => ['uf' => 'BB', 'cities' => ['Potsdam', 'Cottbus', 'Brandenburg an der Havel', 'Frankfurt (Oder)', 'Oranienburg', 'Falkensee', 'Bernau bei Berlin', 'Königs Wusterhausen']],
|
||||
'Bremen' => ['uf' => 'HB', 'cities' => ['Bremen', 'Bremerhaven']],
|
||||
'Hamburg' => ['uf' => 'HH', 'cities' => ['Hamburg']],
|
||||
'Hessen' => ['uf' => 'HE', 'cities' => ['Frankfurt am Main', 'Wiesbaden', 'Kassel', 'Darmstadt', 'Offenbach am Main', 'Hanau', 'Giessen', 'Marburg', 'Fulda', 'Rüsselsheim am Main', 'Bad Homburg vor der Höhe']],
|
||||
'Mecklenburg-Vorpommern' => ['uf' => 'MV', 'cities' => ['Rostock', 'Schwerin', 'Neubrandenburg', 'Stralsund', 'Greifswald', 'Wismar']],
|
||||
'Niedersachsen' => ['uf' => 'NI', 'cities' => ['Hannover', 'Braunschweig', 'Oldenburg', 'Osnabrück', 'Wolfsburg', 'Göttingen', 'Salzgitter', 'Hildesheim', 'Delmenhorst', 'Lüneburg', 'Wilhelmshaven', 'Hameln', 'Wolfenbüttel']],
|
||||
'Nordrhein-Westfalen' => ['uf' => 'NW', 'cities' => ['Köln', 'Düsseldorf', 'Dortmund', 'Essen', 'Duisburg', 'Bochum', 'Wuppertal', 'Bielefeld', 'Bonn', 'Münster', 'Gelsenkirchen', 'Mönchengladbach', 'Aachen', 'Chemnitz', 'Oberhausen', 'Hagen', 'Hamm', 'Mülheim an der Ruhr', 'Leverkusen', 'Solingen', 'Herne', 'Neuss', 'Paderborn', 'Bottrop', 'Recklinghausen', 'Bergisch Gladbach', 'Remscheid', 'Moers', 'Siegen']],
|
||||
'Rheinland-Pfalz' => ['uf' => 'RP', 'cities' => ['Mainz', 'Ludwigshafen am Rhein', 'Koblenz', 'Trier', 'Kaiserslautern', 'Worms', 'Neuwied', 'Neustadt an der Weinstraße', 'Speyer', 'Bad Kreuznach']],
|
||||
'Saarland' => ['uf' => 'SL', 'cities' => ['Saarbrücken', 'Neunkirchen', 'Homburg', 'Völklingen', 'Sankt Ingbert', 'Saarlouis']],
|
||||
'Sachsen' => ['uf' => 'SN', 'cities' => ['Leipzig', 'Dresden', 'Chemnitz', 'Zwickau', 'Plauen', 'Görlitz', 'Bautzen', 'Freiberg']],
|
||||
'Sachsen-Anhalt' => ['uf' => 'ST', 'cities' => ['Magdeburg', 'Halle (Saale)', 'Dessau-Roßlau', 'Lutherstadt Wittenberg', 'Halberstadt', 'Stendal']],
|
||||
'Schleswig-Holstein' => ['uf' => 'SH', 'cities' => ['Kiel', 'Lübeck', 'Flensburg', 'Neumünster', 'Norderstedt', 'Elmshorn', 'Pinneberg', 'Ahrensburg']],
|
||||
'Thüringen' => ['uf' => 'TH', 'cities' => ['Erfurt', 'Jena', 'Gera', 'Weimar', 'Gotha', 'Eisenach', 'Nordhausen', 'Suhl']]
|
||||
];
|
||||
|
||||
foreach ($states as $stateName => $stateData) {
|
||||
// Check if state exists
|
||||
$stateId = Capsule::table('lists_states')->where('states_country_id', $countryId)->where('states_name', $stateName)->value('states_id');
|
||||
|
||||
if (!$stateId) {
|
||||
$stateId = Capsule::table('lists_states')->insertGetId([
|
||||
'states_country_id' => $countryId,
|
||||
'states_name' => $stateName,
|
||||
'states_uf' => $stateData['uf'],
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($stateData['cities'] as $cityName) {
|
||||
// Check if city exists
|
||||
$cityExists = Capsule::table('lists_cities')->where('cities_state_id', $stateId)->where('cities_name', $cityName)->exists();
|
||||
|
||||
if (!$cityExists) {
|
||||
Capsule::table('lists_cities')->insert([
|
||||
'cities_state_id' => $stateId,
|
||||
'cities_name' => $cityName,
|
||||
'cities_slug' => $this->slugify($cityName),
|
||||
'cities_ibge_code' => null, // Not applicable for Germany
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal slugify helper
|
||||
*/
|
||||
private function slugify($text)
|
||||
{
|
||||
// Replace non letter or digits by -
|
||||
$text = preg_replace('~[^\\pL\\d]+~u', '-', $text);
|
||||
// Transliterate
|
||||
if (function_exists('iconv')) {
|
||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
}
|
||||
// Remove unwanted characters
|
||||
$text = preg_replace('~[^-\\w]+~', '', $text);
|
||||
// Trim
|
||||
$text = trim($text, '-');
|
||||
// Remove duplicate -
|
||||
$text = preg_replace('~-+~', '-', $text);
|
||||
// Lowercase
|
||||
$text = strtolower($text);
|
||||
|
||||
if (empty($text)) {
|
||||
return 'n-a';
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'DE')->value('countries_id');
|
||||
if ($countryId) {
|
||||
// Cascading delete should handle states and cities if foreign keys are set
|
||||
Capsule::table('lists_countries')->where('countries_id', $countryId)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
/**
|
||||
* Migration to import detailed data for Mexico (States and Cities)
|
||||
*
|
||||
* This migration adds Mexico to the lists_countries table and populates
|
||||
* its 31 States and Mexico City into the lists_states table,
|
||||
* along with their respective main municipalities into lists_cities.
|
||||
*/
|
||||
class ImportMexicoDetailedData extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// Check if Mexico already exists
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'MX')->value('countries_id');
|
||||
|
||||
if (!$countryId) {
|
||||
$countryId = Capsule::table('lists_countries')->insertGetId([
|
||||
'countries_name' => json_encode([
|
||||
'pt_BR' => 'México',
|
||||
'en_US' => 'Mexico',
|
||||
'es_ES' => 'México',
|
||||
'de_DE' => 'Mexiko',
|
||||
'fr_FR' => 'Mexique'
|
||||
]),
|
||||
'countries_iso_code' => 'MX',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
// States of Mexico with main cities/municipalities
|
||||
$states = [
|
||||
'Aguascalientes' => ['uf' => 'AS', 'cities' => ['Aguascalientes', 'Jesús María', 'Calvillo', 'Pabellón de Arteaga', 'Rincón de Romos']],
|
||||
'Baja California' => ['uf' => 'BC', 'cities' => ['Tijuana', 'Mexicali', 'Ensenada', 'Tecate', 'Playas de Rosarito']],
|
||||
'Baja California Sur' => ['uf' => 'BS', 'cities' => ['La Paz', 'Los Cabos', 'Comondú', 'Loreto', 'Mulegé']],
|
||||
'Campeche' => ['uf' => 'CC', 'cities' => ['Campeche', 'Ciudad del Carmen', 'Champotón', 'Escárcega', 'Calkiní']],
|
||||
'Chiapas' => ['uf' => 'CS', 'cities' => ['Tuxtla Gutiérrez', 'Tapachula', 'San Cristóbal de las Casas', 'Comitán de Domínguez', 'Palenque', 'Chiapa de Corzo']],
|
||||
'Chihuahua' => ['uf' => 'CH', 'cities' => ['Chihuahua', 'Ciudad Juárez', 'Delicias', 'Cuauhtémoc', 'Parral', 'Nuevo Casas Grandes']],
|
||||
'Ciudad de México' => ['uf' => 'DF', 'cities' => ['Iztapalapa', 'Gustavo A. Madero', 'Álvaro Obregón', 'Tlalpan', 'Coyoacán', 'Cuauhtémoc', 'Venustiano Carranza', 'Azcapotzalco', 'Benito Juárez', 'Miguel Hidalgo']],
|
||||
'Coahuila' => ['uf' => 'CL', 'cities' => ['Saltillo', 'Torreón', 'Monclova', 'Piedras Negras', 'Acuña', 'Matamoros']],
|
||||
'Colima' => ['uf' => 'CM', 'cities' => ['Colima', 'Manzanillo', 'Villa de Álvarez', 'Tecomán']],
|
||||
'Durango' => ['uf' => 'DG', 'cities' => ['Durango', 'Gómez Palacio', 'Lerdo', 'Pueblo Nuevo', 'Santiago Papasquiaro']],
|
||||
'Guanajuato' => ['uf' => 'GT', 'cities' => ['León', 'Irapuato', 'Celaya', 'Salamanca', 'Guanajuato', 'San Miguel de Allende', 'Silao']],
|
||||
'Guerrero' => ['uf' => 'GR', 'cities' => ['Acapulco de Juárez', 'Chilpancingo de los Bravo', 'Iguala de la Independencia', 'Zihuatanejo', 'Taxco de Alarcón']],
|
||||
'Hidalgo' => ['uf' => 'HG', 'cities' => ['Pachuca de Soto', 'Tulancingo de Bravo', 'Tula de Allende', 'Tizayuca', 'Huejutla de Reyes']],
|
||||
'Jalisco' => ['uf' => 'JC', 'cities' => ['Guadalajara', 'Zapopan', 'Tlaquepaque', 'Tonalá', 'Puerto Vallarta', 'Tlajomulco de Zúñiga', 'Lagos de Moreno', 'Tepatitlán de Morelos']],
|
||||
'México' => ['uf' => 'MC', 'cities' => ['Ecatepec de Morelos', 'Nezahualcóyotl', 'Naucalpan de Juárez', 'Toluca', 'Tlalnepantla de Baz', 'Chimalhuacán', 'Cuautitlán Izcalli', 'Atizapán de Zaragoza', 'Ixtapaluca', 'Tecámac']],
|
||||
'Michoacán' => ['uf' => 'MN', 'cities' => ['Morelia', 'Uruapan', 'Lázaro Cárdenas', 'Zamora', 'Apatzingán', 'Zitácuaro']],
|
||||
'Morelos' => ['uf' => 'MS', 'cities' => ['Cuernavaca', 'Jiutepec', 'Cuautla', 'Temixco', 'Yautepec']],
|
||||
'Nayarit' => ['uf' => 'NT', 'cities' => ['Tepic', 'Bahía de Banderas', 'Santiago Ixcuintla', 'Compostela']],
|
||||
'Nuevo León' => ['uf' => 'NL', 'cities' => ['Monterrey', 'Guadalupe', 'Apodaca', 'San Nicolás de los Garza', 'General Escobedo', 'Santa Catarina', 'San Pedro Garza García', 'Juárez']],
|
||||
'Oaxaca' => ['uf' => 'OC', 'cities' => ['Oaxaca de Juárez', 'San Juan Bautista Tuxtepec', 'Salina Cruz', 'Juchitán de Zaragoza', 'Huajuapan de León']],
|
||||
'Puebla' => ['uf' => 'PL', 'cities' => ['Puebla de Zaragoza', 'Tehuacán', 'San Martín Texmelucan', 'Atlixco', 'San Pedro Cholula', 'Cuautlancingo']],
|
||||
'Querétaro' => ['uf' => 'QT', 'cities' => ['Querétaro', 'San Juan del Río', 'Corregidora', 'El Marqués', 'Tequisquiapan']],
|
||||
'Quintana Roo' => ['uf' => 'QR', 'cities' => ['Cancún', 'Playa del Carmen', 'Chetumal', 'Cozumel', 'Tulum']],
|
||||
'San Luis Potosí' => ['uf' => 'SP', 'cities' => ['San Luis Potosí', 'Soledad de Graciano Sánchez', 'Ciudad Valles', 'Matehuala', 'Río Verde']],
|
||||
'Sinaloa' => ['uf' => 'SL', 'cities' => ['Culiacán', 'Mazatlán', 'Los Mochis', 'Guasave', 'Navolato']],
|
||||
'Sonora' => ['uf' => 'SR', 'cities' => ['Hermosillo', 'Ciudad Obregón', 'Nogales', 'San Luis Río Colorado', 'Navojoa', 'Guaymas']],
|
||||
'Tabasco' => ['uf' => 'TC', 'cities' => ['Villahermosa', 'Cárdenas', 'Comalcalco', 'Huimanguillo', 'Macuspana']],
|
||||
'Tamaulipas' => ['uf' => 'TS', 'cities' => ['Reynosa', 'Matamoros', 'Nuevo Laredo', 'Ciudad Victoria', 'Tampico', 'Ciudad Madero', 'Altamira']],
|
||||
'Tlaxcala' => ['uf' => 'TL', 'cities' => ['Tlaxcala', 'Huamantla', 'Apizaco', 'Chiautempan', 'San Pablo del Monte']],
|
||||
'Veracruz' => ['uf' => 'VZ', 'cities' => ['Veracruz', 'Xalapa', 'Coatzacoalcos', 'Boca del Río', 'Minatitlán', 'Poza Rica', 'Córdoba', 'Orizaba', 'Tuxpan']],
|
||||
'Yucatán' => ['uf' => 'YN', 'cities' => ['Mérida', 'Kanasín', 'Valladolid', 'Tizimín', 'Progreso']],
|
||||
'Zacatecas' => ['uf' => 'ZS', 'cities' => ['Zacatecas', 'Fresnillo', 'Guadalupe', 'Jerez', 'Sombrerete']]
|
||||
];
|
||||
|
||||
foreach ($states as $stateName => $stateData) {
|
||||
// Check if state exists
|
||||
$stateId = Capsule::table('lists_states')->where('states_country_id', $countryId)->where('states_name', $stateName)->value('states_id');
|
||||
|
||||
if (!$stateId) {
|
||||
$stateId = Capsule::table('lists_states')->insertGetId([
|
||||
'states_country_id' => $countryId,
|
||||
'states_name' => $stateName,
|
||||
'states_uf' => $stateData['uf'],
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($stateData['cities'] as $cityName) {
|
||||
// Check if city exists
|
||||
$cityExists = Capsule::table('lists_cities')->where('cities_state_id', $stateId)->where('cities_name', $cityName)->exists();
|
||||
|
||||
if (!$cityExists) {
|
||||
Capsule::table('lists_cities')->insert([
|
||||
'cities_state_id' => $stateId,
|
||||
'cities_name' => $cityName,
|
||||
'cities_slug' => $this->slugify($cityName),
|
||||
'cities_ibge_code' => null, // Not applicable for Mexico
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal slugify helper
|
||||
*/
|
||||
private function slugify($text)
|
||||
{
|
||||
// Replace non letter or digits by -
|
||||
$text = preg_replace('~[^\\pL\\d]+~u', '-', $text);
|
||||
// Transliterate
|
||||
if (function_exists('iconv')) {
|
||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
}
|
||||
// Remove unwanted characters
|
||||
$text = preg_replace('~[^-\\w]+~', '', $text);
|
||||
// Trim
|
||||
$text = trim($text, '-');
|
||||
// Remove duplicate -
|
||||
$text = preg_replace('~-+~', '-', $text);
|
||||
// Lowercase
|
||||
$text = strtolower($text);
|
||||
|
||||
if (empty($text)) {
|
||||
return 'n-a';
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'MX')->value('countries_id');
|
||||
if ($countryId) {
|
||||
// Cascading delete should handle states and cities if foreign keys are set
|
||||
Capsule::table('lists_countries')->where('countries_id', $countryId)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
/**
|
||||
* Migration to import ALL cities for the USA from a CSV file.
|
||||
*
|
||||
* This migration adds the USA to the lists_countries table and populates
|
||||
* all its states and cities from the usa_cities.csv file.
|
||||
*/
|
||||
class ImportUsaDetailedData extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// Increase memory and time limit for large import
|
||||
ini_set('memory_limit', '512M');
|
||||
set_time_limit(600);
|
||||
|
||||
// Check if USA already exists
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'US')->value('countries_id');
|
||||
|
||||
if (!$countryId) {
|
||||
$countryId = Capsule::table('lists_countries')->insertGetId([
|
||||
'countries_name' => json_encode([
|
||||
'pt_BR' => 'Estados Unidos',
|
||||
'en_US' => 'United States',
|
||||
'es_ES' => 'Estados Unidos',
|
||||
'de_DE' => 'Vereinigte Staaten',
|
||||
'fr_FR' => 'États-Unis'
|
||||
]),
|
||||
'countries_iso_code' => 'US',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
$csvPath = dirname(__DIR__, 4) . DIRECTORY_SEPARATOR . 'usa_cities.csv';
|
||||
if (!file_exists($csvPath)) {
|
||||
// Fallback to root if not found relative to migration
|
||||
$csvPath = 'usa_cities.csv';
|
||||
}
|
||||
|
||||
if (file_exists($csvPath)) {
|
||||
$handle = fopen($csvPath, 'r');
|
||||
if ($handle !== false) {
|
||||
// Skip header
|
||||
fgetcsv($handle, 0, '|');
|
||||
|
||||
$statesMap = []; // state_short => state_id
|
||||
$citiesMap = []; // state_id => [city_name => true]
|
||||
|
||||
// Pre-load existing states for USA to avoid duplicates and speed up
|
||||
$existingStates = Capsule::table('lists_states')->where('states_country_id', $countryId)->get();
|
||||
foreach ($existingStates as $s) {
|
||||
$statesMap[$s->states_uf] = $s->states_id;
|
||||
$citiesMap[$s->states_id] = [];
|
||||
|
||||
// Pre-load existing cities for these states
|
||||
$existingCities = Capsule::table('lists_cities')->where('cities_state_id', $s->states_id)->pluck('cities_name')->toArray();
|
||||
foreach ($existingCities as $cityName) {
|
||||
$citiesMap[$s->states_id][$cityName] = true;
|
||||
}
|
||||
}
|
||||
|
||||
Capsule::transaction(function () use ($handle, $countryId, &$statesMap, &$citiesMap) {
|
||||
$batchSize = 500;
|
||||
$cityBatch = [];
|
||||
|
||||
while (($data = fgetcsv($handle, 0, '|')) !== false) {
|
||||
if (count($data) < 3) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$cityName = trim($data[0]);
|
||||
$stateShort = trim($data[1]);
|
||||
$stateFull = trim($data[2]);
|
||||
|
||||
// Skip non-US states/territories if needed, but let's include what's in CSV
|
||||
// Usually this CSV covers 50 states + PR, VI, GU, etc.
|
||||
|
||||
if (!isset($statesMap[$stateShort])) {
|
||||
$statesMap[$stateShort] = Capsule::table('lists_states')->insertGetId([
|
||||
'states_country_id' => $countryId,
|
||||
'states_name' => $stateFull,
|
||||
'states_uf' => $stateShort,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
$citiesMap[$statesMap[$stateShort]] = [];
|
||||
}
|
||||
|
||||
$stateId = $statesMap[$stateShort];
|
||||
|
||||
if (!isset($citiesMap[$stateId][$cityName])) {
|
||||
$cityBatch[] = [
|
||||
'cities_state_id' => $stateId,
|
||||
'cities_name' => $cityName,
|
||||
'cities_slug' => $this->slugify($cityName),
|
||||
'cities_ibge_code' => null,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
];
|
||||
$citiesMap[$stateId][$cityName] = true;
|
||||
|
||||
if (count($cityBatch) >= $batchSize) {
|
||||
Capsule::table('lists_cities')->insert($cityBatch);
|
||||
$cityBatch = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($cityBatch)) {
|
||||
Capsule::table('lists_cities')->insert($cityBatch);
|
||||
}
|
||||
});
|
||||
|
||||
fclose($handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal slugify helper
|
||||
*/
|
||||
private function slugify($text)
|
||||
{
|
||||
$text = preg_replace('~[^\\pL\\d]+~u', '-', $text);
|
||||
if (function_exists('iconv')) {
|
||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
}
|
||||
$text = preg_replace('~[^-\\w]+~', '', $text);
|
||||
$text = trim($text, '-');
|
||||
$text = preg_replace('~-+~', '-', $text);
|
||||
$text = strtolower($text);
|
||||
return empty($text) ? 'n-a' : $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$countryId = Capsule::table('lists_countries')->where('countries_iso_code', 'US')->value('countries_id');
|
||||
if ($countryId) {
|
||||
Capsule::table('lists_countries')->where('countries_id', $countryId)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
+193
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* Migration to import detailed cities for all countries currently in the database.
|
||||
* This migration uses global datasets from countries-states-cities-database.
|
||||
*
|
||||
* @author SysCMS
|
||||
*/
|
||||
class ImportGlobalDetailedCities extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// Increase memory and execution time for large dataset processing
|
||||
ini_set('memory_limit', '1024M');
|
||||
set_time_limit(1200);
|
||||
|
||||
$statesCsvPath = 'states.csv';
|
||||
$citiesCsvPath = 'cities.csv';
|
||||
|
||||
if (!file_exists($statesCsvPath) || !file_exists($citiesCsvPath)) {
|
||||
// Check in root directory if not found in current (for different execution contexts)
|
||||
$statesCsvPath = dirname(__DIR__, 4) . DIRECTORY_SEPARATOR . 'states.csv';
|
||||
$citiesCsvPath = dirname(__DIR__, 4) . DIRECTORY_SEPARATOR . 'cities.csv';
|
||||
}
|
||||
|
||||
if (!file_exists($statesCsvPath) || !file_exists($citiesCsvPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. Get all countries currently in the database
|
||||
$countries = Capsule::table('lists_countries')->get();
|
||||
$countryMap = []; // iso_code => countries_id
|
||||
foreach ($countries as $country) {
|
||||
$countryMap[$country->countries_iso_code] = $country->countries_id;
|
||||
}
|
||||
|
||||
$isoCodes = array_keys($countryMap);
|
||||
|
||||
// 2. Load and process States
|
||||
$statesMap = []; // csv_state_id => db_states_id
|
||||
$handle = fopen($statesCsvPath, 'r');
|
||||
if ($handle !== false) {
|
||||
$header = fgetcsv($handle);
|
||||
$colIndices = array_flip($header);
|
||||
|
||||
while (($data = fgetcsv($handle)) !== false) {
|
||||
$csvStateId = $data[$colIndices['id']];
|
||||
$stateName = $data[$colIndices['name']];
|
||||
$countryCode = $data[$colIndices['country_code']];
|
||||
$stateUf = $data[$colIndices['iso2']] ?? substr($stateName, 0, 2);
|
||||
|
||||
if (isset($countryMap[$countryCode])) {
|
||||
$dbCountryId = $countryMap[$countryCode];
|
||||
|
||||
// Check if state already exists
|
||||
$existingState = Capsule::table('lists_states')
|
||||
->where('states_country_id', $dbCountryId)
|
||||
->where('states_name', $stateName)
|
||||
->first();
|
||||
|
||||
if (!$existingState) {
|
||||
$dbStateId = Capsule::table('lists_states')->insertGetId([
|
||||
'states_country_id' => $dbCountryId,
|
||||
'states_name' => $stateName,
|
||||
'states_uf' => $stateUf,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
} else {
|
||||
$dbStateId = $existingState->states_id;
|
||||
}
|
||||
|
||||
$statesMap[$csvStateId] = $dbStateId;
|
||||
}
|
||||
}
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
// 3. Load and process Cities
|
||||
$handle = fopen($citiesCsvPath, 'r');
|
||||
if ($handle !== false) {
|
||||
$header = fgetcsv($handle);
|
||||
$colIndices = array_flip($header);
|
||||
|
||||
$batchSize = 500;
|
||||
$cityBatch = [];
|
||||
$processedCities = []; // To avoid duplicates within the same migration run
|
||||
|
||||
Capsule::transaction(function () use ($handle, $colIndices, $statesMap, $countryMap, $batchSize, &$cityBatch, &$processedCities) {
|
||||
while (($data = fgetcsv($handle)) !== false) {
|
||||
$cityName = $data[$colIndices['name']];
|
||||
$csvStateId = $data[$colIndices['state_id']];
|
||||
$countryCode = $data[$colIndices['country_code']];
|
||||
|
||||
if (isset($countryMap[$countryCode]) && isset($statesMap[$csvStateId])) {
|
||||
$dbStateId = $statesMap[$csvStateId];
|
||||
|
||||
// Check if city already exists for this state
|
||||
// To speed up, we only check in DB if not already in our processedCities map
|
||||
$cityKey = $dbStateId . '_' . $cityName;
|
||||
if (isset($processedCities[$cityKey])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$existingCity = Capsule::table('lists_cities')
|
||||
->where('cities_state_id', $dbStateId)
|
||||
->where('cities_name', $cityName)
|
||||
->first();
|
||||
|
||||
if (!$existingCity) {
|
||||
$cityBatch[] = [
|
||||
'cities_state_id' => $dbStateId,
|
||||
'cities_name' => $cityName,
|
||||
'cities_slug' => $this->slugify($cityName),
|
||||
'cities_ibge_code' => null,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
];
|
||||
$processedCities[$cityKey] = true;
|
||||
|
||||
if (count($cityBatch) >= $batchSize) {
|
||||
Capsule::table('lists_cities')->insert($cityBatch);
|
||||
$cityBatch = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($cityBatch)) {
|
||||
Capsule::table('lists_cities')->insert($cityBatch);
|
||||
}
|
||||
});
|
||||
|
||||
fclose($handle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
// This migration is additive. Reversing it completely would be complex
|
||||
// and might delete data that was already there.
|
||||
// We usually don't delete city data in down() unless it's a specific country import.
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a URL-friendly slug.
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
private function slugify($text)
|
||||
{
|
||||
// Replace non letter or digits by -
|
||||
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
|
||||
|
||||
// Transliterate
|
||||
if (function_exists('iconv')) {
|
||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
}
|
||||
|
||||
// Remove unwanted characters
|
||||
$text = preg_replace('~[^-\w]+~', '', $text);
|
||||
|
||||
// Trim
|
||||
$text = trim($text, '-');
|
||||
|
||||
// Remove duplicate -
|
||||
$text = preg_replace('~-+~', '-', $text);
|
||||
|
||||
// Lowercase
|
||||
$text = strtolower($text);
|
||||
|
||||
if (empty($text)) {
|
||||
return 'n-a';
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user