Automation init...3
This commit is contained in:
parent
0bb878409f
commit
f72a46d180
@ -17,10 +17,10 @@ class CrawlerController extends CommonController
|
|||||||
//1. 사이트 로그인 처리
|
//1. 사이트 로그인 처리
|
||||||
$user = $crawler->login();
|
$user = $crawler->login();
|
||||||
$crawler->getMyStorage()->setUser($user);
|
$crawler->getMyStorage()->setUser($user);
|
||||||
$items = [];
|
$itemInfos = [];
|
||||||
//2. 해당사이트 MainPage 처리
|
//2. 해당사이트 MainPage 처리
|
||||||
if ($crawler->getDebug()) {
|
if ($crawler->getDebug()) {
|
||||||
$items[] = [
|
$itemInfos[] = [
|
||||||
'title' => getenv("yamap.view.test.title"),
|
'title' => getenv("yamap.view.test.title"),
|
||||||
'nickname' => getenv("yamap.view.test.nickname"),
|
'nickname' => getenv("yamap.view.test.nickname"),
|
||||||
'detail_url' => getenv("yamap.view.test.url"),
|
'detail_url' => getenv("yamap.view.test.url"),
|
||||||
@ -28,30 +28,25 @@ class CrawlerController extends CommonController
|
|||||||
'hit' => 1
|
'hit' => 1
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
$items = $crawler->mainPage(getenv("yamap.list.url"));
|
$itemInfos = $crawler->mainPage(getenv("yamap.list.url"));
|
||||||
}
|
}
|
||||||
if (!count($items)) {
|
if (!count($itemInfos)) {
|
||||||
throw new \Exception("Yamap 사이트에서 게시물이 존재하지 않습니다.");
|
throw new \Exception("Yamap 사이트에서 게시물이 존재하지 않습니다.");
|
||||||
}
|
}
|
||||||
//Limit가 0이면 $items 갯수만큼 다하고, LIMIT 갯수 혹은 $items의 갯수중 작은수만큼 한다.
|
//Limit가 0이면 $itemInfos 갯수만큼 다하고, LIMIT 갯수 혹은 $items의 갯수중 작은수만큼 한다.
|
||||||
$max_limit = intval(getenv("yamap.list.max_limit"));
|
$max_limit = intval(getenv("yamap.list.max_limit"));
|
||||||
if ($max_limit) {
|
if ($max_limit) {
|
||||||
$max_limit = count($items) <= $max_limit ? count($items) : $max_limit;
|
$max_limit = count($itemInfos) <= $max_limit ? count($itemInfos) : $max_limit;
|
||||||
} else {
|
} else {
|
||||||
$max_limit = count($items);
|
$max_limit = count($itemInfos);
|
||||||
}
|
}
|
||||||
$i = 1;
|
$i = 1;
|
||||||
foreach ($items as $item) {
|
foreach ($itemInfos as $itemInfo) {
|
||||||
if ($i < $max_limit) {
|
if ($i < $max_limit) {
|
||||||
try {
|
try {
|
||||||
log_message("notice", "게시물 {$i}번째 {$item["nickname"]} 작업시작");
|
log_message("notice", "게시물 {$i}번째 {$itemInfo["nickname"]} 작업시작");
|
||||||
//3. DetailPage 처리 : bbs_view > div.contents 가진 객체를 찾아서 처리
|
$crawler->detailPage($itemInfo);
|
||||||
$fileEntitys = $crawler->detailPage($item["detail_url"]);
|
log_message("notice", "게시물 {$i}번째 {$itemInfo["nickname"]} 작업완료.");
|
||||||
//4.망보드 일반게시판에 게시물 등록 처리
|
|
||||||
if (count($fileEntitys)) {
|
|
||||||
$crawler->createBoard($item, $fileEntitys);
|
|
||||||
}
|
|
||||||
log_message("notice", "게시물 {$i}번째 {$item["nickname"]} 작업완료.");
|
|
||||||
$i++;
|
$i++;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
log_message("debug", $e->getMessage());
|
log_message("debug", $e->getMessage());
|
||||||
|
|||||||
@ -37,25 +37,29 @@ abstract class MyCrawlerLibrary extends CommonLibrary
|
|||||||
|
|
||||||
|
|
||||||
//Download한 파일 저장후 추가작업시 사용
|
//Download한 파일 저장후 추가작업시 사용
|
||||||
final protected function download(string $mediaType, Crawler $crawler, array $options, array $entitys = []): array
|
final protected function download(string $mediaType, Crawler $crawler, array $options, array $results = []): array
|
||||||
{
|
{
|
||||||
$nodes = $this->getNodes($crawler, $options);
|
$nodes = $this->getNodes($crawler, $options);
|
||||||
$file_sequence = 1;
|
$file_sequence = 1;
|
||||||
foreach ($nodes as $node) {
|
foreach ($nodes as $node) {
|
||||||
try {
|
try {
|
||||||
list($fileName, $content) = $this->getMySocket()->download($node->attr($options["attr"]));
|
list($fileName, $content) = $this->getMySocket()->download($node->attr($options["attr"]));
|
||||||
$entitys[] = $this->getMyStorage()->save($fileName, $mediaType, $content, $file_sequence);
|
$this->getMyStorage()->setOriginName($fileName);
|
||||||
|
$this->getMyStorage()->setOriginContent($content);
|
||||||
|
$this->getMyStorage()->setOriginType($mediaType);
|
||||||
|
$this->getMyStorage()->setOriginSequence($file_sequence);
|
||||||
|
$results[] = $this->getMyStorage()->save();
|
||||||
$file_sequence++;
|
$file_sequence++;
|
||||||
log_message("notice", __FUNCTION__ . " MediaType->{$mediaType} 작업 완료");
|
log_message("notice", __FUNCTION__ . " OriginType->{$mediaType} 작업 완료");
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
log_message("warning", sprintf(
|
log_message("warning", sprintf(
|
||||||
"\n---%s,MediaType->%s 오류---\n%s\n-----------------------------------------\n",
|
"\n---%s,OriginType->%s 오류---\n%s\n-----------------------------------------\n",
|
||||||
__FUNCTION__,
|
__FUNCTION__,
|
||||||
$mediaType,
|
$mediaType,
|
||||||
$e->getMessage()
|
$e->getMessage()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $entitys;
|
return $results;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -95,48 +95,46 @@ class YamapLibrary extends MyCrawlerLibrary
|
|||||||
return $items;
|
return $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function detailPage(string $url, array $fileEntitys = []): array
|
private function createBoard(array $itemInfo, array $myStorageLibrarys): void
|
||||||
{
|
|
||||||
$crawler = $this->getContent($url, getenv("yamap.view.content.tag"));
|
|
||||||
//3. Image 처리
|
|
||||||
$fileEntitys = $this->download("image", $crawler, ["tag" => "img", "attr" => "src"]);
|
|
||||||
//4. Video(mp4) 처리
|
|
||||||
$fileEntitys = $this->download("video", $crawler, ["tag" => "video", "attr" => "src"], $fileEntitys);
|
|
||||||
log_message("notice", __FUNCTION__ . " 작업 완료");
|
|
||||||
return $fileEntitys;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function createBoard(array $item, array $fileEntitys): BoardEntity
|
|
||||||
{
|
{
|
||||||
//미디어관련정보 entity에 넣기
|
//미디어관련정보 entity에 넣기
|
||||||
$entity = new BoardEntity();
|
$formDatas = [];
|
||||||
$entity->title = $item["title"];
|
$formDatas['title'] = $itemInfo["title"];
|
||||||
$entity->user_pid = $this->getMyStorage()->getUser()->getPK();
|
$formDatas['user_pid'] = $this->getMyStorage()->getUser()->getPK();
|
||||||
$entity->user_id = $this->getMyStorage()->getUser()->getID();
|
$formDatas['user_id'] = $this->getMyStorage()->getUser()->getID();
|
||||||
$entity->user_name = $item["nickname"] != "" ? $item["nickname"] : $this->getMyStorage()->getUser()->getTitle();
|
$formDatas['user_name'] = $itemInfo["nickname"] != "" ? $itemInfo["nickname"] : $this->getMyStorage()->getUser()->getTitle();
|
||||||
$entity->level = $this->getMyStorage()->getBoardLevel();
|
$formDatas['level'] = $this->getMyStorage()->getBoardLevel();
|
||||||
$entity->hit = $item['hit'];
|
$formDatas['hit'] = $itemInfo['hit'];
|
||||||
$entity->reg_date = date("Y-m-d H:i:s", strtotime($item['date']));
|
$formDatas['reg_date'] = date("Y-m-d H:i:s", strtotime($itemInfo['date']));
|
||||||
$entity->data_type = "html";
|
$formDatas['data_type'] = "html";
|
||||||
$entity->editor_type = "S";
|
$formDatas['editor_type'] = "S";
|
||||||
$entity->image_path = false;
|
$formDatas['image_path'] = false;
|
||||||
foreach ($fileEntitys as $fileEntity) {
|
foreach ($myStorageLibrarys as $myStorageLibrary) {
|
||||||
if ($entity->image_path === false) {
|
if ($formDatas['image_path'] === false) {
|
||||||
$entity->image_path = $fileEntity->getPath();
|
$formDatas['image_path'] = $myStorageLibrary->getFileEntity()->getPath();
|
||||||
}
|
}
|
||||||
$entity->content .= $fileEntity->getMediaHTML();
|
$formDatas['content'] .= $myStorageLibrary->getFileEntity()->getMediaHTML();
|
||||||
}
|
}
|
||||||
// echo $entity->image_path . "\n";
|
|
||||||
// echo $entity->title . "\n";
|
|
||||||
// echo $entity->user_name . "\n";
|
|
||||||
// echo $entity->hit . "\n";
|
|
||||||
// echo $entity->reg_date . "\n";
|
|
||||||
// exit;
|
|
||||||
//망보드 게시판에 등록
|
//망보드 게시판에 등록
|
||||||
$entity = $this->getBoardModel()->create($entity);
|
$entity = $this->getBoardModel()->create($formDatas);
|
||||||
//망보드 파일관리툴에 등록된 파일게시물에 등록한 게시판번호 수정하기
|
//망보드 파일관리툴에 등록된 파일게시물에 등록한 게시판번호 수정하기
|
||||||
$this->getMyStorage()->setBoardPID($fileEntitys, intval($entity->getPK()));
|
foreach ($myStorageLibrarys as $myStorageLibrary) {
|
||||||
|
$myStorageLibrary->setBoardPID(intval($entity->getPK()));
|
||||||
|
}
|
||||||
log_message("notice", __FUNCTION__ . " 작업 완료");
|
log_message("notice", __FUNCTION__ . " 작업 완료");
|
||||||
return $entity;
|
}
|
||||||
|
|
||||||
|
public function detailPage(array $itemInfo)
|
||||||
|
{
|
||||||
|
$crawler = $this->getContent($itemInfo['detail_url'], getenv("yamap.view.content.tag"));
|
||||||
|
//3. Image 처리
|
||||||
|
$myStorageLibrarys = $this->download("image", $crawler, ["tag" => "img", "attr" => "src"]);
|
||||||
|
//4. Video(mp4) 처리
|
||||||
|
$myStorageLibrarys = $this->download("video", $crawler, ["tag" => "video", "attr" => "src"], $myStorageLibrarys);
|
||||||
|
log_message("notice", __FUNCTION__ . " 작업 완료");
|
||||||
|
//5.망보드 일반게시판에 게시물 등록 처리
|
||||||
|
if (count($myStorageLibrarys)) {
|
||||||
|
$this->createBoard($itemInfo, $myStorageLibrarys);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,23 +9,32 @@ class FileLibrary extends MyStorageLibrary
|
|||||||
{
|
{
|
||||||
use FileTrait;
|
use FileTrait;
|
||||||
private $_path = "";
|
private $_path = "";
|
||||||
|
private $_mimeType = "";
|
||||||
|
private $_fileSize = 0;
|
||||||
|
private $_fileSequence = 0;
|
||||||
private $_imageLibrary = null;
|
private $_imageLibrary = null;
|
||||||
public function __construct(string $path)
|
public function __construct(string $path)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->_path = $path;
|
$this->_path = $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
final public function getPath(): string
|
final public function getPath(): string
|
||||||
{
|
{
|
||||||
return $this->_path;
|
return $this->_path;
|
||||||
}
|
}
|
||||||
public function createFileEntity(): FileEntity
|
final public function getMimeType(): string
|
||||||
{
|
{
|
||||||
return new FileEntity();
|
return $this->_mimeType;
|
||||||
}
|
}
|
||||||
|
final public function getFileSize(): int
|
||||||
protected function getMediaTag(string $mediaType, FileEntity $entity): string
|
{
|
||||||
|
return $this->_fileSize;
|
||||||
|
}
|
||||||
|
final public function getFileSequence(): int
|
||||||
|
{
|
||||||
|
return $this->_fileSequence;
|
||||||
|
}
|
||||||
|
protected function getMediaTag(string $mediaType): string
|
||||||
{
|
{
|
||||||
$mediaTag = "";
|
$mediaTag = "";
|
||||||
switch ($mediaType) {
|
switch ($mediaType) {
|
||||||
@ -33,9 +42,9 @@ class FileLibrary extends MyStorageLibrary
|
|||||||
$mediaTag = sprintf(
|
$mediaTag = sprintf(
|
||||||
"<img src=\"/%s/%s/%s\" alt=\"%s\">",
|
"<img src=\"/%s/%s/%s\" alt=\"%s\">",
|
||||||
$this->getUploadPath(),
|
$this->getUploadPath(),
|
||||||
$entity->getPath(),
|
$this->getPath(),
|
||||||
$entity->getTitle(),
|
$this->getOriginName(),
|
||||||
$entity->getTitle()
|
$this->getOriginName()
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case "video":
|
case "video":
|
||||||
@ -44,37 +53,31 @@ class FileLibrary extends MyStorageLibrary
|
|||||||
<source src=\"/%s/%s/%s\" type=\"%s\">
|
<source src=\"/%s/%s/%s\" type=\"%s\">
|
||||||
Your browser does not support the video tag.
|
Your browser does not support the video tag.
|
||||||
</video>",
|
</video>",
|
||||||
$entity->getTitle(),
|
$this->getOriginName(),
|
||||||
$this->getUploadPath(),
|
$this->getUploadPath(),
|
||||||
$entity->getPath(),
|
$this->getPath(),
|
||||||
$entity->getTitle(),
|
$this->getOriginName(),
|
||||||
$entity->getMimeType(),
|
$this->getMimeType(),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return $mediaTag;
|
return $mediaTag;
|
||||||
}
|
}
|
||||||
|
public function save(): static
|
||||||
public function save(string $fileName, string $mediaType, string $content, int $file_sequence): FileEntity
|
|
||||||
{
|
{
|
||||||
$fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath();
|
$fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath();
|
||||||
$this->makeDirectory($fullPath);
|
$this->makeDirectory($fullPath);
|
||||||
$saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $fileName;
|
$saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $this->getOriginName();
|
||||||
if (file_exists($saveFilePath)) {
|
if (file_exists($saveFilePath)) {
|
||||||
throw new \Exception(__FUNCTION__ . " 이미 존재하는 파일:{$saveFilePath}");
|
throw new \Exception(__FUNCTION__ . " 이미 존재하는 파일:{$saveFilePath}");
|
||||||
}
|
}
|
||||||
//원본이미지 저장
|
//원본이미지 저장
|
||||||
if (!file_put_contents($saveFilePath, $content)) {
|
if (!file_put_contents($saveFilePath, $this->getOriginContent())) {
|
||||||
throw new \Exception(__FUNCTION__ . " 파일저장 실패:{$saveFilePath}");
|
throw new \Exception(__FUNCTION__ . " 파일저장 실패:{$saveFilePath}");
|
||||||
}
|
}
|
||||||
$entity = $this->createFileEntity();
|
$this->_mimeType = mime_content_type($saveFilePath);
|
||||||
$entity->setPath($this->getPath());
|
$this->_fileSize = filesize($saveFilePath);
|
||||||
$entity->setTitle($fileName);
|
log_message("notice", __FUNCTION__ . " 원본파일 {$this->getOriginName()} 작업 완료");
|
||||||
$entity->setMimeType(mime_content_type($saveFilePath));
|
return $this;
|
||||||
$entity->setSize(filesize($saveFilePath));
|
|
||||||
$entity->setSequence($file_sequence);
|
|
||||||
$entity->setMediaHTML($this->getMediaTag($mediaType, $entity));
|
|
||||||
log_message("notice", __FUNCTION__ . " 원본 {$file_sequence}번째 " . $entity->getTitle() . " 작업 완료");
|
|
||||||
return $entity;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,10 +15,19 @@ class FileLibrary extends MyStorageLibrary
|
|||||||
private $_boardTable = "";
|
private $_boardTable = "";
|
||||||
private $_boardLevel = 1;
|
private $_boardLevel = 1;
|
||||||
private $_model = null;
|
private $_model = null;
|
||||||
|
private $_fileEntity = null;
|
||||||
public function __construct(string $path)
|
public function __construct(string $path)
|
||||||
{
|
{
|
||||||
parent::__construct($path);
|
parent::__construct($path);
|
||||||
}
|
}
|
||||||
|
public function getFileEntity(): FileEntity
|
||||||
|
{
|
||||||
|
return $this->_fileEntity;
|
||||||
|
}
|
||||||
|
private function setFileEntity(FileEntity $fileEntity): void
|
||||||
|
{
|
||||||
|
$this->_fileEntity = $fileEntity;
|
||||||
|
}
|
||||||
public function getModel(): FileModel
|
public function getModel(): FileModel
|
||||||
{
|
{
|
||||||
if ($this->_model === null) {
|
if ($this->_model === null) {
|
||||||
@ -71,24 +80,16 @@ class FileLibrary extends MyStorageLibrary
|
|||||||
$this->_boardLevel = $boardLevel;
|
$this->_boardLevel = $boardLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
//주의:Override함
|
|
||||||
public function createFileEntity(): FileEntity
|
|
||||||
{
|
|
||||||
return new FileEntity();
|
|
||||||
}
|
|
||||||
|
|
||||||
//망보드 Board Table생성 후 관련된 mb_files Table에 Board번호를 넣기 위함
|
//망보드 Board Table생성 후 관련된 mb_files Table에 Board번호를 넣기 위함
|
||||||
public function setBoardPID(array $fileEntitys, int $board_pid): void
|
public function setBoardPID(int $board_pid): void
|
||||||
{
|
{
|
||||||
foreach ($fileEntitys as $fileEntity) {
|
$formDatas['board_pid'] = $board_pid;
|
||||||
$formDatas['board_pid'] = $board_pid;
|
$this->getModel()->modify($this->getFileEntity(), $formDatas);
|
||||||
$this->getModel()->modify($fileEntity, $formDatas);
|
|
||||||
}
|
|
||||||
log_message("notice", __FUNCTION__ . " 작업 완료");
|
log_message("notice", __FUNCTION__ . " 작업 완료");
|
||||||
}
|
}
|
||||||
|
|
||||||
//작은이미지 생성
|
//작은이미지 생성
|
||||||
private function save_small_image(FileEntity $entity, string $file, int $width = 480, int $height = 319): FileEntity
|
private function save_small_image(int $width = 480, int $height = 319): bool
|
||||||
{
|
{
|
||||||
$fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath();
|
$fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath();
|
||||||
$image = new ImageLibrary();
|
$image = new ImageLibrary();
|
||||||
@ -96,71 +97,78 @@ class FileLibrary extends MyStorageLibrary
|
|||||||
$image->setSourcePath($fullPath);
|
$image->setSourcePath($fullPath);
|
||||||
$image->setDestinationPath($fullPath);
|
$image->setDestinationPath($fullPath);
|
||||||
//저장파일명
|
//저장파일명
|
||||||
$fileInfos = pathinfo($image->getDestinationPath() . DIRECTORY_SEPARATOR . $file, PATHINFO_ALL);
|
$fileInfos = pathinfo($image->getDestinationPath() . DIRECTORY_SEPARATOR . $this->getOriginName(), PATHINFO_ALL);
|
||||||
$dstFile = $fileInfos['filename'] . "_small." . $fileInfos['extension'];
|
$dstFile = $fileInfos['filename'] . "_small." . $fileInfos['extension'];
|
||||||
$image->setDestinationFile($dstFile);
|
$image->setDestinationFile($dstFile);
|
||||||
$result = $image->create($file, $width, $height);
|
$result = $image->create($this->getOriginName(), $width, $height);
|
||||||
//개인적인 생각방식
|
|
||||||
// if ($result) {
|
|
||||||
// //작은이미지 생성후 목적지 Path와 파일명을 다시 file_path에 넣는다. URL이 되기때문에 /로 넣어야함
|
|
||||||
// $entity->setPath(sprintf(
|
|
||||||
// "%s/%s",
|
|
||||||
// $entity->getPath(),
|
|
||||||
// $image->getDestinationFile()
|
|
||||||
// ));
|
|
||||||
// } else {
|
|
||||||
// //원본이미지 생성후 목적지 Path와 파일명을 다시 file_path에 넣는다. URL이 되기때문에 /로 넣어야함
|
|
||||||
// $entity->setPath(sprintf(
|
|
||||||
// "%s/%s",
|
|
||||||
// $entity->getPath(),
|
|
||||||
// $entity->getTitle()
|
|
||||||
// ));
|
|
||||||
// }
|
|
||||||
//개인적인 생각방식
|
|
||||||
//
|
|
||||||
//망보드 방식
|
|
||||||
//mb_files에서 file_path가 망보드 게시판 파일관리에서 image로 표시되어 file_path+file_name로 설정
|
|
||||||
//원본이미지 생성후 목적지 Path와 파일명을 다시 file_path에 넣는다. URL이 되기때문에 /로 넣어야함
|
|
||||||
$entity->setPath(sprintf(
|
|
||||||
"%s/%s",
|
|
||||||
$entity->getPath(),
|
|
||||||
$entity->getTitle()
|
|
||||||
));
|
|
||||||
//망보드 방식
|
|
||||||
log_message("notice", sprintf(
|
log_message("notice", sprintf(
|
||||||
"%s %s번째:%s 작업 완료",
|
"%s %s번째:%s 작업 완료",
|
||||||
__FUNCTION__,
|
__FUNCTION__,
|
||||||
$entity->getSequence(),
|
$this->getOriginSequence(),
|
||||||
$entity->getPath()
|
$this->getPath()
|
||||||
));
|
));
|
||||||
return $entity;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//망보드 파일관리 table에 등록
|
//망보드 파일관리 table에 등록
|
||||||
private function save_db(FileEntity $entity): FileEntity
|
private function save_db(array $formDatas): FileEntity
|
||||||
{
|
{
|
||||||
// log_message("notice", sprintf("%s %s번째 작업 시작",__FUNCTION__ ,$entity->getSequence()));
|
$formDatas['user_pid'] = $this->getUser()->getPK();
|
||||||
$entity->user_pid = $this->getUser()->getPK();
|
$formDatas['user_name'] = $this->getUser()->getTitle();
|
||||||
$entity->user_name = $this->getUser()->getTitle();
|
$formDatas['board_name'] = $this->getBoardName();
|
||||||
$entity->board_name = $this->getBoardName();
|
$formDatas['table_name'] = $this->getBoardTable();
|
||||||
$entity->table_name = $this->getBoardTable();
|
$formDatas['file_name'] = $this->getOriginName();
|
||||||
$entity->reg_date = date("Y-m-d H:i:s");
|
$formDatas['file_path'] = $this->getOriginName();
|
||||||
$entity->file_caption = $entity->getTitle();
|
$formDatas['file_type'] = $this->getMimeType();
|
||||||
$entity->file_alt = $entity->getTitle();
|
$formDatas['file_caption'] = $this->getOriginName();
|
||||||
$entity->file_description = "Filedata";
|
$formDatas['file_alt'] = $this->getOriginName();
|
||||||
|
$formDatas['file_description'] = "Filedata";
|
||||||
|
$formDatas['file_size'] = $this->getFileSize();
|
||||||
|
$formDatas['file_sequence'] = $this->getOriginSequence();
|
||||||
|
$formDatas['reg_date'] = date("Y-m-d H:i:s");
|
||||||
// log_message("debug", "\n-----Entity Value-----\n" . var_export($entity->toArray(), true) . "\n---------------------------\n");
|
// log_message("debug", "\n-----Entity Value-----\n" . var_export($entity->toArray(), true) . "\n---------------------------\n");
|
||||||
$entity = $this->getModel()->create($entity);
|
$entity = $this->getModel()->create($formDatas);
|
||||||
log_message("notice", sprintf(
|
log_message("notice", sprintf(
|
||||||
"%s %s번째 작업 완료",
|
"%s %s번째 작업 완료",
|
||||||
__FUNCTION__,
|
__FUNCTION__,
|
||||||
$entity->getSequence()
|
$this->getOriginSequence()
|
||||||
));
|
));
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
public function save(string $fileName, string $mediaType, string $content, int $file_sequence): FileEntity
|
public function save(): static
|
||||||
{
|
{
|
||||||
$entity = parent::save($fileName, $mediaType, $content, $file_sequence);
|
parent::save();
|
||||||
$entity = $this->save_small_image($entity, $fileName);
|
$formDatas = [];;
|
||||||
return $this->save_db($entity);
|
if ($this->save_small_image()) {
|
||||||
|
//개인적인 생각방식
|
||||||
|
// if ($result) {
|
||||||
|
// //작은이미지 생성후 목적지 Path와 파일명을 다시 file_path에 넣는다. URL이 되기때문에 /로 넣어야함
|
||||||
|
// $entity->setPath(sprintf(
|
||||||
|
// "%s/%s",
|
||||||
|
// $entity->getPath(),
|
||||||
|
// $image->getDestinationFile()
|
||||||
|
// ));
|
||||||
|
// } else {
|
||||||
|
// //원본이미지 생성후 목적지 Path와 파일명을 다시 file_path에 넣는다. URL이 되기때문에 /로 넣어야함
|
||||||
|
// $entity->setPath(sprintf(
|
||||||
|
// "%s/%s",
|
||||||
|
// $entity->getPath(),
|
||||||
|
// $this->getOriginName()
|
||||||
|
// ));
|
||||||
|
// }
|
||||||
|
//개인적인 생각방식
|
||||||
|
//
|
||||||
|
//망보드 방식
|
||||||
|
//mb_files에서 file_path가 망보드 게시판 파일관리에서 image로 표시되어 file_path+file_name로 설정
|
||||||
|
//원본이미지 생성후 목적지 Path와 파일명을 다시 file_path에 넣는다. URL이 되기때문에 /로 넣어야함
|
||||||
|
$formDatas['file_path'] = sprintf(
|
||||||
|
"%s/%s",
|
||||||
|
$this->getPath(),
|
||||||
|
$this->getOriginName()
|
||||||
|
);
|
||||||
|
//망보드 방식
|
||||||
|
}
|
||||||
|
$this->setFileEntity($this->save_db($formDatas));
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,14 +7,51 @@ use App\Libraries\CommonLibrary;
|
|||||||
abstract class MyStorageLibrary extends CommonLibrary
|
abstract class MyStorageLibrary extends CommonLibrary
|
||||||
{
|
{
|
||||||
private $_uploadPath = "uploads";
|
private $_uploadPath = "uploads";
|
||||||
|
private $_originName = "";
|
||||||
|
private $_originContent = "";
|
||||||
|
private $_originType = "";
|
||||||
|
private $_originSequence = "";
|
||||||
protected function __construct()
|
protected function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public function save(string $fileName, string $mediaType, string $content, int $file_sequence);
|
abstract public function save(): mixed;
|
||||||
final public function getUploadPath(): string
|
final public function getUploadPath(): string
|
||||||
{
|
{
|
||||||
return $this->_uploadPath;
|
return $this->_uploadPath;
|
||||||
}
|
}
|
||||||
|
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 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -125,28 +125,32 @@ class ImageLibrary extends MyUtilLibrary
|
|||||||
|
|
||||||
public function create(string $file, int $width = 480, int $height = 319): bool
|
public function create(string $file, int $width = 480, int $height = 319): bool
|
||||||
{
|
{
|
||||||
if (!$this->isFileType($this->getSourcePath(), $file)) {
|
try {
|
||||||
log_message("warning", "{$file} Image 형식파일이 아닙니다.");
|
if (!$this->isFileType($this->getSourcePath(), $file)) {
|
||||||
|
throw new \Exception("{$file} Image 형식파일이 아닙니다.");
|
||||||
|
}
|
||||||
|
//저장할 디렉토리 생성
|
||||||
|
$this->makeDirectory($this->getDestinationPath());
|
||||||
|
// 이미지 파일 로드
|
||||||
|
$this->load($this->getSourcePath() . DIRECTORY_SEPARATOR . $file);
|
||||||
|
// 200x200으로 이미지 크기 조정
|
||||||
|
$this->resize($width, $height);
|
||||||
|
// 파일 저장
|
||||||
|
$this->save($this->getDestinationPath() . DIRECTORY_SEPARATOR . $this->getDestinationFile());
|
||||||
|
// 메모리 해제
|
||||||
|
$this->destroy();
|
||||||
|
log_message("debug", sprintf(
|
||||||
|
"%s %s->%s(W:%s,H:%s) 작업완료)",
|
||||||
|
__FUNCTION__,
|
||||||
|
$file,
|
||||||
|
$this->getDestinationFile(),
|
||||||
|
$width,
|
||||||
|
$height
|
||||||
|
));
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
log_message("warning", $e->getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//저장할 디렉토리 생성
|
|
||||||
$this->makeDirectory($this->getDestinationPath());
|
|
||||||
// 이미지 파일 로드
|
|
||||||
$this->load($this->getSourcePath() . DIRECTORY_SEPARATOR . $file);
|
|
||||||
// 200x200으로 이미지 크기 조정
|
|
||||||
$this->resize($width, $height);
|
|
||||||
// 파일 저장
|
|
||||||
$this->save($this->getDestinationPath() . DIRECTORY_SEPARATOR . $this->getDestinationFile());
|
|
||||||
// 메모리 해제
|
|
||||||
$this->destroy();
|
|
||||||
log_message("debug", sprintf(
|
|
||||||
"%s %s->%s(W:%s,H:%s) 작업완료)",
|
|
||||||
__FUNCTION__,
|
|
||||||
$file,
|
|
||||||
$this->getDestinationFile(),
|
|
||||||
$width,
|
|
||||||
$height
|
|
||||||
));
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -136,9 +136,9 @@ class BoardModel extends CommonModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
//create용
|
//create용
|
||||||
public function create(BoardEntity $entity, array $formDatas = []): BoardEntity
|
public function create(array $formDatas = []): BoardEntity
|
||||||
{
|
{
|
||||||
$entity = $this->create_process($entity, $formDatas);
|
$entity = $this->create_process(new BoardEntity(), $formDatas);
|
||||||
//입력후 PID값을 GID값에 넣어주기 위함
|
//입력후 PID값을 GID값에 넣어주기 위함
|
||||||
return $this->modify($entity, ['gid' => intval($entity->getPK())]);
|
return $this->modify($entity, ['gid' => intval($entity->getPK())]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -112,9 +112,9 @@ class FileModel extends CommonModel
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
//create용
|
//create용
|
||||||
public function create(FileEntity $entity, array $formDatas = []): FileEntity
|
public function create(array $formDatas = []): FileEntity
|
||||||
{
|
{
|
||||||
return $this->create_process($entity, $formDatas);
|
return $this->create_process(new FileEntity(), $formDatas);
|
||||||
}
|
}
|
||||||
//modify용
|
//modify용
|
||||||
public function modify(FileEntity $entity, array $formDatas): FileEntity
|
public function modify(FileEntity $entity, array $formDatas): FileEntity
|
||||||
|
|||||||
@ -215,9 +215,9 @@ class UserModel extends CommonModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
//create용
|
//create용
|
||||||
public function create(UserEntity $entity, array $formDatas = []): UserEntity
|
public function create(array $formDatas = []): UserEntity
|
||||||
{
|
{
|
||||||
return $this->create_process($entity, $formDatas);
|
return $this->create_process(new UserEntity(), $formDatas);
|
||||||
}
|
}
|
||||||
//modify용
|
//modify용
|
||||||
public function modify(UserEntity $entity, array $formDatas): UserEntity
|
public function modify(UserEntity $entity, array $formDatas): UserEntity
|
||||||
|
|||||||
@ -55,9 +55,9 @@ class SNSUserModel extends CommonModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
//create용
|
//create용
|
||||||
public function create(SNSUSerEntity $entity, array $formDatas = []): SNSUSerEntity
|
public function create(array $formDatas = []): SNSUSerEntity
|
||||||
{
|
{
|
||||||
return $this->create_process($entity, $formDatas);
|
return $this->create_process(new SNSUSerEntity(), $formDatas);
|
||||||
}
|
}
|
||||||
|
|
||||||
//modify용
|
//modify용
|
||||||
|
|||||||
@ -70,9 +70,9 @@ class UserModel extends CommonModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
//create용
|
//create용
|
||||||
public function create(UserEntity $entity, array $formDatas = []): UserEntity
|
public function create(array $formDatas = []): UserEntity
|
||||||
{
|
{
|
||||||
return $this->create_process($entity, $formDatas);
|
return $this->create_process(new UserEntity(), $formDatas);
|
||||||
}
|
}
|
||||||
|
|
||||||
//modify용
|
//modify용
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user