cfmgrv4 init...2
This commit is contained in:
parent
b5eafe9e36
commit
d62c25888d
@ -21,6 +21,7 @@ $routes->group('/user', function ($routes) {
|
|||||||
$routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) {
|
$routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) {
|
||||||
$routes->group('cloudflare', function ($routes) {
|
$routes->group('cloudflare', function ($routes) {
|
||||||
$routes->cli('reload', 'Cloudflare::reload');
|
$routes->cli('reload', 'Cloudflare::reload');
|
||||||
|
$routes->cli('reload/(:num)', 'Cloudflare::reload/$1');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
$routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:manager'], function ($routes) {
|
$routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:manager'], function ($routes) {
|
||||||
|
|||||||
@ -22,14 +22,17 @@ class Cloudflare extends BaseController
|
|||||||
parent::initController($request, $response, $logger);
|
parent::initController($request, $response, $logger);
|
||||||
$this->_db = \Config\Database::connect();
|
$this->_db = \Config\Database::connect();
|
||||||
}
|
}
|
||||||
private function getAuthModel(): AuthModel
|
private function auth_process(mixed $uid = false): array
|
||||||
{
|
{
|
||||||
return new AuthModel();
|
$authModel = model(AuthModel::class);
|
||||||
}
|
if (is_numeric($uid) && $uid > 0) {
|
||||||
private function auth_process(): array
|
$authModel->where(AuthModel::PK, intval($uid));
|
||||||
{
|
} else {
|
||||||
$this->getAuthModel()->where('status', DEFAULTS["STATUS"]);
|
$authModel->where('status', DEFAULTS["STATUS"]);
|
||||||
return $this->getAuthModel()->getEntitys();
|
}
|
||||||
|
$entitys = $authModel->getEntitys();
|
||||||
|
log_message("debug", $authModel->getLastQuery());
|
||||||
|
return $entitys;
|
||||||
}
|
}
|
||||||
private function account_process(AuthEntity $auth_entity): array
|
private function account_process(AuthEntity $auth_entity): array
|
||||||
{
|
{
|
||||||
@ -46,25 +49,26 @@ class Cloudflare extends BaseController
|
|||||||
$record = new Record($zone_entity);
|
$record = new Record($zone_entity);
|
||||||
return $record->reload();
|
return $record->reload();
|
||||||
}
|
}
|
||||||
public function reload(): void
|
public function reload(mixed $uid = false): void
|
||||||
{
|
{
|
||||||
//Transaction Start
|
//Transaction Start
|
||||||
$this->_db->transStart();
|
$this->_db->transStart();
|
||||||
try {
|
try {
|
||||||
$auths = $this->auth_process();
|
$auths = $this->auth_process($uid);
|
||||||
$accounts = [];
|
$accounts = [];
|
||||||
foreach ($auths as $auth) {
|
foreach ($auths as $auth) {
|
||||||
$accounts = $this->account_process($auth);
|
$accounts += $this->account_process($auth);
|
||||||
}
|
}
|
||||||
|
log_message("debug", "\n-------------총 Accounts:" . count($accounts) . "--------------------\n");
|
||||||
$zones = [];
|
$zones = [];
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $key => $account) {
|
||||||
$zones = $this->zone_process($account);
|
$zones += $this->zone_process($account);
|
||||||
}
|
}
|
||||||
$records = [];
|
log_message("debug", "\n-------------총 Zones:" . count($zones) . "--------------------\n");
|
||||||
foreach ($zones as $zone) {
|
// foreach ($zones as $key => $zone) {
|
||||||
$records = $this->record_process($zone);
|
// $this->record_process($zone);
|
||||||
}
|
// }
|
||||||
log_message("notice", "Reload 작업을 완료하였습니다.");
|
// log_message("notice", "Reload 작업을 완료하였습니다.");
|
||||||
$this->_db->transCommit();
|
$this->_db->transCommit();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
//Transaction Rollback
|
//Transaction Rollback
|
||||||
|
|||||||
@ -36,8 +36,9 @@ return [
|
|||||||
"essentially_off" => "essentially_off",
|
"essentially_off" => "essentially_off",
|
||||||
],
|
],
|
||||||
"STATUS" => [
|
"STATUS" => [
|
||||||
"active" => "active",
|
"initializing" => "initializing",
|
||||||
"pending" => "pending",
|
"pending" => "pending",
|
||||||
|
"active" => "active",
|
||||||
"moved" => "moved"
|
"moved" => "moved"
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
@ -4,6 +4,7 @@ namespace App\Libraries\Cloudflare;
|
|||||||
|
|
||||||
use App\Models\Cloudflare\AccountModel;
|
use App\Models\Cloudflare\AccountModel;
|
||||||
use App\Entities\Cloudflare\AuthEntity;
|
use App\Entities\Cloudflare\AuthEntity;
|
||||||
|
use App\Entities\Cloudflare\AccountEntity;
|
||||||
|
|
||||||
class Account extends Cloudflare
|
class Account extends Cloudflare
|
||||||
{
|
{
|
||||||
@ -34,7 +35,8 @@ class Account extends Cloudflare
|
|||||||
// "legacy_flags":{"enterprise_zone_quota":{"maximum":0,"current":0,"available":0}},
|
// "legacy_flags":{"enterprise_zone_quota":{"maximum":0,"current":0,"available":0}},
|
||||||
// "created_on":"2017-06-26T05:44:49.470184Z"}
|
// "created_on":"2017-06-26T05:44:49.470184Z"}
|
||||||
// ]
|
// ]
|
||||||
public function getArrayByResult($result, array $formDatas = []): array
|
|
||||||
|
protected function getArrayByResult($result, array $formDatas = []): array
|
||||||
{
|
{
|
||||||
$formDatas[AccountModel::PK] = $result->id;
|
$formDatas[AccountModel::PK] = $result->id;
|
||||||
$formDatas[AccountModel::PARENT] = $this->getAuthEntity()->getPK();
|
$formDatas[AccountModel::PARENT] = $this->getAuthEntity()->getPK();
|
||||||
@ -45,20 +47,29 @@ class Account extends Cloudflare
|
|||||||
$formDatas['created_at'] = $result->created_on;
|
$formDatas['created_at'] = $result->created_on;
|
||||||
return $formDatas;
|
return $formDatas;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reload(): array
|
public function reload(): array
|
||||||
{
|
{
|
||||||
log_message("notice", "-----{$this->getAuthEntity()->getTitle()} 처리 시작-----");
|
log_message("notice", "\n----------Auth {$this->getAuthEntity()->getTitle()}의 Account 처리 시작-----------");
|
||||||
$entitys = [];
|
$entitys = [];
|
||||||
foreach ($this->reload_procedure("accounts") as $result) {
|
try {
|
||||||
$formDatas = $this->getArrayByResult($result);
|
$account_results = $this->reload_procedure("accounts");
|
||||||
$entity = $this->getModel()->modify($this->getModel()->getEntity(), $formDatas);
|
if (count($account_results) > 0) {
|
||||||
$entitys[$entity->getPK()] = $entity;
|
foreach ($account_results as $result) {
|
||||||
|
$formDatas = $this->getArrayByResult($result);
|
||||||
|
$entitys[$formDatas[AccountModel::PK]] = $this->getModel()->modify(new AccountEntity(), $formDatas);
|
||||||
|
}
|
||||||
|
//부모키를 기준으로 CF에 존재하지 않는 데이터 삭제용
|
||||||
|
$this->getModel()->where(AccountModel::PARENT, $this->getAuthEntity()->getPK());
|
||||||
|
$this->getModel()->whereNotIn(AccountModel::PK, array_keys($entitys));
|
||||||
|
$this->getModel()->delete();
|
||||||
|
log_message("debug", $this->getModel()->getLastQuery());
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
log_message("error", $e->getMessage());
|
||||||
|
throw new \Exception($e->getMessage());
|
||||||
}
|
}
|
||||||
//부모키를 기준으로 CF에 존재하지 않는 데이터 삭제용
|
log_message("notice", message: "\n-----------Auth {$this->getAuthEntity()->getTitle()}의 Account 처리[" . count($entitys) . "개] 완료-----------");
|
||||||
$this->getModel()->where(AccountModel::PARENT, $this->getAuthEntity());
|
|
||||||
$this->getModel()->whereNotIn(AccountModel::PK, array_keys($entitys));
|
|
||||||
$this->getModel()->delete();
|
|
||||||
log_message("notice", "-----{$this->getAuthEntity()->getTitle()} 처리[" . count($entitys) . "개] 완료-----");
|
|
||||||
return $entitys;
|
return $entitys;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,29 +47,36 @@ abstract class Cloudflare extends CommonLibrary
|
|||||||
}
|
}
|
||||||
return $this->_accountModel;
|
return $this->_accountModel;
|
||||||
}
|
}
|
||||||
final protected function reload_procedure($uri): array
|
|
||||||
|
private function reload_page(string $uri, int $page, int $per_page = 50): mixed
|
||||||
|
{
|
||||||
|
$query = [
|
||||||
|
'page' => $page,
|
||||||
|
'per_page' => $per_page,
|
||||||
|
'match' => 'all',
|
||||||
|
];
|
||||||
|
$response = $this->getMySocket()->get($uri, $query);
|
||||||
|
$cf = json_decode($response->getBody());
|
||||||
|
if (!$cf->success) {
|
||||||
|
$message = __FUNCTION__ . "에서 실패:\nresponse:" . var_export($cf, true);
|
||||||
|
log_message("error", $message);
|
||||||
|
throw new \Exception($message);
|
||||||
|
}
|
||||||
|
return $cf;
|
||||||
|
}
|
||||||
|
final protected function reload_procedure(string $uri): array
|
||||||
{
|
{
|
||||||
$page = 1; //1부터 시작
|
$page = 1; //1부터 시작
|
||||||
$results = [];
|
//한번에 가져올수 있는 갯수 (countfalre 5~50사이)
|
||||||
do {
|
$cf = $this->reload_page($uri, $page);
|
||||||
$query = [
|
$per_page = $cf->result_info->per_page;
|
||||||
'page' => $page,
|
$total_page = $cf->result_info->total_pages;
|
||||||
'per_page' => $this->getMySocket()::$_request_perpage_max,
|
$results = $cf->result;
|
||||||
'match' => 'all',
|
for ($i = $page + 1; $i <= $total_page; $i++) {
|
||||||
];
|
$cf = $this->reload_page($uri, $i, $per_page);
|
||||||
$response = $this->getMySocket()->get($uri, $query);
|
|
||||||
$cf = json_decode($response->getBody());
|
|
||||||
if (!$cf->success) {
|
|
||||||
$message = __FUNCTION__ . "에서 실패:\nresponse:" . var_export($cf, true);
|
|
||||||
log_message("error", $message);
|
|
||||||
throw new \Exception($message);
|
|
||||||
}
|
|
||||||
$results = array_merge($results, $cf->result);
|
$results = array_merge($results, $cf->result);
|
||||||
if (count($cf->result) < $this->getMySocket()::$_request_perpage_max) {
|
log_message("debug", "현재: page[{$i}/{$total_page}] , result수[" . count($results) . "]");
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
$page++;
|
|
||||||
} while (true);
|
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -113,6 +113,7 @@ class Record extends Cloudflare
|
|||||||
//DB삭제
|
//DB삭제
|
||||||
$this->getModel()->where(RecordModel::PK, $entity->getPK());
|
$this->getModel()->where(RecordModel::PK, $entity->getPK());
|
||||||
$this->getModel()->delete();
|
$this->getModel()->delete();
|
||||||
|
log_message("debug", $this->getModel()->getLastQuery());
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
public function sync(RecordEntity $entity): RecordEntity
|
public function sync(RecordEntity $entity): RecordEntity
|
||||||
@ -148,18 +149,26 @@ class Record extends Cloudflare
|
|||||||
//Reload
|
//Reload
|
||||||
public function reload(): array
|
public function reload(): array
|
||||||
{
|
{
|
||||||
log_message("notice", "-----{$this->_zone_entity->getTitle()} 처리 시작-----");
|
log_message("notice", "\n-----------Zone {$this->_zone_entity->getTitle()}의 Record 처리 시작-----------");
|
||||||
$entitys = [];
|
$entitys = [];
|
||||||
foreach ($this->reload_procedure("zones/{$this->_zone_entity->getPK()}/dns_records") as $result) {
|
try {
|
||||||
$formDatas = $this->getArrayByResult($result);
|
$record_results = $this->reload_procedure("zones/{$this->_zone_entity->getPK()}/dns_records");
|
||||||
$entity = $this->getModel()->modify($this->getModel()->getEntity(), $formDatas);
|
if (count($record_results) > 0) {
|
||||||
$entitys[$entity->getPK()] = $entity;
|
foreach ($record_results as $result) {
|
||||||
|
$formDatas = $this->getArrayByResult($result);
|
||||||
|
$entitys[$formDatas[RecordModel::PK]] = $this->getModel()->modify(new RecordEntity(), $formDatas);
|
||||||
|
}
|
||||||
|
//부모키를 기준으로 CF에 존재하지 않는 데이터 DB삭제
|
||||||
|
$this->getModel()->where(RecordModel::PARENT, $this->_zone_entity->getPK());
|
||||||
|
$this->getModel()->whereNotIn(RecordModel::PK, array_keys($entitys));
|
||||||
|
$this->getModel()->delete();
|
||||||
|
log_message("debug", $this->getModel()->getLastQuery());
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
log_message("error", $e->getMessage());
|
||||||
|
throw new \Exception($e->getMessage());
|
||||||
}
|
}
|
||||||
//부모키를 기준으로 CF에 존재하지 않는 데이터 DB삭제
|
log_message("notice", "\n-----------Zone {$this->_zone_entity->getTitle()}의 Record처리[" . count($entitys) . "개] 완료-----------");
|
||||||
$this->getModel()->where(RecordModel::PARENT, $this->_zone_entity);
|
|
||||||
$this->getModel()->whereNotIn(RecordModel::PK, array_keys($entitys));
|
|
||||||
$this->getModel()->delete();
|
|
||||||
log_message("notice", "-----{$this->_zone_entity->getTitle()} 처리[" . count($entitys) . "개] 완료-----");
|
|
||||||
return $entitys;
|
return $entitys;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,16 +58,15 @@ class Zone extends Cloudflare
|
|||||||
return $formDatas;
|
return $formDatas;
|
||||||
}
|
}
|
||||||
//Cfzone에서 가져온 값을 zone에 setting
|
//Cfzone에서 가져온 값을 zone에 setting
|
||||||
private function getCFSetting(ZoneEntity $entity): array
|
private function getCFSetting(string $uid, array $formDatas = []): array
|
||||||
{
|
{
|
||||||
$cf = $this->getMySocket()->get('zones/' . $entity->getPK() . '/settings');
|
$cf = $this->getMySocket()->get('zones/' . $uid . '/settings');
|
||||||
$cf = json_decode($cf->getBody());
|
$cf = json_decode($cf->getBody());
|
||||||
if (!$cf->success) {
|
if (!$cf->success) {
|
||||||
$message = "Zone:" . __FUNCTION__ . "에서 실패:\nresponse:" . var_export($cf, true);
|
$message = "Zone:" . __FUNCTION__ . "에서 실패:\nresponse:" . var_export($cf, true);
|
||||||
log_message("error", $message);
|
log_message("error", $message);
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
$formDatas = [];
|
|
||||||
foreach ($cf->result as $cf) {
|
foreach ($cf->result as $cf) {
|
||||||
if (in_array($cf->id, array_keys($this->_setting_fields))) {
|
if (in_array($cf->id, array_keys($this->_setting_fields))) {
|
||||||
$formDatas[$cf->id] = $cf->value;
|
$formDatas[$cf->id] = $cf->value;
|
||||||
@ -75,10 +74,10 @@ class Zone extends Cloudflare
|
|||||||
}
|
}
|
||||||
return $formDatas;
|
return $formDatas;
|
||||||
}
|
}
|
||||||
private function setCFSetting(ZoneEntity $entity, string $field, string $value): string
|
private function setCFSetting(string $uid, string $field, string $value): string
|
||||||
{
|
{
|
||||||
$datas = ['value' => $value];
|
$datas = ['value' => $value];
|
||||||
$cf = $this->getMySocket()->patch('zones/' . $entity->getPK() . '/settings/' . $field, $datas);
|
$cf = $this->getMySocket()->patch('zones/' . $uid . '/settings/' . $field, $datas);
|
||||||
$cf = json_decode($cf->getBody());
|
$cf = json_decode($cf->getBody());
|
||||||
if (!$cf->success || $cf->result->id !== $field) {
|
if (!$cf->success || $cf->result->id !== $field) {
|
||||||
$message = "Zone:" . __FUNCTION__ . "에서 실패:\nrequest:" . var_export($datas, true) . "\nresponse:" . var_export($cf, true);
|
$message = "Zone:" . __FUNCTION__ . "에서 실패:\nrequest:" . var_export($datas, true) . "\nresponse:" . var_export($cf, true);
|
||||||
@ -106,21 +105,17 @@ class Zone extends Cloudflare
|
|||||||
}
|
}
|
||||||
//DB생성
|
//DB생성
|
||||||
$formDatas = $this->getArrayByResult($cf->result);
|
$formDatas = $this->getArrayByResult($cf->result);
|
||||||
$entity = $this->getModel()->create($formDatas);
|
|
||||||
|
|
||||||
//초기화값 추가셋팅 ipv6 , development_mode , security_level
|
|
||||||
$formDatas = [];
|
|
||||||
foreach ($this->_setting_fields as $field => $default) {
|
foreach ($this->_setting_fields as $field => $default) {
|
||||||
$formDatas[$field] = $this->setCFSetting($entity, $field, $default);
|
//초기화값 추가셋팅 ipv6 , development_mode , security_level
|
||||||
|
$formDatas[$field] = $this->setCFSetting($formDatas[ZoneModel::PK], $field, $default);
|
||||||
}
|
}
|
||||||
//DB수정
|
return $this->getModel()->create($formDatas);
|
||||||
return $this->getModel()->modify($entity, $formDatas);
|
|
||||||
}
|
}
|
||||||
public function modify(ZoneEntity $entity, array $formDatas): ZoneEntity
|
public function modify(ZoneEntity $entity, array $formDatas): ZoneEntity
|
||||||
{
|
{
|
||||||
// throw new \Exception("zone:modify" . var_export($formDatas, true));
|
// throw new \Exception("zone:modify" . var_export($formDatas, true));
|
||||||
//modify,toggle,batchjob 사용 셋팅 ipv6 , //development_mode , //security_level
|
|
||||||
foreach ($formDatas as $field => $value) {
|
foreach ($formDatas as $field => $value) {
|
||||||
|
//modify,toggle,batchjob 사용 셋팅 ipv6 , //development_mode , //security_level
|
||||||
$formDatas[$field] = $this->setCFSetting($entity, $field, $value);
|
$formDatas[$field] = $this->setCFSetting($entity, $field, $value);
|
||||||
}
|
}
|
||||||
//DB수정
|
//DB수정
|
||||||
@ -138,6 +133,7 @@ class Zone extends Cloudflare
|
|||||||
//DB삭제
|
//DB삭제
|
||||||
$this->getModel()->where(ZoneModel::PK, $entity->getPK());
|
$this->getModel()->where(ZoneModel::PK, $entity->getPK());
|
||||||
$this->getModel()->delete();
|
$this->getModel()->delete();
|
||||||
|
log_message("debug", $this->getModel()->getLastQuery());
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
public function sync(ZoneEntity $entity): ZoneEntity
|
public function sync(ZoneEntity $entity): ZoneEntity
|
||||||
@ -149,30 +145,34 @@ class Zone extends Cloudflare
|
|||||||
log_message("error", $message);
|
log_message("error", $message);
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
$formDatas = $this->getArrayByResult($cf->result);
|
$formDatas = $this->getArrayByResult($cf->result);
|
||||||
$entity = $this->getModel()->modify($this->getModel()->getEntity(), $formDatas);
|
$formDatas = $this->getCFSetting($formDatas[ZoneModel::PK], $formDatas);
|
||||||
//추가 셋팅용
|
|
||||||
$formDatas = $this->getCFSetting($entity);
|
|
||||||
return $this->getModel()->modify($entity, $formDatas);
|
return $this->getModel()->modify($entity, $formDatas);
|
||||||
}
|
}
|
||||||
//Reload
|
//Reload
|
||||||
public function reload(): array
|
public function reload(): array
|
||||||
{
|
{
|
||||||
log_message("notice", "-----{$this->_account_entity->getTitle()} 처리 시작-----");
|
log_message("notice", "\n-----------Account {$this->_account_entity->getTitle()}의 Zone처리 시작-----------");
|
||||||
$entitys = [];
|
$entitys = [];
|
||||||
foreach ($this->reload_procedure('zones') as $result) {
|
try {
|
||||||
$formDatas = $this->getArrayByResult($result);
|
$zone_results = $this->reload_procedure("zones");
|
||||||
$entity = $this->getModel()->modify($this->getModel()->getEntity(), $formDatas);
|
if (count($zone_results) > 0) {
|
||||||
//추가 셋팅용
|
foreach ($zone_results as $result) {
|
||||||
$formDatas = $this->getCFSetting($entity);
|
$formDatas = $this->getArrayByResult($result);
|
||||||
$entity = $this->getModel()->modify($entity, $formDatas);
|
$formDatas = $this->getCFSetting($formDatas[ZoneModel::PK], $formDatas);
|
||||||
$entitys[$entity->getPK()] = $entity;
|
$entitys[$formDatas[ZoneModel::PK]] = $this->getModel()->modify(new ZoneEntity(), $formDatas);
|
||||||
|
}
|
||||||
|
//부모키를 기준으로 CF에 존재하지 않는 데이터 삭제용
|
||||||
|
$this->getModel()->where(ZoneModel::PARENT, $this->_account_entity->getPK());
|
||||||
|
$this->getModel()->whereNotIn(ZoneModel::PK, array_keys($entitys));
|
||||||
|
$this->getModel()->delete();
|
||||||
|
log_message("debug", $this->getModel()->getLastQuery());
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
log_message("error", $e->getMessage());
|
||||||
|
throw new \Exception($e->getMessage());
|
||||||
}
|
}
|
||||||
//부모키를 기준으로 CF에 존재하지 않는 데이터 삭제용
|
log_message("notice", "\n----------Account {$this->_account_entity->getTitle()}의 Zone 처리[" . count($entitys) . "개] 완료-----------");
|
||||||
$this->getModel()->where(ZoneModel::PARENT, $this->_account_entity);
|
|
||||||
$this->getModel()->whereNotIn(ZoneModel::PK, array_keys($entitys));
|
|
||||||
$this->getModel()->delete();
|
|
||||||
log_message("notice", "-----{$this->_account_entity->getTitle()} 처리[" . count($entitys) . "개] 완료-----");
|
|
||||||
return $entitys;
|
return $entitys;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,9 +7,8 @@ use App\Entities\Cloudflare\AuthEntity;
|
|||||||
|
|
||||||
class CloudflareSocket extends MySocket
|
class CloudflareSocket extends MySocket
|
||||||
{
|
{
|
||||||
private static int $_request = 0;
|
public static int $_request = 0;
|
||||||
private static int $_request_max = 1000;
|
private static int $_request_max = 1000;
|
||||||
public static int $_request_perpage_max = 700;
|
|
||||||
private static int $_request_timewait = 60;
|
private static int $_request_timewait = 60;
|
||||||
public function __construct(AuthEntity $auth_entity)
|
public function __construct(AuthEntity $auth_entity)
|
||||||
{
|
{
|
||||||
@ -22,7 +21,7 @@ class CloudflareSocket extends MySocket
|
|||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
//override
|
||||||
final public function request(string $method, $uri = '', array $options = []): ResponseInterface
|
final public function request(string $method, $uri = '', array $options = []): ResponseInterface
|
||||||
{
|
{
|
||||||
if (self::$_request >= self::$_request_max) {
|
if (self::$_request >= self::$_request_max) {
|
||||||
@ -32,6 +31,7 @@ class CloudflareSocket extends MySocket
|
|||||||
log_message('warning', sprintf("--Cloudflare API Call %s초 대기 종료--", self::$_request_timewait));
|
log_message('warning', sprintf("--Cloudflare API Call %s초 대기 종료--", self::$_request_timewait));
|
||||||
}
|
}
|
||||||
self::$_request++;
|
self::$_request++;
|
||||||
|
// log_message("debug", "현재 request:[" . self::$_request . "]");
|
||||||
return parent::request($method, $uri, $options);
|
return parent::request($method, $uri, $options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -71,10 +71,10 @@ class MySocket extends Client
|
|||||||
{
|
{
|
||||||
$requestOptions = $this->getRequestOptions($method, $options);
|
$requestOptions = $this->getRequestOptions($method, $options);
|
||||||
$requestOptions[in_array($method, ['get', 'getAsync']) ? 'query' : 'json'] = $options;
|
$requestOptions[in_array($method, ['get', 'getAsync']) ? 'query' : 'json'] = $options;
|
||||||
log_message("debug", __FUNCTION__ .
|
// log_message("debug", __FUNCTION__ .
|
||||||
"=> 호출 Socket URL:{$uri}\n--------------\n" .
|
// "=> 호출 Socket URL:{$uri}\n--------------\n" .
|
||||||
var_export($options, true) .
|
// var_export($options, true) .
|
||||||
"\n--------------\n");
|
// "\n--------------\n");
|
||||||
return parent::request($method, $uri, $requestOptions);
|
return parent::request($method, $uri, $requestOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -166,7 +166,7 @@ abstract class CommonModel extends Model
|
|||||||
if (!$this->save($entity)) {
|
if (!$this->save($entity)) {
|
||||||
throw new \Exception("저장오류:" . var_export($this->errors(), true));
|
throw new \Exception("저장오류:" . var_export($this->errors(), true));
|
||||||
}
|
}
|
||||||
log_message("notice", $this->getTable() . " => " . __FUNCTION__ . " DB 저장이 완료되었습니다.");
|
log_message("notice", $this->getTable() . " => " . __FUNCTION__ . " DB에 {$entity->getTitle()} 저장이 완료되었습니다.");
|
||||||
return $entity;
|
return $entity;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$message = sprintf(
|
$message = sprintf(
|
||||||
@ -192,7 +192,7 @@ abstract class CommonModel extends Model
|
|||||||
$pkField = $this->getPKField();
|
$pkField = $this->getPKField();
|
||||||
$entity->$pkField = $this->getInsertID();
|
$entity->$pkField = $this->getInsertID();
|
||||||
}
|
}
|
||||||
log_message("debug", $this->getTable() . " => " . __FUNCTION__ . " DB 작업 완료");
|
// log_message("debug", $this->getTable() . " => " . __FUNCTION__ . " DB 작업 완료");
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
final protected function modify_process($entity, array $formDatas): mixed
|
final protected function modify_process($entity, array $formDatas): mixed
|
||||||
@ -204,7 +204,7 @@ abstract class CommonModel extends Model
|
|||||||
$entity->$field = $this->convertEntityData($field, $formDatas);
|
$entity->$field = $this->convertEntityData($field, $formDatas);
|
||||||
}
|
}
|
||||||
$this->save_process($entity);
|
$this->save_process($entity);
|
||||||
log_message("debug", $this->getTable() . " => " . __FUNCTION__ . " DB 작업 완료");
|
// log_message("debug", $this->getTable() . " => " . __FUNCTION__ . " DB 작업 완료");
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user