Automation init...3
This commit is contained in:
parent
24bb1fca5d
commit
d1f462bce3
@ -12,17 +12,18 @@ class YamapController extends CommonController
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$fullPath = WRITEPATH . "uploads" . DIRECTORY_SEPARATOR . getenv('yamap.storage.upload.path');
|
$fullPath = WRITEPATH . "uploads" . DIRECTORY_SEPARATOR . getenv('yamap.storage.upload.path');
|
||||||
$image = new ImageLibrary(
|
$image = new ImageLibrary();
|
||||||
$fullPath,
|
|
||||||
$fullPath . DIRECTORY_SEPARATOR . "small"
|
|
||||||
);
|
|
||||||
if (in_array("debug", $params)) {
|
if (in_array("debug", $params)) {
|
||||||
$image->setDebug(true);
|
$image->setDebug(true);
|
||||||
}
|
}
|
||||||
//디렉토리 생성
|
$image->setSourcePath($fullPath);
|
||||||
$image->makeDirectory($image->getDestinationPath());
|
$image->setDestinationPath($fullPath);
|
||||||
foreach ($image->getFilesByExtentionType($image->getSourcePath()) as $file) {
|
foreach ($image->getFilesByExtentionType($image->getSourcePath()) as $file) {
|
||||||
$image->make_small_image($file);
|
//저장파일명
|
||||||
|
$fileInfos = pathinfo($image->getDestinationPath() . DIRECTORY_SEPARATOR . $file, PATHINFO_ALL);
|
||||||
|
$dstFile = $fileInfos['filename'] . "_small." . $fileInfos['extension'];
|
||||||
|
$image->setDestinationFile($dstFile);
|
||||||
|
$image->create($file);
|
||||||
}
|
}
|
||||||
log_message("notice", "Crawler->" . __FUNCTION__ . " 작업이 완료되었습니다.");
|
log_message("notice", "Crawler->" . __FUNCTION__ . " 작업이 완료되었습니다.");
|
||||||
return "완료되었습니다.";
|
return "완료되었습니다.";
|
||||||
|
|||||||
@ -44,6 +44,7 @@ class WebLibrary extends MySocketLibrary
|
|||||||
if (!($this->isContainsHttpOrHttps($url))) {
|
if (!($this->isContainsHttpOrHttps($url))) {
|
||||||
$url = $this->gethost() . $url;
|
$url = $this->gethost() . $url;
|
||||||
}
|
}
|
||||||
|
log_message("debug", "Socket URL-> " . $url);
|
||||||
$response = $this->getClient()->get($url, $options);
|
$response = $this->getClient()->get($url, $options);
|
||||||
if ($response->getStatusCode() != 200) {
|
if ($response->getStatusCode() != 200) {
|
||||||
throw new \Exception("error", "{$url} 접속실패: " . $response->getStatusCode());
|
throw new \Exception("error", "{$url} 접속실패: " . $response->getStatusCode());
|
||||||
@ -80,7 +81,6 @@ class WebLibrary extends MySocketLibrary
|
|||||||
if (!is_array($fileNames) || !count($fileNames)) {
|
if (!is_array($fileNames) || !count($fileNames)) {
|
||||||
throw new \Exception("Socket URL Error:" . $this->getHost() . $url);
|
throw new \Exception("Socket URL Error:" . $this->getHost() . $url);
|
||||||
}
|
}
|
||||||
log_message("debug", "Socket URL-> " . $this->getHost() . $url);
|
|
||||||
$fileName = array_pop($fileNames);
|
$fileName = array_pop($fileNames);
|
||||||
if (!$this->getDebug()) {
|
if (!$this->getDebug()) {
|
||||||
$content = $this->getContent($url, [
|
$content = $this->getContent($url, [
|
||||||
|
|||||||
@ -9,6 +9,7 @@ class FileLibrary extends MyStorageLibrary
|
|||||||
{
|
{
|
||||||
use FileTrait;
|
use FileTrait;
|
||||||
private $_path = "";
|
private $_path = "";
|
||||||
|
private $_imageLibrary = null;
|
||||||
public function __construct(string $path)
|
public function __construct(string $path)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
@ -60,10 +61,11 @@ class FileLibrary extends MyStorageLibrary
|
|||||||
$this->makeDirectory($fullPath);
|
$this->makeDirectory($fullPath);
|
||||||
$saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $fileName;
|
$saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $fileName;
|
||||||
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, $content)) {
|
||||||
throw new \Exception(__FUNCTION__ . "파일저장 실패:{$saveFilePath}");
|
throw new \Exception(__FUNCTION__ . " 파일저장 실패:{$saveFilePath}");
|
||||||
}
|
}
|
||||||
$entity = $this->createFileEntity();
|
$entity = $this->createFileEntity();
|
||||||
$entity->setPath($this->getPath());
|
$entity->setPath($this->getPath());
|
||||||
|
|||||||
@ -2,12 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Libraries\MyStorage;
|
namespace App\Libraries\MyStorage;
|
||||||
|
|
||||||
|
|
||||||
use App\Entities\Mangboard\FileEntity;
|
|
||||||
use App\Entities\Mangboard\UserEntity;
|
|
||||||
use App\Libraries\MyStorage\FileLibrary;
|
|
||||||
use App\Libraries\MyUtil\ImageLibrary;
|
use App\Libraries\MyUtil\ImageLibrary;
|
||||||
|
use App\Libraries\MyStorage\FileLibrary;
|
||||||
use App\Models\Mangboard\FileModel;
|
use App\Models\Mangboard\FileModel;
|
||||||
|
use App\Entities\Mangboard\UserEntity;
|
||||||
|
use App\Entities\Mangboard\FileEntity;
|
||||||
|
|
||||||
class MangboardLibrary extends FileLibrary
|
class MangboardLibrary extends FileLibrary
|
||||||
{
|
{
|
||||||
@ -77,25 +76,37 @@ class MangboardLibrary extends FileLibrary
|
|||||||
{
|
{
|
||||||
return new FileEntity();
|
return new FileEntity();
|
||||||
}
|
}
|
||||||
private function create_small_image(FileEntity $entity, int $file_sequence): FileEntity
|
|
||||||
|
|
||||||
|
private function create_small_image(FileEntity $entity, string $file, int $width = 480, int $height = 319): FileEntity
|
||||||
{
|
{
|
||||||
$fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath();
|
$fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath();
|
||||||
$image = new ImageLibrary(
|
$image = new ImageLibrary();
|
||||||
$fullPath,
|
|
||||||
$fullPath . DIRECTORY_SEPARATOR . "small"
|
|
||||||
);
|
|
||||||
$image->setDebug($this->getDebug());
|
$image->setDebug($this->getDebug());
|
||||||
//Small 디렉토리 생성
|
$image->setSourcePath($fullPath);
|
||||||
$image->makeDirectory($image->getDestinationPath());
|
$image->setDestinationPath($fullPath);
|
||||||
if (!$image->make_small_image($entity->getTitle())) {
|
//저장파일명
|
||||||
log_message("notice", __FUNCTION__ . " {$file_sequence}번째 " . $entity->getTitle() . " 작업 완료");
|
$fileInfos = pathinfo($image->getDestinationPath() . DIRECTORY_SEPARATOR . $file, PATHINFO_ALL);
|
||||||
}
|
$dstFile = $fileInfos['filename'] . "_small." . $fileInfos['extension'];
|
||||||
|
$image->setDestinationFile($dstFile);
|
||||||
|
//작은이미지 생성후 목적지 Path와 파일명을 다시 file_path에 넣는다.
|
||||||
|
$result = $image->create($file, $width, $height);
|
||||||
|
// if ($result) {
|
||||||
|
// //URL이 되기때문에 /로 넣어야함
|
||||||
|
// $entity->setPath(sprintf(
|
||||||
|
// "/%s/%s/%s",
|
||||||
|
// $this->getUploadPath(),
|
||||||
|
// $entity->getPath(),
|
||||||
|
// $image->getDestinationFile()
|
||||||
|
// ));
|
||||||
|
// }
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
//망보드 파일관리 table에 등록
|
//망보드 파일관리 table에 등록
|
||||||
private function create_db(FileEntity $entity, int $file_sequence): FileEntity
|
private function create_db(FileEntity $entity, int $file_sequence): FileEntity
|
||||||
{
|
{
|
||||||
// log_message("debug", $this->getModel()->getTable() . " Table에 {$file_sequence}번째 등록 준비->{$entity->getTitle()}|{$entity->getMimeType()}");
|
// log_message("notice", __FUNCTION__ . " {$file_sequence}번째 작업 시작");
|
||||||
$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();
|
||||||
@ -103,9 +114,8 @@ class MangboardLibrary extends FileLibrary
|
|||||||
$entity->reg_date = date("Y-m-d H:i:s");
|
$entity->reg_date = date("Y-m-d H:i:s");
|
||||||
$entity->file_caption = $entity->getTitle();
|
$entity->file_caption = $entity->getTitle();
|
||||||
$entity->file_alt = $entity->getTitle();
|
$entity->file_alt = $entity->getTitle();
|
||||||
//mb_files에서 file_path가 망보드 게시판 파일관리에서 image로 표시되어 file_path+file_name로 설정
|
|
||||||
$entity->file_path = $entity->getPath() . DIRECTORY_SEPARATOR . $entity->getTitle();
|
|
||||||
$entity->file_description = "Filedata";
|
$entity->file_description = "Filedata";
|
||||||
|
// log_message("debug", "\n-----Entity Value-----\n" . var_export($entity->toArray(), true) . "\n---------------------------\n");
|
||||||
$entity = $this->getModel()->create($entity);
|
$entity = $this->getModel()->create($entity);
|
||||||
log_message("notice", __FUNCTION__ . " {$file_sequence}번째 작업 완료");
|
log_message("notice", __FUNCTION__ . " {$file_sequence}번째 작업 완료");
|
||||||
return $entity;
|
return $entity;
|
||||||
@ -113,9 +123,18 @@ class MangboardLibrary extends FileLibrary
|
|||||||
public function save(string $fileName, string $mediaType, string $content, int $file_sequence): FileEntity
|
public function save(string $fileName, string $mediaType, string $content, int $file_sequence): FileEntity
|
||||||
{
|
{
|
||||||
$entity = parent::save($fileName, $mediaType, $content, $file_sequence);
|
$entity = parent::save($fileName, $mediaType, $content, $file_sequence);
|
||||||
$entity = $this->create_db($$entity, $file_sequence);
|
//mb_files에서 file_path가 망보드 게시판 파일관리에서 image로 표시되어 file_path+file_name로 설정
|
||||||
$entity = $this->create_small_image($entity, $file_sequence);
|
//원본이미지 생성후 목적지 Path와 파일명을 다시 file_path에 넣는다.
|
||||||
return $entity;
|
//URL이 되기때문에 /로 넣어야함
|
||||||
|
$entity->setPath(sprintf(
|
||||||
|
"/%s/%s/%s",
|
||||||
|
$this->getUploadPath(),
|
||||||
|
$entity->getPath(),
|
||||||
|
$entity->getTitle()
|
||||||
|
));
|
||||||
|
//작은이미지 생성
|
||||||
|
$entity = $this->create_small_image($entity, $fileName);
|
||||||
|
return $this->create_db($entity, $file_sequence);
|
||||||
}
|
}
|
||||||
public function setBoardPID(array $fileEntitys, int $board_pid)
|
public function setBoardPID(array $fileEntitys, int $board_pid)
|
||||||
{
|
{
|
||||||
@ -123,7 +142,7 @@ class MangboardLibrary extends FileLibrary
|
|||||||
foreach ($fileEntitys as $fileEntity) {
|
foreach ($fileEntitys as $fileEntity) {
|
||||||
$fileEntity->board_pid = $board_pid;
|
$fileEntity->board_pid = $board_pid;
|
||||||
//수정시 mb_files에서 file_path가 변경하지 못하게 하기위함
|
//수정시 mb_files에서 file_path가 변경하지 못하게 하기위함
|
||||||
$this->getModel()->setFields($this->getModel()->getFields(['file_path']));
|
$this->getModel()->setFields($this->getModel()->getFields("except", ['file_path']));
|
||||||
$this->getModel()->modify($fileEntity);
|
$this->getModel()->modify($fileEntity);
|
||||||
}
|
}
|
||||||
log_message("notice", __FUNCTION__ . " 작업 완료");
|
log_message("notice", __FUNCTION__ . " 작업 완료");
|
||||||
|
|||||||
@ -10,23 +10,39 @@ class ImageLibrary extends MyUtilLibrary
|
|||||||
use FileTrait;
|
use FileTrait;
|
||||||
private $_srcPath = "";
|
private $_srcPath = "";
|
||||||
private $_dstPath = "";
|
private $_dstPath = "";
|
||||||
|
private $_dstFile = "";
|
||||||
private $_image;
|
private $_image;
|
||||||
private $_imageType;
|
private $_imageType;
|
||||||
public function __construct(string $srcPath, string $dstPath)
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->_srcPath = $srcPath;
|
|
||||||
$this->_dstPath = $dstPath;
|
|
||||||
}
|
}
|
||||||
// 이미지의 현재 너비를 반환하는 메소드
|
// 이미지의 현재 너비를 반환하는 메소드
|
||||||
public function getSourcePath(): string
|
public function getSourcePath(): string
|
||||||
{
|
{
|
||||||
return $this->_srcPath;
|
return $this->_srcPath;
|
||||||
}
|
}
|
||||||
|
public function setSourcePath(string $srcPath): void
|
||||||
|
{
|
||||||
|
$this->_srcPath = $srcPath;
|
||||||
|
}
|
||||||
public function getDestinationPath(): string
|
public function getDestinationPath(): string
|
||||||
{
|
{
|
||||||
return $this->_dstPath;
|
return $this->_dstPath;
|
||||||
}
|
}
|
||||||
|
public function setDestinationPath(string $dstPath): void
|
||||||
|
{
|
||||||
|
$this->_dstPath = $dstPath;
|
||||||
|
}
|
||||||
|
public function getDestinationFile(): string
|
||||||
|
{
|
||||||
|
return $this->_dstFile;
|
||||||
|
}
|
||||||
|
public function setDestinationFile(string $dstFile): void
|
||||||
|
{
|
||||||
|
$this->_dstFile = $dstFile;
|
||||||
|
}
|
||||||
|
|
||||||
public function getWidth()
|
public function getWidth()
|
||||||
{
|
{
|
||||||
return imagesx($this->_image);
|
return imagesx($this->_image);
|
||||||
@ -107,21 +123,23 @@ class ImageLibrary extends MyUtilLibrary
|
|||||||
imagedestroy($this->_image);
|
imagedestroy($this->_image);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function make_small_image(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)) {
|
if (!$this->isFileType($this->getSourcePath(), $file)) {
|
||||||
|
log_message("warning", "{$file} Image 형식파일이 아닙니다.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//소스파일
|
//저장할 디렉토리 생성
|
||||||
$srcfile = $this->getSourcePath() . DIRECTORY_SEPARATOR . $file;
|
$this->makeDirectory($this->getDestinationPath());
|
||||||
$fileInfos = pathinfo($srcfile, PATHINFO_ALL);
|
// 이미지 파일 로드
|
||||||
//저장파일
|
$this->load($this->getSourcePath() . DIRECTORY_SEPARATOR . $file);
|
||||||
$dstfile = $this->getDestinationPath() . DIRECTORY_SEPARATOR . $fileInfos['filename'] . "_small." . $fileInfos['extension'];
|
// 200x200으로 이미지 크기 조정
|
||||||
$this->load($srcfile); // 이미지 파일 로드
|
$this->resize($width, $height);
|
||||||
$this->resize($width, $height); // 200x200으로 이미지 크기 조정
|
// 파일 저장
|
||||||
$this->save($dstfile); // 저장
|
$this->save($this->getDestinationPath() . DIRECTORY_SEPARATOR . $this->getDestinationFile());
|
||||||
$this->destroy(); // 메모리 해제
|
// 메모리 해제
|
||||||
log_message("notice", __FUNCTION__ . " 작업 완료");
|
$this->destroy();
|
||||||
|
log_message("notice", __FUNCTION__ . " Image 작업 완료");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -65,19 +65,26 @@ abstract class CommonModel extends Model
|
|||||||
{
|
{
|
||||||
return $this->_action = $action;
|
return $this->_action = $action;
|
||||||
}
|
}
|
||||||
final public function getFields(array $options = []): array
|
final public function getFields(string $key = "", $fields = []): array
|
||||||
{
|
{
|
||||||
if (isset($options['except'])) {
|
$this->allowedFields = array_filter(
|
||||||
return array_diff_key($this->allowedFields, array_flip($options['except']));
|
$this->allowedFields,
|
||||||
} elseif (isset($options['only'])) {
|
function ($value) use (&$key, &$fields) {
|
||||||
return array_intersect_key($this->allowedFields, array_flip($options['only']));
|
if ($key == 'except') {
|
||||||
}
|
return !in_array($value, $fields);
|
||||||
|
} elseif ($key == 'only') {
|
||||||
|
return in_array($value, $fields);
|
||||||
|
} else {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
return $this->allowedFields;
|
return $this->allowedFields;
|
||||||
}
|
}
|
||||||
final public function setFields(array $fields): void
|
final public function setFields(array $fields): void
|
||||||
{
|
{
|
||||||
$this->allowedFields = $fields;
|
$this->allowedFields = $fields;
|
||||||
//array_unshift는 array의 맨앞에 넣기위함
|
//수동입력인경우 PrimaryKey추가 (array_unshift는 array의 맨앞에 넣기위함)
|
||||||
if (!$this->useAutoIncrement) {
|
if (!$this->useAutoIncrement) {
|
||||||
array_unshift($this->allowedFields, $this->getPKField());
|
array_unshift($this->allowedFields, $this->getPKField());
|
||||||
}
|
}
|
||||||
@ -188,11 +195,9 @@ abstract class CommonModel extends Model
|
|||||||
$this->setAction(DB_ACTION['CREATE']);
|
$this->setAction(DB_ACTION['CREATE']);
|
||||||
//Field에 맞는 Validation Rule 재정의
|
//Field에 맞는 Validation Rule 재정의
|
||||||
$this->setValidationRules($this->getFieldRules($this->getFields()));
|
$this->setValidationRules($this->getFieldRules($this->getFields()));
|
||||||
//primaryKey가 수동입력이면
|
//수동입력인경우
|
||||||
$pkField = $this->getPKField();
|
$pkField = $this->getPKField();
|
||||||
if (!$this->useAutoIncrement && $entity->$pkField === null) {
|
if (!$this->useAutoIncrement && $entity->$pkField === null) {
|
||||||
//PrimayKey Field를 allowedFields의 맨앞에 넣기 -> array_unshif
|
|
||||||
array_unshift($this->allowedFields, $this->getPKField());
|
|
||||||
$entity = $this->convertEntityData($entity, $this->getPKField());
|
$entity = $this->convertEntityData($entity, $this->getPKField());
|
||||||
}
|
}
|
||||||
$entity = $this->save_process($entity);
|
$entity = $this->save_process($entity);
|
||||||
|
|||||||
@ -107,9 +107,6 @@ class FileModel extends CommonModel
|
|||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
switch ($field) {
|
switch ($field) {
|
||||||
case "file_path":
|
|
||||||
$entity->$field .= DIRECTORY_SEPARATOR . $entity->getTitle();
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
$entity = parent::convertEntityData($entity, $field);
|
$entity = parent::convertEntityData($entity, $field);
|
||||||
break;
|
break;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user