dbms_init...1
This commit is contained in:
parent
7b12ec4896
commit
89f85762e7
@ -15,6 +15,8 @@ $routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes)
|
||||
$routes->cli('billing', 'Payment::billing');
|
||||
$routes->group('migration', ['namespace' => 'App\Controllers\CLI\DBMigration'], function ($routes) {
|
||||
$routes->cli('client', 'SourceDB::client');
|
||||
$routes->cli('servercode', 'SourceDB::servercode');
|
||||
$routes->cli('switchcode', 'SourceDB::switchcode');
|
||||
});
|
||||
});
|
||||
$routes->group('', ['namespace' => 'App\Controllers'], function ($routes) {
|
||||
|
||||
@ -18,6 +18,8 @@ abstract class DBMigration extends BaseController
|
||||
abstract protected function getSourceDB(): BaseConnection;
|
||||
abstract protected function getClient(): array;
|
||||
abstract protected function getLine(): array;
|
||||
abstract protected function getServerCode(): array;
|
||||
abstract protected function getSwitchCode(): array;
|
||||
final protected function getTargetDB(): BaseConnection
|
||||
{
|
||||
if ($this->_targetDB === null) {
|
||||
@ -26,7 +28,7 @@ abstract class DBMigration extends BaseController
|
||||
return $this->_targetDB;
|
||||
}
|
||||
|
||||
protected function client_process(mixed $row, int $cnt): void
|
||||
protected function client_process(array $row, int $cnt): void
|
||||
{
|
||||
$temps = [];
|
||||
$temps['code'] = $row['Client_Code'];
|
||||
@ -61,7 +63,8 @@ abstract class DBMigration extends BaseController
|
||||
$this->getTargetDB()->transStart();
|
||||
try {
|
||||
$cnt = 1;
|
||||
foreach ($this->getClient() as $row) {
|
||||
$rows = $this->getClient();
|
||||
foreach ($rows as $row) {
|
||||
$this->client_process($row, $cnt);
|
||||
$cnt++;
|
||||
}
|
||||
@ -74,28 +77,9 @@ abstract class DBMigration extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
protected function line_process(mixed $row, int $cnt): void
|
||||
protected function line_process(array $row, int $cnt): void
|
||||
{
|
||||
$temps = [];
|
||||
$temps['code'] = $row['Client_Code'];
|
||||
$temps['role'] = $row['Client_Reseller'] == 30 ? "reseller" : "user";
|
||||
$temps['name'] = $row['Client_Name'];
|
||||
$temps['phone'] = empty($row['Client_Phone1']) ? "" : $row['Client_Phone1'];
|
||||
if (empty($temps['phone'])) {
|
||||
$temps['phone'] = empty($row['Client_Phone2']) ? "" : $row['Client_Phone2'];
|
||||
}
|
||||
$temps['email'] = empty($row['Client_EMail1']) ? "" : $row['Client_EMail1'];
|
||||
if (empty($temps['email'])) {
|
||||
$temps['email'] = empty($row['Client_EMail2']) ? "" : $row['Client_EMail2'];
|
||||
}
|
||||
$temps['account_balance'] = intval($row['Client_Money']);
|
||||
$temps['coupon_balance'] = 0;
|
||||
$temps['point_balance'] = 0;
|
||||
$temps['status'] = 'default';
|
||||
$temps['updated_at'] = empty($row['Client_Renew_date']) ? NULL : $row['Client_Renew_date'];;
|
||||
if (!empty($row['Client_Receive_date'])) {
|
||||
$temps['created_at'] = $row['Client_Receive_date'];;
|
||||
}
|
||||
//신규DB에 삽입
|
||||
if (!$this->getTargetDB()->table('lineinfo')->insert($temps)) {
|
||||
throw new \Exception($this->getTargetDB()->error()['message']);
|
||||
@ -109,7 +93,8 @@ abstract class DBMigration extends BaseController
|
||||
$this->getTargetDB()->transStart();
|
||||
try {
|
||||
$cnt = 1;
|
||||
foreach ($this->getClient() as $row) {
|
||||
$rows = $this->getLine();
|
||||
foreach ($rows as $row) {
|
||||
$this->line_process($row, $cnt);
|
||||
$cnt++;
|
||||
}
|
||||
@ -121,4 +106,72 @@ abstract class DBMigration extends BaseController
|
||||
echo __FUNCTION__ . " 작업을 실패하였습니다.\n--------------\n" . $e->getMessage() . "\n--------------\n";
|
||||
}
|
||||
}
|
||||
|
||||
protected function servercode_process(array $row, int $cnt): void
|
||||
{
|
||||
$temps = [];
|
||||
$temps['code'] = trim($row['server_code']);
|
||||
$temps['status'] = 'default';
|
||||
//신규DB에 삽입
|
||||
if (!$this->getTargetDB()->table('codeinfo')->insert($temps)) {
|
||||
throw new \Exception($this->getTargetDB()->error()['message']);
|
||||
}
|
||||
echo "{$cnt} -> {$temps['code']} SERVERCODE 완료.\n";
|
||||
}
|
||||
|
||||
final public function servercode(): void
|
||||
{
|
||||
//Transaction Start
|
||||
$this->getTargetDB()->transStart();
|
||||
try {
|
||||
$cnt = 1;
|
||||
$rows = $this->getServerCode();
|
||||
// var_dump($rows);
|
||||
// exit;
|
||||
foreach ($rows as $row) {
|
||||
$this->servercode_process($row, $cnt);
|
||||
$cnt++;
|
||||
}
|
||||
echo __FUNCTION__ . " 작업을 완료하였습니다.";
|
||||
$this->getTargetDB()->transCommit();
|
||||
} catch (\Exception $e) {
|
||||
//Transaction Rollback
|
||||
$this->getTargetDB()->transRollback();
|
||||
echo __FUNCTION__ . " 작업을 실패하였습니다.\n--------------\n" . $e->getMessage() . "\n--------------\n";
|
||||
}
|
||||
}
|
||||
|
||||
protected function switchcode_process(array $row, int $cnt): void
|
||||
{
|
||||
$temps = [];
|
||||
$temps['code'] = trim($row['service_sw']);
|
||||
$temps['status'] = 'default';
|
||||
//신규DB에 삽입
|
||||
if (!$this->getTargetDB()->table('switchinfo')->insert($temps)) {
|
||||
throw new \Exception($this->getTargetDB()->error()['message']);
|
||||
}
|
||||
echo "{$cnt} -> {$temps['code']} SWITCHCODE 완료.\n";
|
||||
}
|
||||
|
||||
final public function switchcode(): void
|
||||
{
|
||||
//Transaction Start
|
||||
$this->getTargetDB()->transStart();
|
||||
try {
|
||||
$cnt = 1;
|
||||
$rows = $this->getSwitchCode();
|
||||
// var_dump($rows);
|
||||
// exit;
|
||||
foreach ($rows as $row) {
|
||||
$this->switchcode_process($row, $cnt);
|
||||
$cnt++;
|
||||
}
|
||||
echo __FUNCTION__ . " 작업을 완료하였습니다.";
|
||||
$this->getTargetDB()->transCommit();
|
||||
} catch (\Exception $e) {
|
||||
//Transaction Rollback
|
||||
$this->getTargetDB()->transRollback();
|
||||
echo __FUNCTION__ . " 작업을 실패하였습니다.\n--------------\n" . $e->getMessage() . "\n--------------\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,10 +44,20 @@ class SourceDB extends DBMigration
|
||||
}
|
||||
protected function getClient(): array
|
||||
{
|
||||
return $this->getSourceDB()->query('SELECT * FROM clientdb')->getResultArray();
|
||||
return $this->getSourceDB()->query("SELECT * FROM clientdb")->getResultArray();
|
||||
}
|
||||
protected function getLine(): array
|
||||
{
|
||||
return $this->getSourceDB()->query('select Line_code,line_case,Line_ip,line_client_name,line_gateway,line_id,line_pass,line_name,line_haveip,line_phone,line_mainip from linedb;select Line_code,line_case,Line_ip,line_client_name,line_gateway,line_id,line_pass,line_name,line_haveip,line_phone,line_mainip from linedb')->getResultArray();
|
||||
return $this->getSourceDB()->query("SELECT Line_code,line_case,Line_ip,line_client_name,line_gateway,line_id,line_pass,line_name,line_haveip,line_phone,line_mainip from linedb;select Line_code,line_case,Line_ip,line_client_name,line_gateway,line_id,line_pass,line_name,line_haveip,line_phone,line_mainip FROM linedb")->getResultArray();
|
||||
}
|
||||
|
||||
protected function getServerCode(): array
|
||||
{
|
||||
return $this->getSourceDB()->query("SELECT DISTINCT(server_code) FROM serverdb WHERE server_code NOT LIKE ('%일회성%')")->getResultArray();
|
||||
}
|
||||
|
||||
protected function getSwitchCode(): array
|
||||
{
|
||||
return $this->getSourceDB()->query("SELECT DISTINCT(service_sw) FROM servicedb WHERE service_sw NOT LIKE ('%일회성%')")->getResultArray();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user