Revert "改名"
This reverts commit fdf58326
This commit is contained in:
@@ -114,8 +114,7 @@ class Model extends Base\Model
|
|||||||
}
|
}
|
||||||
$model = new static();
|
$model = new static();
|
||||||
|
|
||||||
$database = $model->getConnection();
|
$database = $model->getConnection()->beginTransaction();
|
||||||
$database->beginTransaction();
|
|
||||||
try {
|
try {
|
||||||
/** @var static $select */
|
/** @var static $select */
|
||||||
$select = static::query()->where($condition)->first();
|
$select = static::query()->where($condition)->first();
|
||||||
@@ -152,16 +151,23 @@ class Model extends Base\Model
|
|||||||
return $logger->addError(FIND_OR_CREATE_MESSAGE, 'mysql');
|
return $logger->addError(FIND_OR_CREATE_MESSAGE, 'mysql');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var static $select */
|
$database = (new static())->getConnection()->beginTransaction();
|
||||||
$select = static::query()->where($condition)->first();
|
try {
|
||||||
if (empty($select)) {
|
/** @var static $select */
|
||||||
$select = duplicate(static::class);
|
$select = static::query()->where($condition)->first();
|
||||||
|
if (empty($select)) {
|
||||||
|
$select = duplicate(static::class);
|
||||||
|
}
|
||||||
|
$select->attributes = $attributes;
|
||||||
|
if (!$select->save()) {
|
||||||
|
throw new Exception($select->getLastError());
|
||||||
|
}
|
||||||
|
$database->commit();
|
||||||
|
return $select;
|
||||||
|
} catch (\Throwable $throwable) {
|
||||||
|
$database->rollback();
|
||||||
|
return $logger->addError($throwable->getMessage(), 'mysql');
|
||||||
}
|
}
|
||||||
$select->attributes = $attributes;
|
|
||||||
if (!$select->save()) {
|
|
||||||
$select = $logger->addError($select->getLastError(), 'mysql');
|
|
||||||
}
|
|
||||||
return $select;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user