초기 설치 코드 정돈, meekrodb 반영
This commit is contained in:
@@ -17,18 +17,11 @@ if (!class_exists('\\sammo\\RootDB')) {
|
|||||||
|
|
||||||
$rootDB = RootDB::db();
|
$rootDB = RootDB::db();
|
||||||
|
|
||||||
$rootDB->throw_exception_on_nonsql_error = false;
|
$rootDB->addHook('run_failed', function ($params) {
|
||||||
$rootDB->nonsql_error_handler = function ($params) {
|
|
||||||
Json::die([
|
|
||||||
'step' => 'conn_fail'
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
|
|
||||||
$rootDB->error_handler = function ($params) {
|
|
||||||
Json::die([
|
Json::die([
|
||||||
'step' => 'sql_fail'
|
'step' => 'sql_fail'
|
||||||
]);
|
]);
|
||||||
};
|
});
|
||||||
|
|
||||||
$memberCnt = $rootDB->queryFirstField('SELECT count(`NO`) from member');
|
$memberCnt = $rootDB->queryFirstField('SELECT count(`NO`) from member');
|
||||||
if ($memberCnt == 0) {
|
if ($memberCnt == 0) {
|
||||||
|
|||||||
@@ -150,20 +150,12 @@ if (!file_exists(ROOT . '/d_setting/.htaccess')) {
|
|||||||
$rootDB = new \MeekroDB($host, $username, $password, $dbName, $port, 'utf8mb4');
|
$rootDB = new \MeekroDB($host, $username, $password, $dbName, $port, 'utf8mb4');
|
||||||
$rootDB->connect_options[MYSQLI_OPT_INT_AND_FLOAT_NATIVE] = true;
|
$rootDB->connect_options[MYSQLI_OPT_INT_AND_FLOAT_NATIVE] = true;
|
||||||
|
|
||||||
$rootDB->throw_exception_on_nonsql_error = false;
|
$rootDB->addHook('run_failed', function ($args) {
|
||||||
$rootDB->nonsql_error_handler = function ($params) {
|
|
||||||
Json::die([
|
Json::die([
|
||||||
'result' => false,
|
'result' => false,
|
||||||
'reason' => 'DB 접속에 실패했습니다.'
|
'reason' => '에러.'. $args['error']
|
||||||
]);
|
]);
|
||||||
};
|
});
|
||||||
|
|
||||||
$rootDB->error_handler = function ($params) {
|
|
||||||
Json::die([
|
|
||||||
'result' => false,
|
|
||||||
'reason' => 'SQL을 제대로 실행하지 못했습니다. DB상태를 확인해 주세요.'
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
|
|
||||||
$mysqli_obj = $rootDB->get(); //로그인에 실패할 경우 자동으로 dbConnFail()이 실행됨.
|
$mysqli_obj = $rootDB->get(); //로그인에 실패할 경우 자동으로 dbConnFail()이 실행됨.
|
||||||
|
|
||||||
|
|||||||
+29
-14
@@ -53,22 +53,17 @@ if($fullReset){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function dbConnFail($params){
|
$db = new \MeekroDB($host,$username,$password,$dbName,$port,'utf8mb4');
|
||||||
|
$db->connect_options[MYSQLI_OPT_INT_AND_FLOAT_NATIVE] = true;
|
||||||
|
|
||||||
|
$db->addHook('run_failed', function(){
|
||||||
Json::die([
|
Json::die([
|
||||||
'result'=>false,
|
'result'=>false,
|
||||||
'reason'=>'DB 접속에 실패했습니다.'
|
'reason'=>'DB 접속에 실패했습니다.'
|
||||||
]);
|
]);
|
||||||
}
|
});
|
||||||
|
|
||||||
|
$mysqli_obj = $db->get();
|
||||||
$db = new \MeekroDB($host,$username,$password,$dbName,$port,'utf8mb4');
|
|
||||||
$db->connect_options[MYSQLI_OPT_INT_AND_FLOAT_NATIVE] = true;
|
|
||||||
|
|
||||||
$db->throw_exception_on_nonsql_error = false;
|
|
||||||
$db->nonsql_error_handler = 'dbConnFail';
|
|
||||||
|
|
||||||
|
|
||||||
$mysqli_obj = $db->get(); //로그인에 실패할 경우 자동으로 dbConnFail()이 실행됨.
|
|
||||||
|
|
||||||
$prefix = basename(__DIR__);
|
$prefix = basename(__DIR__);
|
||||||
|
|
||||||
@@ -84,8 +79,6 @@ $result = Util::generateFileUsingSimpleTemplate(
|
|||||||
], true
|
], true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if($result !== true){
|
if($result !== true){
|
||||||
Json::die([
|
Json::die([
|
||||||
'result'=>false,
|
'result'=>false,
|
||||||
@@ -93,7 +86,29 @@ if($result !== true){
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResetHelper::clearDB();
|
//최소한의 테이블 처리를 위해 수동으로 초기화하도록 하자
|
||||||
|
if($mysqli_obj->multi_query(file_get_contents(__DIR__.'/sql/reset.sql'))){
|
||||||
|
while(true){
|
||||||
|
if (!$mysqli_obj->more_results()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(!$mysqli_obj->next_result()){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if($mysqli_obj->multi_query(file_get_contents(__DIR__.'/sql/schema.sql'))){
|
||||||
|
while(true){
|
||||||
|
if (!$mysqli_obj->more_results()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(!$mysqli_obj->next_result()){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ServConfig::getServerList()[$prefix]->closeServer();
|
ServConfig::getServerList()[$prefix]->closeServer();
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class ResetHelper{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function clearDB(){
|
static public function clearDB():array{
|
||||||
$servRoot = realpath(__DIR__.'/../');
|
$servRoot = realpath(__DIR__.'/../');
|
||||||
|
|
||||||
if(!file_exists($servRoot.'/logs') || !file_exists($servRoot.'/data')){
|
if(!file_exists($servRoot.'/logs') || !file_exists($servRoot.'/data')){
|
||||||
@@ -73,12 +73,13 @@ class ResetHelper{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$prefix = DB::prefix();
|
$prefix = DB::prefix();
|
||||||
|
|
||||||
ServConfig::getServerList()[$prefix]->closeServer();
|
ServConfig::getServerList()[$prefix]->closeServer();
|
||||||
|
|
||||||
$db = DB::db();
|
$db = DB::db();
|
||||||
$mysqli_obj = $db->get();
|
$mysqli_obj = $db->get();
|
||||||
|
|
||||||
$serverID = DB::prefix().'_'.date("ymd").'_'.Util::randomStr(4);
|
$serverID = $prefix.'_'.date("ymd").'_'.Util::randomStr(4);
|
||||||
|
|
||||||
mkdir($servRoot.'/logs/'.$serverID, 0775);
|
mkdir($servRoot.'/logs/'.$serverID, 0775);
|
||||||
mkdir($servRoot.'/data/'.$serverID, 0775);
|
mkdir($servRoot.'/data/'.$serverID, 0775);
|
||||||
|
|||||||
Reference in New Issue
Block a user