diff --git a/app/Entities/Mangboard/FileEntity.php b/app/Entities/Mangboard/FileEntity.php
index d3b2575..bc24728 100644
--- a/app/Entities/Mangboard/FileEntity.php
+++ b/app/Entities/Mangboard/FileEntity.php
@@ -16,4 +16,14 @@ class FileEntity extends ParentEntity
{
return $this->attributes['pid'];
}
+
+ //한게시물에 여러개가 있을경우 번호
+ final public function getSequence(): int
+ {
+ return $this->attributes['file_sequence'];
+ }
+ public function setSequence(int $file_sequence): void
+ {
+ $this->attributes['file_sequence'] = $file_sequence;
+ }
}
diff --git a/app/Libraries/Mangboard/FileLibrary.php b/app/Libraries/Mangboard/FileLibrary.php
index 2d3b0b1..a1d05eb 100644
--- a/app/Libraries/Mangboard/FileLibrary.php
+++ b/app/Libraries/Mangboard/FileLibrary.php
@@ -3,16 +3,18 @@
namespace App\Libraries\Mangboard;
-use App\Libraries\MyStorage\FileLibrary as ParentLibrary;
use App\Models\Mangboard\FileModel;
+use App\Libraries\MyStorage\FileLibrary as ParentLibrary;
use App\Entities\Mangboard\UserEntity;
use App\Entities\Mangboard\FileEntity;
+use App\Entities\Mangboard\BoardEntity;
class FileLibrary extends ParentLibrary
{
private $_user = null;
private $_boardName = "";
private $_boardTable = "";
+ private $_boardLevel = 1;
private $_model = null;
public function __construct(string $path)
{
@@ -69,24 +71,46 @@ class FileLibrary extends ParentLibrary
{
$this->_boardTable = $boardTable;
}
+ public function getBoardLevel(): int
+ {
+ if ($this->_boardLevel === null) {
+ throw new \Exception("BoardModel Level이 지정되지 않았습니다.");
+ }
+ return $this->_boardLevel;
+ }
+ public function setBoardLevel(string $boardLevel): void
+ {
+ $this->_boardLevel = $boardLevel;
+ }
- public function save($content): null|FileEntity
+
+ public function save(string $fileName, string $mediaType, string $content, int $file_sequence)
{
//망보드 파일관리 table에 등록
try {
- $entity = parent::save($content);
- if ($entity === null) {
+ $entity = parent::save($fileName, $mediaType, $content, $file_sequence);
+ if (!$entity) {
return null;
}
+ $entity = $this->getEntity();
$entity->user_pid = $this->getUser()->getPK();
$entity->user_name = $this->getUser()->getTitle();
$entity->board_name = $this->getBoardName();
$entity->table_name = $this->getBoardTable();
$entity->reg_date = date("Y-m-d H:i:s");
- return $this->getModel()->create($entity);
+ $entity->file_description = "Filedata";
+ $entity->setSequence($file_sequence);
+ $entity = $this->getModel()->create($entity);
+ return $entity;
} catch (\Exception $e) {
log_message("error", $e->getMessage());
return null;
}
}
+
+ public function updateFileEntityBoardPK(FileEntity $entity, BoardEntity $boardEntity): FileEntity
+ {
+ $entity->board_pid = $boardEntity->getPK();
+ return $this->getModel()->modify($entity);
+ }
}
diff --git a/app/Libraries/MyCrawler/MyCrawlerLibrary.php b/app/Libraries/MyCrawler/MyCrawlerLibrary.php
index 3719e37..ecad4c4 100644
--- a/app/Libraries/MyCrawler/MyCrawlerLibrary.php
+++ b/app/Libraries/MyCrawler/MyCrawlerLibrary.php
@@ -4,6 +4,7 @@ namespace App\Libraries\MyCrawler;
use Symfony\Component\DomCrawler\Crawler;
use App\Libraries\CommonLibrary;
+use App\Entities\Mangboard\FileEntity;
abstract class MyCrawlerLibrary extends CommonLibrary
{
@@ -35,57 +36,27 @@ abstract class MyCrawlerLibrary extends CommonLibrary
);
return $nodes;
}
- protected function getMediaTag(string $mediaType): string
+
+
+ //Download한 파일 저장후 추가작업시 사용
+ protected function download_process($entity, int $file_sequence)
{
- $mediaTag = "";
- switch ($mediaType) {
- case "image":
- $mediaTag = sprintf(
- "
",
- $this->getMyStorage()->getUploadPath(),
- $this->getMyStorage()->getEntity()->getPath(),
- $this->getMyStorage()->getEntity()->getTitle(),
- $this->getMyStorage()->getEntity()->getTitle()
- );
- break;
- case "video":
- $mediaTag = sprintf(
- "",
- $this->getMyStorage()->getEntity()->getTitle(),
- $this->getMyStorage()->getUploadPath(),
- $this->getMyStorage()->getEntity()->getPath(),
- $this->getMyStorage()->getEntity()->getTitle(),
- $this->getMyStorage()->getEntity()->getMimeType(),
- );
- break;
- }
- return $mediaTag;
+ return $entity;
}
- final protected function download(Crawler $crawler, array $options): array
+ final protected function download(string $mediaType, Crawler $crawler, array $options, array $entitys = []): array
{
- $downloadInfos = [];
$nodes = $this->getNodes($crawler, $options);
+ $file_sequence = 1;
foreach ($nodes as $node) {
- $url = $node->attr($options["attr"]);
- $downloadInfos[] = $this->getMySocket()->download($url);
- }
- return $downloadInfos;
- }
- protected function save(string $mediaType, array $downloadInfos, $fileEntitys = []): array
- {
- foreach ($downloadInfos as $downloadInfo) {
- $entity = $this->getMyStorage()->getEntity();
- $entity->setTitle($downloadInfo['fileName']);
- if (!$this->getMyStorage()->save($downloadInfo['content'])) {
+ list($fileName, $content) = $this->getMySocket()->download($node->attr($options["attr"]));
+ $entity = $this->getMyStorage()->save($fileName, $mediaType, $content, $file_sequence);
+ if ($entity === null) {
continue;
}
- $entity->setMediaHTML($this->getMediaTag($mediaType));
- $fileEntitys[] = $entity;
+ $entitys[] = $this->download_process($entity, $file_sequence);
+ $file_sequence++;
}
- return $fileEntitys;
+ return $entitys;
}
}
diff --git a/app/Libraries/MyCrawler/YamapLibrary.php b/app/Libraries/MyCrawler/YamapLibrary.php
index d751778..0f54374 100644
--- a/app/Libraries/MyCrawler/YamapLibrary.php
+++ b/app/Libraries/MyCrawler/YamapLibrary.php
@@ -34,8 +34,10 @@ class YamapLibrary extends MyCrawlerLibrary
{
if ($this->_myStorage === null) {
$this->_myStorage = new FileLibrary(getenv('yamap.storage.upload.path'));
+ //원래는 mb_board에서 해당Board정보를 읽어서 처리해아함
$this->_myStorage->setBoardName(getenv('yamap.storage.board.name'));
$this->_myStorage->setBoardTable($this->getBoardModel()->getTable());
+ $this->_myStorage->setBoardlevel(getenv('yamap.storage.board.level'));
}
return $this->_myStorage;
}
@@ -77,11 +79,9 @@ class YamapLibrary extends MyCrawlerLibrary
{
$crawler = $this->getContent($url, getenv("yamap.view.content.tag"));
//3. Image 처리
- $downloadInfos = $this->download($crawler, ["tag" => "img", "attr" => "src"]);
- $fileEntitys = $this->save("image", $downloadInfos);
+ $fileEntitys = $this->download("image", $crawler, ["tag" => "img", "attr" => "src"]);
//4. Video(mp4) 처리
- $downloadInfos = $this->download($crawler, ["tag" => "video", "attr" => "src"]);
- return $this->save("video", $downloadInfos, $fileEntitys);
+ return $this->download("video", $crawler, ["tag" => "video", "attr" => "src"], $fileEntitys);
}
private function createBoard(array $item, array $fileEntitys): BoardEntity
@@ -95,6 +95,7 @@ class YamapLibrary extends MyCrawlerLibrary
$entity->user_pid = $this->getMyStorage()->getUser()->getPK();
$entity->user_id = $this->getMyStorage()->getUser()->getID();
$entity->user_name = $item["nickname"] != "" ? $item["nickname"] : $this->getMyStorage()->getUser()->getTitle();
+ $entity->level = $this->getMyStorage()->getBoardLevel();
$entity->hit = $item['hit'];
$entity->reg_date = date("Y-m-d H:i:s", strtotime($item['date']));
$entity->data_type = "html";
@@ -107,8 +108,14 @@ class YamapLibrary extends MyCrawlerLibrary
// echo $entity->hit . "\n";
// echo $entity->reg_date . "\n";
// exit;
- //망보드에 넣기
- return $board->create($entity);
+ //망보드 게시판에 등록
+ $entity = $board->create($entity);
+
+ //망보드 파일관리툴에 등록된 파일게시물에 등록한 게시판번호 수정하기
+ foreach ($fileEntitys as $fileEntity) {
+ $this->getMyStorage()->updateFileEntityBoardPK($fileEntity, $entity);
+ }
+ return $entity;
}
public function execute(): void
diff --git a/app/Libraries/MySocket/WebLibrary.php b/app/Libraries/MySocket/WebLibrary.php
index f9b20c5..281e600 100644
--- a/app/Libraries/MySocket/WebLibrary.php
+++ b/app/Libraries/MySocket/WebLibrary.php
@@ -97,6 +97,6 @@ class WebLibrary extends MySocketLibrary
}
log_message("notice", "{$fileName} 파일이 다운로드되었습니다!");
}
- return ["fileName" => $fileName, "content" => $content];
+ return array($fileName, $content);
}
}
diff --git a/app/Libraries/MyStorage/FileLibrary.php b/app/Libraries/MyStorage/FileLibrary.php
index 9d4f608..ba448df 100644
--- a/app/Libraries/MyStorage/FileLibrary.php
+++ b/app/Libraries/MyStorage/FileLibrary.php
@@ -27,7 +27,37 @@ class FileLibrary extends MyStorageLibrary
return $this->_entity;
}
- public function save($content): null|FileEntity
+ private function getMediaTag(string $mediaType): string
+ {
+ $mediaTag = "";
+ switch ($mediaType) {
+ case "image":
+ $mediaTag = sprintf(
+ "
",
+ $this->getUploadPath(),
+ $this->getEntity()->getPath(),
+ $this->getEntity()->getTitle(),
+ $this->getEntity()->getTitle()
+ );
+ break;
+ case "video":
+ $mediaTag = sprintf(
+ "",
+ $this->getEntity()->getTitle(),
+ $this->getUploadPath(),
+ $this->getEntity()->getPath(),
+ $this->getEntity()->getTitle(),
+ $this->getEntity()->getMimeType(),
+ );
+ break;
+ }
+ return $mediaTag;
+ }
+
+ public function save(string $fileName, string $mediaType, string $content, int $file_sequence)
{
$fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath();
if (!is_dir($fullPath)) {
@@ -35,14 +65,16 @@ class FileLibrary extends MyStorageLibrary
throw new \Exception("Make Directory Error:" . $fullPath);
}
}
- $entity = $this->getEntity();
- $saveFile = $fullPath . DIRECTORY_SEPARATOR . $entity->getTitle();
- log_message("debug", "Storage Save-> " . $saveFile);
- if (!file_put_contents($saveFile, $content)) {
- return null;
+ $saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $fileName;
+ log_message("debug", "Storage Save-> " . $saveFilePath);
+ if (!file_put_contents($saveFilePath, $content)) {
+ return false;
}
- //File형식에 따른 MimeType 지정
- $entity->setMimeType(mime_content_type($saveFile));
+
+ $entity = $this->getEntity();
+ $entity->setTitle($fileName);
+ $entity->setMimeType(mime_content_type($saveFilePath));
+ $entity->setMediaHTML($this->getMediaTag($mediaType));
return $entity;
}
}
diff --git a/app/Libraries/MyStorage/MyStorageLibrary.php b/app/Libraries/MyStorage/MyStorageLibrary.php
index 8e64425..11f2b48 100644
--- a/app/Libraries/MyStorage/MyStorageLibrary.php
+++ b/app/Libraries/MyStorage/MyStorageLibrary.php
@@ -3,7 +3,6 @@
namespace App\Libraries\MyStorage;
use App\Libraries\CommonLibrary;
-use App\Entities\MyStorage\FileEntity;
abstract class MyStorageLibrary extends CommonLibrary
{
@@ -13,7 +12,7 @@ abstract class MyStorageLibrary extends CommonLibrary
parent::__construct();
}
- abstract public function save($content): null|FileEntity;
+ abstract public function save(string $fileName, string $mediaType, string $content, int $file_sequence);
final public function getUploadPath(): string
{
return $this->_uploadPath;
diff --git a/app/Models/Mangboard/BoardModel.php b/app/Models/Mangboard/BoardModel.php
index a880e10..9abfe64 100644
--- a/app/Models/Mangboard/BoardModel.php
+++ b/app/Models/Mangboard/BoardModel.php
@@ -75,7 +75,7 @@ class BoardModel extends CommonModel
public function __construct(string $table)
{
$this->table = $table;
- $fields = ["title", "user_pid", "user_id", "user_name", "data_type", "editor_type", "reg_date", "hit", "content"];
+ $fields = ["title", "user_pid", "user_id", "user_name", "level", "data_type", "editor_type", "reg_date", "hit", "content"];
parent::__construct($fields);
}
public function getTitleField(): string
@@ -101,6 +101,7 @@ class BoardModel extends CommonModel
$rules[$field] = "required|trim|string";
break;
case 'hit':
+ case 'level':
case 'user_pid':
$rules[$field] = "if_exist|numeric";
break;
diff --git a/app/Models/Mangboard/FileModel.php b/app/Models/Mangboard/FileModel.php
index 29f87fb..7f39758 100644
--- a/app/Models/Mangboard/FileModel.php
+++ b/app/Models/Mangboard/FileModel.php
@@ -38,7 +38,7 @@ class FileModel extends CommonModel
public function __construct()
{
- $fields = ["user_pid", "user_name", "board_name", "table_name", "file_name", "file_path", "file_type", "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
@@ -48,7 +48,9 @@ class FileModel extends CommonModel
public function getFieldRule(string $field, array $rules): array
{
switch ($field) {
+ case "board_pid":
case "user_pid":
+ case "file_sequence":
$rules[$field] = "if_exist|numeric";
break;
case "board_name":
@@ -58,6 +60,9 @@ class FileModel extends CommonModel
case "file_type":
$rules[$field] = "required|trim|string";
break;
+ case "file_description":
+ $rules[$field] = "if_exist|trim|string";
+ break;
case "reg_date":
$rules[$field] = "if_exist|valid_date";
break;