| version 1.16, 2017/09/23 00:53:31 |
version 1.17, 2017/10/07 09:33:42 |
|
|
| * Changelog: |
* Changelog: |
| * 2007-03-09 - created |
* 2007-03-09 - created |
| * 2017-09-12 - implemented new SK-NIC-EPP/CentralNic export |
* 2017-09-12 - implemented new SK-NIC-EPP/CentralNic export |
| |
* 2017-10-07 - added import of expired domains (droplist) |
| */ |
*/ |
| |
|
| /* $Platon: scripts/php/sk-nic/SK-NIC.php,v 1.15 2017/09/19 02:20:11 nepto Exp $ */ |
/* $Platon: scripts/php/sk-nic/SK-NIC.php,v 1.16 2017/09/23 00:53:31 nepto Exp $ */ |
| |
|
| require_once 'DB.php'; |
require_once 'DB.php'; |
| |
|
|
|
| $this->table_current = 'sknic_domains'; |
$this->table_current = 'sknic_domains'; |
| $this->table_import = 'sknic_domains_import'; |
$this->table_import = 'sknic_domains_import'; |
| $this->table_history = 'sknic_domains_history'; |
$this->table_history = 'sknic_domains_history'; |
| |
$this->pk_header_del = 'domena'; |
| |
break; |
| |
case 'droplist': |
| |
$this->context = 'droplist'; |
| |
$this->primary_key = 'domain'; |
| |
$this->table_current = 'sknic_droplist'; |
| |
$this->table_import = 'sknic_droplist_import'; |
| |
$this->table_history = 'sknic_droplist_history'; |
| |
$this->pk_header_del = 'Domain_Name'; |
| break; |
break; |
| case 'registrar': |
case 'registrar': |
| $this->context = 'registrar'; |
$this->context = 'registrar'; |
|
|
| $this->table_current = 'sknic_registrars'; |
$this->table_current = 'sknic_registrars'; |
| $this->table_import = 'sknic_registrars_import'; |
$this->table_import = 'sknic_registrars_import'; |
| $this->table_history = 'sknic_registrars_history'; |
$this->table_history = 'sknic_registrars_history'; |
| |
$this->pk_header_del = 'Reg ID'; |
| break; |
break; |
| default: |
default: |
| die(sprintf("%s() ERROR: unknown context: %s\n", __FUNCTION__, $context)); |
die(sprintf("%s() ERROR: unknown context: %s\n", __FUNCTION__, $context)); |
|
|
| $basefile = basename($filename); |
$basefile = basename($filename); |
| if (preg_match('/^domain/', $basefile)) { |
if (preg_match('/^domain/', $basefile)) { |
| return $this->setContext('domain'); |
return $this->setContext('domain'); |
| |
} elseif (preg_match('/^droplist/', $basefile)) { |
| |
return $this->setContext('droplist'); |
| } elseif (preg_match('/^registrar/', $basefile)) { |
} elseif (preg_match('/^registrar/', $basefile)) { |
| return $this->setContext('registrar'); |
return $this->setContext('registrar'); |
| } |
} |
|
|
| $query = 'SELECT COUNT(*) FROM '.$this->table_import; |
$query = 'SELECT COUNT(*) FROM '.$this->table_import; |
| $count = $this->_db->getOne($query); |
$count = $this->_db->getOne($query); |
| DB::isError($count) && $this->error($count); |
DB::isError($count) && $this->error($count); |
| |
// here droplist shares limits with registrars (1000/9900) |
| $min_count = ($this->context == 'domain') ? 100000 : 1000; |
$min_count = ($this->context == 'domain') ? 100000 : 1000; |
| $max_count = ($this->context == 'domain') ? 900000 : 9000; |
$max_count = ($this->context == 'domain') ? 900000 : 9900; |
| if ($count < $min_count) { |
if ($count < $min_count) { |
| die(sprintf("%s() ERROR: too less imported records: %d (must be min %d)\n", |
die(sprintf("%s() ERROR: too less imported %s records: %d (must be min %d)\n", |
| __FUNCTION__, $count, $min_count)); |
__FUNCTION__, $this->context, $count, $min_count)); |
| } |
} |
| if ($count > $max_count) { |
if ($count > $max_count) { |
| die(sprintf("%s() ERROR: too much imported records: %d (must be max 600000)\n", |
die(sprintf("%s() ERROR: too much imported %s records: %d (must be max 600000)\n", |
| __FUNCTION__, $count, $max_count)); |
__FUNCTION__, $this->context, $count, $max_count)); |
| } |
} |
| return true; |
return true; |
| } /* }}} */ |
} /* }}} */ |
|
|
| { /* Sorts by: |
{ /* Sorts by: |
| * 1. length - shorter hostname first |
* 1. length - shorter hostname first |
| * 2. alphabeticaly |
* 2. alphabeticaly |
| * Sorted exmaple: |
* Properly sorted example: |
| * - ns.platon.sk |
* - ns.platon.sk |
| * - dns.platon.sk |
* - dns.platon.sk |
| * - ns.platon.org |
* - ns.platon.org |
|
|
| } /* }}} */ |
} /* }}} */ |
| |
|
| function _writeImportWithInserts($filename, $changed_date) /* {{{ */ |
function _writeImportWithInserts($filename, $changed_date) /* {{{ */ |
| { |
{ // DELETEME 1Q/2018 |
| if (($f = fopen($filename, 'r')) == false) { |
if (($f = fopen($filename, 'r')) == false) { |
| $this->error('unable to open: '.$filename); |
$this->error('unable to open: '.$filename); |
| } |
} |
|
|
| $this->_db->quote($changed_date)); |
$this->_db->quote($changed_date)); |
| $result = $this->_db->query($query); |
$result = $this->_db->query($query); |
| DB::isError($result) && $this->error($result); |
DB::isError($result) && $this->error($result); |
| |
} elseif ($this->context == 'droplist') { |
| |
$query = sprintf('LOAD DATA LOCAL INFILE %s' |
| |
.' INTO TABLE %s' |
| |
.' CHARACTER SET UTF8' |
| |
.' FIELDS TERMINATED BY ","' // note different separator |
| |
.' (domain,date_entered,date_leaves,date_purged)' |
| |
.' SET dt_changed = %s', |
| |
$this->_db->quote($filename), |
| |
$this->table_import, |
| |
$this->_db->quote($changed_date)); |
| |
$result = $this->_db->query($query); |
| |
DB::isError($result) && $this->error($result); |
| } elseif ($this->context == 'registrar') { |
} elseif ($this->context == 'registrar') { |
| $this->_db->query('SET NAMES UTF8'); |
$this->_db->query('SET NAMES UTF8'); |
| $query = sprintf('LOAD DATA LOCAL INFILE %s' |
$query = sprintf('LOAD DATA LOCAL INFILE %s' |
|
|
| die(sprintf("%s() ERROR: unknown context: %s\n", __FUNCTION__, $context)); |
die(sprintf("%s() ERROR: unknown context: %s\n", __FUNCTION__, $context)); |
| } |
} |
| |
|
| $query = "DELETE FROM $this->table_import WHERE $this->primary_key LIKE '-- %'"; |
// Remove all lines started with "--" |
| |
$query = sprintf('DELETE FROM %s WHERE %s LIKE "-- %%"', |
| |
$this->table_import, $this->primary_key); |
| |
$result = $this->_db->query($query); |
| |
DB::isError($result) && $this->error($result); |
| |
// Remove table headers (we want just data) |
| |
$query = sprintf('DELETE FROM %s WHERE %s = %s LIMIT 1', |
| |
$this->table_import, $this->primary_key, |
| |
$this->_db->quote($this->pk_header_del)); |
| $result = $this->_db->query($query); |
$result = $this->_db->query($query); |
| DB::isError($result) && $this->error($result); |
DB::isError($result) && $this->error($result); |
| } /* }}} */ |
} /* }}} */ |