/** * Create domain and return transaction status * * @access public * @param Domain $domain * @param int $period Domain registration period * @param array $extra Extra data * @version v1000 * @return Domain */ public function CreateDomain(Domain $domain, $period, $extra = array()) { // Validate contacts $contact_list = $domain->GetContactList(); foreach (CONTACT_TYPE::GetKeys() as $contact_type) { $config = $this->GetManifest()->GetContactConfig($contact_type); if ($config instanceof SimpleXMLElement) { if ((int) $config->attributes()->required && !$contact_list[$contact_type]) { throw new Exception(sprintf(_('%s contact is required'), ucfirst($contact_type))); } } } // $nameserver_list = $domain->GetNameserverList(); foreach ($nameserver_list as $ns) { try { try { $can_create = $this->NameserverCanBeCreated($ns); } catch (NotImplementedException $e) { $can_create = true; } if ($can_create) { $this->CreateNameserver($ns); } } catch (ObjectExistsException $e) { // Ignore errors } catch (NotImplementedException $e) { // Ignore errors } } $this->FireEvent('BeforeCreateDomain', $domain); $Resp = $this->RegModule->CreateDomain($domain, $period, $extra); $this->ValidateModuleResponse($Resp, 'CreateDomainResponse'); if ($Resp->IsFailed()) { Log::Log(sprintf('CreateDomain failed. Registry error: %s', $Resp->ErrMsg), E_USER_ERROR); throw new RegistryException($Resp->ErrMsg, $Resp->Code); } $domain->Period = $period; $domain->AuthCode = $Resp->AuthCode; $domain->CreateDate = $Resp->CreateDate; $domain->ExpireDate = $Resp->ExpireDate; $domain->Protocol = $Resp->Protocol; $domain->Status = $Resp->Status == REGISTRY_RESPONSE_STATUS::PENDING ? DOMAIN_STATUS::REGISTRATION_PENDING : DOMAIN_STATUS::DELEGATED; $domain->IncompleteOrderOperation = null; if ($domain->Status == DOMAIN_STATUS::DELEGATED) { $this->FireEvent('DomainOperation', $domain, self::OP_CREATE); $this->FireEvent('DomainCreated', $domain); } else { if ($domain->Status == DOMAIN_STATUS::REGISTRATION_PENDING) { $this->AddPendingOperation($domain, self::OP_CREATE, $Resp->OperationId); } } $this->DBDomain->Save($domain); // db operation return $domain; }
public function UpdateContactsAfterTransfer(Domain $Domain, Domain $Saved) { $domainName = $this->MakeNameIDNCompatible($Saved->GetHostName()); // Flags, indicates that saved contact will be assigned to transferred domain. $assignSavedContacts = array(); foreach (CONTACT_TYPE::GetKeys() as $ctype) { $assignSavedContacts[$ctype] = 1; } if (in_array($this->Extension, array("be", "eu", "it", "nl"))) { $GrdResponse = $this->GetRemoteDomain($Domain); foreach (CONTACT_TYPE::GetKeys() as $ctype) { $clid_property = ucfirst($ctype) . "Contact"; // ex: RegistrantContact $clid = $GrdResponse->{$clid_property}; // clid started from domain TLD means native registry contact, // which is unoperational by rrpproxy api. // ex: be.tr55322 if (preg_match("/^{$this->Extension}/", $clid)) { // Create dummy contact with non-strict fields and assign it to domain. $Contact = $this->RegistryAccessible->NewContactInstance($ctype); $Contact->CLID = $clid; $Contact->SetFieldList(array("firstname" => $clid), 0); $Domain->SetContact($Contact, $ctype); } // Контакты заданные при инициации трансфера не применяются к домену. $assignSavedContacts[$ctype] = 0; // Возможна ситуация когда среди нативных контактов попадаются rrpproxy-вые, // они импортируются в БД ЕПП-ДРС. // ex: // property[billing contact][0] = eu.c89406 // property[owner contact][0] = eu.c10720031 // property[admin contact][0] = eu.c10720031 // property[tech contact][0] = P-JZW723 // P-JZW723 будет запрошен операцией GetRemoteContact аплевел кодом; // для остальных контактов будут созданы заглушки. } } else { if ("nu" == $this->Extension) { // In .NU change registrant is a special operation that requires fax sending. // Sync registrant contact, update admin, tech, billing try { $Registrant = $Domain->GetContact(CONTACT_TYPE::REGISTRANT); $Registrant = $this->RegistryAccessible->GetRemoteContact($Registrant); $Domain->SetContact($Registrant, CONTACT_TYPE::REGISTRANT); $assignSavedContacts[CONTACT_TYPE::REGISTRANT] = 0; } catch (Exception $e) { throw new Exception("Cannot synchronize registrant contact with registry. {$e->getMessage()}"); } $params = array('domain' => $domainName); foreach (array("admin", "billing", "tech") as $ctype) { $params["{$ctype}contact0"] = $Saved->GetContact($ctype)->CLID; } $response = $this->Request("ModifyDomain", $params); } else { // Default behaviour: // Set new contacts in an atomic operation $params = array('domain' => $domainName, 'ownercontact0' => $Saved->GetContact(CONTACT_TYPE::REGISTRANT)->CLID); foreach (array("admin", "billing", "tech") as $ctype) { $params["{$ctype}contact0"] = $Saved->GetContact($ctype)->CLID; } $response = $this->Request("ModifyDomain", $params); } } // Set updated contacts to domain. foreach ($Saved->GetContactList() as $ctype => $Contact) { if ($assignSavedContacts[$ctype]) { $Domain->SetContact($Contact, $ctype); } } }
/** * Set domain contact * * @param Contact $contact * @throws Exception on contact has no type */ public function SetContact(Contact $contact = null, $type) { if (!in_array($type, CONTACT_TYPE::GetKeys())) { throw new Exception(sprintf(_("Invalid contact type '%s'"), $type)); } if ($contact instanceof Contact) { $group_arr = $this->ConfigXml->xpath('contacts/contact[@type="' . $type . '"]/@group'); if ((string) $group_arr[0] != $contact->GroupName) { throw new Exception(sprintf(_("Contact of group '%s' can't be used as '%s'"), $contact->GroupName, $type)); } $this->Contacts[$type] = $contact; } else { unset($this->Contacts[$type]); } }
/** * Request domain name ingoing transfer * * @param $params = array( * name string Domain name * authCode string Domain auth code * registrant string * admin string * billing string * tech string * extraFields array(key => value) @see GetTldInfo * userId int User ID (In admin mode) * noBilling bool Disable billing for domain opeartion (In admin mode) * ) * @return object */ function TransferDomain($params = null) { // Check params if ($this->access_mode == self::ACCESS_MODE_ADMIN) { if (!$params["userId"]) { throw new Exception(sprintf("'%s' parameter is required", "userId")); } } else { $params["noBilling"] = false; } $user_id = $this->user_id ? $this->user_id : $params["userId"]; if (!$params["name"]) { throw new Exception(sprintf("'%s' parameter is required", "name")); } list($name, $tld) = explode(".", $params["name"], 2); $registry = $this->registry_factory->GetRegistryByExtension($tld); $db_domain = DBDomain::GetInstance(); $already_exists = $this->db->GetOne("SELECT * FROM domains WHERE \n\t\t\t\t\tname = ? AND TLD = ? AND userid = ? AND incomplete_operation = ?", array($name, $tld, $user_id, INCOMPLETE_OPERATION::DOMAIN_TRANSFER)); if ($already_exists) { $domain = $db_domain->LoadByName($name, $tld); } else { $domain = $registry->NewDomainInstance(); $domain->Name = $name; $domain->UserID = $user_id; $domain->Period = 1; $domain->IncompleteOrderOperation = INCOMPLETE_OPERATION::DOMAIN_TRANSFER; if (!$params["noBilling"]) { $domain->Status = DOMAIN_STATUS::AWAITING_PAYMENT; // Check that enougth money $client = Client::Load($user_id); $balance = DBBalance::GetInstance()->LoadClientBalance($user_id); $invoice = new Invoice(INVOICE_PURPOSE::DOMAIN_TRANSFER, $domain, $domain->UserID); $invoice->Description = sprintf(_("%s domain name transfer"), $domain->GetHostName()); $this->CheckEnoughtMoney($client, $balance, $invoice); } else { $domain->Status = DOMAIN_STATUS::PENDING; } } // Check that domain is available for transfer $registry = $this->registry_factory->GetRegistryByExtension($domain->Extension); if (!$registry->DomainCanBeTransferred($domain)) { throw new Exception("This domain name cannot be transferred"); } if (!$domain->ID) { // Save domain after all checks $db_domain->Save($domain); if (!$params["noBilling"]) { $invoice->ItemID = $domain->ID; $this->MakePayment($client, $balance, $invoice); $domain->Status = DOMAIN_STATUS::PENDING; $db_domain->Save($domain); } } // Run transfer action $extra_fields = $params["extraFields"]; $extra_fields["pw"] = $params["authCode"]; $db_contact = DBContact::GetInstance(); foreach (CONTACT_TYPE::GetKeys() as $ctype) { if ($params[$ctype] || $extra_fields[$ctype]) { $clid = $params[$ctype] ? $params[$ctype] : $extra_fields[$ctype]; $c = $db_contact->LoadByCLID($clid); $domain->SetContact($c, $ctype); $extra_fields[$ctype] = $clid; } } if ($params["ns"] && !$extra_fields["ns1"]) { $extra_fields["ns1"] = $params["ns"][0]; $extra_fields["ns2"] = $params["ns"][1]; } $registry->TransferRequest($domain, $extra_fields); // Remove incomplete order operation $domain->IncompleteOrderOperation = null; $db_domain->Save($domain); $ret = new stdClass(); return $ret; }