/** * Assign Service * * Create a HostingServicePurchaseDBO and add it to the database */ function assign_service() { // If this HostingService requires a unique IP, make sure the user selected one if ($this->post['service']->getUniqueIP() == "Required" && !isset($this->post['ipaddress'])) { throw new FieldMissingException("ipaddress"); } // If this HostingService requires a domain, make sure the user selected one if ($this->post['service']->isDomainRequired() && !isset($this->post['domainname'])) { throw new FieldMissingException("domainname"); } // Create new HostingServicePurchase DBO $serverID = isset($this->post['server']) ? $this->post['server']->getID() : null; $purchase_dbo = new HostingServicePurchaseDBO(); $purchase_dbo->setAccountID($this->get['account']->getID()); $purchase_dbo->setPurchasable($this->post['service']); $purchase_dbo->setTerm(isset($this->post['term']) ? $this->post['term']->getTermLength() : null); $purchase_dbo->setServerID($serverID); $purchase_dbo->setDate(DBConnection::format_datetime($this->post['date'])); $purchase_dbo->setDomainName($this->post['domainname']); $purchase_dbo->setNote($this->post['note']); // Save purchase add_HostingServicePurchaseDBO($purchase_dbo); // If an IP address was selected, assign that IP address to this purchase if (isset($this->post['ipaddress'])) { if ($this->post['ipaddress']->getServerID() != $serverID) { // Roll-back delete_HostingServicePurchaseDBO($purchase_dbo); throw new SWUserException("[IP_MISMATCH]"); } // Update IP Address record $this->post['ipaddress']->setPurchaseID($purchase_dbo->getID()); try { update_IPAddressDBO($this->post['ipaddress']); } catch (DBException $e) { // Roll-back delete_HostingServicePurchaseDBO($purchase_dbo); throw new SWUserException("[DB_IP_UPDATE_FAILED]"); } } // Success $this->setMessage(array("type" => "[HOSTING_ASSIGNED]")); $this->gotoPage("accounts_view_account", null, "action=services&account=" . $this->get['account']->getID()); }
/** * Execute Hosting Service Order * * Create a new Hosting Service Purchase for this order item * * @param AccountDBO $accountDBO Account object * @return boolean True for success */ public function execute($accountDBO) { // Create a hosting service purchase record $purchaseDBO = new HostingServicePurchaseDBO(); $purchaseDBO->setAccountID($accountDBO->getID()); $purchaseDBO->setHostingServiceID($this->getServiceID()); $purchaseDBO->setTerm($this->getTerm()); $purchaseDBO->setDate(DBConnection::format_datetime(time())); $purchaseDBO->setDomainName($this->getDomainName()); $purchaseDBO->setPrevInvoiceID(-1); $purchaseDBO->incrementNextBillingDate(); add_HostingServicePurchaseDBO($purchaseDBO); // Fulfill the order and return $this->setStatus("Fulfilled"); update_OrderHostingDBO($this); // Success return true; }