function Handle(Task $Task) { $Job = $Task->JobObject; Log::Log("This is job: " . var_export($Job, true), E_USER_NOTICE); $Order = new Order($Task->userid); foreach ($Job->tlds as $tld) { // Get all domains of $tld $targets = $this->GetTargetsForTld($Task->GetActiveTargets(), $tld); Log::Log("{$tld} has " . count($targets) . " targets", E_USER_NOTICE); $RegAction = null; try { Log::Log("Init {$tld} registry"); $Registry = RegistryModuleFactory::GetInstance()->GetRegistryByExtension($tld); Log::Log("Init {$tld} reg action"); $RegAction = new RegisterDomainAction(array('tld' => $tld, 'Registry' => $Registry, 'Order' => $Order, 'clid_list' => $Job->contact_list[$tld], 'ns_list' => $Job->ns_list, 'managed_dns_enabled' => false, 'extra_data' => $Job->extra[$tld])); } catch (RegisterDomainAction_Exception $e) { $msg = $e->getMessage(); if ($e->ErrorList) { $msg .= ". " . join(" ", $e->ErrorList->GetAllMessages()); } Log::Log(sprintf("Failed to init RegisterDomainAction. %s. File:%s Line:%s \n%s", $msg, $e->getFile(), $e->getLine(), $e->getTraceAsString()), E_USER_NOTICE); foreach ($targets as $Target) { $Target->fail_reason = "RegisterDomainAction initialization failed. {$msg}"; $Task->TargetFailed($Target); } continue; } // Register each domain foreach ($targets as $Target) { try { list($domain_name, ) = explode(".", $Target->target, 2); $Domain = $Registry->NewDomainInstance(); $Domain->Name = $domain_name; $Domain->Period = $Job->periods[$tld]; $Domain->UserID = $Task->userid; Log::Log("Register {$Domain->GetHostName()}", E_USER_NOTICE); $result = $RegAction->Run($Domain); $Target->action_result = $result; $Task->TargetCompleted($Target); } catch (RegisterDomainAction_Exception $e) { $msg = $e->getMessage(); if ($e->ErrorList) { $msg .= ". " . join(" ", $e->ErrorList->GetAllMessages()); } Log::Log(sprintf("Registration failed for %s. %s. File:%s Line:%s \n%s", $Domain->GetHostName(), $msg, $e->getFile(), $e->getLine(), $e->getTraceAsString()), E_USER_NOTICE); $Target->fail_reason = $msg; $Task->TargetFailed($Target); } } } Log::Log("Order has " . count($Order->GetInvoiceList()) . " invoices", E_USER_NOTICE); $Order->Save(); }
/** * * @param $params = array ( * name string * period int * registrant string * admin string * billing string * tech string * ns array[string] * extraFields array(key => value) * userId int User ID (In admin mode) * noBilling bool Disable billing for domain opeartion (In admin mode) * ) * @return object */ function CreateDomain($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 { // Reset user disabled params $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")); } if (!$params["period"]) { throw new Exception(sprintf("'%s' parameter is required", "period")); } list($name, $tld) = explode(".", $params["name"], 2); $registry = $this->registry_factory->GetRegistryByExtension($tld); // Create and init RegisterDomainAction $contact_list = array(); foreach (CONTACT_TYPE::GetKeys() as $ctype) { if ($params[$ctype]) { $contact_list[$ctype] = $params[$ctype]; } } try { $action = new RegisterDomainAction(array("Registry" => $registry, "period" => $params["period"], "clid_list" => $contact_list, "ns_list" => (array) $params["ns"], "extra_data" => $params["extraFields"])); } catch (RegisterDomainAction_Exception $e) { // TODO better error messages instead of 'Comment required' if ($e->ErrorList) { $message = join("; ", $e->ErrorList->GetAllMessages()); } else { $message = $e->getMessage(); } throw new Exception($message); } // Create domain object $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_CREATE)); if ($already_exists) { $domain = $db_domain->LoadByName($name, $tld); } else { $domain = $registry->NewDomainInstance(); $domain->Name = $name; $domain->UserID = $user_id; $domain->Period = $params["period"]; $domain->IncompleteOrderOperation = INCOMPLETE_OPERATION::DOMAIN_CREATE; if (!$params["noBilling"]) { // Trigger domain registration by invoice payment $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_CREATE, $domain, $domain->UserID); $invoice->Description = sprintf(_("%s domain name registration for %s year(s)"), $domain->GetHostName(), $domain->Period); $this->CheckEnoughtMoney($client, $balance, $invoice); } else { // Direct domain registration $domain->Status = DOMAIN_STATUS::PENDING; } } // Check that domain is available for registration $registry = $this->registry_factory->GetRegistryByExtension($domain->Extension); if (!$registry->DomainCanBeRegistered($domain)) { throw new Exception("This domain name is already taken"); } if (!$domain->ID) { // Save domain after all checks $db_domain->Save($domain); if (!$params["noBilling"]) { $invoice->ItemID = $domain->ID; // Make payment for domain registration $this->MakePayment($client, $balance, $invoice); $domain->Status = DOMAIN_STATUS::PENDING; $db_domain->Save($domain); } } // Run registration action try { $action_result = $action->Run($domain); $ret = new stdClass(); $ret->name = $domain->GetHostName(); if ($action_result == RegisterDomainAction_Result::OK) { $ret->status = "ok"; } elseif ($action_result == RegisterDomainAction_Result::PENDING) { $ret->status = "okPending"; } else { $ret->status = "unknown"; } // Remove incomplete order operation $domain->IncompleteOrderOperation = null; $db_domain->Save($domain); return $ret; } catch (RegisterDomainAction_Exception $e) { if ($e->ErrorList) { $message = join("; ", $e->ErrorList->GetAllMessages()); } else { $message = $e->getMessage(); } throw new Exception($message); } }