97 lines
3.8 KiB
PHP
97 lines
3.8 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;
|
|
|
|
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->class_path = "Cloudflare/";
|
|
$this->uri_path .= strtolower($this->class_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 sync_process(string $uid): void {}
|
|
final protected function sync_procedure(string $uid): RedirectResponse
|
|
{
|
|
//Transaction Start
|
|
$this->getModel()->transStart();
|
|
try {
|
|
$this->sync_process($uid);
|
|
$this->message = "{$this->class_name}: 동기화작업을 완료하였습니다.";
|
|
$this->getModel()->transCommit();
|
|
log_message("notice", $this->message);
|
|
$this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], $this->message);
|
|
return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
|
|
} catch (\Exception $e) {
|
|
//Transaction Rollback
|
|
$this->getModel()->transRollback();
|
|
log_message("error", $e->getMessage());
|
|
$this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage());
|
|
return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
|
|
}
|
|
}
|
|
|
|
protected function reload_process(mixed $uid): void {}
|
|
final protected function reload_procedure(mixed $uid): RedirectResponse
|
|
{
|
|
//Transaction Start
|
|
$this->getModel()->transStart();
|
|
try {
|
|
$this->reload_process($uid);
|
|
$this->message = "{$this->class_name}: Reload 작업이 완료되었습니다.";
|
|
$this->getModel()->transCommit();
|
|
log_message("notice", $this->message);
|
|
$this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], $this->message);
|
|
return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
|
|
} catch (\Exception $e) {
|
|
//Transaction Rollback
|
|
$this->getModel()->transRollback();
|
|
log_message("error", $e->getMessage());
|
|
$this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage());
|
|
return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
|
|
}
|
|
}
|
|
}
|