|
|
|
@ -119,12 +119,24 @@ class ActiveRecord extends BaseActiveRecord
|
|
|
|
|
|
|
|
|
|
$key = static::keyPrefix() . ':a:' . static::buildKey($pk); |
|
|
|
|
// save attributes |
|
|
|
|
$args = [$key]; |
|
|
|
|
$setArgs = [$key]; |
|
|
|
|
$delArgs = [$key]; |
|
|
|
|
foreach ($values as $attribute => $value) { |
|
|
|
|
$args[] = $attribute; |
|
|
|
|
$args[] = $value; |
|
|
|
|
if ($value !== null) { |
|
|
|
|
$setArgs[] = $attribute; |
|
|
|
|
$setArgs[] = $value; |
|
|
|
|
} else { |
|
|
|
|
$delArgs[] = $attribute; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (count($setArgs) > 1) { |
|
|
|
|
$db->executeCommand('HMSET', $setArgs); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (count($delArgs) > 1) { |
|
|
|
|
$db->executeCommand('HDEL', $delArgs); |
|
|
|
|
} |
|
|
|
|
$db->executeCommand('HMSET', $args); |
|
|
|
|
|
|
|
|
|
$changedAttributes = array_fill_keys(array_keys($values), null); |
|
|
|
|
$this->setOldAttributes($values); |
|
|
|
@ -158,26 +170,41 @@ class ActiveRecord extends BaseActiveRecord
|
|
|
|
|
$pk = static::buildKey($pk); |
|
|
|
|
$key = static::keyPrefix() . ':a:' . $pk; |
|
|
|
|
// save attributes |
|
|
|
|
$args = [$key]; |
|
|
|
|
$delArgs = [$key]; |
|
|
|
|
$setArgs = [$key]; |
|
|
|
|
foreach ($attributes as $attribute => $value) { |
|
|
|
|
if (isset($newPk[$attribute])) { |
|
|
|
|
$newPk[$attribute] = $value; |
|
|
|
|
} |
|
|
|
|
$args[] = $attribute; |
|
|
|
|
$args[] = $value; |
|
|
|
|
if ($value !== null) { |
|
|
|
|
$setArgs[] = $attribute; |
|
|
|
|
$setArgs[] = $value; |
|
|
|
|
} else { |
|
|
|
|
$delArgs[] = $attribute; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$newPk = static::buildKey($newPk); |
|
|
|
|
$newKey = static::keyPrefix() . ':a:' . $newPk; |
|
|
|
|
// rename index if pk changed |
|
|
|
|
if ($newPk != $pk) { |
|
|
|
|
$db->executeCommand('MULTI'); |
|
|
|
|
$db->executeCommand('HMSET', $args); |
|
|
|
|
if (count($setArgs) > 1) { |
|
|
|
|
$db->executeCommand('HMSET', $setArgs); |
|
|
|
|
} |
|
|
|
|
if (count($delArgs) > 1) { |
|
|
|
|
$db->executeCommand('HDEL', $delArgs); |
|
|
|
|
} |
|
|
|
|
$db->executeCommand('LINSERT', [static::keyPrefix(), 'AFTER', $pk, $newPk]); |
|
|
|
|
$db->executeCommand('LREM', [static::keyPrefix(), 0, $pk]); |
|
|
|
|
$db->executeCommand('RENAME', [$key, $newKey]); |
|
|
|
|
$db->executeCommand('EXEC'); |
|
|
|
|
} else { |
|
|
|
|
$db->executeCommand('HMSET', $args); |
|
|
|
|
if (count($setArgs) > 1) { |
|
|
|
|
$db->executeCommand('HMSET', $setArgs); |
|
|
|
|
} |
|
|
|
|
if (count($delArgs) > 1) { |
|
|
|
|
$db->executeCommand('HDEL', $delArgs); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$n++; |
|
|
|
|
} |
|
|
|
|