Revert "改名"
This reverts commit fdf58326
This commit is contained in:
@@ -43,7 +43,8 @@ class Db implements ISqlBuilder
|
|||||||
public static function beginTransaction()
|
public static function beginTransaction()
|
||||||
{
|
{
|
||||||
if (!static::transactionsActive()) {
|
if (!static::transactionsActive()) {
|
||||||
di(EventDispatch::class)->dispatch(new BeginTransaction());
|
$event = \Kiri::getDi()->get(EventDispatch::class);
|
||||||
|
$event->dispatch(new BeginTransaction());
|
||||||
}
|
}
|
||||||
static::$_inTransaction = true;
|
static::$_inTransaction = true;
|
||||||
}
|
}
|
||||||
@@ -55,7 +56,8 @@ class Db implements ISqlBuilder
|
|||||||
public static function commit()
|
public static function commit()
|
||||||
{
|
{
|
||||||
if (static::transactionsActive()) {
|
if (static::transactionsActive()) {
|
||||||
di(EventDispatch::class)->dispatch(new Commit());
|
$event = \Kiri::getDi()->get(EventDispatch::class);
|
||||||
|
$event->dispatch(new Commit());
|
||||||
}
|
}
|
||||||
static::$_inTransaction = false;
|
static::$_inTransaction = false;
|
||||||
}
|
}
|
||||||
@@ -67,7 +69,8 @@ class Db implements ISqlBuilder
|
|||||||
public static function rollback()
|
public static function rollback()
|
||||||
{
|
{
|
||||||
if (static::transactionsActive()) {
|
if (static::transactionsActive()) {
|
||||||
di(EventDispatch::class)->dispatch(new Rollback());
|
$event = \Kiri::getDi()->get(EventDispatch::class);
|
||||||
|
$event->dispatch(new Rollback());
|
||||||
}
|
}
|
||||||
static::$_inTransaction = false;
|
static::$_inTransaction = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,7 +112,8 @@ 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');
|
||||||
}
|
}
|
||||||
// Db::beginTransaction();
|
var_dump('start transaction');
|
||||||
|
Db::beginTransaction();
|
||||||
/** @var static $select */
|
/** @var static $select */
|
||||||
$select = static::query()->where($condition)->first();
|
$select = static::query()->where($condition)->first();
|
||||||
if (empty($select)) {
|
if (empty($select)) {
|
||||||
@@ -120,11 +121,15 @@ class Model extends Base\Model
|
|||||||
$select->attributes = $attributes;
|
$select->attributes = $attributes;
|
||||||
$select->setIsNowExample(true);
|
$select->setIsNowExample(true);
|
||||||
if (!$select->save()) {
|
if (!$select->save()) {
|
||||||
// Db::rollback();
|
var_dump('end rollback');
|
||||||
|
Db::rollback();
|
||||||
return $logger->addError($select->getLastError(), 'mysql');
|
return $logger->addError($select->getLastError(), 'mysql');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Db::commit();
|
|
||||||
|
var_dump('end commit');
|
||||||
|
|
||||||
|
Db::commit();
|
||||||
return $select;
|
return $select;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user