cfmgrv3/app/Controllers/CLI/Cloudflare/API/Zone.php
2024-05-15 11:06:17 +09:00

65 lines
2.5 KiB
PHP

<?php
namespace App\Controllers\CLI\Cloudflare\API;
use App\Libraries\Log\Log;
class Zone extends API
{
private function getZones(string $account_uid = ''): array
{
$wheres = ['status' => 'active'];
if ($account_uid) {
$wheres = ['account_uid' => $account_uid];
}
$entitys = $this->getZoneModel()->getEntitys($wheres);
// dd($this->getZoneModel()->getLastQuery());
Log::add("error", __FUNCTION__ . "에서 호출:" . $this->getZoneModel()->getLastQuery());
// dd($entitys);
return $entitys;
}
final public function record($account_uid = '', $page_limit = 0,)
{
//transation처리
// $this->getZoneModel()->db->transBegin();
try {
//Record
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);
}
//CDN값 수정 못하는 고정 Record 처리
$fixedRecordModel = new \App\Models\Cloudflare\API\FixedRecordModel();
$this->getRecordModel()->setFixedCDNRecord($fixedRecordModel->findColumn("host"));
Log::add("error", __METHOD__ . "에서 Record Reload 완료\n");
//transation 완료
// $this->getZoneModel()->db->transCommit();
} catch (\Exception $e) {
//transaction 오류복구
// $this->getZoneModel()->db->transRollback();
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 {
//Firewall
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);
}
Log::add("error", __METHOD__ . "에서 Firewall Reload 완료\n");
//transation 완료
// $this->getZoneModel()->db->transCommit();
} catch (\Exception $e) {
//transaction 오류복구
// $this->getZoneModel()->db->transRollback();
Log::add("error", __METHOD__ . "에서 Firewall Reload 오류\n" . $e->getMessage());
}
}
}