change CLITools...

This commit is contained in:
최준흠 2024-05-15 10:37:47 +09:00
parent 35143e9b70
commit 8eb87ebf43
3 changed files with 30 additions and 43 deletions

View File

@ -3,28 +3,26 @@
namespace App\Controllers\CLI\Cloudflare\API; namespace App\Controllers\CLI\Cloudflare\API;
use App\Entities\Cloudflare\API\AccountEntity; use App\Entities\Cloudflare\API\AccountEntity;
use App\Libraries\Log\Log;
class Account extends API class Account extends API
{ {
private function getAccounts(int $auth_uid): array private function getAccounts(int $account_uid): array
{ {
if ($auth_uid) { $this->getAccountModel()->where(['status' => 'active']);
$entitys = $this->getAccountModel()->asObject(AccountEntity::class) if ($account_uid) {
->where(['auth_uid' => $auth_uid]) $this->getAccountModel()->where(['account_uid' => $account_uid]);
->findAll();
} else { } else {
$entitys = $this->getAccountModel()->asObject(AccountEntity::class) $this->getAccountModel()->where(['status' => 'use']);
->where('status', 'use')
->findAll();
} }
echo __FUNCTION__ . "에서 호출:" . $this->getAccountModel()->getLastQuery(); Log::add("error", __FUNCTION__ . "에서 호출:" . $this->getAccountModel()->getLastQuery());
return $entitys; return $this->getAccountModel()->asObject(AccountEntity::class)->findAll();
} }
final public function execute($auth_uid = 0, $page_limit = 0) final public function execute($auth_uid = 0, $page_limit = 0)
{ {
//transation처리
// $this->getAccountModel()->db->transBegin();
try { try {
//transation처리
// $this->getAccountModel()->db->transBegin();
//Zone 처리 //Zone 처리
foreach ($this->getAccounts((int)$auth_uid) as $entity) { foreach ($this->getAccounts((int)$auth_uid) as $entity) {
$api = new \App\Libraries\Cloudflare\API\Zone($entity, true); $api = new \App\Libraries\Cloudflare\API\Zone($entity, true);
@ -32,13 +30,11 @@ class Account extends API
} }
//transation 완료 //transation 완료
// $this->getAccountModel()->db->transCommit(); // $this->getAccountModel()->db->transCommit();
echo __METHOD__ . "에서 Zone Reload 완료"; Log::add("error", __METHOD__ . "에서 Zone Reload 완료");
} catch (\Exception $e) { } catch (\Exception $e) {
// transaction 오류복구 // transaction 오류복구
// $this->getAccountModel()->db->transRollback(); // $this->getAccountModel()->db->transRollback();
$message = __METHOD__ . "에서 Zone Reload 오류\n" . $e->getMessage(); Log::add("error", __METHOD__ . "에서 Zone Reload 오류\n" . $e->getMessage());
log_message("error", $message);
echo $message;
} }
} }
} }

View File

@ -3,28 +3,27 @@
namespace App\Controllers\CLI\Cloudflare\API; namespace App\Controllers\CLI\Cloudflare\API;
use App\Entities\Cloudflare\API\AuthEntity; use App\Entities\Cloudflare\API\AuthEntity;
use App\Libraries\Log\Log;
class Auth extends API class Auth extends API
{ {
final public function execute() final public function execute()
{ {
//transation처리
// $this->getAuthModel()->db->transBegin();
try { try {
$entitys = $this->getAuthModel()->asObject(AuthEntity::class)->where(['status' => 'use'])->findAll(); $entitys = $this->getAuthModel()->asObject(AuthEntity::class)->where(['status' => 'use'])->findAll();
//transation처리
// $this->getAuthModel()->db->transBegin();
foreach ($entitys as $entity) { foreach ($entitys as $entity) {
$api = new \App\Libraries\Cloudflare\API\Account($entity); $api = new \App\Libraries\Cloudflare\API\Account($entity);
$api->reload(); $api->reload();
} }
//transation 완료 //transation 완료
// $this->getAuthModel()->db->transCommit(); // $this->getAuthModel()->db->transCommit();
echo __METHOD__ . "에서 Account Reload 완료"; Log::add("error", __METHOD__ . "에서 Account Reload 완료");
} catch (\Exception $e) { } catch (\Exception $e) {
//transaction 오류복구 //transaction 오류복구
// $this->getAuthModel()->db->transRollback(); // $this->getAuthModel()->db->transRollback();
$message = __METHOD__ . "에서 Account Reload 오류\n" . $e->getMessage(); Log::add("error", __METHOD__ . "에서 Account Reload 오류\n" . $e->getMessage());
log_message("error", $message);
echo $message;
} }
} }
} }

View File

@ -10,24 +10,20 @@ class Zone extends API
private function getZones(string $account_uid): array private function getZones(string $account_uid): array
{ {
if ($account_uid) { if ($account_uid) {
$entitys = $this->getZoneModel()->asObject(ZoneEntity::class) $this->getZoneModel()->where(['account_uid' => $account_uid]);
->where(['status' => 'active', 'account_uid' => $account_uid])
->findAll();
} else { } else {
$entitys = $this->getZoneModel()->asObject(ZoneEntity::class) $this->getZoneModel()->where(['status' => 'active']);
->where('status', 'active')
->findAll();
} }
Log::add("error", __FUNCTION__ . "에서 호출:" . $this->getZoneModel()->getLastQuery()); 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,) final public function record($account_uid = '', $page_limit = 0,)
{ {
//transation처리
// $this->getZoneModel()->db->transBegin();
try { try {
//transation처리
// $this->getZoneModel()->db->transBegin();
//Record //Record
echo __METHOD__ . "에서 Record Reload 시작\n"; Log::add("error", __METHOD__ . "에서 Record Reload 시작\n");
foreach ($this->getZones($account_uid) as $entity) { foreach ($this->getZones($account_uid) as $entity) {
$api = new \App\Libraries\Cloudflare\API\Record($entity); $api = new \App\Libraries\Cloudflare\API\Record($entity);
$api->reload((int)$page_limit); $api->reload((int)$page_limit);
@ -35,37 +31,33 @@ class Zone extends API
//CDN값 수정 못하는 고정 Record 처리 //CDN값 수정 못하는 고정 Record 처리
$fixedRecordModel = new \App\Models\Cloudflare\API\FixedRecordModel(); $fixedRecordModel = new \App\Models\Cloudflare\API\FixedRecordModel();
$this->getRecordModel()->setFixedCDNRecord($fixedRecordModel->findColumn("host")); $this->getRecordModel()->setFixedCDNRecord($fixedRecordModel->findColumn("host"));
echo __METHOD__ . "에서 Record Reload 완료\n"; Log::add("error", __METHOD__ . "에서 Record Reload 완료\n");
//transation 완료 //transation 완료
// $this->getZoneModel()->db->transCommit(); // $this->getZoneModel()->db->transCommit();
} catch (\Exception $e) { } catch (\Exception $e) {
//transaction 오류복구 //transaction 오류복구
// $this->getZoneModel()->db->transRollback(); // $this->getZoneModel()->db->transRollback();
$message = __METHOD__ . "에서 Record Reload 오류\n" . $e->getMessage(); Log::add("error", __METHOD__ . "에서 Record Reload 오류\n" . $e->getMessage());
log_message("error", $message);
echo $message;
} }
} }
final public function firewall(int $page_limit = 0, string $account_uid = '') final public function firewall(int $page_limit = 0, string $account_uid = '')
{ {
//transation처리
// $this->getZoneModel()->db->transBegin();
try { try {
//transation처리
// $this->getZoneModel()->db->transBegin();
//Firewall //Firewall
echo __METHOD__ . "에서 Firewall Reload 시작\n"; Log::add("error", __METHOD__ . "에서 Firewall Reload 시작\n");
foreach ($this->getZones($account_uid) as $entity) { foreach ($this->getZones($account_uid) as $entity) {
$api = new \App\Libraries\Cloudflare\API\Firewall($entity); $api = new \App\Libraries\Cloudflare\API\Firewall($entity);
$api->reload((int)$page_limit); $api->reload((int)$page_limit);
} }
echo __METHOD__ . "에서 Firewall Reload 완료\n"; Log::add("error", __METHOD__ . "에서 Firewall Reload 완료\n");
//transation 완료 //transation 완료
// $this->getZoneModel()->db->transCommit(); // $this->getZoneModel()->db->transCommit();
} catch (\Exception $e) { } catch (\Exception $e) {
//transaction 오류복구 //transaction 오류복구
// $this->getZoneModel()->db->transRollback(); // $this->getZoneModel()->db->transRollback();
$message = __METHOD__ . "에서 Firewall Reload 오류\n" . $e->getMessage(); Log::add("error", __METHOD__ . "에서 Firewall Reload 오류\n" . $e->getMessage());
log_message("error", $message);
echo $message;
} }
} }
} }