- //
- //
- //
- //
- //

- //

- //

- //

- //

- //
- //
- //
^^
- //
- //
- //
- protected function detail_process(int $cnt, array $listInfo): array
- {
- $response = $this->getMySocket()->getContent($listInfo['detail_url']);
- $selector = $this->getSelector($response, getenv("inven.view.content.tag"));
- if ($this->isCopy) {
- $formDatas = [];
- $formDatas['image_path'] = "";
- $formDatas['content'] = $selector->html();
- //File DB 및 Board DB 등록작업등
- $this->getBoardModel()->createByCrawler(
- $this->getBoardsEntity(),
- $this->getUserEntity(),
- $cnt,
- $listInfo,
- [],
- $formDatas
- );
- } else {
- $media_urls = $this->getUrlsByMediaType($selector, "img", "src");
- $media_urls = $this->getUrlsByMediaType($selector, "video", "src", $media_urls);
- if ($this->isDebug) {
- throw new \Exception(sprintf(
- "\n--------------%s Debug--------------\n%s%s\n---------------------------------------\n",
- __FUNCTION__,
- var_export($listInfo, true),
- var_export($media_urls, true)
- ));
- } else {
- // Image 나 Video 소스들의 url을 가져와서 실제 다운받는 처리
- $storages = $this->media_process($media_urls);
- if (!count($storages)) {
- throw new \Exception("등록할 자료가 없습니다.");
- }
- $this->backend_process($cnt, $listInfo, $storages);
- }
- }
- log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
- return $listInfo;
- }
- protected function copy_process(int $cnt, array $listInfo): array
- {
- $response = $this->getMySocket()->getContent($listInfo['detail_url']);
- return $listInfo;
- }
- //리스트내용
- //
- //
- //
- // | 1589 |
- //
- //
- // |
- //
- //
- // 배수민
- // |
- // 09-15 |
- // 1,502 |
- // 1 |
- //
- //
- //
- public function execute(): void
- {
- try {
- if ($this->isDebug) {
- $listInfo = [];
- $listInfo['title'] = 'test_title';
- $listInfo['nickname'] = 'test_name';
- $listInfo['hit'] = 1;
- $listInfo['date'] = date("Y-m-d H:i:s");
- $listInfo['detail_url'] = getenv("inven.view.test.url.{$this->getBoardName()}");
- $this->detail_process(1, $listInfo);
- log_message("notice", __FUNCTION__ . "=> DEBUG 게시물 {$listInfo['detail_url']} 작업종료");
- } else {
- $listInfos = [];
- $response = $this->getMySocket()->getContent(getenv("inven.list.url.{$this->getBoardName()}"));
- $this->getSelector($response, getenv("inven.list.tag.{$this->getBoardName()}"))->each(
- function (Crawler $node) use (&$listInfos): void {
- $hit = $node->filter(getenv("inven.list.item.hit.tag"))->text();
- $date = date("Y") . "-" . $node->filter(getenv("inven.list.item.date.tag"))->text();
- $nickname = $node->filter(getenv("inven.list.item.nickname.tag"))->text();
- //작성자가 "관리자"가 아닌 게시물이면 해당 bbs_item에서 a.list_subject 객체를 찾아서
- $link_node = $node->filter(getenv("inven.list.item.link.tag"));
- $detail_url = $link_node->attr("href");
- $title = $link_node->text();
- $listInfos[] = ['title' => $title, 'nickname' => $nickname, 'detail_url' => $detail_url, 'date' => $date, 'hit' => $hit];
- }
- );
- if (!count($listInfos)) {
- throw new \Exception("Target URL이 없습니다.");
- }
- $this->list_process(intval(getenv("inven.list.max_limit.{$this->getBoardName()}")), $listInfos);
- }
- log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
- } catch (\Exception $e) {
- log_message("warning", sprintf(
- "\n---%s 오류---\n%s\n-----------------------------------------\n",
- __FUNCTION__,
- $e->getMessage()
- ));
- }
- }
-}
+class InvenCrawler extends MangboardCrawler {}
diff --git a/app/Libraries/MyCrawler/Mangboard/MangboardCrawler.php b/app/Libraries/MyCrawler/Mangboard/MangboardCrawler.php
deleted file mode 100644
index f5e0455..0000000
--- a/app/Libraries/MyCrawler/Mangboard/MangboardCrawler.php
+++ /dev/null
@@ -1,118 +0,0 @@
-_host = $host;
- $this->_board_name = $board_name;
- $this->_user_entity = $user_entity;
- }
- abstract protected function detail_process(int $cnt, array $listInfo): array;
- abstract public function execute(): void;
- final protected function getMySocket()
- {
- if ($this->_mySocket === null) {
- $this->_mySocket = new WebSocket($this->_host);
- }
- return $this->_mySocket;
- }
- final protected function createMyStorage()
- {
- return new MangboardStorage($this->getBoardName(), $this->getUserEntity());
- }
- final protected function getBoardModel(): BoardModel
- {
- if ($this->_board_model === null) {
- $this->_board_model = new BoardModel("mb_" . $this->getBoardName());
- }
- return $this->_board_model;
- }
- final protected function getBoardName(): string
- {
- return $this->_board_name;
- }
- final protected function getBoardsEntity(): BoardsEntity
- {
- if ($this->_boards_entity === null) {
- $boardsModel = new BoardsModel();
- $this->_boards_entity = $boardsModel->getEntityByID($this->getBoardName());
- if ($this->_boards_entity === null) {
- throw new \Exception(__FUNCTION__ . "=> {$this->getBoardName()}에 해당 Board 정보가 존재하지 않습니다.");
- }
- }
- return $this->_boards_entity;
- }
- final protected function getUserEntity(): UserEntity
- {
- return $this->_user_entity;
- }
- protected function backend_process(int $cnt, array $listInfo, array $storages)
- {
- //File DB 및 Board DB 등록작업등
- $board_entity = $this->getBoardModel()->createByCrawler(
- $this->getBoardsEntity(),
- $this->getUserEntity(),
- $cnt,
- $listInfo,
- $storages
- );
- foreach ($storages as $storage) {
- try {
- $storage->backend_process($this->getBoardsEntity(), $board_entity, $this->getBoardModel()->getTable());
- } catch (\Exception $e) {
- log_message("notice", sprintf(
- "\n---%s -> %s 게시물의 %s번째:%s 파일 등록 오류---\n%s\n--------------------------------\n",
- __FUNCTION__,
- $board_entity->getTitle(),
- $storage->getOriginSequence(),
- $storage->getOriginName(),
- $e->getMessage()
- ));
- }
- }
- log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
- }
- protected function list_process(int $max_limit, array $listInfos): void
- {
- //Limit가 0이면 $listInfos 갯수만큼 다하고, LIMIT 갯수 혹은 item의 갯수중 작은수만큼 한다.
- $max_limit = !$max_limit || count($listInfos) <= $max_limit ? count($listInfos) : $max_limit;
- $total = count($listInfos);
- $i = 1;
- foreach ($listInfos as $listInfo) {
- if ($i <= $max_limit) {
- log_message("notice", __FUNCTION__ . " 게시물 {$i}번째/총:{$total} {$listInfo["nickname"]} 작업시작");
- try {
- //listInfo는 title,작성자,작성시간등등의 정보를 가지고 있어 detail_process 처리 안에서 바뀔 수 있으므로 다시 반환 받는다.
- $listInfo = $this->detail_process($i, $listInfo);
- } catch (\Exception $e) {
- log_message("warning", sprintf(
- "\n---%s {$i}번째/총:{$total} 오류---\n%s\n-----------------------------------------\n",
- __FUNCTION__,
- $e->getMessage()
- ));
- }
- log_message("notice", __FUNCTION__ . " 게시물 {$i}번째/총:{$total} {$listInfo["nickname"]} 작업완료.");
- $i++;
- }
- }
- log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
- }
-}
diff --git a/app/Libraries/MyCrawler/Mangboard/SirCrawler.php b/app/Libraries/MyCrawler/Mangboard/SirCrawler.php
index 56564ce..ff0b740 100644
--- a/app/Libraries/MyCrawler/Mangboard/SirCrawler.php
+++ b/app/Libraries/MyCrawler/Mangboard/SirCrawler.php
@@ -3,7 +3,7 @@
namespace App\Libraries\MyCrawler\Mangboard;
use App\Entities\Mangboard\UserEntity;
-use App\Libraries\MySocket\WebSocket;
+use App\Libraries\MyCrawler\MangboardCrawler;
use DateTime;
use Symfony\Component\DomCrawler\Crawler;
diff --git a/app/Libraries/MyCrawler/Mangboard/YamapCrawler.php b/app/Libraries/MyCrawler/Mangboard/YamapCrawler.php
index 8e71518..5fa55fc 100644
--- a/app/Libraries/MyCrawler/Mangboard/YamapCrawler.php
+++ b/app/Libraries/MyCrawler/Mangboard/YamapCrawler.php
@@ -3,6 +3,7 @@
namespace App\Libraries\MyCrawler\Mangboard;
use App\Entities\Mangboard\UserEntity;
+use App\Libraries\MyCrawler\MangboardCrawler;
use Symfony\Component\DomCrawler\Crawler;
class YamapCrawler extends MangboardCrawler
diff --git a/app/Libraries/MyCrawler/Mangboard/YamoonCrawler.php b/app/Libraries/MyCrawler/Mangboard/YamoonCrawler.php
index 6fa4fad..072cac7 100644
--- a/app/Libraries/MyCrawler/Mangboard/YamoonCrawler.php
+++ b/app/Libraries/MyCrawler/Mangboard/YamoonCrawler.php
@@ -3,6 +3,7 @@
namespace App\Libraries\MyCrawler\Mangboard;
use App\Entities\Mangboard\UserEntity;
+use App\Libraries\MyCrawler\MangboardCrawler;
use Symfony\Component\DomCrawler\Crawler;
class YamoonCrawler extends MangboardCrawler
diff --git a/app/Libraries/MyCrawler/MyCrawler.php b/app/Libraries/MyCrawler/MyCrawler.php
index 84f07ea..63fde6b 100644
--- a/app/Libraries/MyCrawler/MyCrawler.php
+++ b/app/Libraries/MyCrawler/MyCrawler.php
@@ -129,6 +129,7 @@ abstract class MyCrawler extends CommonLibrary
$file_sequence++;
}
}
+ log_message("notice", __FUNCTION__ . "=> 게시물 {$url} 작업종료");
return $storages;
}
}
diff --git a/app/Libraries/MySocket/Cloudflare/AccountSocket.php b/app/Libraries/MySocket/Cloudflare/AccountSocket.php
new file mode 100644
index 0000000..225b3f7
--- /dev/null
+++ b/app/Libraries/MySocket/Cloudflare/AccountSocket.php
@@ -0,0 +1,30 @@
+ $name . "'s Account",
+ 'type' => $type,
+ ];
+ $result = $this->getClient()->post("accounts", $datas);
+ $result = json_decode($result->getBody());
+ if (!$result->success) {
+ throw new \Exception(var_export($result, true));
+ }
+ return $result;
+ }
+}
diff --git a/app/Libraries/MySocket/CloudflareSocket.php b/app/Libraries/MySocket/CloudflareSocket.php
new file mode 100644
index 0000000..fbdd110
--- /dev/null
+++ b/app/Libraries/MySocket/CloudflareSocket.php
@@ -0,0 +1,39 @@
+_email = $email;
+ $this->_api_key = $api_key;
+ self::$_request_max = getenv("cfmgr.request.max");
+ }
+ final public function getClient(): Guzzle
+ {
+ if ($this->_client === null) {
+ $this->_client = new Guzzle(
+ $this->_client = new APIKey($this->_email, $this->_api_key)
+ );
+ }
+ if (self::$_request >= self::$_request_max) {
+ log_message('warning', sprintf("--Cloudflare API Call %s초 대기 시작--", self::$_request_timewait));
+ sleep(intval(getenv("cf.mgr.request.time.wait")));
+ self::$_request = 0;
+ log_message('warning', sprintf("--Cloudflare API Call %s초 대기 종료--", self::$_request_timewait));
+ }
+ self::$_request++;
+ return $this->_client;
+ }
+}
diff --git a/app/Libraries/MySocket/Web/GoogleSocket.php b/app/Libraries/MySocket/GoogleSocket.php
similarity index 67%
rename from app/Libraries/MySocket/Web/GoogleSocket.php
rename to app/Libraries/MySocket/GoogleSocket.php
index dbe45db..7df7c9d 100644
--- a/app/Libraries/MySocket/Web/GoogleSocket.php
+++ b/app/Libraries/MySocket/GoogleSocket.php
@@ -1,30 +1,30 @@
_session = \Config\Services::session();
}
//Override
- public function getClient()
+ public function getClient(): Google_Client
{
if (is_null($this->_client)) {
- // $this->_client = new \Google_Client();
- // $this->_client->setClientId(getenv("socket.google.client.id"));
- // $this->_client->setClientSecret(getenv("socket.google.client.key"));
- // $this->_client->setRedirectUri(base_url() . getenv("socket.google.client.callback_url"));
- // $this->_client->addScope('email');
- // $this->_client->addScope('profile');
+ $this->_client = new Google_Client();
+ $this->_client->setClientId(getenv("socket.google.client.id"));
+ $this->_client->setClientSecret(getenv("socket.google.client.key"));
+ $this->_client->setRedirectUri(base_url() . getenv("socket.google.client.callback_url"));
+ $this->_client->addScope('email');
+ $this->_client->addScope('profile');
}
return $this->_client;
}
diff --git a/app/Libraries/MySocket/MySocket.php b/app/Libraries/MySocket/MySocket.php
deleted file mode 100644
index 18135a5..0000000
--- a/app/Libraries/MySocket/MySocket.php
+++ /dev/null
@@ -1,20 +0,0 @@
-_host = $host;
- }
- abstract public function getClient();
- final public function getHost(): string
- {
- return $this->_host;
- }
-}
diff --git a/app/Libraries/MySocket/Web/CloudflareSocket.php b/app/Libraries/MySocket/Web/CloudflareSocket.php
deleted file mode 100644
index d5357db..0000000
--- a/app/Libraries/MySocket/Web/CloudflareSocket.php
+++ /dev/null
@@ -1,42 +0,0 @@
-_api_email = $api_email;
- $this->_api_key = $api_key;
- }
-
- //Override
- public function getClient()
- {
- if (is_null($this->_client)) {
- $apikey = new APIKey($this->_api_email, $this->_api_key);
- $this->_client = new Guzzle($apikey);
- self::$_request_max = intval(getenv("cfmgr.request.max"));
- self::$_request_timewait = intval(getenv("cfmgr.request.timewait"));
- }
- if (self::$_request_max <= self::$_request_count) {
- log_message('warning', sprintf("--Cloudflare API Call %s초 대기 시작--", self::$_request_timewait));
- sleep(intval(getenv("cf.mgr.request.time.wait")));
- self::$_request_count = 0;
- log_message('warning', sprintf("--Cloudflare API Call %s초 대기 종료--", self::$_request_timewait));
- }
- self::$_request_count++;
- return $this->_client;
- }
-}
diff --git a/app/Libraries/MySocket/WebSocket.php b/app/Libraries/MySocket/WebSocket.php
index a7850b4..03b0754 100644
--- a/app/Libraries/MySocket/WebSocket.php
+++ b/app/Libraries/MySocket/WebSocket.php
@@ -2,19 +2,26 @@
namespace App\Libraries\MySocket;
+use App\Libraries\CommonLibrary;
use GuzzleHttp\Cookie\CookieJar;
use GuzzleHttp\Client;
-class WebSocket extends MySocket
+class WebSocket extends CommonLibrary
{
+ private $_host = null;
private $_client = null;
private $_cookieJar = null;
public function __construct(string $host)
{
- parent::__construct($host);
+ parent::__construct();
+ $this->_host = $host;
+ }
+ final public function getHost(): string
+ {
+ return $this->_host;
}
- public function getClient()
+ final public function getClient(): Client
{
if ($this->_client === null) {
$this->_client = new Client(['verify' => getenv("socket.web.ssl.verify") == "true" ? true : false]);
diff --git a/app/Libraries/MyStorage/FileStorage.php b/app/Libraries/MyStorage/FileStorage.php
index 39c9173..6d43dc3 100644
--- a/app/Libraries/MyStorage/FileStorage.php
+++ b/app/Libraries/MyStorage/FileStorage.php
@@ -2,15 +2,19 @@
namespace App\Libraries\MyStorage;
+use App\Libraries\CommonLibrary;
use App\Traits\FileTrait;
-class FileStorage extends MyStorage
+class FileStorage extends CommonLibrary
{
use FileTrait;
private $_path = "";
+ private $_originName = "";
+ private $_originContent = "";
+ private $_originMediaTag = "";
+ private $_originSequence = "";
private $_mimeType = "";
private $_fileSize = 0;
- private $_fileSequence = 0;
private $_imageLibrary = null;
public function __construct(string $path)
{
@@ -35,7 +39,38 @@ class FileStorage extends MyStorage
{
return "uploads";
}
-
+ final public function getOriginName(): string
+ {
+ return $this->_originName;
+ }
+ final public function setOriginName(string $originName): void
+ {
+ $this->_originName = $originName;
+ }
+ final public function getOriginContent(): string
+ {
+ return $this->_originContent;
+ }
+ final public function setOriginContent(string $originContent): void
+ {
+ $this->_originContent = $originContent;
+ }
+ final public function getOriginMediaTag(): string
+ {
+ return $this->_originMediaTag;
+ }
+ final public function setOriginMediaTag(string $originMediaTag): void
+ {
+ $this->_originMediaTag = $originMediaTag;
+ }
+ final public function getOriginSequence(): int
+ {
+ return $this->_originSequence;
+ }
+ final public function setOriginSequence(int $originSequence): void
+ {
+ $this->_originSequence = $originSequence;
+ }
final public function getMimeType(): string
{
return $this->_mimeType;
@@ -44,11 +79,6 @@ class FileStorage extends MyStorage
{
return $this->_fileSize;
}
- final public function getFileSequence(): int
- {
- return $this->_fileSequence;
- }
-
public function save(): static
{
// log_message("notice", __FUNCTION__ . " 원본파일 {$this->getOriginName()} 작업 시작 2");
diff --git a/app/Libraries/MyStorage/MangboardStorage.php b/app/Libraries/MyStorage/MangboardStorage.php
index 2f45915..248d674 100644
--- a/app/Libraries/MyStorage/MangboardStorage.php
+++ b/app/Libraries/MyStorage/MangboardStorage.php
@@ -42,7 +42,7 @@ class MangboardStorage extends FileStorage
final public function getHTMLTag(string $content = ""): string
{
//Board 게시판 image_path , content용 데이터 배열에 추가 후 modifyBoard에서 처리
- switch ($this->getOrintginType()) {
+ switch ($this->getOriginMediaTag()) {
case "img":
$content = sprintf(
"

",
diff --git a/app/Libraries/MyStorage/MyStorage.php b/app/Libraries/MyStorage/MyStorage.php
deleted file mode 100644
index 5e25bfb..0000000
--- a/app/Libraries/MyStorage/MyStorage.php
+++ /dev/null
@@ -1,51 +0,0 @@
-_originName;
- }
- final public function setOriginName(string $originName): void
- {
- $this->_originName = $originName;
- }
- final public function getOriginContent(): string
- {
- return $this->_originContent;
- }
- final public function setOriginContent(string $originContent): void
- {
- $this->_originContent = $originContent;
- }
-
- final public function getOrintginType(): string
- {
- return $this->_originType;
- }
- final public function setOriginType(string $originType): void
- {
- $this->_originType = $originType;
- }
- final public function getOriginSequence(): int
- {
- return $this->_originSequence;
- }
- final public function setOriginSequence(int $originSequence): void
- {
- $this->_originSequence = $originSequence;
- }
-}
diff --git a/app/Models/Cloudflare/AccountModel.php b/app/Models/Cloudflare/AccountModel.php
new file mode 100644
index 0000000..bf8fe0e
--- /dev/null
+++ b/app/Models/Cloudflare/AccountModel.php
@@ -0,0 +1,62 @@
+where($this->getPKField(), $uid);
+ return $this->getEntity();
+ }
+ public function getEntityByID(string $id): null | AccountEntity
+ {
+ $this->where($this->getTitleField(), $id);
+ return $this->getEntity();
+ }
+
+ //create용
+ public function create(array $formDatas = []): AccountEntity
+ {
+ return $this->create_process(new AccountEntity(), $formDatas);
+ }
+ //modify용
+ public function modify(AccountEntity $entity, array $formDatas): AccountEntity
+ {
+ return $this->modify_process($entity, $formDatas);
+ }
+}
diff --git a/app/Models/Cloudflare/FirewallModel.php b/app/Models/Cloudflare/FirewallModel.php
new file mode 100644
index 0000000..fb6d614
--- /dev/null
+++ b/app/Models/Cloudflare/FirewallModel.php
@@ -0,0 +1,93 @@
+ "if_exist|min_length[10]|max_length[200]",
+ "zone_uid" => "if_exist|min_length[10]|max_length[200]",
+ "description" => "if_exist|string",
+ "filter_id" => "if_exist|min_length[10]|max_length[200]",
+ "filter_expression" => "if_exist|string",
+ "filter_paused" => "if_exist|in_list[on,off]",
+ "paused" => "if_exist|in_list[on,off]",
+ "action" => "if_exist|string",
+ "updated_at" => "if_exist|valid_date",
+ "created_at" => "if_exist|valid_date",
+ ];
+ protected $validationMessages = [];
+ protected $skipValidation = true;
+ protected $cleanValidationRules = true;
+
+ // Callbacks
+ protected $allowCallbacks = true;
+ protected $beforeInsert = [];
+ protected $afterInsert = [];
+ protected $beforeUpdate = [];
+ protected $afterUpdate = [];
+ protected $beforeFind = [];
+ protected $afterFind = [];
+ protected $beforeDelete = [];
+ protected $afterDelete = [];
+
+ public function getTableName()
+ {
+ return $this->table;
+ }
+
+ public function getEntity(string $uid): FirewallEntity
+ {
+ $entity = $this->asObject(FirewallEntity::class)->where("uid", $uid)->first();
+ if (is_null($entity)) {
+ throw new \Exception(__METHOD__ . "에서 {$uid} 해당 정보가 없습니다.");
+ }
+ return $entity;
+ }
+ public function getEntitys(array $wheres)
+ {
+ return $this->asObject(FirewallEntity::class)->where($wheres)->findAll();
+ }
+ public function getEntitysByZone(ZoneEntity $zone)
+ {
+ return $this->getEntitys([self::PARENT_FIELD, $zone->getPrimaryKey()]);
+ }
+
+ //Index 검색용
+ public function setIndexWordFilter(string $word)
+ {
+ $this->like("description", $word, "both"); //befor , after , both
+ }
+ public function setIndexDateFilter($start, $end)
+ {
+ $this->where("created_at >=", $start);
+ $this->where("created_at <=", $end);
+ }
+ public function setIndexOrderBy($field, $order = "ASC")
+ {
+ $this->orderBy("zone_uid ASC, description ASC, {$field} {$order}");
+ }
+}
diff --git a/app/Models/Cloudflare/RecordModel.php b/app/Models/Cloudflare/RecordModel.php
new file mode 100644
index 0000000..041afa4
--- /dev/null
+++ b/app/Models/Cloudflare/RecordModel.php
@@ -0,0 +1,115 @@
+ 'if_exist|min_length[10]|max_length[200]',
+ 'zone_uid' => 'if_exist|min_length[10]|max_length[200]',
+ 'host' => 'if_exist|string',
+ 'content' => 'if_exist|string',
+ 'type' => 'if_exist|string',
+ 'ttl' => 'if_exist|numeric',
+ 'proxiable' => 'if_exist|in_list[on,off]',
+ 'proxied' => 'if_exist|in_list[on,off]',
+ 'fixed' => 'if_exist|in_list[on,off]',
+ 'locked' => 'if_exist|in_list[on,off]',
+ 'updated_at' => 'if_exist|valid_date',
+ 'created_at' => 'if_exist|valid_date',
+ ];
+ protected $validationMessages = [];
+ protected $skipValidation = true;
+ protected $cleanValidationRules = true;
+
+ // Callbacks
+ protected $allowCallbacks = true;
+ protected $beforeInsert = [];
+ protected $afterInsert = [];
+ protected $beforeUpdate = [];
+ protected $afterUpdate = [];
+ protected $beforeFind = [];
+ protected $afterFind = [];
+ protected $beforeDelete = [];
+ protected $afterDelete = [];
+
+ public function getTableName()
+ {
+ return $this->table;
+ }
+
+ public function getEntity(string $uid): RecordEntity
+ {
+ $entity = $this->asObject(RecordEntity::class)->where('uid', $uid)->first();
+ if (is_null($entity)) {
+ throw new \Exception(__METHOD__ . "에서 {$uid} 해당 정보가 없습니다.");
+ }
+ return $entity;
+ }
+ public function getEntitys(array $wheres)
+ {
+ return $this->asObject(RecordEntity::class)->where($wheres)->findAll();
+ }
+ public function getEntitysByZone(ZoneEntity $zone)
+ {
+ return $this->getEntitys([self::PARENT_FIELD => $zone->getPrimaryKey()]);
+ }
+
+ //Index 검색어용
+ public function setIndexWordFilter(string $word)
+ {
+ $this->like('host', $word, 'before'); //befor , after , both
+ $this->orWhere('content', $word);
+ }
+ public function setIndexDateFilter($start, $end)
+ {
+ $this->where('created_at >=', $start);
+ $this->where('created_at <=', $end);
+ }
+ public function setIndexOrderBy($field, $order = 'ASC')
+ {
+ $this->orderBy("zone_uid ASC, host ASC, {$field} {$order}");
+ }
+
+ //도메인이 이미 존재하는지 체크
+ public function isUniqueHost($zone_uid, string $host, string $content): bool
+ {
+ $this->where('zone_uid', $zone_uid);
+ $this->where('host', $host);
+ $this->where('content', $content);
+ return is_null($this->first()) ? true : false;
+ }
+
+ //CDN값 수정 못하는 고정 Record 처리
+ public function setFixedCDNRecord(array $hosts)
+ {
+ if (count($hosts)) {
+ $this->whereIn('host', $hosts)->set(['fixed' => 'on'])->update();
+ Log::add("notice", "-----set fixed Records " . implode(",", $hosts) . "처리 완료-----");
+ }
+ }
+}
diff --git a/app/Models/Cloudflare/ZoneModel.php b/app/Models/Cloudflare/ZoneModel.php
new file mode 100644
index 0000000..431705c
--- /dev/null
+++ b/app/Models/Cloudflare/ZoneModel.php
@@ -0,0 +1,101 @@
+ 'if_exist|min_length[10]|max_length[200]',
+ 'account_uid' => 'if_exist|min_length[10]|max_length[200]',
+ 'domain' => 'if_exist|string',
+ 'name_servers' => 'if_exist|string',
+ 'plan' => 'if_exist|string',
+ 'development_mode' => 'if_exist|in_list[on,off]',
+ 'ipv6' => 'if_exist|in_list[on,off]',
+ 'security_level' => 'if_exist|string',
+ 'status' => 'if_exist|string',
+ 'updated_at' => 'if_exist|valid_date',
+ 'created_at' => 'if_exist|valid_date',
+ ];
+ // 'security_level' => 'if_exist|in_list[essentially_off,low,medium,under_attack]',
+ // 'status' => 'if_exist|in_list[active,pending]',
+ protected $validationMessages = [];
+ protected $skipValidation = true;
+ protected $cleanValidationRules = true;
+
+ // Callbacks
+ protected $allowCallbacks = true;
+ protected $beforeInsert = [];
+ protected $afterInsert = [];
+ protected $beforeUpdate = [];
+ protected $afterUpdate = [];
+ protected $beforeFind = [];
+ protected $afterFind = [];
+ protected $beforeDelete = [];
+ protected $afterDelete = [];
+
+ public function getTableName()
+ {
+ return $this->table;
+ }
+
+ public function getEntity(string $uid): ZoneEntity
+ {
+ $entity = $this->asObject(ZoneEntity::class)->where('uid', $uid)->first();
+ if (is_null($entity)) {
+ throw new \Exception(__METHOD__ . "에서 {$uid} 해당 정보가 없습니다.");
+ }
+ return $entity;
+ }
+ public function getEntitys(array $wheres)
+ {
+ return $this->asObject(ZoneEntity::class)->where($wheres)->findAll();
+ }
+
+ //Index 검색용
+ public function setIndexWordFilter(string $word)
+ {
+ $subquery = $this->db->table('cloudflarerecord')->select('zone_uid')->like('content', $word, 'both');
+ $this->like('domain', $word, 'both'); //befor , after , both
+ $this->orWhereIn('uid', $subquery);
+ }
+ public function setIndexDateFilter($start, $end)
+ {
+ $this->where('created_at >=', $start);
+ $this->where('created_at <=', $end);
+ }
+ public function setIndexOrderBy($field, $order = 'ASC')
+ {
+ $this->orderBy("domain ASC, {$field} {$order}");
+ }
+
+ //도메인이 이미 존재하는지 체크
+ public function isUniqueDomain(string $account_uid, string $domain): bool
+ {
+ $this->where('account_uid', $account_uid);
+ $this->where('domain', $domain);
+ return is_null($this->first()) ? true : false;
+ }
+}
diff --git a/app/Models/CommonModel.php b/app/Models/CommonModel.php
index 81bca62..3c73b77 100644
--- a/app/Models/CommonModel.php
+++ b/app/Models/CommonModel.php
@@ -83,15 +83,11 @@ abstract class CommonModel extends Model
);
return $allowedFields;
}
- final public function getFieldRules(array $fields, array $rules = []): array
- {
- foreach ($fields as $field) {
- $rules = $this->getFieldRule($field, $rules);
- }
- return $rules;
- }
public function getFieldRule(string $field, array $rules): array
{
+ if (is_array($field)) {
+ throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
+ }
switch ($field) {
case $this->getPKField():
//수동입력인경우
@@ -117,6 +113,9 @@ abstract class CommonModel extends Model
case 'image':
$rules[$field] = "is_image[{$field}]|mime_in[{$field},image/jpg,image/jpeg,image/gif,image/png,image/webp]|max_size[{$field},300]|max_dims[{$field},2048,768]";
break;
+ case "status":
+ $rules[$field] = "if_exist|in_list[use,unuse]";
+ break;
case "updated_at":
case "created_at":
case "deleted_at":
@@ -128,7 +127,13 @@ abstract class CommonModel extends Model
}
return $rules;
}
-
+ final public function getFieldRules(array $fields, array $rules = []): array
+ {
+ foreach ($fields as $field) {
+ $rules = $this->getFieldRule($field, $rules);
+ }
+ return $rules;
+ }
final public function getEntity(): array|object|null
{
return $this->asObject($this->returnType)->first();
diff --git a/app/Models/Mangboard/BoardModel.php b/app/Models/Mangboard/BoardModel.php
index 80061fb..608a207 100644
--- a/app/Models/Mangboard/BoardModel.php
+++ b/app/Models/Mangboard/BoardModel.php
@@ -133,7 +133,7 @@ class BoardModel extends CommonModel
}
public function getEntityByID(string $id): null | BoardEntity
{
- $this->where('user_id', $id);
+ $this->where($this->getTitleField(), $id);
return $this->getEntity();
}
diff --git a/app/Models/Mangboard/BoardsModel.php b/app/Models/Mangboard/BoardsModel.php
index 1fab02b..8175d9b 100644
--- a/app/Models/Mangboard/BoardsModel.php
+++ b/app/Models/Mangboard/BoardsModel.php
@@ -86,7 +86,7 @@ class BoardsModel extends CommonModel
}
public function getTitleField(): string
{
- return 'title';
+ return 'board_name';
}
public function getFieldRule(string $field, array $rules): array
{
@@ -124,9 +124,9 @@ class BoardsModel extends CommonModel
$this->where($this->getPKField(), $uid);
return $this->getEntity();
}
- public function getEntityByID(string $board_name): null | BoardsEntity
+ public function getEntityByID(string $id): null | BoardsEntity
{
- $this->where('board_name', $board_name);
+ $this->where($this->getTitleField(), $id);
return $this->getEntity();
}
diff --git a/app/Models/Mangboard/FileModel.php b/app/Models/Mangboard/FileModel.php
index 51194e2..22de1f9 100644
--- a/app/Models/Mangboard/FileModel.php
+++ b/app/Models/Mangboard/FileModel.php
@@ -101,7 +101,7 @@ class FileModel extends CommonModel
}
public function getEntityByID(string $id): null | FileEntity
{
- $this->where('user_id', $id);
+ $this->where($this->getTitleField(), $id);
return $this->getEntity();
}