改名
This commit is contained in:
@@ -121,18 +121,20 @@ class ActiveRecord extends BaseActiveRecord
|
|||||||
*/
|
*/
|
||||||
public static function findOrCreate(array $condition, array $attributes = []): bool|static
|
public static function findOrCreate(array $condition, array $attributes = []): bool|static
|
||||||
{
|
{
|
||||||
|
$logger = Snowflake::app()->getLogger();
|
||||||
|
|
||||||
/** @var static $select */
|
/** @var static $select */
|
||||||
$select = static::find()->where($condition)->first();
|
$select = static::find()->where($condition)->first();
|
||||||
if (!empty($select)) {
|
if (!empty($select)) {
|
||||||
return $select;
|
return $select;
|
||||||
}
|
}
|
||||||
if (empty($attributes)) {
|
if (empty($attributes)) {
|
||||||
return \logger()->addError(FIND_OR_CREATE_MESSAGE, 'mysql');
|
return $logger->addError(FIND_OR_CREATE_MESSAGE, 'mysql');
|
||||||
}
|
}
|
||||||
$select = self::getModelClass();
|
$select = self::getModelClass();
|
||||||
$select->attributes = $attributes;
|
$select->attributes = $attributes;
|
||||||
if (!$select->save()) {
|
if (!$select->save()) {
|
||||||
return \logger()->addError($select->getLastError(), 'mysql');
|
return $logger->addError($select->getLastError(), 'mysql');
|
||||||
}
|
}
|
||||||
return $select;
|
return $select;
|
||||||
}
|
}
|
||||||
@@ -146,8 +148,9 @@ class ActiveRecord extends BaseActiveRecord
|
|||||||
*/
|
*/
|
||||||
public static function createOrUpdate(array $condition, array $attributes = []): bool|static
|
public static function createOrUpdate(array $condition, array $attributes = []): bool|static
|
||||||
{
|
{
|
||||||
|
$logger = Snowflake::app()->getLogger();
|
||||||
if (empty($attributes)) {
|
if (empty($attributes)) {
|
||||||
return \logger()->addError(FIND_OR_CREATE_MESSAGE, 'mysql');
|
return $logger->addError(FIND_OR_CREATE_MESSAGE, 'mysql');
|
||||||
}
|
}
|
||||||
/** @var static $select */
|
/** @var static $select */
|
||||||
$select = static::find()->where($condition)->first();
|
$select = static::find()->where($condition)->first();
|
||||||
@@ -156,7 +159,7 @@ class ActiveRecord extends BaseActiveRecord
|
|||||||
}
|
}
|
||||||
$select->attributes = $attributes;
|
$select->attributes = $attributes;
|
||||||
if (!$select->save()) {
|
if (!$select->save()) {
|
||||||
return \logger()->addError($select->getLastError(), 'mysql');
|
return $logger->addError($select->getLastError(), 'mysql');
|
||||||
}
|
}
|
||||||
return $select;
|
return $select;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user