cfmgrv4/app/Controllers/Admin/Cloudflare/AccountController.php
2024-09-28 15:07:19 +09:00

69 lines
2.6 KiB
PHP

<?php
namespace App\Controllers\Admin\Cloudflare;
use Psr\Log\LoggerInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\RedirectResponse;
use App\Models\Cloudflare\AccountModel;
use App\Libraries\MySocket\Cloudflare\ZoneSocket;
use App\Libraries\MySocket\Cloudflare\AccountSocket;
class AccountController extends CloudflareController
{
private $_mySocket = null;
private $_model = null;
private $_auth_key = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->class_name = "Account";
$this->class_path .= $this->class_name;
$this->title = lang("{$this->class_path}.title");
helper($this->class_path);
}
final protected function getModel(): AccountModel
{
if ($this->_model === null) {
$this->_model = new AccountModel();
}
return $this->_model;
}
final protected function getMySocket(): AccountSocket
{
if ($this->_mySocket === null) {
$this->_mySocket = new AccountSocket($this->_auth_key);
}
return $this->_mySocket;
}
// 리스트
public function index(): string
{
$this->fields = [$this->getModel()::TITLE, 'oldkey', 'type', 'status', 'updated_at', 'created_at'];
$this->field_rules = $this->getModel()->getFieldRules(__FUNCTION__, $this->fields);
$this->filter_fields = ['type', 'status'];
$this->batchjob_fields = ['status'];
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
return $this->list_procedure();
}
public function reload(): RedirectResponse
{
try {
//Transaction Start
$this->getModel()->transStart();
foreach ($this->getModel()->getEntitys as $entity) {
$zone_socket = new ZoneSocket($entity);
$zone_socket->reload();
}
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']) ?: "/");
}
}
}