dbmsv2/app/Libraries/DBMigration/Process/PartCodeProcess.php
2025-09-25 13:19:06 +09:00

53 lines
1.2 KiB
PHP

<?php
namespace App\Libraries\DBMigration\Process;
use CodeIgniter\Database\BaseConnection;
class PartCodeProcess implements MigrationProcessInterface
{
private $db;
public function __construct(BaseConnection $db)
{
$this->db = $db;
}
public function process(array $row, int $cnt): void
{
try {
if (count($row) < 2) {
throw new \Exception("{$cnt} {$row[0]}:{$row[1]} -> SKIP PARTCODE\n");
}
$temps = [];
$temps['title'] = trim($row[1]);
$temps['price'] = trim($row[2]);
$temps['stock'] = 100;
$temps['status'] = "available";
switch (trim($row[0])) {
case 'CPU':
$table = 'cpuinfo';
break;
case 'RAM':
$table = 'raminfo';
break;
case 'DISK':
$table = 'diskinfo';
break;
case 'OS':
$table = 'osinfo';
break;
case 'SOFTWARE':
$table = 'softwareinfo';
break;
}
$result = $this->db->table($table)->insert($temps);
if (!$result) {
throw new \Exception($this->db->error()['message']);
}
echo "{$cnt} -> {$temps['title']} 완료.\n";
} catch (\Exception $e) {
echo $e->getMessage();
}
}
}