Automation init...3

This commit is contained in:
최준흠 2024-09-13 21:56:17 +09:00
parent 3e2ff5b6c0
commit 5b20de9b8a
7 changed files with 184 additions and 127 deletions

View File

@ -24,4 +24,20 @@ class BoardEntity extends CommonEntity
{
return $this->attributes['pid'];
}
public function getImagePath(): string
{
return $this->attributes['image_path'];
}
public function setImagePath(string $image_path): void
{
$this->attributes['image_path'] = $image_path;
}
public function getContent(): string
{
return $this->attributes['content'];
}
public function setContent(string $content): void
{
$this->attributes['content'] = $content;
}
}

View File

@ -12,11 +12,11 @@ class BoardsEntity extends CommonEntity
}
public function getTitle(): string
{
return $this->attributes['title'];
return $this->attributes['board_name'];
}
public function setTitle(string $title): void
public function setTitle(string $board_name): void
{
$this->attributes['title'] = $title;
$this->attributes['board_name'] = $board_name;
}
//Common Function

View File

@ -2,17 +2,18 @@
namespace App\Libraries\MyCrawler;
use App\Entities\Mangboard\UserEntity;
use App\Libraries\MySocket\WebLibrary as MySocketLibrary;
use Symfony\Component\DomCrawler\Crawler;
use App\Libraries\MyStorage\Mangboard\FileLibrary as MyStorageLibrary;
use App\Libraries\MyStorage\Mangboard\BoardsLibrary;
use Symfony\Component\DomCrawler\Crawler;
use App\Libraries\MyStorage\Mangboard\BoardLibrary;
use App\Libraries\MySocket\WebLibrary as MySocketLibrary;
use App\Entities\Mangboard\UserEntity;
class YamapLibrary extends MyCrawlerLibrary
{
private $_user_entity = null;
private $_boards_library = null;
private $_media_tags = [];
private $_board_library = null;
public function __construct()
{
parent::__construct();
@ -28,7 +29,7 @@ class YamapLibrary extends MyCrawlerLibrary
{
if ($this->_myStorage === null) {
$this->_myStorage = new MyStorageLibrary(getenv('yamap.storage.upload.path'));
$this->_myStorage->setBoardsLibrary($this->getBoardsLibrary());
$this->_myStorage->setBoardsEntity($this->getBoardsLibrary()->getEntity());
$this->_myStorage->setUserEntity($this->getUserEntity());
}
return $this->_myStorage;
@ -36,11 +37,23 @@ class YamapLibrary extends MyCrawlerLibrary
public function getBoardsLibrary(): BoardsLibrary
{
if ($this->_boards_library === null) {
$this->_boards_library = new BoardsLibrary(getenv('yamap.storage.board.name'));
$this->_boards_library->setUserEntity($this->getUserEntity());
$this->_boards_library = new BoardsLibrary(
getenv('yamap.storage.board.name'),
$this->getUserEntity()
);
}
return $this->_boards_library;
}
public function getBoardLibrary(): BoardLibrary
{
if ($this->_board_library === null) {
$this->_board_library = new BoardLibrary(
$this->getBoardsLibrary()->getEntity(),
$this->getUserEntity()
);
}
return $this->_board_library;
}
public function getUserEntity(): UserEntity
{
if ($this->_user_entity === null) {
@ -88,8 +101,8 @@ class YamapLibrary extends MyCrawlerLibrary
if ($content === "") {
throw new \Exception(__FUNCTION__ . " Content의 내용없음");
}
$this->_media_tags["image_path"][] = sprintf("%s/%s", $this->getMyStorage()->getPath(), $this->getMyStorage()->getOriginName());
$this->_media_tags["content"][] = $content;
//망보드 Content 추가
$this->getBoardLibrary()->addContent($content);
return $myStorageLibrary;
}
@ -97,17 +110,17 @@ class YamapLibrary extends MyCrawlerLibrary
{
//1. Yamap ViewPage의 이미지나영상데이터가 있으면
$response = $this->getMySocket()->getContent($listInfo['detail_url']);
//1.망보드 일반게시판에 게시물 생성 처리
$this->getBoardsLibrary()->createBoard($listInfo);
$this->_media_tags = ["image_path" => [], "content" => []];
//1.망보드 게시판에 게시물 생성 처리
$this->getMyStorage()->setBoardEntity($this->getBoardLibrary()->create($listInfo));
//망보드 image_path설정
$this->getBoardLibrary()->setImagePath(sprintf("%s/%s", $this->getMyStorage()->getPath(), $this->getMyStorage()->getOriginName()));
$selector = $this->getSelector($response, getenv("yamap.view.content.tag"));
//3. Image 처리
log_message("debug", sprintf("\n-------------DetailPage------------\n%s\n--------------------------\n", $selector->html()));
$myStorageLibrarys = $this->download("image", $selector, ["tag" => "img", "attr" => "src"]);
//4. Video(mp4) 처리
$myStorageLibrarys = $this->download("video", $selector, ["tag" => "video", "attr" => "src"], $myStorageLibrarys);
//5.망보드 일반게시판에 게시물 수정 처리
$this->getBoardsLibrary()->modifyBoard($this->_media_tags);
//5.망보드 게시판에 게시물 수정 처리
$this->getBoardLibrary()->modify();
log_message("notice", __FUNCTION__ . " 작업 완료");
}

View File

@ -0,0 +1,82 @@
<?php
namespace App\Libraries\MyStorage\Mangboard;
use App\Models\Mangboard\BoardModel;
use App\Entities\Mangboard\UserEntity;
use App\Entities\Mangboard\BoardsEntity;
use App\Entities\Mangboard\BoardEntity;
class BoardLibrary
{
private $_model = null;
private $_entity = null;
private $_boards_entity = null;
private $_user_entity = null;
private $_mediaTags = ["image_path" => "", "content" => ""];
public function __construct(BoardsEntity $boards_entity, UserEntity $user_entity)
{
$this->_boards_entity = $boards_entity;
$this->_user_entity = $user_entity;
}
public function getModel(): BoardModel
{
if ($this->_model === null) {
$table_name = "mb_" . $this->_boards_entity->getTitle();
$this->_model = new BoardModel($table_name);
}
return $this->_model;
}
public function getEntity(): BoardEntity
{
return $this->_entity;
}
public function getBoardsEntity(): BoardsEntity
{
return $this->_boards_entity;
}
public function getUserEntity(): UserEntity
{
return $this->_user_entity;
}
public function setImagePath(string $image_path): void
{
$this->_mediaTags['image_path'] = $image_path;
}
public function addContent(string $content)
{
if ($content != "") {
$this->_mediaTags['content'] .= $content;
}
}
public function create(array $listInfo): BoardEntity
{
//미디어관련정보 entity에 넣기
$formDatas = [];
$formDatas['title'] = $listInfo["title"];
$formDatas['user_pid'] = $this->getUserEntity()->getPK();
$formDatas['user_id'] = $this->getUserEntity()->getID();
$formDatas['user_name'] = $listInfo["nickname"] != "" ? $listInfo["nickname"] : $this->getUserEntity()->getTitle();
$formDatas['level'] = $this->getBoardsEntity()->getListLevel();
$formDatas['hit'] = $listInfo['hit'];
$formDatas['reg_date'] = date("Y-m-d H:i:s", strtotime($listInfo['date']));
$formDatas['data_type'] = "html";
$formDatas['editor_type'] = "S";
$formDatas['image_path'] = "";
$formDatas['content'] = "";
//망보드 게시판에 등록
$this->_entity = $this->getModel()->create($formDatas);
log_message("notice", message: __FUNCTION__ . "=>{$this->_entity->getPK()}:{$this->_entity->getTitle()} 생성 작업 완료");
return $this->_entity;
}
public function modify(): void
{
if ($this->_mediaTags['content'] != "") {
$this->getModel()->modify($this->_entity, $this->_mediaTags);
log_message("notice", __FUNCTION__ . "=>{$this->_entity->getPK()}:{$this->_entity->getTitle()} 수정 작업 완료");
} else {
$this->getModel()->delete([$this->getModel()->getPKField() => $$this->_entity->getPK()]);
log_message("warning", __FUNCTION__ . "=>{$this->_entity->getPK()}:{$this->_entity->getTitle()} 내용이 없어 삭제처리");
}
}
}

View File

@ -2,63 +2,40 @@
namespace App\Libraries\MyStorage\Mangboard;
use App\Entities\Mangboard\BoardEntity;
use App\Entities\Mangboard\BoardsEntity;
use App\Entities\Mangboard\UserEntity;
use App\Models\Mangboard\BoardModel;
use App\Models\Mangboard\BoardsModel;
use App\Entities\Mangboard\UserEntity;
use App\Entities\Mangboard\BoardsEntity;
class BoardsLibrary
{
private $_boards_model = null;
private $_boards_entity = null;
private $_model = null;
private $_entity = null;
private $_board_name = null;
private $_board_model = null;
private $_board_entity = null;
private $_user_entity = null;
public function __construct(string $board_name)
public function __construct(string $board_name, UserEntity $uer_entity)
{
$this->_board_name = $board_name;
$this->_boards_entity = $this->getBoardsModel()->getEntityByID($this->getBoardName());
$this->_user_entity = $uer_entity;
}
public function getBoardsModel(): BoardsModel
public function getModel(): BoardsModel
{
if ($this->_boards_model === null) {
$this->_boards_model = new BoardsModel();
if ($this->_model === null) {
$this->_model = new BoardsModel();
}
return $this->_boards_model;
return $this->_model;
}
public function getBoardsEntity(): BoardsEntity
public function getEntity(): BoardsEntity
{
return $this->_boards_entity;
if ($this->_entity === null) {
$this->_entity = $this->getModel()->getEntityByID($this->getBoardName());
}
public function setBoardsEntity(BoardsEntity $boards_entity): void
{
$this->_boards_entity = $boards_entity;
return $this->_entity;
}
//---------------------------------------------------------------------//
public function getBoardName(): string
{
return $this->_board_name;
}
public function getBoardModel(): BoardModel
{
if ($this->_board_model === null) {
$this->_board_model = new BoardModel("mb_" . $this->getBoardName());
}
return $this->_board_model;
}
public function getBoardEntity(): BoardEntity
{
if ($this->_board_entity === null) {
throw new \Exception("{$this->getBoardName()} 게시판 정보가 없습니다.");
}
return $this->_board_entity;
}
public function setBoardEntity(BoardEntity $board_entity): void
{
$this->_board_entity = $board_entity;
}
public function getUserEntity(): UserEntity
{
if ($this->_user_entity === null) {
@ -66,43 +43,4 @@ class BoardsLibrary
}
return $this->_user_entity;
}
public function setUserEntity(UserEntity $user_entity): void
{
$this->_user_entity = $user_entity;
}
public function createBoard(array $listInfo): void
{
//미디어관련정보 entity에 넣기
$formDatas = [];
$formDatas['title'] = $listInfo["title"];
$formDatas['user_pid'] = $this->getUserEntity()->getPK();
$formDatas['user_id'] = $this->getUserEntity()->getID();
$formDatas['user_name'] = $listInfo["nickname"] != "" ? $listInfo["nickname"] : $this->getUserEntity()->getTitle();
$formDatas['level'] = $this->getBoardsEntity()->getListLevel();
$formDatas['hit'] = $listInfo['hit'];
$formDatas['reg_date'] = date("Y-m-d H:i:s", strtotime($listInfo['date']));
$formDatas['data_type'] = "html";
$formDatas['editor_type'] = "S";
$formDatas['image_path'] = "";
$formDatas['content'] = "";
//망보드 게시판에 등록
$this->setBoardEntity($this->getBoardModel()->create($formDatas));
log_message("notice", message: __FUNCTION__ . "=>{$this->getBoardName()} 생성 작업 완료");
}
public function modifyBoard(array $media_tags): void
{
$content = implode("\n", $media_tags["content"]);
if ($content !== "") {
$formDatas = [
"image_path" => array_shift($media_tags["image_path"]),
"content" => $content
];
$this->getBoardModel()->modify($this->getBoardEntity(), $formDatas);
log_message("notice", __FUNCTION__ . "=>{$this->getBoardEntity()->getPK()}:{$this->getBoardEntity()->getTitle()} 수정 작업 완료");
} else {
$this->getBoardModel()->delete([$this->getBoardModel()->getPKField() => $this->getBoardEntity()->getPK()]);
log_message("warning", __FUNCTION__ . "=>{$this->getBoardEntity()->getPK()}:{$this->getBoardEntity()->getTitle()} 내용이 없어 삭제처리");
}
}
}

View File

@ -2,18 +2,21 @@
namespace App\Libraries\MyStorage\Mangboard;
use App\Entities\Mangboard\FileEntity;
use App\Entities\Mangboard\UserEntity;
use App\Libraries\MyStorage\FileLibrary as MyStorageLibrary;
use App\Libraries\MyStorage\Mangboard\SmallImageLibrary;
use App\Models\Mangboard\FileModel;
use App\Libraries\MyStorage\Mangboard\SmallImageLibrary;
use App\Libraries\MyStorage\FileLibrary as MyStorageLibrary;
use App\Entities\Mangboard\UserEntity;
use App\Entities\Mangboard\FileEntity;
use App\Entities\Mangboard\BoardsEntity;
use App\Entities\Mangboard\BoardEntity;
class FileLibrary extends MyStorageLibrary
{
private $_file_model = null;
private $_model = null;
private $_entity = null;
private $_boards_entity = null;
private $_board_entity = null;
private $_user_entity = null;
private $_boards_library = null;
private $_file_entity = null;
private $_imageLibrary = null;
public function __construct(string $path)
{
@ -24,43 +27,50 @@ class FileLibrary extends MyStorageLibrary
$this->_imageLibrary->setSourcePath($fullPath);
$this->_imageLibrary->setDestinationPath($fullPath);
}
public function getFileModel(): FileModel
public function getModel(): FileModel
{
if ($this->_file_model === null) {
return $this->_file_model = new FileModel();
if ($this->_model === null) {
return $this->_model = new FileModel();
}
return $this->_file_model;
return $this->_model;
}
public function getFileEntity(): FileEntity
public function getEntity(): FileEntity
{
return $this->_file_entity;
return $this->_entity;
}
private function setFileEntity(FileEntity $file_entity): void
public function getBoardsEntity(): BoardsEntity
{
$this->_file_entity = $file_entity;
}
public function getBoardsLibrary(): BoardsLibrary
{
if ($this->_boards_library === null) {
if ($this->_boards_entity === null) {
throw new \Exception("Board Library가 정의되지 않았습니다.");
}
return $this->_boards_library;
return $this->_boards_entity;
}
public function setBoardsLibrary(BoardsLibrary $boards_library): void
public function setBoardsEntity(BoardsEntity $boards_entity): void
{
$this->_boards_library = $boards_library;
$this->_boards_entity = $boards_entity;
}
public function getUserEntity(): UserEntity
public function getBoardEntity(): BoardEntity
{
if ($this->_user_entity === null) {
throw new \Exception("사용자정보가 없습니다.");
if ($this->_board_entity === null) {
throw new \Exception("Board Entity가 정의되지 않았습니다.");
}
return $this->_user_entity;
return $this->_board_entity;
}
public function setUserEntity(UserEntity $user_entity): void
{
$this->_user_entity = $user_entity;
}
public function getUserEntity(): UserEntity
{
if ($this->_user_entity === null) {
throw new \Exception("User Entity가 정의되지 않았습니다.");
}
return $this->_user_entity;
}
public function setBoardEntity(BoardEntity $board_entity): void
{
$this->_board_entity = $board_entity;
}
final public function getHTMLTag(string $content = ""): string
{
//Board 게시판 image_path , content용 데이터 배열에 추가 후 modifyBoard에서 처리
@ -101,7 +111,7 @@ class FileLibrary extends MyStorageLibrary
//파일관리 table에 등록
$formDatas = [];
//Board PID 넣기
$formDatas['board_pid'] = $this->getBoardsLibrary()->getBoardEntity()->getPk();
$formDatas['board_pid'] = $this->getBoardEntity()->getPk();
//작은이미지생성후 Path/파일명 넣기
$fileInfos = pathinfo($this->_imageLibrary->getDestinationPath() . DIRECTORY_SEPARATOR . $this->getOriginName(), PATHINFO_ALL);
$dstFile = $fileInfos['filename'] . "_small." . $fileInfos['extension'];
@ -114,8 +124,8 @@ class FileLibrary extends MyStorageLibrary
$formDatas['user_pid'] = $this->getUserEntity()->getPK();
$formDatas['user_name'] = $this->getUserEntity()->getTitle();
$formDatas['board_name'] = $this->getBoardsLibrary()->getBoardName();
$formDatas['table_name'] = $this->getBoardsLibrary()->getBoardModel()->getTable();
$formDatas['board_name'] = $this->getBoardsEntity()->getTitle();
$formDatas['table_name'] = $this->getModel()->getTable();
$formDatas['file_name'] = $this->getOriginName();
$formDatas['file_type'] = $this->getMimeType();
$formDatas['file_caption'] = $this->getOriginName();
@ -124,13 +134,12 @@ class FileLibrary extends MyStorageLibrary
$formDatas['file_size'] = $this->getFileSize();
$formDatas['file_sequence'] = $this->getOriginSequence();
$formDatas['reg_date'] = date("Y-m-d H:i:s");
$entity = $this->getFileModel()->create($formDatas);
$entity = $this->getModel()->create($formDatas);
log_message("notice", sprintf(
"%s %s번째 작업 완료",
__FUNCTION__,
$this->getOriginSequence()
));
$this->setFileEntity($entity);
return $this;
}
}

View File

@ -10,7 +10,6 @@ class UserLibrary extends WebLibrary
{
private $_web_library = null;
private $_user_model = null;
private $_user_entity = null;
public function __construct() {}
public function getUserModel(): UserModel
{