diff --git a/app/Controllers/CLI/Cloudflare/API/Account.php b/app/Controllers/CLI/Cloudflare/API/Account.php index 2033618..200da8f 100644 --- a/app/Controllers/CLI/Cloudflare/API/Account.php +++ b/app/Controllers/CLI/Cloudflare/API/Account.php @@ -3,28 +3,26 @@ namespace App\Controllers\CLI\Cloudflare\API; use App\Entities\Cloudflare\API\AccountEntity; +use App\Libraries\Log\Log; class Account extends API { - private function getAccounts(int $auth_uid): array + private function getAccounts(int $account_uid): array { - if ($auth_uid) { - $entitys = $this->getAccountModel()->asObject(AccountEntity::class) - ->where(['auth_uid' => $auth_uid]) - ->findAll(); + $this->getAccountModel()->where(['status' => 'active']); + if ($account_uid) { + $this->getAccountModel()->where(['account_uid' => $account_uid]); } else { - $entitys = $this->getAccountModel()->asObject(AccountEntity::class) - ->where('status', 'use') - ->findAll(); + $this->getAccountModel()->where(['status' => 'use']); } - echo __FUNCTION__ . "에서 호출:" . $this->getAccountModel()->getLastQuery(); - return $entitys; + Log::add("error", __FUNCTION__ . "에서 호출:" . $this->getAccountModel()->getLastQuery()); + return $this->getAccountModel()->asObject(AccountEntity::class)->findAll(); } final public function execute($auth_uid = 0, $page_limit = 0) { + //transation처리 + // $this->getAccountModel()->db->transBegin(); try { - //transation처리 - // $this->getAccountModel()->db->transBegin(); //Zone 처리 foreach ($this->getAccounts((int)$auth_uid) as $entity) { $api = new \App\Libraries\Cloudflare\API\Zone($entity, true); @@ -32,13 +30,11 @@ class Account extends API } //transation 완료 // $this->getAccountModel()->db->transCommit(); - echo __METHOD__ . "에서 Zone Reload 완료"; + Log::add("error", __METHOD__ . "에서 Zone Reload 완료"); } catch (\Exception $e) { // transaction 오류복구 // $this->getAccountModel()->db->transRollback(); - $message = __METHOD__ . "에서 Zone Reload 오류\n" . $e->getMessage(); - log_message("error", $message); - echo $message; + Log::add("error", __METHOD__ . "에서 Zone Reload 오류\n" . $e->getMessage()); } } } diff --git a/app/Controllers/CLI/Cloudflare/API/Auth.php b/app/Controllers/CLI/Cloudflare/API/Auth.php index 841b3d7..ecfec56 100644 --- a/app/Controllers/CLI/Cloudflare/API/Auth.php +++ b/app/Controllers/CLI/Cloudflare/API/Auth.php @@ -3,28 +3,27 @@ namespace App\Controllers\CLI\Cloudflare\API; use App\Entities\Cloudflare\API\AuthEntity; +use App\Libraries\Log\Log; class Auth extends API { final public function execute() { + //transation처리 + // $this->getAuthModel()->db->transBegin(); try { $entitys = $this->getAuthModel()->asObject(AuthEntity::class)->where(['status' => 'use'])->findAll(); - //transation처리 - // $this->getAuthModel()->db->transBegin(); foreach ($entitys as $entity) { $api = new \App\Libraries\Cloudflare\API\Account($entity); $api->reload(); } //transation 완료 // $this->getAuthModel()->db->transCommit(); - echo __METHOD__ . "에서 Account Reload 완료"; + Log::add("error", __METHOD__ . "에서 Account Reload 완료"); } catch (\Exception $e) { //transaction 오류복구 // $this->getAuthModel()->db->transRollback(); - $message = __METHOD__ . "에서 Account Reload 오류\n" . $e->getMessage(); - log_message("error", $message); - echo $message; + Log::add("error", __METHOD__ . "에서 Account Reload 오류\n" . $e->getMessage()); } } } diff --git a/app/Controllers/CLI/Cloudflare/API/Zone.php b/app/Controllers/CLI/Cloudflare/API/Zone.php index af6e0ae..40c6670 100644 --- a/app/Controllers/CLI/Cloudflare/API/Zone.php +++ b/app/Controllers/CLI/Cloudflare/API/Zone.php @@ -10,24 +10,20 @@ class Zone extends API private function getZones(string $account_uid): array { if ($account_uid) { - $entitys = $this->getZoneModel()->asObject(ZoneEntity::class) - ->where(['status' => 'active', 'account_uid' => $account_uid]) - ->findAll(); + $this->getZoneModel()->where(['account_uid' => $account_uid]); } else { - $entitys = $this->getZoneModel()->asObject(ZoneEntity::class) - ->where('status', 'active') - ->findAll(); + $this->getZoneModel()->where(['status' => 'active']); } Log::add("error", __FUNCTION__ . "에서 호출:" . $this->getZoneModel()->getLastQuery()); - return $entitys; + return $this->getZoneModel()->asObject(ZoneEntity::class)->findAll(); } final public function record($account_uid = '', $page_limit = 0,) { + //transation처리 + // $this->getZoneModel()->db->transBegin(); try { - //transation처리 - // $this->getZoneModel()->db->transBegin(); //Record - echo __METHOD__ . "에서 Record Reload 시작\n"; + Log::add("error", __METHOD__ . "에서 Record Reload 시작\n"); foreach ($this->getZones($account_uid) as $entity) { $api = new \App\Libraries\Cloudflare\API\Record($entity); $api->reload((int)$page_limit); @@ -35,37 +31,33 @@ class Zone extends API //CDN값 수정 못하는 고정 Record 처리 $fixedRecordModel = new \App\Models\Cloudflare\API\FixedRecordModel(); $this->getRecordModel()->setFixedCDNRecord($fixedRecordModel->findColumn("host")); - echo __METHOD__ . "에서 Record Reload 완료\n"; + Log::add("error", __METHOD__ . "에서 Record Reload 완료\n"); //transation 완료 // $this->getZoneModel()->db->transCommit(); } catch (\Exception $e) { //transaction 오류복구 // $this->getZoneModel()->db->transRollback(); - $message = __METHOD__ . "에서 Record Reload 오류\n" . $e->getMessage(); - log_message("error", $message); - echo $message; + Log::add("error", __METHOD__ . "에서 Record Reload 오류\n" . $e->getMessage()); } } final public function firewall(int $page_limit = 0, string $account_uid = '') { + //transation처리 + // $this->getZoneModel()->db->transBegin(); try { - //transation처리 - // $this->getZoneModel()->db->transBegin(); //Firewall - echo __METHOD__ . "에서 Firewall Reload 시작\n"; + Log::add("error", __METHOD__ . "에서 Firewall Reload 시작\n"); foreach ($this->getZones($account_uid) as $entity) { $api = new \App\Libraries\Cloudflare\API\Firewall($entity); $api->reload((int)$page_limit); } - echo __METHOD__ . "에서 Firewall Reload 완료\n"; + Log::add("error", __METHOD__ . "에서 Firewall Reload 완료\n"); //transation 완료 // $this->getZoneModel()->db->transCommit(); } catch (\Exception $e) { //transaction 오류복구 // $this->getZoneModel()->db->transRollback(); - $message = __METHOD__ . "에서 Firewall Reload 오류\n" . $e->getMessage(); - log_message("error", $message); - echo $message; + Log::add("error", __METHOD__ . "에서 Firewall Reload 오류\n" . $e->getMessage()); } } }