54 lines
1.2 KiB
PHP
Executable File
54 lines
1.2 KiB
PHP
Executable File
#!/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
|
|
]);
|
|
|
|
if(!$country->save()) {
|
|
die(__FILE__.": Error saving new country!\n");
|
|
}
|
|
} |