dbms_init...1
This commit is contained in:
parent
b8ca0bcda7
commit
c5a6349a1d
@ -7,19 +7,27 @@ use CodeIgniter\Database\BaseConnection;
|
|||||||
use CodeIgniter\HTTP\RequestInterface;
|
use CodeIgniter\HTTP\RequestInterface;
|
||||||
use CodeIgniter\HTTP\ResponseInterface;
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use App\Libraries\DBMigration\Process\ClientProcess;
|
||||||
|
use App\Libraries\DBMigration\Process\LineProcess;
|
||||||
|
use App\Libraries\DBMigration\Process\ServerCodeProcess;
|
||||||
|
use App\Libraries\DBMigration\Process\SwitchCodeProcess;
|
||||||
|
use App\Libraries\DBMigration\Process\MigrationProcessInterface;
|
||||||
|
|
||||||
abstract class DBMigration extends BaseController
|
abstract class DBMigration extends BaseController
|
||||||
{
|
{
|
||||||
private $_targetDB = null;
|
private $_targetDB = null;
|
||||||
|
|
||||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||||
{
|
{
|
||||||
parent::initController($request, $response, $logger);
|
parent::initController($request, $response, $logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract protected function getSourceDB(): BaseConnection;
|
abstract protected function getSourceDB(): BaseConnection;
|
||||||
abstract protected function getClient(): array;
|
abstract protected function getClient(): array;
|
||||||
abstract protected function getLine(): array;
|
abstract protected function getLine(): array;
|
||||||
abstract protected function getServerCode(): array;
|
abstract protected function getServerCode(): array;
|
||||||
abstract protected function getSwitchCode(): array;
|
abstract protected function getSwitchCode(): array;
|
||||||
|
|
||||||
final protected function getTargetDB(): BaseConnection
|
final protected function getTargetDB(): BaseConnection
|
||||||
{
|
{
|
||||||
if ($this->_targetDB === null) {
|
if ($this->_targetDB === null) {
|
||||||
@ -28,150 +36,59 @@ abstract class DBMigration extends BaseController
|
|||||||
return $this->_targetDB;
|
return $this->_targetDB;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function client_process(array $row, int $cnt): void
|
/**
|
||||||
|
* 공통 마이그레이션 처리 로직
|
||||||
|
*/
|
||||||
|
private function processMigration(MigrationProcessInterface $processor, array $rows, string $functionName): void
|
||||||
{
|
{
|
||||||
$temps = [];
|
$this->getTargetDB()->transStart();
|
||||||
$temps['code'] = $row['Client_Code'];
|
try {
|
||||||
$temps['role'] = $row['Client_Reseller'] == 30 ? "reseller" : "user";
|
$cnt = 1;
|
||||||
$temps['name'] = $row['Client_Name'];
|
foreach ($rows as $row) {
|
||||||
$temps['phone'] = empty($row['Client_Phone1']) ? "" : $row['Client_Phone1'];
|
$processor->process($row, $cnt);
|
||||||
if (empty($temps['phone'])) {
|
$cnt++;
|
||||||
$temps['phone'] = empty($row['Client_Phone2']) ? "" : $row['Client_Phone2'];
|
|
||||||
}
|
}
|
||||||
$temps['email'] = empty($row['Client_EMail1']) ? "" : $row['Client_EMail1'];
|
echo "{$functionName} 작업을 완료하였습니다.";
|
||||||
if (empty($temps['email'])) {
|
$this->getTargetDB()->transCommit();
|
||||||
$temps['email'] = empty($row['Client_EMail2']) ? "" : $row['Client_EMail2'];
|
} catch (\Exception $e) {
|
||||||
|
$this->getTargetDB()->transRollback();
|
||||||
|
echo "{$functionName} 작업을 실패하였습니다.\n--------------\n" . $e->getMessage() . "\n--------------\n";
|
||||||
}
|
}
|
||||||
$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('clientinfo')->insert($temps)) {
|
|
||||||
throw new \Exception($this->getTargetDB()->error()['message']);
|
|
||||||
}
|
|
||||||
echo "{$cnt} -> {$temps['name']} 고객완료.\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final public function client(): void
|
final public function client(): void
|
||||||
{
|
{
|
||||||
//Transaction Start
|
$this->processMigration(
|
||||||
$this->getTargetDB()->transStart();
|
new ClientProcess($this->getTargetDB()),
|
||||||
try {
|
$this->getClient(),
|
||||||
$cnt = 1;
|
__FUNCTION__
|
||||||
$rows = $this->getClient();
|
);
|
||||||
foreach ($rows as $row) {
|
|
||||||
$this->client_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 line_process(array $row, int $cnt): void
|
|
||||||
{
|
|
||||||
$temps = [];
|
|
||||||
//신규DB에 삽입
|
|
||||||
if (!$this->getTargetDB()->table('lineinfo')->insert($temps)) {
|
|
||||||
throw new \Exception($this->getTargetDB()->error()['message']);
|
|
||||||
}
|
|
||||||
echo "{$cnt} -> {$temps['name']} Line완료.\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final public function line(): void
|
final public function line(): void
|
||||||
{
|
{
|
||||||
//Transaction Start
|
$this->processMigration(
|
||||||
$this->getTargetDB()->transStart();
|
new LineProcess($this->getTargetDB()),
|
||||||
try {
|
$this->getLine(),
|
||||||
$cnt = 1;
|
__FUNCTION__
|
||||||
$rows = $this->getLine();
|
);
|
||||||
foreach ($rows as $row) {
|
|
||||||
$this->line_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 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
|
final public function servercode(): void
|
||||||
{
|
{
|
||||||
//Transaction Start
|
$this->processMigration(
|
||||||
$this->getTargetDB()->transStart();
|
new ServerCodeProcess($this->getTargetDB()),
|
||||||
try {
|
$this->getServerCode(),
|
||||||
$cnt = 1;
|
__FUNCTION__
|
||||||
$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
|
final public function switchcode(): void
|
||||||
{
|
{
|
||||||
//Transaction Start
|
$this->processMigration(
|
||||||
$this->getTargetDB()->transStart();
|
new SwitchCodeProcess($this->getTargetDB()),
|
||||||
try {
|
$this->getSwitchCode(),
|
||||||
$cnt = 1;
|
__FUNCTION__
|
||||||
$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";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
41
app/Libraries/DBMigration/Process/ClientProcess.php
Normal file
41
app/Libraries/DBMigration/Process/ClientProcess.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Libraries\DBMigration\Process;
|
||||||
|
|
||||||
|
use CodeIgniter\Database\BaseConnection;
|
||||||
|
|
||||||
|
class ClientProcess implements MigrationProcessInterface
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
public function __construct(BaseConnection $db)
|
||||||
|
{
|
||||||
|
$this->db = $db;
|
||||||
|
}
|
||||||
|
public function 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'];
|
||||||
|
}
|
||||||
|
if (!$this->db->table('clientinfo')->insert($temps)) {
|
||||||
|
throw new \Exception($this->db->error()['message']);
|
||||||
|
}
|
||||||
|
echo "{$cnt} -> {$temps['name']} 고객완료.\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
23
app/Libraries/DBMigration/Process/LineProcess.php
Normal file
23
app/Libraries/DBMigration/Process/LineProcess.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Libraries\DBMigration\Process;
|
||||||
|
|
||||||
|
use CodeIgniter\Database\BaseConnection;
|
||||||
|
|
||||||
|
class LineProcess implements MigrationProcessInterface
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
public function __construct(BaseConnection $db)
|
||||||
|
{
|
||||||
|
$this->db = $db;
|
||||||
|
}
|
||||||
|
public function process(array $row, int $cnt): void
|
||||||
|
{
|
||||||
|
$temps = [];
|
||||||
|
// TODO: $temps에 필요한 데이터 매핑 추가
|
||||||
|
if (!$this->db->table('lineinfo')->insert($temps)) {
|
||||||
|
throw new \Exception($this->db->error()['message']);
|
||||||
|
}
|
||||||
|
echo "{$cnt} -> {$temps['name']} Line완료.\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Libraries\DBMigration\Process;
|
||||||
|
|
||||||
|
interface MigrationProcessInterface
|
||||||
|
{
|
||||||
|
public function process(array $row, int $cnt): void;
|
||||||
|
}
|
||||||
24
app/Libraries/DBMigration/Process/ServerCodeProcess.php
Normal file
24
app/Libraries/DBMigration/Process/ServerCodeProcess.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Libraries\DBMigration\Process;
|
||||||
|
|
||||||
|
use CodeIgniter\Database\BaseConnection;
|
||||||
|
|
||||||
|
class ServerCodeProcess implements MigrationProcessInterface
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
public function __construct(BaseConnection $db)
|
||||||
|
{
|
||||||
|
$this->db = $db;
|
||||||
|
}
|
||||||
|
public function process(array $row, int $cnt): void
|
||||||
|
{
|
||||||
|
$temps = [];
|
||||||
|
$temps['code'] = trim($row['server_code']);
|
||||||
|
$temps['status'] = 'default';
|
||||||
|
if (!$this->db->table('codeinfo')->insert($temps)) {
|
||||||
|
throw new \Exception($this->db->error()['message']);
|
||||||
|
}
|
||||||
|
echo "{$cnt} -> {$temps['code']} SERVERCODE 완료.\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
24
app/Libraries/DBMigration/Process/SwitchCodeProcess.php
Normal file
24
app/Libraries/DBMigration/Process/SwitchCodeProcess.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Libraries\DBMigration\Process;
|
||||||
|
|
||||||
|
use CodeIgniter\Database\BaseConnection;
|
||||||
|
|
||||||
|
class SwitchCodeProcess implements MigrationProcessInterface
|
||||||
|
{
|
||||||
|
private $db;
|
||||||
|
public function __construct(BaseConnection $db)
|
||||||
|
{
|
||||||
|
$this->db = $db;
|
||||||
|
}
|
||||||
|
public function process(array $row, int $cnt): void
|
||||||
|
{
|
||||||
|
$temps = [];
|
||||||
|
$temps['code'] = trim($row['service_sw']);
|
||||||
|
$temps['status'] = 'default';
|
||||||
|
if (!$this->db->table('switchinfo')->insert($temps)) {
|
||||||
|
throw new \Exception($this->db->error()['message']);
|
||||||
|
}
|
||||||
|
echo "{$cnt} -> {$temps['code']} SWITCHCODE 완료.\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user