From 5275d593b0980e4ee7b34936d615e13fdb949de3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Wed, 31 Mar 2021 01:58:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/ActiveRecord.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Database/ActiveRecord.php b/Database/ActiveRecord.php index 081ddbde..0295fee9 100644 --- a/Database/ActiveRecord.php +++ b/Database/ActiveRecord.php @@ -121,18 +121,20 @@ class ActiveRecord extends BaseActiveRecord */ public static function findOrCreate(array $condition, array $attributes = []): bool|static { + $logger = Snowflake::app()->getLogger(); + /** @var static $select */ $select = static::find()->where($condition)->first(); if (!empty($select)) { return $select; } if (empty($attributes)) { - return \logger()->addError(FIND_OR_CREATE_MESSAGE, 'mysql'); + return $logger->addError(FIND_OR_CREATE_MESSAGE, 'mysql'); } $select = self::getModelClass(); $select->attributes = $attributes; if (!$select->save()) { - return \logger()->addError($select->getLastError(), 'mysql'); + return $logger->addError($select->getLastError(), 'mysql'); } return $select; } @@ -146,8 +148,9 @@ class ActiveRecord extends BaseActiveRecord */ public static function createOrUpdate(array $condition, array $attributes = []): bool|static { + $logger = Snowflake::app()->getLogger(); if (empty($attributes)) { - return \logger()->addError(FIND_OR_CREATE_MESSAGE, 'mysql'); + return $logger->addError(FIND_OR_CREATE_MESSAGE, 'mysql'); } /** @var static $select */ $select = static::find()->where($condition)->first(); @@ -156,7 +159,7 @@ class ActiveRecord extends BaseActiveRecord } $select->attributes = $attributes; if (!$select->save()) { - return \logger()->addError($select->getLastError(), 'mysql'); + return $logger->addError($select->getLastError(), 'mysql'); } return $select; }