From 52574d40dd3e7c8afbe18efedd86646fec5a2d65 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 16 Apr 2021 09:08:42 +0200 Subject: [PATCH] fix: comparing multidimensional array on migration --- src/Appwrite/Migration/Migration.php | 31 ++++++++++++++++++++++++-- src/Appwrite/Migration/Version/V07.php | 1 - 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index a1370029a5..78b0f6acdf 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -89,8 +89,8 @@ abstract class Migration if (empty($new->getId())) { throw new Exception('Missing ID'); } - - if (!array_diff_assoc($new->getArrayCopy(), $old)) { + + if (!$this->check_diff_multi($new->getArrayCopy(), $old)) { return; } @@ -112,6 +112,33 @@ abstract class Migration } } + public function check_diff_multi($array1, $array2){ + $result = array(); + + foreach($array1 as $key => $val) { + if(is_array($val) && isset($array2[$key])) { + $tmp = $this->check_diff_multi($val, $array2[$key]); + if($tmp) { + $result[$key] = $tmp; + } + } + elseif(!isset($array2[$key])) { + $result[$key] = null; + } + elseif($val !== $array2[$key]) { + $result[$key] = $array2[$key]; + } + + if(isset($array2[$key])) { + unset($array2[$key]); + } + } + + $result = array_merge($result, $array2); + + return $result; + } + /** * Executes migration for set project. */ diff --git a/src/Appwrite/Migration/Version/V07.php b/src/Appwrite/Migration/Version/V07.php index 7cd3b8fefd..9c3054a286 100644 --- a/src/Appwrite/Migration/Version/V07.php +++ b/src/Appwrite/Migration/Version/V07.php @@ -38,7 +38,6 @@ class V07 extends Migration $document->removeAttribute('oauth2' . \ucfirst($key) . 'AccessToken'); } } - /** * Invalidate all Login Tokens, since they can't be migrated to the new structure. * Reason for it is the missing distinction between E-Mail and OAuth2 tokens.