dbmsv4 init...5
This commit is contained in:
parent
9b805c755d
commit
8948974c4e
@ -62,6 +62,9 @@ class ServerHelper extends EquipmentHelper
|
||||
'template' => 'serverlist',
|
||||
]);
|
||||
break;
|
||||
case 'viewer':
|
||||
$value = $viewDatas['entity']->getViewer() ? $this->getListButton('console', "", $viewDatas) : "";
|
||||
break;
|
||||
default:
|
||||
$value = parent::getFieldView($field, $value, $viewDatas, $extras);
|
||||
break;
|
||||
|
||||
@ -199,44 +199,19 @@ abstract class CommonService
|
||||
}
|
||||
}
|
||||
//CURD 결과처리용
|
||||
protected function handle_save_result(mixed $result, int|string $uid): int|string
|
||||
{
|
||||
if ($result === false) {
|
||||
$errors = $this->model->errors();
|
||||
$errorMsg = is_array($errors) ? implode(", ", $errors) : "DB 저장 작업이 실패했습니다.";
|
||||
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: " . $errorMsg);
|
||||
}
|
||||
$pk = $uid; // 기본적으로 기존 $uid (업데이트의 경우)
|
||||
// AUTO_INCREMENT 필드를 사용하는 경우, INSERT 작업이라면 새로 생성된 ID를 가져옵니다.
|
||||
// INSERT 작업은 보통 $uid가 0 또는 null/빈 문자열일 때 실행됩니다.
|
||||
if ($this->model->useAutoIncrement() && (empty($uid) || $uid === 0)) {
|
||||
// CodeIgniter 모델의 getInsertID()를 사용하여 새로 생성된 PK를 확실히 가져옵니다.
|
||||
$insertID = $this->model->getInsertID();
|
||||
if ($insertID > 0) {
|
||||
$pk = $insertID;
|
||||
}
|
||||
} elseif ($this->model->useAutoIncrement() && is_numeric($result) && (int) $result > 0) {
|
||||
// save()가 성공적인 INSERT 후 PK를 반환하는 경우를 대비 (CI4의 동작)
|
||||
$pk = (int) $result;
|
||||
}
|
||||
// 최종적으로 PK가 유효한지 확인합니다.
|
||||
if (empty($pk)) {
|
||||
$errors = $this->model->errors();
|
||||
$errorMsg = is_array($errors) && !empty($errors) ? implode(", ", $errors) : "DB 작업 성공 후 PK를 확인할 수 없거나 모델 오류 발생:{$pk}";
|
||||
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: " . $errorMsg);
|
||||
}
|
||||
return $pk;
|
||||
}
|
||||
|
||||
protected function save_process(CommonEntity $entity): CommonEntity
|
||||
{
|
||||
try {
|
||||
// INSERT 시 Entity의 PK는 0 또는 NULL이어야 함 (DB가 ID를 생성하도록)
|
||||
$initialPK = $entity->getPK();
|
||||
$result = $this->model->save($entity);
|
||||
// 최종적으로 DB에 반영된 PK를 반환받습니다. (UPDATE이면 기존 PK, INSERT이면 새 PK)
|
||||
$entity->{$this->getPKField()} = $this->handle_save_result($result, $initialPK);
|
||||
// handle_save_result에서 확인된 최종 PK를 사용하여 DB에서 최신 엔티티를 가져옴
|
||||
if (!$this->model->save($entity)) {
|
||||
$errors = $this->model->errors();
|
||||
$errorMsg = is_array($errors) ? implode(", ", $errors) : "DB 저장 작업이 실패했습니다.";
|
||||
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: " . $errorMsg);
|
||||
}
|
||||
// CodeIgniter 모델의 getInsertID()를 사용하여 새로 생성된 PK를 확실히 가져옵니다.
|
||||
if ($this->model->useAutoIncrement()) {
|
||||
$entity->{$this->getPKField()} = $this->model->getInsertID();
|
||||
}
|
||||
return $entity;
|
||||
} catch (\Throwable $e) {
|
||||
log_message('debug', __FUNCTION__ . ":" . var_export($entity, true));
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<table class="table table-bordered table-striped">
|
||||
<?php foreach ($serverCellDatas['entities'] as $entity): ?>
|
||||
<?php foreach ($serverCellDatas['entities'] as $entity): ?>
|
||||
<?php $serverCellDatas['entity'] = $entity ?>
|
||||
<tr class="text-center">
|
||||
<th style="width: 150px">
|
||||
@ -18,11 +18,9 @@
|
||||
<div><?= $entity->getIP() ?></div>
|
||||
<div><?= $entity->getOS() ?></div>
|
||||
<div>금액 : <span class="text-danger"><?= number_format($entity->getPrice()) ?></span>원</div>
|
||||
<?php if ($serverCellDatas['entity']->getViewer()): ?>
|
||||
<div>
|
||||
<?= $serverCellDatas['helper']->getListButton('console', "", $serverCellDatas) ?>
|
||||
<?= $serverCellDatas['helper']->getFieldView('viewer', $serverCellDatas['entity']->getViewer(), $serverCellDatas) ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<?= view_cell("\App\Cells\Equipment\ServerPartCell::parttable", [
|
||||
@ -31,5 +29,5 @@
|
||||
]) ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
Loading…
Reference in New Issue
Block a user