diff --git a/app/Config/Constants.php b/app/Config/Constants.php
index 2c4143c..c62d222 100644
--- a/app/Config/Constants.php
+++ b/app/Config/Constants.php
@@ -138,7 +138,7 @@ define('LAYOUTS', [
define('SESSION_NAMES', [
'RETURN_URL' => "return_url",
'ISLOGIN' => "islogined",
- 'AUTH' => 'auth'
+ 'AUTH' => 'auth',
]);
define('AUTH_FIELDS', ['ID' => 'id', 'TITLE' => 'title', 'ROLE' => 'role']);
diff --git a/app/Config/Routes.php b/app/Config/Routes.php
index 1a51480..21bb0ac 100644
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -108,31 +108,6 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
});
$routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($routes) {
$routes->get('/', 'Home::index');
- $routes->group('user', static function ($routes) {
- $routes->get('', 'UserController::index');
- $routes->get('excel', 'UserController::excel');
- $routes->get('insert', 'UserController::insert_form');
- $routes->post('insert', 'UserController::insert');
- $routes->get('update/(:uuid)', 'UserController::update_form/$1');
- $routes->post('update/(:uuid)', 'UserController::update/$1');
- $routes->get('view/(:uuid)', 'UserController::view/$1');
- $routes->get('delete/(:uuid)', 'UserController::delete/$1', ['filter' => 'authFilter:master']);
- $routes->get('toggle/(:uuid)/(:hash)', 'UserController::toggle/$1/$2');
- $routes->post('batchjob', 'UserController::batchjob');
- });
- $routes->group('board', static function ($routes) {
- $routes->get('', 'BoardController::index');
- $routes->get('excel', 'BoardController::excel/$1');
- $routes->get('insert', 'BoardController::insert_form');
- $routes->post('insert', 'BoardController::insert');
- $routes->get('update/(:num)', 'BoardController::update_form/$1');
- $routes->post('update/(:num)', 'BoardController::update/$1');
- $routes->get('view/(:num)', 'BoardController::view/$1');
- $routes->get('reply/(:num)', 'BoardController::reply_form/$1');
- $routes->post('reply/(:num)', 'BoardController::reply/$1');
- $routes->get('delete/(:num)', 'BoardController::delete/$1', ['filter' => 'authFilter:master']);
- $routes->get('download/(:alpha)/(:num)', 'BoardController::download/$1/$2');
- });
});
/*
* --------------------------------------------------------------------
diff --git a/app/Controllers/Admin/AdminHierarchyController.php b/app/Controllers/Admin/AdminHierarchyController.php
index 18a5501..6d5f9ed 100644
--- a/app/Controllers/Admin/AdminHierarchyController.php
+++ b/app/Controllers/Admin/AdminHierarchyController.php
@@ -5,7 +5,6 @@ namespace App\Controllers\Admin;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
-use App\Libraries\Log\Log;
abstract class AdminHierarchyController extends AdminController
{
diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php
index 2202f0f..1487fea 100644
--- a/app/Controllers/BaseController.php
+++ b/app/Controllers/BaseController.php
@@ -2,14 +2,14 @@
namespace App\Controllers;
+use App\Models\UserModel;
use CodeIgniter\Controller;
use CodeIgniter\HTTP\CLIRequest;
+use CodeIgniter\HTTP\Files\UploadedFile;
use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
-use CodeIgniter\HTTP\Files\UploadedFile;
use Psr\Log\LoggerInterface;
-use App\Models\UserModel;
/**
* Class BaseController
@@ -208,7 +208,7 @@ abstract class BaseController extends Controller
//$this->_session->setTempdata('success', 'Page updated successfully', 3);
return alert_CommonHelper($message, $this->_session->get(SESSION_NAMES['RETURN_URL']));
} catch (\Exception $e) {
- $message = __FUNCTION__ . " 실패하였습니다.";
+ $message = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.";
log_message("warning", $e->getMessage());
log_message("warning", var_export($this->_viewDatas['fieldDatas'], true));
log_message("info", "{$this->_viewDatas['title']} {$message}");
@@ -227,7 +227,7 @@ abstract class BaseController extends Controller
final public function update_form($uid)
{
try {
- $entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
+ $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$this->_viewDatas['fields'] = $this->_model->getFields('update');
$this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'update');
$this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters();
@@ -262,7 +262,7 @@ abstract class BaseController extends Controller
{
$message = "";
try {
- $entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
+ $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$this->_viewDatas['fields'] = $this->_model->getFields('update');
$this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'update');
$this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters();
@@ -272,7 +272,7 @@ abstract class BaseController extends Controller
log_message("info", "{$this->_viewDatas['title']} {$message}");
return alert_CommonHelper($message, $this->_session->get(SESSION_NAMES['RETURN_URL']));
} catch (\Exception $e) {
- $message = __FUNCTION__ . " 실패하였습니다.";
+ $message = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.";
log_message("warning", $e->getMessage());
log_message("warning", var_export($this->_viewDatas['fieldDatas'], true));
log_message("info", "{$this->_viewDatas['title']} {$message}");
@@ -294,7 +294,7 @@ abstract class BaseController extends Controller
{
$message = "";
try {
- $entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
+ $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$this->_viewDatas['fields'] = [$field];
$this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'toggle');
$this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters();
@@ -304,7 +304,7 @@ abstract class BaseController extends Controller
log_message("info", "{$this->_viewDatas['title']} {$message}");
return alert_CommonHelper($message, $this->_session->get(SESSION_NAMES['RETURN_URL']));
} catch (\Exception $e) {
- $message = __FUNCTION__ . " 실패하였습니다.";
+ $message = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.";
log_message("warning", $e->getMessage());
log_message("warning", var_export($this->_viewDatas['fieldDatas'], true));
log_message("info", "{$this->_viewDatas['title']} {$message}");
@@ -322,12 +322,13 @@ abstract class BaseController extends Controller
}
public function batchjob()
{
- $uids = $this->request->getVar('batchjob_uids');
- if (is_null($uids) || !is_array($uids) || !count($uids)) {
- return alert_CommonHelper($this->_viewDatas['title'] . '에서 변경할 항목(uid)이 선택되지 않았습니다.', 'back');
- }
- $message = "";
+ $messages = array();
+ $this->_model->transStart();
try {
+ $uids = $this->request->getVar('batchjob_uids');
+ if (is_null($uids) || !is_array($uids) || !count($uids)) {
+ throw new \Exception($this->_viewDatas['title'] . '에서 변경할 항목(uid)이 선택되지 않았습니다.', 'back');
+ }
//fields 해당하는 field중 선택된 값이 있는경우만 fields로 정의
$fields = array();
foreach ($this->_model->getFieldBatchFilters() as $field) {
@@ -344,23 +345,25 @@ abstract class BaseController extends Controller
$this->_viewDatas['fieldFilters'] = $this->_model->getFieldFilters();
$entitys = array();
foreach ($uids as $uid) {
- $entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
+ $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
try {
$entity = $this->batchjob_validate($entity);
array_push($entitys, $this->batchjob_process($entity));
+ array_push($messages, "{$entity->getTitle()}는 수정이 완료되었습니다.");
} catch (\Exception $e) {
- log_message("warning", "{$entity->getTitle()}는 다음과 같은 이유로 수정되지 않았습니다.\n
" . $e->getMessage());
+ array_push($messages, "{$entity->getTitle()}는 다음과 같은 이유로 수정되지 않았습니다.\\n
" . $e->getMessage());
+ throw new \Exception($e->getMessage());
}
}
- $message = "총: " . count($entitys) . "개의 수정(Batchjob)을 완료하였습니다.";
- log_message("info", "{$this->_viewDatas['title']} {$message}");
- return alert_CommonHelper($message, $this->_session->get(SESSION_NAMES['RETURN_URL']));
+ $this->_model->transComplete();
+ log_message("info", "{$this->_viewDatas['title']}에서 " . implode("\n" . $messages));
+ return alert_CommonHelper(implode("\\n" . $messages), $this->_session->get(SESSION_NAMES['RETURN_URL']));
} catch (\Exception $e) {
- $message = "총: " . count($uids) . "개의 수정(Batchjob)을 실패하였습니다.";
+ $this->_model->transRollback();
log_message("warning", $e->getMessage());
+ log_message("info", implode("\n" . $messages));
log_message("warning", var_export($this->_viewDatas['fieldDatas'], true));
- log_message("info", "{$this->_viewDatas['title']} {$message}");
- return alert_CommonHelper($message . "
\n{$e->getMessage()}", 'back');
+ return alert_CommonHelper($e->getMessage() . "\\n" . implode("\\n" . $messages), 'back');
}
}
@@ -378,13 +381,13 @@ abstract class BaseController extends Controller
{
$message = "";
try {
- $entity = $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
+ $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$this->delete_process($entity);
$message = "{$entity->getTitle()} " . __FUNCTION__ . " 완료하였습니다.";
log_message("info", "{$this->_viewDatas['title']} {$message}");
return alert_CommonHelper($message, $this->_session->get(SESSION_NAMES['RETURN_URL']));
} catch (\Exception $e) {
- $message = __FUNCTION__ . " 실패하였습니다.";
+ $message = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.";
log_message("warning", $e->getMessage());
log_message("info", "{$this->_viewDatas['title']} {$message}");
return alert_CommonHelper($message . "
\n{$e->getMessage()}", 'back');
@@ -399,7 +402,6 @@ abstract class BaseController extends Controller
public function view($uid)
{
try {
-
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$this->_viewDatas['fields'] = $this->_model->getFields('view');
$this->_viewDatas['fieldRules'] = $this->_model->getFieldRules($this->_viewDatas['fields'], 'view');
@@ -442,9 +444,7 @@ abstract class BaseController extends Controller
//Rows 처리
$this->index_setCondition();
//OrderBy
- $order_field = $this->request->getVar('order_field') ?: 'uid';
- $order_value = $this->request->getVar('order_value') ?: 'DESC';
- $this->_model->setIndexOrderBy($order_field, $order_value);
+ $this->_model->setIndexOrderBy($this->request->getVar('order_field'), $this->request->getVar('order_value'));
//Limit
$entitys = $per_page ? $this->_model->findAll($per_page, $page * $per_page - $per_page) : $this->_model->findAll();
// log_message("debug", __METHOD__ . "에서 호출[{$per_page}:{$page}=>{$page}*{$per_page}-{$per_page}]\n" . $this->_model->getLastQuery());
diff --git a/app/Database/base.sql b/app/Database/base.sql
index 2225dbb..1c65dc2 100644
--- a/app/Database/base.sql
+++ b/app/Database/base.sql
@@ -11,6 +11,7 @@ CREATE TABLE servermgr.tw_user (
status varchar(10) NOT NULL DEFAULT 'use' COMMENT 'use: 사용,unuse: 사용않함',
updated_at timestamp NULL DEFAULT NULL,
created_at timestamp NOT NULL DEFAULT current_timestamp(),
+ deleted_at timestamp NULL DEFAULT NULL,
PRIMARY KEY (uid),
UNIQUE KEY (id),
UNIQUE KEY (email)
diff --git a/app/Database/servermgr.sql b/app/Database/hpilo.sql
similarity index 100%
rename from app/Database/servermgr.sql
rename to app/Database/hpilo.sql
diff --git a/app/Models/BaseHierarchyModel.php b/app/Models/BaseHierarchyModel.php
index 31cb732..1e6ab74 100644
--- a/app/Models/BaseHierarchyModel.php
+++ b/app/Models/BaseHierarchyModel.php
@@ -55,10 +55,11 @@ abstract class BaseHierarchyModel extends BaseModel
return parent::create_process($entity, $formDatas);
}
- public function setIndexOrderBy($field, $order = "DESC")
+ public function setIndexOrderBy(?string $field, ?string $order)
{
- parent::setIndexOrderBy($field, $order);
+ //계단식의 경우는 먼저 다른것보다 먼저 orderBy가 수행되어야 하므로
$this->orderBy("grpno", "DESC");
$this->orderBy("grporder", "ASC");
+ parent::setIndexOrderBy($field, $order);
}
}
diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php
index 420ba73..219b164 100644
--- a/app/Models/BaseModel.php
+++ b/app/Models/BaseModel.php
@@ -55,9 +55,12 @@ abstract class BaseModel extends Model
}
abstract public function getTitle(): string;
abstract public function getEntity($uid): BaseEntity;
- abstract public function getEntitys($conditions): array;
abstract public function getFieldFilters(): array;
abstract public function getFields(string $action): array;
+ final public function getEntitys($conditions = false): array
+ {
+ return $conditions ? $this->where($conditions)->findAll() : $this->findAll();
+ }
protected function getFieldRule(string $field, array $rules, string $action = ""): array
{
switch ($field) {
@@ -101,16 +104,9 @@ abstract class BaseModel extends Model
}
return $rules;
}
- public function getFieldBatchFilters(array $skips = array()): array
+ public function getFieldBatchFilters(): array
{
- //allowedFields에서 추가했으므로 Controller에는 적용되지 않게하기위함
- $fields = array();
- foreach ($this->getFieldFilters() as $field) {
- if (!in_array($field, $skips)) {
- array_push($fields, $field);
- }
- }
- return $fields;
+ return $this->getFieldFilters();
}
public function getFieldFormOptions($conditions, $options = array()): array
@@ -230,7 +226,10 @@ abstract class BaseModel extends Model
$this->where("created_at >=", $start);
$this->where("created_at <=", $end);
}
- public function setIndexOrderBy($field, $order = "ASC")
+ public function setIndexOrderBy(?string $field, ?string $order)
{
+ if (!is_null($field) && !is_null($order)) {
+ $this->orderBy($field ?: $this->primaryKey, $order ?: "DESC");
+ }
}
}
diff --git a/app/Models/BoardConfigModel.php b/app/Models/BoardConfigModel.php
index 7418be9..2af7238 100644
--- a/app/Models/BoardConfigModel.php
+++ b/app/Models/BoardConfigModel.php
@@ -45,10 +45,9 @@ class BoardConfigModel extends BaseModel
{
return ["isaccess", "isread", "iswrite", "isreply", "isupload", "isdownload", "status"];
}
- public function getFieldBatchFilters(array $skips = array()): array
+ public function getFieldBatchFilters(): array
{
- $skips = ["isupload", "isdownload", ...$skips];
- return parent::getFieldBatchFilters($skips);
+ return parent::getFieldBatchFilters();
}
protected function getFieldRule(string $field, array $rules, string $action = ""): array
{
@@ -77,12 +76,7 @@ class BoardConfigModel extends BaseModel
}
public function getEntity($conditions): BoardConfigEntity
{
- $entity = $this->where($conditions)->first();
- return $entity ?: throw new \Exception("{$conditions}의 해당 데이터가 없습니다.\n ");
- }
- public function getEntitys($conditions): array
- {
- return $this->where($conditions)->findAll();
+ return $this->where($conditions)->first() ?: throw new \Exception("해당 데이터가 없습니다.\n" . var_export($conditions, true));
}
protected function changeFormData(string $field, array $formDatas, $entity)
@@ -132,9 +126,4 @@ class BoardConfigModel extends BaseModel
$this->orLike("isupload", $word, "both"); //befor , after , both
$this->orLike("isdownload", $word, "both"); //befor , after , both
}
- public function setIndexOrderBy($field, $order = "ASC")
- {
- parent::setIndexOrderBy($field, $order);
- $this->orderBy($this->getTitle(), "ASC");
- }
}
diff --git a/app/Models/BoardModel.php b/app/Models/BoardModel.php
index c4c069f..2f4c8ac 100644
--- a/app/Models/BoardModel.php
+++ b/app/Models/BoardModel.php
@@ -35,9 +35,13 @@ class BoardModel extends BaseHierarchyModel
break;
}
}
- public function getFieldFilters(array $fields = array()): array
+ public function getFieldFilters(): array
{
- return ["board_config_uid", "user_uid", "status", ...$fields];
+ return ["board_config_uid", "user_uid", "status"];
+ }
+ public function getFieldBatchFilters(): array
+ {
+ return parent::getFieldBatchFilters();
}
protected function getFieldRule(string $field, array $rules, string $action = ""): array
{
@@ -64,13 +68,9 @@ class BoardModel extends BaseHierarchyModel
public function getEntity($conditions): BoardEntity
{
- $entity = $this->where($conditions)->first();
- return $entity ?: throw new \Exception("{$conditions}의 해당 데이터가 없습니다.\n ");
- }
- public function getEntitys($conditions): array
- {
- return $this->where($conditions)->findAll();
+ return $this->where($conditions)->first() ?: throw new \Exception("해당 데이터가 없습니다.\n" . var_export($conditions, true));
}
+
public function create(array $formDatas): BoardEntity
{
return $this->create_process(new BoardEntity(), $formDatas);
@@ -91,9 +91,4 @@ class BoardModel extends BaseHierarchyModel
$this->orLike($this->getTitle(), $word, "both");
$this->orLike("content", $word, "both"); //befor , after , both
}
- public function setIndexOrderBy($field, $order = "ASC")
- {
- parent::setIndexOrderBy($field, $order);
- $this->orderBy($this->getTitle(), "ASC");
- }
}
diff --git a/app/Models/UserModel.php b/app/Models/UserModel.php
index 32bc2f6..59a8c84 100644
--- a/app/Models/UserModel.php
+++ b/app/Models/UserModel.php
@@ -9,6 +9,7 @@ class UserModel extends BaseModel
protected $table = "tw_user";
protected $useAutoIncrement = false;
protected $returnType = UserEntity::class;
+ protected $useSoftDeletes = false;
public function __construct()
{
parent::__construct();
@@ -35,9 +36,13 @@ class UserModel extends BaseModel
break;
}
}
- public function getFieldFilters(array $fields = array()): array
+ public function getFieldFilters(): array
{
- return ["role", "status", ...$fields];
+ return ["role", "status"];
+ }
+ public function getFieldBatchFilters(): array
+ {
+ return parent::getFieldBatchFilters();
}
protected function getFieldRule(string $field, array $rules, string $action = ""): array
{
@@ -67,12 +72,7 @@ class UserModel extends BaseModel
}
public function getEntity($conditions): UserEntity
{
- $entity = $this->where($conditions)->first();
- return $entity ?: throw new \Exception("{$conditions}의 해당 사용자가 없습니다.\n ");
- }
- public function getEntitys($conditions): array
- {
- return $this->where($conditions)->findAll();
+ return $this->where($conditions)->first() ?: throw new \Exception("해당 데이터가 없습니다.\n" . var_export($conditions, true));
}
protected function changeFormData(string $field, array $formDatas, $entity)
@@ -105,9 +105,4 @@ class UserModel extends BaseModel
$this->orLike("id", $word, "both");
$this->orLike($this->getTitle(), $word, "both"); //befor , after , both
}
- public function setIndexOrderBy($field, $order = "ASC")
- {
- parent::setIndexOrderBy($field, $order);
- $this->orderBy($this->getTitle(), "ASC");
- }
}
diff --git a/app/Models/UserSNSModel.php b/app/Models/UserSNSModel.php
index 64cab5c..4e5f3ed 100644
--- a/app/Models/UserSNSModel.php
+++ b/app/Models/UserSNSModel.php
@@ -34,9 +34,13 @@ class UserSNSModel extends BaseModel
break;
}
}
- public function getFieldFilters(array $fields = array()): array
+ public function getFieldFilters(): array
{
- return ["user_uid", "status", ...$fields];
+ return ["user_uid", "status"];
+ }
+ public function getFieldBatchFilters(): array
+ {
+ return parent::getFieldBatchFilters();
}
protected function getFieldRule(string $field, array $rules, string $action = ""): array
{
@@ -65,12 +69,7 @@ class UserSNSModel extends BaseModel
}
public function getEntity($conditions): UserSNSEntity
{
- $entity = $this->where($conditions)->first();
- return $entity ?: throw new \Exception("{$conditions}의 해당 데이터가 없습니다.\n ");
- }
- public function getEntitys($conditions): array
- {
- return $this->where($conditions)->findAll();
+ return $this->where($conditions)->first() ?: throw new \Exception("해당 데이터가 없습니다.\n" . var_export($conditions, true));
}
public function create(array $formDatas): UserSNSEntity
@@ -89,9 +88,4 @@ class UserSNSModel extends BaseModel
$this->orLike($this->getTitle(), $word, "both");
$this->orLike("email", $word, "both"); //befor , after , both
}
- public function setIndexOrderBy($field, $order = "ASC")
- {
- parent::setIndexOrderBy($field, $order);
- $this->orderBy($this->getTitle(), "ASC");
- }
}
diff --git a/app/Views/admin/board/index.php b/app/Views/admin/board/index.php
index 3c46671..4172d7b 100644
--- a/app/Views/admin/board/index.php
+++ b/app/Views/admin/board/index.php
@@ -20,7 +20,7 @@
-