| version 1.1, 2007/03/11 03:49:48 |
version 1.2, 2007/03/11 03:54:40 |
|
|
| * |
* |
| */ |
*/ |
| |
|
| /* $Platon$ */ |
/* $Platon: scripts/php/sk-nic/SK-NIC.php,v 1.1 2007-03-11 03:49:48 nepto Exp $ */ |
| |
|
| require_once 'DB.php'; |
require_once 'DB.php'; |
| |
|
|
|
| |
|
| function _cleanImport() /* {{{ */ |
function _cleanImport() /* {{{ */ |
| { |
{ |
| $result = $this->_db->query('DELETE FROM domains_import'); |
$result = $this->_db->query('DELETE FROM sknic_domains_import'); |
| DB::isError($result) && $this->error($result); |
DB::isError($result) && $this->error($result); |
| } /* }}} */ |
} /* }}} */ |
| |
|
|
|
| $dt_valid = strtotime($dt_valid); |
$dt_valid = strtotime($dt_valid); |
| $dt_valid = date('Y-m-d', $dt_valid); |
$dt_valid = date('Y-m-d', $dt_valid); |
| |
|
| $query = sprintf('INSERT INTO domains_import' |
$query = sprintf('INSERT INTO sknic_domains_import' |
| .' (domain,id_reg,id_owner,flag,status,ns1,ns2,ns3,ns4,ico_owner,dt_valid,dt_changed)' |
.' (domain,id_reg,id_owner,flag,status,ns1,ns2,ns3,ns4,ico_owner,dt_valid,dt_changed)' |
| .' VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)', |
.' VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)', |
| $this->_db->quote($domain), $this->_db->quote($id_reg), $this->_db->quote($id_owner), |
$this->_db->quote($domain), $this->_db->quote($id_reg), $this->_db->quote($id_owner), |
|
|
| { |
{ |
| static $dt_deleted = null; |
static $dt_deleted = null; |
| if ($dt_deleted == null) { |
if ($dt_deleted == null) { |
| $dt_deleted = $this->_db->getOne('select distinct dt_changed from domains_import'); |
$dt_deleted = $this->_db->getOne('select distinct dt_changed from sknic_domains_import'); |
| if (strlen($dt_deleted) <= 0) { |
if (strlen($dt_deleted) <= 0) { |
| $dt_deleted = date('Y-m-d'); |
$dt_deleted = date('Y-m-d'); |
| } |
} |
| } |
} |
| $history_cols = $this->_tableColumns('domains_history'); |
$history_cols = $this->_tableColumns('sknic_domains_history'); |
| $cols = ''; |
$cols = ''; |
| $vals = ''; |
$vals = ''; |
| foreach ($history_cols as $col) { |
foreach ($history_cols as $col) { |
|
|
| $vals .= ','; |
$vals .= ','; |
| } |
} |
| } |
} |
| $query = sprintf('INSERT INTO domains_history' |
$query = sprintf('INSERT INTO sknic_domains_history' |
| .' (%s dt_deleted) VALUES (%s %s)', |
.' (%s dt_deleted) VALUES (%s %s)', |
| $cols, $vals, |
$cols, $vals, |
| $deleted ? $this->_db->quote($dt_deleted) : 'NULL'); |
$deleted ? $this->_db->quote($dt_deleted) : 'NULL'); |
|
|
| $this->_db->popExpect(); |
$this->_db->popExpect(); |
| if (DB::isError($result)) { |
if (DB::isError($result)) { |
| if ($result->getCode() == DB_ERROR_ALREADY_EXISTS) { |
if ($result->getCode() == DB_ERROR_ALREADY_EXISTS) { |
| echo 'WARNING: domains_history entry already exists',"\n"; |
echo 'WARNING: sknic_domains_history entry already exists',"\n"; |
| } else { |
} else { |
| $this->error($result); |
$this->error($result); |
| } |
} |
|
|
| $update_str .= "$col = ".$this->_db->quote($rec["i_$col"]).','; |
$update_str .= "$col = ".$this->_db->quote($rec["i_$col"]).','; |
| } |
} |
| $update_str = substr($update_str, 0, strlen($update_str) - 1); |
$update_str = substr($update_str, 0, strlen($update_str) - 1); |
| $query = sprintf('UPDATE domains SET %s WHERE domain = %s', |
$query = sprintf('UPDATE sknic_domains SET %s WHERE domain = %s', |
| $update_str, |
$update_str, |
| $this->_db->quote($rec['c_domain'])); |
$this->_db->quote($rec['c_domain'])); |
| $result = $this->_db->query($query); |
$result = $this->_db->query($query); |
|
|
| |
|
| function _insertDomain($rec) /* {{{ */ |
function _insertDomain($rec) /* {{{ */ |
| { |
{ |
| $columns = $this->_tableColumns('domains'); |
$columns = $this->_tableColumns('sknic_domains'); |
| $cols = ''; |
$cols = ''; |
| $vals = ''; |
$vals = ''; |
| foreach ($columns as $col) { |
foreach ($columns as $col) { |
|
|
| } |
} |
| $cols = substr($cols, 0, strlen($cols) - 1); |
$cols = substr($cols, 0, strlen($cols) - 1); |
| $vals = substr($vals, 0, strlen($vals) - 1); |
$vals = substr($vals, 0, strlen($vals) - 1); |
| $query = sprintf('INSERT INTO domains' |
$query = sprintf('INSERT INTO sknic_domains' |
| .' (%s) VALUES (%s)', |
.' (%s) VALUES (%s)', |
| $cols, $vals); |
$cols, $vals); |
| $result = $this->_db->query($query); |
$result = $this->_db->query($query); |
|
|
| function doComparison() /* {{{ */ |
function doComparison() /* {{{ */ |
| { |
{ |
| $changed = 0; |
$changed = 0; |
| $import_cols = $this->_tableColumns('domains_import'); |
$import_cols = $this->_tableColumns('sknic_domains_import'); |
| $domains_cols = $this->_tableColumns('domains'); |
$domains_cols = $this->_tableColumns('sknic_domains'); |
| |
|
| $query = 'SELECT 1'; |
$query = 'SELECT 1'; |
| foreach ($import_cols as $col) { |
foreach ($import_cols as $col) { |
|
|
| foreach ($domains_cols as $col) { |
foreach ($domains_cols as $col) { |
| $query .= ",c.$col AS c_$col"; // 'c' means "current" |
$query .= ",c.$col AS c_$col"; // 'c' means "current" |
| } |
} |
| $query .= ' FROM domains_import i %s domains c'; |
$query .= ' FROM sknic_domains_import i %s sknic_domains c'; |
| $query .= ' ON i.domain = c.domain'; |
$query .= ' ON i.domain = c.domain'; |
| |
|
| //$data = array(); |
//$data = array(); |
|
|
| //echo 'deleted domain: ',$rec['c_domain'],"\n"; |
//echo 'deleted domain: ',$rec['c_domain'],"\n"; |
| $changed++; |
$changed++; |
| $this->_writeDomainHistory($rec, 1); |
$this->_writeDomainHistory($rec, 1); |
| $query = sprintf('DELETE FROM domains WHERE domain = %s', |
$query = sprintf('DELETE FROM sknic_domains WHERE domain = %s', |
| $this->_db->quote($rec['c_domain'])); |
$this->_db->quote($rec['c_domain'])); |
| $result = $this->_db->query($query); |
$result = $this->_db->query($query); |
| DB::isError($result) && $this->error($result); |
DB::isError($result) && $this->error($result); |