change RecordController.php
This commit is contained in:
parent
48827e45cc
commit
b9b1bcc2f4
@ -2,12 +2,13 @@
|
||||
|
||||
namespace App\Controllers\Admin\Cloudflare\API;
|
||||
|
||||
use App\Libraries\Cloudflare\API\Record;
|
||||
use App\Libraries\Log\Log;
|
||||
use App\Models\Cloudflare\API\RecordModel;
|
||||
use App\Models\Cloudflare\FixedRecordModel;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use App\Libraries\Cloudflare\API\Record;
|
||||
|
||||
class RecordController extends APIController
|
||||
{
|
||||
@ -235,9 +236,9 @@ class RecordController extends APIController
|
||||
//CDN고정관련
|
||||
final public function cdnToggle(string $uid)
|
||||
{
|
||||
$entity = $this->_model->getEntity($uid);
|
||||
try {
|
||||
$entity = $this->_model->getEntity($uid);
|
||||
$fixedRecordModel = new \App\Models\Cloudflare\API\FixedRecordModel();
|
||||
$fixedRecordModel = new FixedRecordModel();
|
||||
if ($entity->fixed == 'on') {
|
||||
$entity->fixed = "off";
|
||||
$this->_model->save($entity);
|
||||
@ -246,8 +247,10 @@ class RecordController extends APIController
|
||||
} else {
|
||||
$entity->fixed = "on";
|
||||
$this->_model->save($entity);
|
||||
//throw new \Exception($entity);
|
||||
$fixedRecordModel->insert(['host' => $entity->host]);
|
||||
//cloudflarefixedrecord에 추가
|
||||
$fixedRecord = new \App\Entities\Cloudflare\FiexedRecordEntity();
|
||||
$fixedRecord->host = $entity->host;
|
||||
$fixedRecordModel->insert($fixedRecord);
|
||||
Log::add("info", "{$entity->getTitle()}의 fixed : off=>on");
|
||||
}
|
||||
$message = "{$entity->getTitle()} " . __FUNCTION__ . " 완료하였습니다.";
|
||||
|
||||
@ -85,9 +85,7 @@ class CommonController extends BaseController
|
||||
$this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []];
|
||||
helper(['form']);
|
||||
}
|
||||
protected function insert_form_process()
|
||||
{
|
||||
}
|
||||
protected function insert_form_process() {}
|
||||
final public function insert_form()
|
||||
{
|
||||
try {
|
||||
|
||||
25
app/Entities/Cloudflare/FixedRecordEntity.php
Normal file
25
app/Entities/Cloudflare/FixedRecordEntity.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Cloudflare;
|
||||
|
||||
use App\Entities\CommonEntity;
|
||||
|
||||
class FiexedRecordEntity extends CommonEntity
|
||||
{
|
||||
protected $datamap = [];
|
||||
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
|
||||
protected $casts = [];
|
||||
|
||||
public function getPrimaryKey()
|
||||
{
|
||||
return $this->attributes['uid'];
|
||||
}
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->attributes['host'];
|
||||
}
|
||||
public function __toString()
|
||||
{
|
||||
return "uid:{$this->attributes['uid']}|host:{$this->attributes['host']}";
|
||||
}
|
||||
}
|
||||
@ -75,15 +75,20 @@ class Record extends API
|
||||
public function update(\App\Entities\Cloudflare\API\RecordEntity $entity, array $fieldDatas): \App\Entities\Cloudflare\API\RecordEntity
|
||||
{
|
||||
//TTL값은 CDN(proxied)가 사용함일때는 무조건 1, 않함일때는 120이 적용
|
||||
|
||||
$options = [
|
||||
'type' => isset($fieldDatas['type']) ? $fieldDatas['type'] : $entity->type,
|
||||
'name' => isset($fieldDatas['host']) ? $fieldDatas['host'] : $entity->host,
|
||||
'content' => isset($fieldDatas['content']) ? $fieldDatas['content'] : $entity->content,
|
||||
'proxied' => isset($fieldDatas['proxied']) && $fieldDatas['proxied'] === 'on' ? true : false
|
||||
'proxied' => $entity->proxied == 'on' ? true : false,
|
||||
'ttl' => $entity->ttl
|
||||
];
|
||||
if (isset($entity->ttl) && $entity->ttl > 0) {
|
||||
$options['ttl'] = $options['proxied'] ? 1 : 120;
|
||||
$options['proxied'] = $entity->proxied == 'on' ? true : false;
|
||||
if (isset($fieldDatas['proxied']) && $fieldDatas['proxied'] === 'on') {
|
||||
$options['proxied'] = true;
|
||||
$options['ttl'] = 1;
|
||||
}
|
||||
//dd($options);
|
||||
// throw new \Exception(var_export($fieldDatas, true) . "<HR>" . var_export($options, true));
|
||||
$cfResult = $this->getAdapter()->put('zones/' . $this->getParent()->getPrimaryKey() . '/dns_records/' . $entity->getPrimaryKey(), $options);
|
||||
$cfResult = json_decode($cfResult->getBody());
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Cloudflare\API;
|
||||
namespace App\Models\Cloudflare;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user