diff --git a/app/Controllers/CLI/Cloudflare.php b/app/Controllers/CLI/Cloudflare.php index 9434f89..b91fa92 100644 --- a/app/Controllers/CLI/Cloudflare.php +++ b/app/Controllers/CLI/Cloudflare.php @@ -105,42 +105,19 @@ class Cloudflare extends BaseController ); } } - public function expire(string $domain): void + public function expire(string $domain = ""): void { //Transaction Start // $this->_db->transStart(); try { $zone_model = model(ZoneModel::class); - $zone_model->where(['domain' => $domain]); - $zone_entity = $zone_model->getEntity(); - $zone = new ZoneService(); - $zone->expire($zone_entity); - log_message("notice", "Expire 작업을 완료하였습니다."); - // $this->_db->transCommit(); - } catch (\Exception $e) { - //Transaction Rollback - // $this->_db->transRollback(); - log_message( - "error", - "Expire 작업을 실패하였습니다.\n--------------\n" . - $e->getMessage() . - "\n--------------\n" - ); - } - } - - public function hosts(string $ip): void - { - //Transaction Start - // $this->_db->transStart(); - try { - $record_model = model(RecordModel::class); - $record_model->where(['content' => $ip]); - $hosts = []; - foreach ($record_model->getEntitys() as $entity) { - $hosts[] = $entity->host; + if ($domain !== "") { + $zone_model->where(['domain' => $domain]); + } + $zone = new ZoneService(); + foreach ($zone_model->getEntitys() as $entity) { + $zone->expire($entity); } - echo implode("\n", $hosts); log_message("notice", "Expire 작업을 완료하였습니다."); // $this->_db->transCommit(); } catch (\Exception $e) { diff --git a/app/Services/Cloudflare/ZoneService.php b/app/Services/Cloudflare/ZoneService.php index c720f02..d08e730 100644 --- a/app/Services/Cloudflare/ZoneService.php +++ b/app/Services/Cloudflare/ZoneService.php @@ -159,15 +159,12 @@ class ZoneService extends CloudflareService // log_message("debug", $this->getModel()->getLastQuery()); return $entity; } - public function expire(ZoneEntity $entity) + public function expire(ZoneEntity $entity): void { $whois = Factory::get()->createWhois(); $info = $whois->loadDomainInfo($entity->getTitle()); - print_r([ - 'Domain created' => date("Y-m-d", $info->creationDate), - 'Domain expires' => date("Y-m-d", $info->expirationDate), - 'Domain owner' => $info->owner, - ]); + $formDatas = ['expire_date' => date("Y-m-d", $info->expirationDate)]; + $this->getModel()->modify($entity, $formDatas); } //Reload