You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$from = $this->removeExcluded($event->changedAttributes); //hopefully this is correct - see https://stackoverflow.com/questions/51645487/yii-2-getoldattribute-method-not-working-in-aftersave
@@ -130,10 +131,23 @@ public function logChanges($event) {
130
131
$logAttributes = [];
131
132
132
133
if ($from || $to) {
133
-
if ($this->nonStrictChangesOnly && $event->name === ActiveRecord::EVENT_AFTER_UPDATE) {
134
+
if ($event->name === ActiveRecord::EVENT_AFTER_UPDATE) {
134
135
foreach ($fromas$currAttr => $currValue) {
135
-
if ((string) $from[$currAttr] === (string) $to[$currAttr]) {
136
-
unset($from[$currAttr], $to[$currAttr]);
136
+
if (is_array($from[$currAttr]) && is_array($to[$currAttr])) { //compare array attributes correctly
137
+
if (serialize($from[$currAttr]) === serialize($to[$currAttr])) { //see https://stackoverflow.com/questions/804045/preferred-method-to-store-php-arrays-json-encode-vs-serialize
138
+
unset($from[$currAttr], $to[$currAttr]);
139
+
}
140
+
}
141
+
}
142
+
if ($this->nonStrictChangesOnly) {
143
+
foreach ($fromas$currAttr => $currValue) {
144
+
if (is_array($from[$currAttr]) && is_array($to[$currAttr])) { //ensure array attributes are not converted to just "Array" and removed by the code below (they are handled above instead)
145
+
// do nothing, they are handled above
146
+
} else {
147
+
if ((string) $from[$currAttr] === (string) $to[$currAttr]) {
148
+
unset($from[$currAttr], $to[$currAttr]);
149
+
}
150
+
}
137
151
}
138
152
}
139
153
}
@@ -175,6 +189,24 @@ public function logChanges($event) {
175
189
}
176
190
}
177
191
192
+
/**
193
+
* If any attributes has been set as array attributes using winternet\yii2\behaviors\ArrayAttributesBehavior, ensure they are not strings but arrays when being logged
0 commit comments