175 lines
6.6 KiB
PHP
175 lines
6.6 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Admin\Cloudflare;
|
|
|
|
use App\Controllers\Admin\AdminController;
|
|
use App\Models\Cloudflare\AccountModel;
|
|
use App\Models\Cloudflare\AuthModel;
|
|
use App\Models\Cloudflare\RecordModel;
|
|
use App\Models\Cloudflare\ZoneModel;
|
|
use CodeIgniter\HTTP\RedirectResponse;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
use App\Services\MyLogService;
|
|
|
|
abstract class CloudflareController extends AdminController
|
|
{
|
|
private $_authModel = null;
|
|
private $_accountModel = null;
|
|
private $_zoneModel = null;
|
|
private $_recordModel = null;
|
|
|
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
$this->uri_path .= "cloudflare/";
|
|
// dd($this->uri_path);
|
|
}
|
|
final protected function getAuthModel(): AuthModel
|
|
{
|
|
if ($this->_authModel === null) {
|
|
$this->_authModel = new AuthModel();
|
|
}
|
|
return $this->_authModel;
|
|
}
|
|
final protected function getAccountModel(): AccountModel
|
|
{
|
|
if ($this->_accountModel === null) {
|
|
$this->_accountModel = new AccountModel();
|
|
}
|
|
return $this->_accountModel;
|
|
}
|
|
final protected function getZoneModel(): ZoneModel
|
|
{
|
|
if ($this->_zoneModel === null) {
|
|
$this->_zoneModel = new ZoneModel();
|
|
}
|
|
return $this->_zoneModel;
|
|
}
|
|
final protected function getRecordModel(): RecordModel
|
|
{
|
|
if ($this->_recordModel === null) {
|
|
$this->_recordModel = new RecordModel();
|
|
}
|
|
return $this->_recordModel;
|
|
}
|
|
//생성
|
|
protected function create_process_result($message): RedirectResponse|string
|
|
{
|
|
MyLogService::save($this->getService(), $this->myauth, $message, DEFAULTS['STATUS']);
|
|
return parent::create_process_result($message);
|
|
}
|
|
protected function create_process_failed($message): RedirectResponse|string
|
|
{
|
|
MyLogService::save($this->getService(), $this->myauth, $message);
|
|
return parent::create_process_failed($message);
|
|
}
|
|
//수정
|
|
protected function modify_process_result($message): RedirectResponse|string
|
|
{
|
|
MyLogService::save($this->getService(), $this->myauth, $message, DEFAULTS['STATUS']);
|
|
return parent::modify_process_result($message);
|
|
}
|
|
protected function modify_process_failed($message): RedirectResponse|string
|
|
{
|
|
MyLogService::save($this->getService(), $this->myauth, $message);
|
|
return parent::modify_process_failed($message);
|
|
}
|
|
//단일필드작업
|
|
protected function toggle_process_result($message): RedirectResponse|string
|
|
{
|
|
MyLogService::save($this->getService(), $this->myauth, $message, DEFAULTS['STATUS']);
|
|
return parent::toggle_process_result($message);
|
|
}
|
|
protected function toggle_process_failed($message): RedirectResponse|string
|
|
{
|
|
MyLogService::save($this->getService(), $this->myauth, $message);
|
|
return parent::toggle_process_failed($message);
|
|
}
|
|
//일괄처리작업
|
|
protected function batchjob_process_result($message): RedirectResponse|string
|
|
{
|
|
MyLogService::save($this->getService(), $this->myauth, $message, DEFAULTS['STATUS']);
|
|
return parent::batchjob_process_result($message);
|
|
}
|
|
protected function batchjob_process_failed($message): RedirectResponse|string
|
|
{
|
|
MyLogService::save($this->getService(), $this->myauth, $message);
|
|
return parent::batchjob_process_failed($message);
|
|
}
|
|
//삭제 delete,batchjob_delete 공통사용
|
|
protected function delete_process_result($message): RedirectResponse|string
|
|
{
|
|
MyLogService::save($this->getService(), $this->myauth, $message, DEFAULTS['STATUS']);
|
|
return parent::delete_process_result($message);
|
|
}
|
|
protected function delete_process_failed($message): RedirectResponse|string
|
|
{
|
|
MyLogService::save($this->getService(), $this->myauth, $message);
|
|
return parent::delete_process_failed($message);
|
|
}
|
|
//일괄삭제
|
|
protected function batchjob_delete_process_result($message): RedirectResponse|string
|
|
{
|
|
MyLogService::save($this->getService(), $this->myauth, $message, DEFAULTS['STATUS']);
|
|
return parent::batchjob_delete_process_result($message);
|
|
}
|
|
protected function batchjob_delete_process_failed($message): RedirectResponse|string
|
|
{
|
|
MyLogService::save($this->getService(), $this->myauth, $message);
|
|
return parent::batchjob_delete_process_failed($message);
|
|
}
|
|
//Sync관련
|
|
protected function sync_process_result($message): RedirectResponse|string
|
|
{
|
|
MyLogService::save($this->getService(), $this->myauth, $message, DEFAULTS['STATUS']);
|
|
return redirect()->to($this->myauth->popPreviousUrl())->with('error', $message);
|
|
}
|
|
protected function sync_process_failed($message): RedirectResponse|string
|
|
{
|
|
MyLogService::save($this->getService(), $this->myauth, $message);
|
|
return redirect()->to($this->myauth->popPreviousUrl())->with('error', $message);
|
|
}
|
|
protected function sync_process(string $uid): void {}
|
|
final protected function sync_procedure(string $uid): RedirectResponse
|
|
{
|
|
//Transaction Start
|
|
$this->getService()->getModel()->transStart();
|
|
try {
|
|
$this->sync_process($uid);
|
|
$this->getService()->getModel()->transCommit();
|
|
return $this->sync_process_result(MESSAGES["SUCCESS"]);
|
|
} catch (\Exception $e) {
|
|
//Transaction Rollback
|
|
$this->getService()->getModel()->transRollback();
|
|
return $this->sync_process_failed($e->getMessage());
|
|
}
|
|
}
|
|
final public function sync(string $uid): RedirectResponse
|
|
{
|
|
return $this->sync_procedure($uid);
|
|
}
|
|
|
|
//Reload관련
|
|
protected function reload_process(mixed $uid): void {}
|
|
final protected function reload_procedure(mixed $uid): RedirectResponse
|
|
{
|
|
//Transaction Start
|
|
$this->getService()->getModel()->transStart();
|
|
try {
|
|
$this->reload_process($uid);
|
|
$this->getService()->getModel()->transCommit();
|
|
return redirect()->to($this->myauth->popPreviousUrl())->with('error', MESSAGES["SUCCESS"]);
|
|
} catch (\Exception $e) {
|
|
//Transaction Rollback
|
|
$this->getService()->getModel()->transRollback();
|
|
return redirect()->to($this->myauth->popPreviousUrl())->with('error', $e->getMessage());
|
|
}
|
|
}
|
|
final public function reload(string $uid): RedirectResponse
|
|
{
|
|
return $this->reload_procedure($uid);
|
|
}
|
|
}
|