function DispatchPollUpdateContact(PollUpdateContactResponse $resp) { if ($resp->IsFailed()) { Log::Log(sprintf('DispatchPollUpdateContact failed. Registry response: %s', $resp->ErrMsg), E_USER_ERROR); throw new Exception($resp->ErrMsg, $resp->Code); } if ($resp->Succeed()) { $Contact = $this->DBContact->LoadByCLID($resp->CLID); try { // Get remote updated contact $Contact = $this->GetRemoteContact($Contact); } catch (NotImplementedException $e) { // Get updates from local history $op = $this->DB->GetRow('SELECT * FROM pending_operations WHERE objectid=? AND objecttype=?', array($Contact->ID, self::OBJ_CONTACT)); if (!$op) { throw new Exception('Pending operation not found'); } $After = unserialize($op['object_after']); $fields = array(); foreach ($Contact->GetEditableNames() as $n) { $fields[$n] = $After->GetField($n); } $Contact->SetFieldList($fields); } $this->DBContact->Save($Contact); $this->FireEvent('ContactUpdated', $Contact); } }
public function ConvertContacts() { $contact_data = $this->DbOld->GetAll('SELECT * FROM contacts'); $ok = $fail = 0; foreach ($contact_data as $i => $contact_row) { $imported = (int) $this->DbNew->GetOne('SELECT COUNT(*) FROM contacts WHERE clid = ?', array($contact_row['clid'])); if ($imported) { // Skip contact, that was imported with domain in $this->ConvertActiveDomains continue; } $this->Log(sprintf('Import contact %s', $contact_row['clid'])); if ($contact_row['type'] == 'bill') { $contact_row['type'] = CONTACT_TYPE::BILLING; } $Registry = $this->RegistryFactory->GetRegistryByExtension($contact_row['TLD'], $db_check = false); $Contact = $Registry->NewContactInstance($contact_row['type']); $Contact->CLID = $contact_row['clid']; $Contact->AuthCode = $contact_row['pw']; $Contact->UserID = $contact_row['userid']; try { $Contact = $Registry->GetRemoteContact($Contact); $this->DBContact->Save($Contact); $ok++; } catch (Exception $e) { $this->Log($e->getMessage(), E_USER_ERROR); $fail++; } } $this->Log(sprintf("Imported: %s; Failed: %s", $ok, $fail)); }
function _testPhoneField() { $e164_phone = '+380.507243484'; $phone = '+380-50-7243484'; $Phone = Phone::GetInstance(); $this->assertTrue($Phone->PhoneToE164($phone) == $e164_phone, 'phone to e164'); $this->assertTrue($Phone->IsPhone($phone), 'phone is phone.. la lay lalala'); $this->assertTrue($Phone->IsE164($e164_phone), 'phone is e164'); $Contact = $this->Registry->NewContactInstance(CONTACT_TYPE::TECH); $field_list = $this->ContactFields; $field_list['voice'] = $phone; $field_list['fax'] = ''; $Contact->SetFieldList($field_list); try { } catch (ErrorList $e) { var_dump($e->GetAllMessages()); } $this->DBContact->Save($Contact); /* $this->assertTrue( $Contact->GetField('voice') == $phone_e164 && $Contact->GetField('voice_display') == $phone, 'Set phone' ); */ }
function import() { $module = strtolower($this->module); if ($module == "dotnl") { $parser = new DotNLParser(); $registry = $this->registryFactory->GetRegistryByName('DotNL'); } else { if ($module == "rrpproxy") { $parser = new RRPProxyParser(); $registry = $this->registryFactory->GetRegistryByName('RRPProxy'); } } if ($parser == null) { throw new Exception("Cannot find line parser for module '{$module}'"); } // Import process $fp = $this->fopen($this->in); $headers = $this->fgetcsv($fp); for ($lineno = 1; !feof($fp); $lineno++) { $line = $this->fgetcsv($fp); $line = array_combine($headers, array_map('trim', $line)); try { $parseResult = $parser->parseLine($line); if (!$parseResult) { continue; } } catch (Exception $e) { print "Cannot parse line {$lineno}\n"; continue; } if ($this->dbContact->FindByCLID($parseResult['clid'])) { // Skip existing in database print "[{$parseResult['clid']}] Skipped. Already exists in database.\n"; continue; } // Construct contact $contact = $registry->NewContactInstanceByGroup($parseResult['group']); $contact->CLID = $parseResult['clid']; $contact->UserID = $this->userid; try { $contact->SetFieldList($parseResult['fields'], 1); } catch (ErrorList $e) { print "[{$contact->CLID}] Contact data violates manifest rules. " . join("; ", $e->GetAllMessages()) . "\n"; print "[{$contact->CLID}] Set non strict mode\n"; $contact->SetFieldList($parseResult['fields'], 0); } // Save contact try { $this->dbContact->Save($contact); print "[{$contact->CLID}] Imported\n"; } catch (Exception $e) { print "[{$contact->CLID}] Cannot save. {$e->getMessage()}\n"; } } fclose($fp); }
/** * Save domain in database * * @param Domain $domain * @return Domain */ public function Save(Domain $domain) { if (!$domain->ID) { // check for duplicate domain $duplicate = $this->DB->GetOne('SELECT COUNT(*) FROM domains WHERE name = ? AND TLD = ?', array($domain->Name, $domain->Extension)); if ($duplicate) { throw new Exception(sprintf(_('Domain %s already exists in DB and could\'t be added twice'), $domain->GetHostName())); } } // Properties data $row = array(); foreach ($this->FieldPropertyMap as $field => $property) { $row[$field] = $domain->{$property} !== null ? $domain->{$property} : ""; } if ($domain->IncompleteOrderOperation === null) { $row['incomplete_operation'] = null; } // Nameservers data $nslist = $domain->GetNameserverList(); // If nameservers list smaller then size of db slots for ($i = 2; $i > count($ns_list); $i--) { $row['ns' . $i] = ''; } $ns_n = array(); foreach (array_values($nslist) as $i => $ns) { if ($i < 2) { $row['ns' . ($i + 1)] = $ns->HostName; } else { $ns_n[] = $ns->HostName; } } $row['ns_n'] = join(';', $ns_n); // Contacts data $contact_list = $domain->GetContactList(); foreach ($this->ContactFieldTypeMap as $field => $contact_type) { $contact = $contact_list[$contact_type]; // Add/Remove references to contact $row[$field] = $contact ? $contact->CLID : ''; } // Domain extra fields $extra_fields = array(); foreach ($domain->GetConfig()->xpath('registration/extra_fields/field') as $field) { settype($field, "array"); $field = $field["@attributes"]; if (isset($domain->{$field['name']})) { $extra_fields[$field['name']] = $domain->{$field['name']}; } } foreach ((array) $domain->ExtraFields as $k => $v) { $extra_fields[$k] = $v; } // Prepare data for DB $row["start_date"] = $row["start_date"] ? date("Y-m-d H:i:s", $row["start_date"]) : '0000-00-00 00:00:00'; $row["end_date"] = $row["end_date"] ? date("Y-m-d H:i:s", $row["end_date"]) : '0000-00-00 00:00:00'; $row['dtTransfer'] = $row['dtTransfer'] ? date("Y-m-d H:i:s", $row["dtTransfer"]) : '0000-00-00 00:00:00'; $row["islocked"] = (int) (bool) $row["islocked"]; $row['managed_dns'] = (int) (bool) $row['managed_dns']; $row['period'] = (int) $row['period']; $row['delete_status'] = (int) $row['delete_status']; $row['renew_disabled'] = (int) (bool) $row['renew_disabled']; // Save it! //if ($domain->ID) unset($row['id']); // Prepare SQL statement $set = array(); $bind = array(); foreach ($row as $field => $value) { $set[] = "`{$field}` = ?"; $bind[] = $value; } $set = join(', ', $set); $this->DB->BeginTrans(); try { if ($domain->ID) { // Perform Update $bind[] = $domain->ID; $this->DB->Execute("UPDATE domains SET {$set} WHERE id = ?", $bind); } else { // Perform Insert $this->DB->Execute("INSERT INTO domains SET {$set}", $bind); $domain->ID = $this->DB->Insert_ID(); } // Save extra data $this->DB->Execute('DELETE FROM domains_data WHERE domainid = ?', array($domain->ID)); foreach ($extra_fields as $name => $value) { $this->DB->Execute('INSERT INTO domains_data SET `domainid` = ?, `key` = ?, `value` = ?', array($domain->ID, $name, $value)); } // Save flags $this->DB->Execute('DELETE FROM domains_flags WHERE domainid = ?', array($domain->ID)); $flag_list = $domain->GetFlagList(); foreach ($flag_list as $flag) { $this->DB->Execute('INSERT INTO domains_flags SET domainid = ?, flag = ?', array($domain->ID, $flag)); } // Save contacts foreach ($contact_list as $contact) { if (!$contact->UserID) { $contact->UserID = $domain->UserID; } $this->DBContact->Save($contact); } // Save nameserver hosts $ns_list = $domain->GetNameserverHostList(); foreach ($ns_list as $ns) { $ns_id = $this->DB->GetOne('SELECT id FROM nhosts WHERE domainid=? AND hostname=?', array($domain->ID, $ns->GetBaseName())); if ($ns_id) { $this->DB->Execute('UPDATE nhosts SET ipaddr=? WHERE hostname=? AND domainid=?', array($ns->IPAddr, $ns->GetBaseName(), $domain->ID)); } else { $this->DB->Execute('INSERT INTO nhosts SET domainid=?, hostname=?, ipaddr=?', array($domain->ID, $ns->GetBaseName(), $ns->IPAddr)); $ns_id = $this->DB->Insert_ID(); } $ns->ID = $ns_id; } //$this->DBNameserverHost->SaveList($ns_list, $domain->ID); } catch (Exception $e) { $this->DB->RollbackTrans(); throw new ApplicationException($e->getMessage(), $e->getCode()); } $this->DB->CompleteTrans(); // Update domain in loaded objects storage $this->LoadedObjects[$domain->ID] = clone $domain; return $domain; }