Added Country table and import script
This commit is contained in:
52
scripts/import-countries.php
Executable file
52
scripts/import-countries.php
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
//require 'vendor/autoload.php';
|
||||
require("../config/config.php");
|
||||
|
||||
define('FRONKDB_SQLDEBUG',false);
|
||||
error_reporting(E_ALL & ~(E_NOTICE | E_STRICT | E_DEPRECATED));
|
||||
|
||||
require_once(LIBDIR."/mvcfronk/mfRouter/mfRouter.php");
|
||||
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseModel.php");
|
||||
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseController.php");
|
||||
|
||||
$me = new User(1);
|
||||
define("INTERNAL_USER_ID", $me->id);
|
||||
define("INTERNAL_USER_USERNAME", $me->username);
|
||||
|
||||
$folder = __DIR__."/import/";
|
||||
$csvname = "iso_codes.csv";
|
||||
$filename = $folder.$csvname;
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
$log = mfLoghandler::singleton();
|
||||
|
||||
$input = fopen($filename, "r");
|
||||
|
||||
$l = 0;
|
||||
$c = 0;
|
||||
while($csv = fgetcsv($input, 0, ";")) {
|
||||
$l++;
|
||||
if($l == 1) continue;
|
||||
|
||||
if(!trim($csv[0])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$name = trim($csv[0]);
|
||||
$isocode = trim($csv[1]);
|
||||
$is_eu = trim($csv[2]);
|
||||
|
||||
if(CountryModel::getFirst(["name" => $name]) || CountryModel::getFirst(["isocode" => $isocode])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$country = CountryModel::create([
|
||||
"name" => $name,
|
||||
"isocode" => $isocode,
|
||||
"is_eu" => ($is_eu) ? 1 : 0
|
||||
]);
|
||||
|
||||
$country->save();
|
||||
}
|
||||
Reference in New Issue
Block a user