diff --git a/app/Controllers/CLI/Cloudflare.php b/app/Controllers/CLI/Cloudflare.php index 131262e..14ab342 100644 --- a/app/Controllers/CLI/Cloudflare.php +++ b/app/Controllers/CLI/Cloudflare.php @@ -23,55 +23,34 @@ class Cloudflare extends BaseController parent::initController($request, $response, $logger); // $this->_db = \Config\Database::connect(); } - private function auth_process(mixed $uid = false): array - { - $authModel = model(AuthModel::class); - if (is_numeric($uid) && $uid > 0) { - $authModel->where(AuthModel::PK, intval($uid)); - } else { - $authModel->where('status', DEFAULTS["STATUS"]); - } - $entitys = $authModel->getEntitys(); - log_message("debug", $authModel->getLastQuery()); - return $entitys; - } - private function account_process(AuthEntity $auth_entity): array - { - $account = new AccountService(); - return $account->reload($auth_entity); - } - private function zone_process(AccountEntity $account_entity): array - { - $zone = new ZoneService(); - return $zone->reload($account_entity); - } - private function record_process(ZoneEntity $zone_entity): array - { - $record = new RecordService(); - return $record->reload($zone_entity); - } - private function firewall_process(ZoneEntity $zone_entity): array - { - $firewall = new FirewallService(); - return $firewall->reload($zone_entity); - } + public function reload(mixed $uid = false): void { //Transaction Start // $this->_db->transStart(); try { - $auths = $this->auth_process($uid); - foreach ($auths as $auth) { - $accounts = $this->account_process($auth); - foreach (array_values($accounts) as $account) { - $zones = $this->zone_process($account); + $auth_model = model(AuthModel::class); + if (is_numeric($uid) && $uid > 0) { + $auth_model->where(AuthModel::PK, intval($uid)); + } else { + $auth_model->where('status', DEFAULTS["STATUS"]); + } + $auth_entitys = $auth_model->getEntitys(); + foreach ($auth_entitys as $auth_entity) { + $account = new AccountService(); + $account_entitys = $account->reload($auth_entity); + foreach (array_values($account_entitys) as $account_entity) { + $zone = new ZoneService(); + $record = new RecordService(); + $firewall = new FirewallService(); + $zone_entitys = $zone->reload($account_entity); $cnt = 1; - $total = count($zones); - foreach (array_values($zones) as $zone) { - log_message("notice", "\n-----------[{$cnt}/$total}] Zone {$zone->getTitle()}의 Record/Firewall 처리 시작-----------"); - $records = $this->record_process($zone); - $firewalls = $this->firewall_process($zone); - log_message("notice", "\n-----------[{$cnt}/$total}] Zone {$zone->getTitle()}의 Record/Firewall 처리 완료-----------"); + $total = count($zone_entitys); + foreach (array_values($zone_entitys) as $zone_entity) { + log_message("notice", "\n-----------[{$cnt}/$total}] Zone {$zone_entity->getTitle()}의 Record/Firewall 처리 시작-----------"); + $record->reload($zone_entity); + $firewall->reload($zone_entity); + log_message("notice", "\n-----------[{$cnt}/$total}] Zone {$zone_entity->getTitle()}의 Record/Firewall 처리 완료-----------"); $cnt++; } } diff --git a/app/Controllers/Cloudflare/CloudflareController.php b/app/Controllers/Cloudflare/CloudflareController.php deleted file mode 100644 index a2228c8..0000000 --- a/app/Controllers/Cloudflare/CloudflareController.php +++ /dev/null @@ -1,76 +0,0 @@ -_authModel === null) { - $this->_authModel = new AuthModel(); - } - return $this->_authModel; - } - final protected function getAccountModel(): AccountModel - { - if ($this->_accountModel === null) { - $this->_accountModel = new AccountModel(); - } - return $this->_accountModel; - } - final protected function getZoneModel(): ZoneModel - { - if ($this->_zoneModel === null) { - $this->_zoneModel = new ZoneModel(); - } - return $this->_zoneModel; - } - final protected function getRecordModel(): RecordModel - { - if ($this->_recordModel === null) { - $this->_recordModel = new RecordModel(); - } - return $this->_recordModel; - } - //Trigger - protected function webhook_process(): void - { - log_message("debug", var_export($this->request->getVar(), true)); - } - final protected function webhook_procedure(): ResponseInterface - { - //Transaction Start - $this->getService()->getModel()->transStart(); - try { - // 여기에 필요한 로직을 구현하세요 - log_message("debug", var_export($this->request->getVar(), true)); - $this->webhook_process(); - $this->message = "{$this->class_name}: Trigger 작업이 완료되었습니다."; - $this->getService()->getModel()->transCommit(); - log_message("notice", __FUNCTION__ . $this->message); - return $this->response->setJSON(['status' => 200, $this->message], 200); - } catch (\Exception $e) { - //Transaction Rollback - $this->getService()->getModel()->transRollback(); - log_message("error", $e->getMessage()); - return $this->response->setJSON(['status' => 500, 'message' => $e->getMessage()], 500); - } - } -} diff --git a/app/Controllers/Cloudflare/FirewallController.php b/app/Controllers/Cloudflare/FirewallController.php deleted file mode 100644 index c172e9f..0000000 --- a/app/Controllers/Cloudflare/FirewallController.php +++ /dev/null @@ -1,51 +0,0 @@ -model === null) { - $this->model = new FirewallModel(); - } - return $this->model; - } - protected function getService(): FirewallService - { - if ($this->service === null) { - $this->service = new FirewallService(); - } - return $this->service; - } - //Trigger작업 - protected function webhook_process(): void - { - parent::webhook_process(); - // //자신정보정의 - // $this->entity = $this->getModel()->getEntityByPK($uid); - // if ($this->entity === null) { - // throw new \Exception("{$uid} 정보를 찾을수 없습니다."); - // } - // //부모데이터정의 - // $this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->entity->getParent()); - // //Socket처리 - // $this->entity = $this->getMyLibrary()->sync($this->entity); - log_message("notice", message: "Firewall Trigger 작업완료"); - } - public function webhook(): ResponseInterface - { - return $this->webhook_procedure(); - } -} diff --git a/app/Controllers/Cloudflare/RecordController.php b/app/Controllers/Cloudflare/RecordController.php deleted file mode 100644 index 189c904..0000000 --- a/app/Controllers/Cloudflare/RecordController.php +++ /dev/null @@ -1,51 +0,0 @@ -model === null) { - $this->model = new RecordModel(); - } - return $this->model; - } - protected function getService(): RecordService - { - if ($this->service === null) { - $this->service = new RecordService(); - } - return $this->service; - } - //Trigger작업 - protected function webhook_process(): void - { - parent::webhook_process(); - // //자신정보정의 - // $this->entity = $this->getModel()->getEntityByPK($uid); - // if ($this->entity === null) { - // throw new \Exception("{$uid} 정보를 찾을수 없습니다."); - // } - // //부모데이터정의 - // $this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->entity->getParent()); - // //Socket처리 - // $this->entity = $this->getMyLibrary()->sync($this->entity); - log_message("notice", "Record Trigger 작업완료"); - } - public function webhook(): ResponseInterface - { - return $this->webhook_procedure(); - } -} diff --git a/app/Controllers/Cloudflare/ZoneController.php b/app/Controllers/Cloudflare/ZoneController.php deleted file mode 100644 index bb6718c..0000000 --- a/app/Controllers/Cloudflare/ZoneController.php +++ /dev/null @@ -1,51 +0,0 @@ -model === null) { - $this->model = new ZoneModel(); - } - return $this->model; - } - protected function getService(): ZoneService - { - if ($this->service === null) { - $this->service = new ZoneService(); - } - return $this->service; - } - //Trigger작업 - protected function webhook_process(): void - { - parent::webhook_process(); - // //자신정보정의 - // $this->entity = $this->getModel()->getEntityByPK($uid); - // if ($this->entity === null) { - // throw new \Exception("{$uid} 정보를 찾을수 없습니다."); - // } - // //부모데이터정의 - // $this->_account_entity = $this->getAccountModel()->getEntityByPK($this->entity->getParent()); - // //Socket처리 - // $this->entity = $this->getMyLibrary()->sync($this->entity); - log_message("notice", "Zone Trigger 작업완료"); - } - public function webhook(): ResponseInterface - { - return $this->webhook_procedure(); - } -}