diff --git a/Servicedns/Providers/PowerDNS.php b/Servicedns/Providers/PowerDNS.php index e3d31c5..63c78c2 100644 --- a/Servicedns/Providers/PowerDNS.php +++ b/Servicedns/Providers/PowerDNS.php @@ -34,28 +34,28 @@ public function __construct($config) { } public function createDomain($domainName) { - if (empty($domainName)) { - throw new \FOSSBilling\Exception("Domain name cannot be empty"); - } + if (empty($domainName)) { + throw new \FOSSBilling\Exception("Domain name cannot be empty"); + } - $nsRecords = array_filter($this->nsRecords); - $formattedNsRecords = array_values(array_map(function($nsRecord) { - return rtrim($nsRecord, '.') . '.'; - }, $nsRecords)); - - try { - $this->client->createZone($domainName, $formattedNsRecords); - // On successful creation, simply return true. - return true; - } catch (\Exception $e) { - // Throw an exception to indicate failure, including for conflicts. - if (strpos($e->getMessage(), 'Conflict') !== false) { - throw new \FOSSBilling\Exception("Zone already exists for domain: " . $domainName); - } else { - throw new \FOSSBilling\Exception("Failed to create zone for domain: " . $domainName . ". Error: " . $e->getMessage()); + $nsRecords = array_filter($this->nsRecords); + $formattedNsRecords = array_values(array_map(function($nsRecord) { + return rtrim($nsRecord, '.') . '.'; + }, $nsRecords)); + + try { + $this->client->createZone($domainName, $formattedNsRecords); + // On successful creation, simply return true. + return true; + } catch (\Exception $e) { + // Throw an exception to indicate failure, including for conflicts. + if (strpos($e->getMessage(), 'Conflict') !== false) { + throw new \FOSSBilling\Exception("Zone already exists for domain: " . $domainName); + } else { + throw new \FOSSBilling\Exception("Failed to create zone for domain: " . $domainName . ". Error: " . $e->getMessage()); + } } } -} public function listDomains() { throw new \FOSSBilling\Exception("Not yet implemented"); diff --git a/Servicedns/Service.php b/Servicedns/Service.php index 045b91b..6b67257 100644 --- a/Servicedns/Service.php +++ b/Servicedns/Service.php @@ -121,45 +121,44 @@ public function uncancel(OODBBean $order, OODBBean $model): bool public function delete(?OODBBean $order, ?OODBBean $model): void { - if ($order === null) { - throw new \FOSSBilling\Exception("Order is not provided."); - } + if ($order === null) { + throw new \FOSSBilling\Exception("Order is not provided."); + } - $config = json_decode($order->config, true); - if (!$config) { - throw new \FOSSBilling\Exception("Invalid or missing DNS provider configuration."); - } + $config = json_decode($order->config, true); + if (!$config) { + throw new \FOSSBilling\Exception("Invalid or missing DNS provider configuration."); + } - $this->chooseDnsProvider($config); - if ($this->dnsProvider === null) { - throw new \FOSSBilling\Exception("DNS provider is not set."); - } + $this->chooseDnsProvider($config); + if ($this->dnsProvider === null) { + throw new \FOSSBilling\Exception("DNS provider is not set."); + } - $domainName = $config['domain_name'] ?? null; - if (empty($domainName)) { - throw new \FOSSBilling\Exception("Domain name is not set."); - } + $domainName = $config['domain_name'] ?? null; + if (empty($domainName)) { + throw new \FOSSBilling\Exception("Domain name is not set."); + } - try { - // Attempt to delete the domain from PowerDNS. - $this->dnsProvider->deleteDomain($domainName); - } catch (\Exception $e) { - // Check if the exception is due to the domain not being found. - if (strpos($e->getMessage(), 'Not Found') !== false) { - // Log the not found error but proceed with deleting the order. - error_log("Domain $domainName not found in PowerDNS, but proceeding with order deletion."); - } else { - // For other exceptions, rethrow them as they indicate actual issues. - throw new \FOSSBilling\Exception("Failed to delete domain $domainName: " . $e->getMessage()); + try { + // Attempt to delete the domain + $this->dnsProvider->deleteDomain($domainName); + } catch (\Exception $e) { + // Check if the exception is due to the domain not being found. + if (strpos($e->getMessage(), 'Not Found') !== false) { + // Log the not found error but proceed with deleting the order. + error_log("Domain $domainName not found in PowerDNS, but proceeding with order deletion."); + } else { + // For other exceptions, rethrow them as they indicate actual issues. + throw new \FOSSBilling\Exception("Failed to delete domain $domainName: " . $e->getMessage()); + } } - } - // Proceed with deleting the order from the database. - if (is_object($model)) { - $this->di['db']->trash($model); + // Proceed with deleting the order from the database. + if (is_object($model)) { + $this->di['db']->trash($model); + } } -} - public function toApiArray(OODBBean $model): array {