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