mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
Merge pull request #1092 from TorstenDittmann/fix-migrate-0.8
fix: migration script to 0.8
This commit is contained in:
commit
f62a06da74
2 changed files with 45 additions and 19 deletions
|
|
@ -14,22 +14,22 @@ abstract class Migration
|
||||||
/**
|
/**
|
||||||
* @var PDO
|
* @var PDO
|
||||||
*/
|
*/
|
||||||
protected PDO $db;
|
protected $db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
protected int $limit = 50;
|
protected $limit = 50;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Document
|
* @var Document
|
||||||
*/
|
*/
|
||||||
protected Document $project;
|
protected $project;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Database
|
* @var Database
|
||||||
*/
|
*/
|
||||||
protected Database $projectDB;
|
protected $projectDB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Migration constructor.
|
* Migration constructor.
|
||||||
|
|
@ -90,7 +90,7 @@ abstract class Migration
|
||||||
throw new Exception('Missing ID');
|
throw new Exception('Missing ID');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!array_diff_assoc($new->getArrayCopy(), $old)) {
|
if (!$this->check_diff_multi($new->getArrayCopy(), $old)) {
|
||||||
return;
|
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.
|
* Executes migration for set project.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,10 @@ class V07 extends Migration
|
||||||
|
|
||||||
switch ($document->getAttribute('$collection')) {
|
switch ($document->getAttribute('$collection')) {
|
||||||
case Database::SYSTEM_COLLECTION_USERS:
|
case Database::SYSTEM_COLLECTION_USERS:
|
||||||
|
/**
|
||||||
|
* Remove deprecated OAuth2 properties in the Users Documents.
|
||||||
|
*/
|
||||||
foreach ($providers as $key => $provider) {
|
foreach ($providers as $key => $provider) {
|
||||||
/**
|
|
||||||
* Remove deprecated OAuth2 properties in the Users Documents.
|
|
||||||
*/
|
|
||||||
if (!empty($document->getAttribute('oauth2' . \ucfirst($key)))) {
|
if (!empty($document->getAttribute('oauth2' . \ucfirst($key)))) {
|
||||||
$document->removeAttribute('oauth2' . \ucfirst($key));
|
$document->removeAttribute('oauth2' . \ucfirst($key));
|
||||||
}
|
}
|
||||||
|
|
@ -37,17 +37,16 @@ class V07 extends Migration
|
||||||
if (!empty($document->getAttribute('oauth2' . \ucfirst($key) . 'AccessToken'))) {
|
if (!empty($document->getAttribute('oauth2' . \ucfirst($key) . 'AccessToken'))) {
|
||||||
$document->removeAttribute('oauth2' . \ucfirst($key) . 'AccessToken');
|
$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.
|
|
||||||
*/
|
|
||||||
$tokens = array_filter($document->getAttribute('tokens', []), function($token) {
|
|
||||||
return ($token->getAttribute('type') != Auth::TOKEN_TYPE_LOGIN);
|
|
||||||
});
|
|
||||||
|
|
||||||
$document->setAttribute('tokens', array_values($tokens));
|
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
$tokens = array_filter($document->getAttribute('tokens', []), function ($token) {
|
||||||
|
return ($token->getAttribute('type') != Auth::TOKEN_TYPE_LOGIN);
|
||||||
|
});
|
||||||
|
$document->setAttribute('tokens', array_values($tokens));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue