89 lines
3.5 KiB
PHP
89 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Cloudflare;
|
|
|
|
use App\Models\Cloudflare\AccountModel;
|
|
use App\Entities\Cloudflare\AuthEntity;
|
|
use App\Entities\Cloudflare\AccountEntity;
|
|
|
|
class Account extends Cloudflare
|
|
{
|
|
private ?AuthEntity $_parent_entity = null;
|
|
private ?AccountModel $_model = null;
|
|
public function __construct(AuthEntity $parent_entity)
|
|
{
|
|
$this->_parent_entity = $parent_entity;
|
|
parent::__construct($parent_entity);
|
|
}
|
|
protected function getParentEntity(): AuthEntity
|
|
{
|
|
if ($this->_parent_entity === null) {
|
|
throw new \Exception(__FUNCTION__ . "에서 부모정보가 없습니다.");
|
|
}
|
|
return $this->_parent_entity;
|
|
}
|
|
protected function getModel(): AccountModel
|
|
{
|
|
if ($this->_model === null) {
|
|
$this->_model = new AccountModel();
|
|
}
|
|
return $this->_model;
|
|
}
|
|
//Result 형태
|
|
// [
|
|
// {"id":"078e88a7735965b661715af13031ecb0",
|
|
// "name":"Cloudwin002@idcjp.jp's Auth",
|
|
// "type":"standard",
|
|
// "settings":{
|
|
// "enforce_twofactor":false,
|
|
// "api_access_enabled":null,
|
|
// "access_approval_expiry":null,
|
|
// "use_account_custom_ns_by_default":false
|
|
// },
|
|
// "legacy_flags":{"enterprise_zone_quota":{"maximum":0,"current":0,"available":0}},
|
|
// "created_on":"2017-06-26T05:44:49.470184Z"}
|
|
// ]
|
|
|
|
protected function getArrayByResult(\stdClass $result, array $formDatas = []): array
|
|
{
|
|
$formDatas[AccountModel::PK] = $result->id;
|
|
$formDatas[AccountModel::PARENT] = $this->getAuthEntity()->getPK();
|
|
$formDatas[AccountModel::TITLE] = $result->name;
|
|
$formDatas['type'] = $result->type;
|
|
$formDatas['status'] = $this->getAuthEntity()->status;
|
|
$formDatas['updated_at'] = date("Y-m-d H:i:s");
|
|
$formDatas['created_at'] = $result->created_on;
|
|
return $formDatas;
|
|
}
|
|
|
|
public function reload(): array
|
|
{
|
|
log_message("notice", "\n----------Auth {$this->getAuthEntity()->getTitle()}의 Account 처리 시작-----------");
|
|
$entitys = [];
|
|
try {
|
|
$results_array = $this->reload_procedure("accounts");
|
|
if (count(value: $results_array) > 0) {
|
|
foreach ($results_array as $results) {
|
|
foreach ($results as $result) {
|
|
if (!is_object($result) || get_class($result) !== 'stdClass') {
|
|
throw new \Exception("Account: result is not a stdClass:\n" . var_export($result, true) . "\n");
|
|
}
|
|
$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());
|
|
}
|
|
log_message("notice", message: "\n-----------Auth {$this->getAuthEntity()->getTitle()}의 Account 처리[" . count($entitys) . "개] 완료-----------");
|
|
return $entitys;
|
|
}
|
|
}
|