Skip to content

Commit

Permalink
Formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
getpinga committed Feb 9, 2024
1 parent c6b14ac commit e9be7e6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 51 deletions.
38 changes: 19 additions & 19 deletions Servicedns/Providers/PowerDNS.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
63 changes: 31 additions & 32 deletions Servicedns/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit e9be7e6

Please sign in to comment.