diff --git a/app/Entities/Mangboard/FileEntity.php b/app/Entities/Mangboard/FileEntity.php index bc24728..e213cca 100644 --- a/app/Entities/Mangboard/FileEntity.php +++ b/app/Entities/Mangboard/FileEntity.php @@ -2,9 +2,9 @@ namespace App\Entities\Mangboard; -use App\Entities\MyStorage\FileEntity as ParentEntity; +use App\Entities\MyStorage\FileEntity as MyStorageEntity; -class FileEntity extends ParentEntity +class FileEntity extends MyStorageEntity { public function __toString(): string { diff --git a/app/Libraries/Mangboard/FileLibrary.php b/app/Libraries/Mangboard/FileLibrary.php index 0ce09c3..428bd81 100644 --- a/app/Libraries/Mangboard/FileLibrary.php +++ b/app/Libraries/Mangboard/FileLibrary.php @@ -4,12 +4,12 @@ namespace App\Libraries\Mangboard; use App\Models\Mangboard\FileModel; -use App\Libraries\MyStorage\FileLibrary as ParentLibrary; +use App\Libraries\MyStorage\FileLibrary as MyStorageLibrary; use App\Entities\Mangboard\UserEntity; use App\Entities\Mangboard\FileEntity; use App\Entities\Mangboard\BoardEntity; -class FileLibrary extends ParentLibrary +class FileLibrary extends MyStorageLibrary { private $_user = null; private $_boardName = ""; @@ -29,14 +29,6 @@ class FileLibrary extends ParentLibrary } //override - public function getEntity(): FileEntity - { - if ($this->_entity === null) { - $this->_entity = new FileEntity(); - $this->_entity->setPath($this->getPath()); - } - return $this->_entity; - } public function getUser(): UserEntity { @@ -84,7 +76,7 @@ class FileLibrary extends ParentLibrary } - public function save(string $fileName, string $mediaType, string $content, int $file_sequence) + public function save(string $fileName, string $mediaType, string $content, int $file_sequence): null|FileEntity { //망보드 파일관리 table에 등록 try { @@ -92,7 +84,8 @@ class FileLibrary extends ParentLibrary if (!$entity) { return null; } - $entity = $this->getEntity(); + $entity = new FileEntity($entity->toRawArray()); //형변환을 위해서 + $entity->setPath($this->getPath()); $entity->user_pid = $this->getUser()->getPK(); $entity->user_name = $this->getUser()->getTitle(); $entity->board_name = $this->getBoardName(); @@ -111,6 +104,7 @@ class FileLibrary extends ParentLibrary public function updateFileEntityBoardPK(FileEntity $entity, BoardEntity $boardEntity): FileEntity { $entity->board_pid = $boardEntity->getPK(); + $this->getModel()->setFields(["board_pid"]); return $this->getModel()->modify($entity); } } diff --git a/app/Libraries/MyCrawler/YamapLibrary.php b/app/Libraries/MyCrawler/YamapLibrary.php index 0f54374..643e386 100644 --- a/app/Libraries/MyCrawler/YamapLibrary.php +++ b/app/Libraries/MyCrawler/YamapLibrary.php @@ -9,7 +9,6 @@ use App\Models\Mangboard\BoardModel; use App\Libraries\MySocket\WebLibrary; use App\Libraries\Mangboard\FileLibrary; use App\Libraries\Mangboard\BoardLibrary; -use App\Entities\Mangboard\UserEntity; use App\Entities\Mangboard\BoardEntity; class YamapLibrary extends MyCrawlerLibrary @@ -100,9 +99,14 @@ class YamapLibrary extends MyCrawlerLibrary $entity->reg_date = date("Y-m-d H:i:s", strtotime($item['date'])); $entity->data_type = "html"; $entity->editor_type = "S"; + $entity->image_path = false; foreach ($fileEntitys as $fileEntity) { + if ($entity->image_path === false) { + $entity->image_path = $fileEntity->getPath() . DIRECTORY_SEPARATOR . $fileEntity->getTitle(); + } $entity->content .= $fileEntity->getMediaHTML(); } + // echo $entity->image_path . "\n"; // echo $entity->title . "\n"; // echo $entity->user_name . "\n"; // echo $entity->hit . "\n"; diff --git a/app/Libraries/MyStorage/FileLibrary.php b/app/Libraries/MyStorage/FileLibrary.php index ba448df..a17fdcb 100644 --- a/app/Libraries/MyStorage/FileLibrary.php +++ b/app/Libraries/MyStorage/FileLibrary.php @@ -7,7 +7,6 @@ use App\Entities\MyStorage\FileEntity; class FileLibrary extends MyStorageLibrary { private $_path = ""; - protected $_entity = null; public function __construct(string $path) { parent::__construct(); @@ -18,16 +17,7 @@ class FileLibrary extends MyStorageLibrary return $this->_path; } - public function getEntity(): FileEntity - { - if ($this->_entity === null) { - $this->_entity = new FileEntity(); - $this->_entity->setPath($this->getPath()); - } - return $this->_entity; - } - - private function getMediaTag(string $mediaType): string + protected function getMediaTag(string $mediaType, FileEntity $entity): string { $mediaTag = ""; switch ($mediaType) { @@ -35,9 +25,9 @@ class FileLibrary extends MyStorageLibrary $mediaTag = sprintf( "\"%s\"", $this->getUploadPath(), - $this->getEntity()->getPath(), - $this->getEntity()->getTitle(), - $this->getEntity()->getTitle() + $entity->getPath(), + $entity->getTitle(), + $entity->getTitle() ); break; case "video": @@ -46,18 +36,18 @@ class FileLibrary extends MyStorageLibrary Your browser does not support the video tag. ", - $this->getEntity()->getTitle(), + $entity->getTitle(), $this->getUploadPath(), - $this->getEntity()->getPath(), - $this->getEntity()->getTitle(), - $this->getEntity()->getMimeType(), + $entity->getPath(), + $entity->getTitle(), + $entity->getMimeType(), ); break; } return $mediaTag; } - public function save(string $fileName, string $mediaType, string $content, int $file_sequence) + public function save(string $fileName, string $mediaType, string $content, int $file_sequence): null|FileEntity { $fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath(); if (!is_dir($fullPath)) { @@ -68,13 +58,14 @@ class FileLibrary extends MyStorageLibrary $saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $fileName; log_message("debug", "Storage Save-> " . $saveFilePath); if (!file_put_contents($saveFilePath, $content)) { - return false; + return null; } - $entity = $this->getEntity(); + $entity = new FileEntity(); + $entity->setPath($this->getPath()); $entity->setTitle($fileName); $entity->setMimeType(mime_content_type($saveFilePath)); - $entity->setMediaHTML($this->getMediaTag($mediaType)); + $entity->setMediaHTML($this->getMediaTag($mediaType, $entity)); return $entity; } } diff --git a/app/Models/Mangboard/BoardModel.php b/app/Models/Mangboard/BoardModel.php index 9abfe64..8d9ea53 100644 --- a/app/Models/Mangboard/BoardModel.php +++ b/app/Models/Mangboard/BoardModel.php @@ -75,7 +75,19 @@ class BoardModel extends CommonModel public function __construct(string $table) { $this->table = $table; - $fields = ["title", "user_pid", "user_id", "user_name", "level", "data_type", "editor_type", "reg_date", "hit", "content"]; + $fields = [ + "title", + "user_pid", + "user_id", + "user_name", + "level", + "data_type", + "editor_type", + "image_path", + "reg_date", + "hit", + "content" + ]; parent::__construct($fields); } public function getTitleField(): string diff --git a/app/Models/Mangboard/FileModel.php b/app/Models/Mangboard/FileModel.php index 7f39758..269303b 100644 --- a/app/Models/Mangboard/FileModel.php +++ b/app/Models/Mangboard/FileModel.php @@ -38,7 +38,19 @@ class FileModel extends CommonModel public function __construct() { - $fields = ["user_pid", "user_name", "board_pid", "board_name", "table_name", "file_name", "file_path", "file_type", "file_description", "file_sequence", "reg_date"]; + $fields = [ + "user_pid", + "user_name", + "board_pid", + "board_name", + "table_name", + "file_name", + "file_path", + "file_type", + "file_description", + "file_sequence", + "reg_date" + ]; parent::__construct($fields); } public function getTitleField(): string