Automation init...2
This commit is contained in:
parent
eaf7986815
commit
2ab886919c
@ -16,4 +16,14 @@ class FileEntity extends ParentEntity
|
|||||||
{
|
{
|
||||||
return $this->attributes['pid'];
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,16 +3,18 @@
|
|||||||
namespace App\Libraries\Mangboard;
|
namespace App\Libraries\Mangboard;
|
||||||
|
|
||||||
|
|
||||||
use App\Libraries\MyStorage\FileLibrary as ParentLibrary;
|
|
||||||
use App\Models\Mangboard\FileModel;
|
use App\Models\Mangboard\FileModel;
|
||||||
|
use App\Libraries\MyStorage\FileLibrary as ParentLibrary;
|
||||||
use App\Entities\Mangboard\UserEntity;
|
use App\Entities\Mangboard\UserEntity;
|
||||||
use App\Entities\Mangboard\FileEntity;
|
use App\Entities\Mangboard\FileEntity;
|
||||||
|
use App\Entities\Mangboard\BoardEntity;
|
||||||
|
|
||||||
class FileLibrary extends ParentLibrary
|
class FileLibrary extends ParentLibrary
|
||||||
{
|
{
|
||||||
private $_user = null;
|
private $_user = null;
|
||||||
private $_boardName = "";
|
private $_boardName = "";
|
||||||
private $_boardTable = "";
|
private $_boardTable = "";
|
||||||
|
private $_boardLevel = 1;
|
||||||
private $_model = null;
|
private $_model = null;
|
||||||
public function __construct(string $path)
|
public function __construct(string $path)
|
||||||
{
|
{
|
||||||
@ -69,24 +71,46 @@ class FileLibrary extends ParentLibrary
|
|||||||
{
|
{
|
||||||
$this->_boardTable = $boardTable;
|
$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에 등록
|
//망보드 파일관리 table에 등록
|
||||||
try {
|
try {
|
||||||
$entity = parent::save($content);
|
$entity = parent::save($fileName, $mediaType, $content, $file_sequence);
|
||||||
if ($entity === null) {
|
if (!$entity) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
$entity = $this->getEntity();
|
||||||
$entity->user_pid = $this->getUser()->getPK();
|
$entity->user_pid = $this->getUser()->getPK();
|
||||||
$entity->user_name = $this->getUser()->getTitle();
|
$entity->user_name = $this->getUser()->getTitle();
|
||||||
$entity->board_name = $this->getBoardName();
|
$entity->board_name = $this->getBoardName();
|
||||||
$entity->table_name = $this->getBoardTable();
|
$entity->table_name = $this->getBoardTable();
|
||||||
$entity->reg_date = date("Y-m-d H:i:s");
|
$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) {
|
} catch (\Exception $e) {
|
||||||
log_message("error", $e->getMessage());
|
log_message("error", $e->getMessage());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function updateFileEntityBoardPK(FileEntity $entity, BoardEntity $boardEntity): FileEntity
|
||||||
|
{
|
||||||
|
$entity->board_pid = $boardEntity->getPK();
|
||||||
|
return $this->getModel()->modify($entity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ namespace App\Libraries\MyCrawler;
|
|||||||
|
|
||||||
use Symfony\Component\DomCrawler\Crawler;
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
use App\Libraries\CommonLibrary;
|
use App\Libraries\CommonLibrary;
|
||||||
|
use App\Entities\Mangboard\FileEntity;
|
||||||
|
|
||||||
abstract class MyCrawlerLibrary extends CommonLibrary
|
abstract class MyCrawlerLibrary extends CommonLibrary
|
||||||
{
|
{
|
||||||
@ -35,57 +36,27 @@ abstract class MyCrawlerLibrary extends CommonLibrary
|
|||||||
);
|
);
|
||||||
return $nodes;
|
return $nodes;
|
||||||
}
|
}
|
||||||
protected function getMediaTag(string $mediaType): string
|
|
||||||
|
|
||||||
|
//Download한 파일 저장후 추가작업시 사용
|
||||||
|
protected function download_process($entity, int $file_sequence)
|
||||||
{
|
{
|
||||||
$mediaTag = "";
|
return $entity;
|
||||||
switch ($mediaType) {
|
|
||||||
case "image":
|
|
||||||
$mediaTag = sprintf(
|
|
||||||
"<img src=\"/%s/%s/%s\" alt=\"%s\">",
|
|
||||||
$this->getMyStorage()->getUploadPath(),
|
|
||||||
$this->getMyStorage()->getEntity()->getPath(),
|
|
||||||
$this->getMyStorage()->getEntity()->getTitle(),
|
|
||||||
$this->getMyStorage()->getEntity()->getTitle()
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case "video":
|
|
||||||
$mediaTag = sprintf(
|
|
||||||
"<video alt=\"%s\" controls autoplay>
|
|
||||||
<source src=\"/%s/%s/%s\" type=\"%s\">
|
|
||||||
Your browser does not support the video tag.
|
|
||||||
</video>",
|
|
||||||
$this->getMyStorage()->getEntity()->getTitle(),
|
|
||||||
$this->getMyStorage()->getUploadPath(),
|
|
||||||
$this->getMyStorage()->getEntity()->getPath(),
|
|
||||||
$this->getMyStorage()->getEntity()->getTitle(),
|
|
||||||
$this->getMyStorage()->getEntity()->getMimeType(),
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return $mediaTag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
$nodes = $this->getNodes($crawler, $options);
|
||||||
|
$file_sequence = 1;
|
||||||
foreach ($nodes as $node) {
|
foreach ($nodes as $node) {
|
||||||
$url = $node->attr($options["attr"]);
|
list($fileName, $content) = $this->getMySocket()->download($node->attr($options["attr"]));
|
||||||
$downloadInfos[] = $this->getMySocket()->download($url);
|
$entity = $this->getMyStorage()->save($fileName, $mediaType, $content, $file_sequence);
|
||||||
}
|
if ($entity === null) {
|
||||||
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'])) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$entity->setMediaHTML($this->getMediaTag($mediaType));
|
$entitys[] = $this->download_process($entity, $file_sequence);
|
||||||
$fileEntitys[] = $entity;
|
$file_sequence++;
|
||||||
}
|
}
|
||||||
return $fileEntitys;
|
return $entitys;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,8 +34,10 @@ class YamapLibrary extends MyCrawlerLibrary
|
|||||||
{
|
{
|
||||||
if ($this->_myStorage === null) {
|
if ($this->_myStorage === null) {
|
||||||
$this->_myStorage = new FileLibrary(getenv('yamap.storage.upload.path'));
|
$this->_myStorage = new FileLibrary(getenv('yamap.storage.upload.path'));
|
||||||
|
//원래는 mb_board에서 해당Board정보를 읽어서 처리해아함
|
||||||
$this->_myStorage->setBoardName(getenv('yamap.storage.board.name'));
|
$this->_myStorage->setBoardName(getenv('yamap.storage.board.name'));
|
||||||
$this->_myStorage->setBoardTable($this->getBoardModel()->getTable());
|
$this->_myStorage->setBoardTable($this->getBoardModel()->getTable());
|
||||||
|
$this->_myStorage->setBoardlevel(getenv('yamap.storage.board.level'));
|
||||||
}
|
}
|
||||||
return $this->_myStorage;
|
return $this->_myStorage;
|
||||||
}
|
}
|
||||||
@ -77,11 +79,9 @@ class YamapLibrary extends MyCrawlerLibrary
|
|||||||
{
|
{
|
||||||
$crawler = $this->getContent($url, getenv("yamap.view.content.tag"));
|
$crawler = $this->getContent($url, getenv("yamap.view.content.tag"));
|
||||||
//3. Image 처리
|
//3. Image 처리
|
||||||
$downloadInfos = $this->download($crawler, ["tag" => "img", "attr" => "src"]);
|
$fileEntitys = $this->download("image", $crawler, ["tag" => "img", "attr" => "src"]);
|
||||||
$fileEntitys = $this->save("image", $downloadInfos);
|
|
||||||
//4. Video(mp4) 처리
|
//4. Video(mp4) 처리
|
||||||
$downloadInfos = $this->download($crawler, ["tag" => "video", "attr" => "src"]);
|
return $this->download("video", $crawler, ["tag" => "video", "attr" => "src"], $fileEntitys);
|
||||||
return $this->save("video", $downloadInfos, $fileEntitys);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createBoard(array $item, array $fileEntitys): BoardEntity
|
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_pid = $this->getMyStorage()->getUser()->getPK();
|
||||||
$entity->user_id = $this->getMyStorage()->getUser()->getID();
|
$entity->user_id = $this->getMyStorage()->getUser()->getID();
|
||||||
$entity->user_name = $item["nickname"] != "" ? $item["nickname"] : $this->getMyStorage()->getUser()->getTitle();
|
$entity->user_name = $item["nickname"] != "" ? $item["nickname"] : $this->getMyStorage()->getUser()->getTitle();
|
||||||
|
$entity->level = $this->getMyStorage()->getBoardLevel();
|
||||||
$entity->hit = $item['hit'];
|
$entity->hit = $item['hit'];
|
||||||
$entity->reg_date = date("Y-m-d H:i:s", strtotime($item['date']));
|
$entity->reg_date = date("Y-m-d H:i:s", strtotime($item['date']));
|
||||||
$entity->data_type = "html";
|
$entity->data_type = "html";
|
||||||
@ -107,8 +108,14 @@ class YamapLibrary extends MyCrawlerLibrary
|
|||||||
// echo $entity->hit . "\n";
|
// echo $entity->hit . "\n";
|
||||||
// echo $entity->reg_date . "\n";
|
// echo $entity->reg_date . "\n";
|
||||||
// exit;
|
// exit;
|
||||||
//망보드에 넣기
|
//망보드 게시판에 등록
|
||||||
return $board->create($entity);
|
$entity = $board->create($entity);
|
||||||
|
|
||||||
|
//망보드 파일관리툴에 등록된 파일게시물에 등록한 게시판번호 수정하기
|
||||||
|
foreach ($fileEntitys as $fileEntity) {
|
||||||
|
$this->getMyStorage()->updateFileEntityBoardPK($fileEntity, $entity);
|
||||||
|
}
|
||||||
|
return $entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(): void
|
public function execute(): void
|
||||||
|
|||||||
@ -97,6 +97,6 @@ class WebLibrary extends MySocketLibrary
|
|||||||
}
|
}
|
||||||
log_message("notice", "{$fileName} 파일이 다운로드되었습니다!");
|
log_message("notice", "{$fileName} 파일이 다운로드되었습니다!");
|
||||||
}
|
}
|
||||||
return ["fileName" => $fileName, "content" => $content];
|
return array($fileName, $content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,7 +27,37 @@ class FileLibrary extends MyStorageLibrary
|
|||||||
return $this->_entity;
|
return $this->_entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function save($content): null|FileEntity
|
private function getMediaTag(string $mediaType): string
|
||||||
|
{
|
||||||
|
$mediaTag = "";
|
||||||
|
switch ($mediaType) {
|
||||||
|
case "image":
|
||||||
|
$mediaTag = sprintf(
|
||||||
|
"<img src=\"/%s/%s/%s\" alt=\"%s\">",
|
||||||
|
$this->getUploadPath(),
|
||||||
|
$this->getEntity()->getPath(),
|
||||||
|
$this->getEntity()->getTitle(),
|
||||||
|
$this->getEntity()->getTitle()
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case "video":
|
||||||
|
$mediaTag = sprintf(
|
||||||
|
"<video alt=\"%s\" controls autoplay>
|
||||||
|
<source src=\"/%s/%s/%s\" type=\"%s\">
|
||||||
|
Your browser does not support the video tag.
|
||||||
|
</video>",
|
||||||
|
$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();
|
$fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath();
|
||||||
if (!is_dir($fullPath)) {
|
if (!is_dir($fullPath)) {
|
||||||
@ -35,14 +65,16 @@ class FileLibrary extends MyStorageLibrary
|
|||||||
throw new \Exception("Make Directory Error:" . $fullPath);
|
throw new \Exception("Make Directory Error:" . $fullPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$entity = $this->getEntity();
|
$saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $fileName;
|
||||||
$saveFile = $fullPath . DIRECTORY_SEPARATOR . $entity->getTitle();
|
log_message("debug", "Storage Save-> " . $saveFilePath);
|
||||||
log_message("debug", "Storage Save-> " . $saveFile);
|
if (!file_put_contents($saveFilePath, $content)) {
|
||||||
if (!file_put_contents($saveFile, $content)) {
|
return false;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
//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;
|
return $entity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
namespace App\Libraries\MyStorage;
|
namespace App\Libraries\MyStorage;
|
||||||
|
|
||||||
use App\Libraries\CommonLibrary;
|
use App\Libraries\CommonLibrary;
|
||||||
use App\Entities\MyStorage\FileEntity;
|
|
||||||
|
|
||||||
abstract class MyStorageLibrary extends CommonLibrary
|
abstract class MyStorageLibrary extends CommonLibrary
|
||||||
{
|
{
|
||||||
@ -13,7 +12,7 @@ abstract class MyStorageLibrary extends CommonLibrary
|
|||||||
parent::__construct();
|
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
|
final public function getUploadPath(): string
|
||||||
{
|
{
|
||||||
return $this->_uploadPath;
|
return $this->_uploadPath;
|
||||||
|
|||||||
@ -75,7 +75,7 @@ class BoardModel extends CommonModel
|
|||||||
public function __construct(string $table)
|
public function __construct(string $table)
|
||||||
{
|
{
|
||||||
$this->table = $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);
|
parent::__construct($fields);
|
||||||
}
|
}
|
||||||
public function getTitleField(): string
|
public function getTitleField(): string
|
||||||
@ -101,6 +101,7 @@ class BoardModel extends CommonModel
|
|||||||
$rules[$field] = "required|trim|string";
|
$rules[$field] = "required|trim|string";
|
||||||
break;
|
break;
|
||||||
case 'hit':
|
case 'hit':
|
||||||
|
case 'level':
|
||||||
case 'user_pid':
|
case 'user_pid':
|
||||||
$rules[$field] = "if_exist|numeric";
|
$rules[$field] = "if_exist|numeric";
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -38,7 +38,7 @@ class FileModel extends CommonModel
|
|||||||
|
|
||||||
public function __construct()
|
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);
|
parent::__construct($fields);
|
||||||
}
|
}
|
||||||
public function getTitleField(): string
|
public function getTitleField(): string
|
||||||
@ -48,7 +48,9 @@ class FileModel extends CommonModel
|
|||||||
public function getFieldRule(string $field, array $rules): array
|
public function getFieldRule(string $field, array $rules): array
|
||||||
{
|
{
|
||||||
switch ($field) {
|
switch ($field) {
|
||||||
|
case "board_pid":
|
||||||
case "user_pid":
|
case "user_pid":
|
||||||
|
case "file_sequence":
|
||||||
$rules[$field] = "if_exist|numeric";
|
$rules[$field] = "if_exist|numeric";
|
||||||
break;
|
break;
|
||||||
case "board_name":
|
case "board_name":
|
||||||
@ -58,6 +60,9 @@ class FileModel extends CommonModel
|
|||||||
case "file_type":
|
case "file_type":
|
||||||
$rules[$field] = "required|trim|string";
|
$rules[$field] = "required|trim|string";
|
||||||
break;
|
break;
|
||||||
|
case "file_description":
|
||||||
|
$rules[$field] = "if_exist|trim|string";
|
||||||
|
break;
|
||||||
case "reg_date":
|
case "reg_date":
|
||||||
$rules[$field] = "if_exist|valid_date";
|
$rules[$field] = "if_exist|valid_date";
|
||||||
break;
|
break;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user