Changeset View
Changeset View
Standalone View
Standalone View
src/app/Domain.php
Show First 20 Lines • Show All 226 Lines • ▼ Show 20 Lines | class Domain extends Model | ||||
*/ | */ | ||||
public function setStatusAttribute($status) | public function setStatusAttribute($status) | ||||
{ | { | ||||
$new_status = 0; | $new_status = 0; | ||||
$allowed_values = [ | $allowed_values = [ | ||||
self::STATUS_NEW, | self::STATUS_NEW, | ||||
self::STATUS_ACTIVE, | self::STATUS_ACTIVE, | ||||
self::STATUS_CONFIRMED, | |||||
self::STATUS_SUSPENDED, | self::STATUS_SUSPENDED, | ||||
self::STATUS_DELETED, | self::STATUS_DELETED, | ||||
self::STATUS_LDAP_READY, | self::STATUS_CONFIRMED, | ||||
self::STATUS_VERIFIED, | self::STATUS_VERIFIED, | ||||
self::STATUS_LDAP_READY, | |||||
]; | ]; | ||||
foreach ($allowed_values as $value) { | foreach ($allowed_values as $value) { | ||||
if ($status & $value) { | if ($status & $value) { | ||||
$new_status |= $value; | $new_status |= $value; | ||||
$status ^= $value; | $status ^= $value; | ||||
} | } | ||||
} | } | ||||
if ($status > 0) { | if ($status > 0) { | ||||
throw new \Exception("Invalid domain status: {$status}"); | throw new \Exception("Invalid domain status: {$status}"); | ||||
} | } | ||||
if ($this->isPublic()) { | |||||
$this->attributes['status'] = $new_status; | |||||
return; | |||||
} | |||||
if ($new_status & self::STATUS_CONFIRMED) { | |||||
// if we have confirmed ownership of or management access to the domain, then we have | |||||
machniak: You don't really need this `if`, just use the `else` code. | |||||
// also confirmed the domain exists in DNS. | |||||
$new_status |= self::STATUS_VERIFIED; | |||||
$new_status |= self::STATUS_ACTIVE; | |||||
} | |||||
if ($new_status & self::STATUS_DELETED && $new_status & self::STATUS_ACTIVE) { | |||||
$new_status ^= self::STATUS_ACTIVE; | |||||
} | |||||
if ($new_status & self::STATUS_SUSPENDED && $new_status & self::STATUS_ACTIVE) { | |||||
$new_status ^= self::STATUS_ACTIVE; | |||||
} | |||||
// if the domain is now active, it is not new anymore. | |||||
if ($new_status & self::STATUS_ACTIVE && $new_status & self::STATUS_NEW) { | |||||
$new_status ^= self::STATUS_NEW; | |||||
} | |||||
$this->attributes['status'] = $new_status; | $this->attributes['status'] = $new_status; | ||||
} | } | ||||
/** | /** | ||||
* Ownership verification by checking for a TXT (or CNAME) record | * Ownership verification by checking for a TXT (or CNAME) record | ||||
* in the domain's DNS (that matches the verification hash). | * in the domain's DNS (that matches the verification hash). | ||||
* | * | ||||
* @return bool True if verification was successful, false otherwise | * @return bool True if verification was successful, false otherwise | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | public function suspend(): void | ||||
$this->status |= Domain::STATUS_SUSPENDED; | $this->status |= Domain::STATUS_SUSPENDED; | ||||
$this->save(); | $this->save(); | ||||
} | } | ||||
/** | /** | ||||
* Unsuspend this domain. | * Unsuspend this domain. | ||||
* | * | ||||
* The domain is unsuspended through either of the following courses of actions; | |||||
* | |||||
* * The account balance has been topped up, or | |||||
* * a suspected spammer has resolved their issues, or | |||||
* * the command-line is triggered. | |||||
* | |||||
* Therefore, we can also confidently set the domain status to 'active' should the ownership of or management | |||||
* access to have been confirmed before. | |||||
* | |||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function unsuspend(): void | public function unsuspend(): void | ||||
{ | { | ||||
if (!$this->isSuspended()) { | if (!$this->isSuspended()) { | ||||
return; | return; | ||||
} | } | ||||
$this->status ^= Domain::STATUS_SUSPENDED; | $this->status ^= Domain::STATUS_SUSPENDED; | ||||
if ($this->isConfirmed() && $this->isVerified()) { | |||||
$this->status |= Domain::STATUS_ACTIVE; | |||||
} | |||||
$this->save(); | $this->save(); | ||||
} | } | ||||
/** | /** | ||||
* Verify if a domain exists in DNS | * Verify if a domain exists in DNS | ||||
* | * | ||||
* @return bool True if registered, False otherwise | * @return bool True if registered, False otherwise | ||||
* @throws \Exception Throws exception on DNS or DB errors | * @throws \Exception Throws exception on DNS or DB errors | ||||
Show All 38 Lines |
You don't really need this if, just use the else code.