cfmgrv3 init..3
This commit is contained in:
parent
90fd41ed76
commit
2e63be13eb
@ -99,23 +99,26 @@ class FirewallController extends APIController
|
||||
$start = $this->request->getVar('start') ? $this->request->getVar('start') : '';
|
||||
$end = $this->request->getVar('end') ? $this->request->getVar('end') : '';
|
||||
if (isset($start) && $start !== '' && isset($end) && $end !== '') {
|
||||
$builder->where('cloudflarerecord.created_at >=', $start);
|
||||
$builder->where('cloudflarerecord.created_at <=', $end);
|
||||
$builder->where('cloudflarefirewall.created_at >=', $start);
|
||||
$builder->where('cloudflarefirewall.created_at <=', $end);
|
||||
}
|
||||
return $builder;
|
||||
}
|
||||
//Index관련
|
||||
protected function index_getRows(int $page = 0, int $per_page = 0): array
|
||||
{
|
||||
//모델 Join
|
||||
//Totalcount 처리
|
||||
$builder = $this->_model->builder();
|
||||
$builder->select("cloudflarefirewall.*");
|
||||
$builder->join("cloudflarezone", "cloudflarezone.uid = cloudflarefirewall.zone_uid");
|
||||
//Totalcount 처리
|
||||
$this->index_setCondition();
|
||||
$this->_viewDatas['total_count'] = $this->_model->countAllResults();
|
||||
$builder = $this->index_setCondition_builder($builder);
|
||||
// log_message("debug", __METHOD__ . "에서 호출\n" . $builder->getCompiledSelect(false));
|
||||
$this->_viewDatas['total_count'] = $builder->countAllResults();
|
||||
//Rows 처리
|
||||
$this->index_setCondition();
|
||||
$builder = $this->_model->builder();
|
||||
$builder->select("cloudflarefirewall.*");
|
||||
$builder->join("cloudflarezone", "cloudflarezone.uid = cloudflarefirewall.zone_uid");
|
||||
$builder = $this->index_setCondition_builder($builder);
|
||||
//OrderBy
|
||||
$order_field = $this->request->getVar('order_field') ? $this->request->getVar('order_field') : 'uid';
|
||||
$order_value = $this->request->getVar('order_value') ? $this->request->getVar('order_value') : 'DESC';
|
||||
|
||||
@ -160,7 +160,7 @@ class RecordController extends APIController
|
||||
return $builder;
|
||||
}
|
||||
//Index관련
|
||||
protected function index_getRow(int $page = 0, int $per_page = 0): array
|
||||
protected function index_getRows(int $page = 0, int $per_page = 0): array
|
||||
{
|
||||
//Totalcount 처리
|
||||
$builder = $this->_model->builder();
|
||||
@ -179,7 +179,7 @@ class RecordController extends APIController
|
||||
$builder->orderBy("cloudflarezone.domain ASC, cloudflarerecord.host ASC, cloudflarerecord.{$order_field} {$order_value}");
|
||||
//Limit
|
||||
$builder->limit($per_page, $page * $per_page - $per_page);
|
||||
// log_message("debug", __METHOD__ . "에서 호출\n" . $builder->getCompiledSelect(false));
|
||||
log_message("debug", __METHOD__ . "에서 호출\n" . $builder->getCompiledSelect(false));
|
||||
return $builder->get()->getResultArray();
|
||||
}
|
||||
//CDN고정관련
|
||||
|
||||
@ -140,10 +140,35 @@ class ZoneController extends APIController
|
||||
//Delete 관련
|
||||
protected function delete_process($entity)
|
||||
{
|
||||
//Zone삭제전에 Record부터 삭제하기위함
|
||||
$api = new \App\Libraries\Cloudflare\API\Record($entity);
|
||||
$api->deleteByZone();
|
||||
$api = new Zone($this->getAccountModel()->getEntity($entity->getParentFieldData()));
|
||||
$api->delete($entity);
|
||||
return parent::delete_process($entity);
|
||||
}
|
||||
//일괄삭제관련
|
||||
final public function batchjob_delete()
|
||||
{
|
||||
$message = "";
|
||||
try {
|
||||
$uids = $this->request->getVar('batchjob_uids');
|
||||
if (!is_array($uids) || count($uids) === 0) {
|
||||
throw new \Exception($this->_viewDatas['title'] . '가 uid가 선택되지 않았습니다.');
|
||||
}
|
||||
foreach ($uids as $uid) {
|
||||
$this->delete_process($this->_model->getEntity($uid));
|
||||
}
|
||||
$message = "총:" . count($uids) . "개의 삭제 완료하였습니다.";
|
||||
Log::save("{$this->_viewDatas['title']} {$message}");
|
||||
return alert_CommonHelper($message, session()->get(RETURN_URL));
|
||||
} catch (\Exception $e) {
|
||||
$message = "삭제 실패하였습니다.";
|
||||
Log::add("warning", $message . "\n" . $e->getMessage());
|
||||
Log::save("{$this->_viewDatas['title']} {$message}", false);
|
||||
return alert_CommonHelper($message . "\n" . $e->getMessage(), 'back');
|
||||
}
|
||||
}
|
||||
//Sync관련
|
||||
protected function sync_process($entity)
|
||||
{
|
||||
@ -217,26 +242,4 @@ class ZoneController extends APIController
|
||||
return alert_CommonHelper($e->getMessage(), 'back');
|
||||
}
|
||||
}
|
||||
//일괄삭제관련
|
||||
final public function batchjob_delete()
|
||||
{
|
||||
$message = "";
|
||||
try {
|
||||
$uids = $this->request->getVar('batchjob_uids');
|
||||
if (!is_array($uids) || count($uids) === 0) {
|
||||
throw new \Exception($this->_viewDatas['title'] . '가 uid가 선택되지 않았습니다.');
|
||||
}
|
||||
foreach ($uids as $uid) {
|
||||
$this->delete_process($this->_model->getEntity($uid));
|
||||
}
|
||||
$message = "총:" . count($uids) . "개의 삭제 완료하였습니다.";
|
||||
Log::save("{$this->_viewDatas['title']} {$message}");
|
||||
return alert_CommonHelper($message, session()->get(RETURN_URL));
|
||||
} catch (\Exception $e) {
|
||||
$message = "삭제 실패하였습니다.";
|
||||
Log::add("warning", $message . "\n" . $e->getMessage());
|
||||
Log::save("{$this->_viewDatas['title']} {$message}", false);
|
||||
return alert_CommonHelper($message . "\n" . $e->getMessage(), 'back');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -333,6 +333,7 @@ class CommonController extends BaseController
|
||||
$entity = $this->_model->getEntity($uid);
|
||||
$entity = $this->batchjob_validate($entity);
|
||||
$entity = $this->batchjob_process($entity);
|
||||
Log::add("warning", "{$entity->getTitle()} " . __FUNCTION__ . " 완료하였습니다.");
|
||||
}
|
||||
$message = "총: " . implode(",", $uids) . "의 수정(Batchjob)을 완료하였습니다.";
|
||||
Log::save("{$this->_viewDatas['title']} {$message}");
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Libraries\Cloudflare\API;
|
||||
|
||||
use App\Libraries\Log\Log;
|
||||
|
||||
class Record extends API
|
||||
{
|
||||
private $_endPoint = null;
|
||||
@ -85,6 +87,7 @@ class Record extends API
|
||||
}
|
||||
return $this->getEntityByResult($cfResult->result);
|
||||
}
|
||||
//Zone삭제전에 Record부터 삭제하기위함
|
||||
public function deleteByZone()
|
||||
{
|
||||
$records = $this->_model->where($this->_model::PARENT_FIELD, $this->getParent()->getPrimaryKey())->findAll();
|
||||
@ -100,6 +103,7 @@ class Record extends API
|
||||
if (!$cfResult->success) {
|
||||
throw new \Exception(var_export($cfResult, true));
|
||||
}
|
||||
Log::add("warning", "API {$entity->getTitle()} " . __FUNCTION__ . " 완료하였습니다.");
|
||||
}
|
||||
public function sync(\App\Entities\Cloudflare\API\RecordEntity $entity): \App\Entities\Cloudflare\API\RecordEntity
|
||||
{
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Libraries\Cloudflare\API;
|
||||
|
||||
use App\Libraries\Log\Log;
|
||||
|
||||
class Zone extends API
|
||||
{
|
||||
private $_endPoint = null;
|
||||
@ -120,15 +122,13 @@ class Zone extends API
|
||||
}
|
||||
public function delete(\App\Entities\Cloudflare\API\ZoneEntity $entity)
|
||||
{
|
||||
//Zone에 해당하는 Record 삭제를 먼저한다.
|
||||
$api = new \App\Libraries\Cloudflare\API\Record($entity);
|
||||
$api->deleteByZone();
|
||||
//Zone 삭제
|
||||
$cfResult = $this->getAdapter()->delete('zones/' . $entity->getPrimaryKey());
|
||||
$cfResult = json_decode($cfResult->getBody());
|
||||
if (!$cfResult->success) {
|
||||
throw new \Exception(var_export($cfResult, true));
|
||||
}
|
||||
Log::add("warning", "API {$entity->getTitle()} " . __FUNCTION__ . " 완료하였습니다.");
|
||||
}
|
||||
public function sync(\App\Entities\Cloudflare\API\ZoneEntity $entity): \App\Entities\Cloudflare\API\ZoneEntity
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user