_targetDB === null) { $this->_targetDB = \Config\Database::connect('default'); } return $this->_targetDB; } protected function client_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('clientinfo')->insert($temps)) { throw new \Exception($this->getTargetDB()->error()['message']); } echo "{$cnt} -> {$temps['name']} 고객완료.\n"; } final public function client(): void { //Transaction Start $this->getTargetDB()->transStart(); try { $cnt = 1; $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 { //Transaction Start $this->getTargetDB()->transStart(); try { $cnt = 1; $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 { //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"; } } }