mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Merge branch '0.8.x' of https://github.com/appwrite/appwrite into feat-upgrade-php-version
This commit is contained in:
commit
e4c02dda80
45 files changed
+538
-209
No files matched your search
@@ -14,22 +14,22 @@ abstract class Migration
|
||||
/**
|
||||
* @var PDO
|
||||
*/
|
||||
protected PDO $db;
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected int $limit = 50;
|
||||
protected $limit = 50;
|
||||
|
||||
/**
|
||||
* @var Document
|
||||
*/
|
||||
protected Document $project;
|
||||
protected $project;
|
||||
|
||||
/**
|
||||
* @var Database
|
||||
*/
|
||||
protected Database $projectDB;
|
||||
protected $projectDB;
|
||||
|
||||
/**
|
||||
* Migration constructor.
|
||||
@@ -75,11 +75,10 @@ abstract class Migration
|
||||
]);
|
||||
|
||||
$sum = \count($all);
|
||||
Runtime::setHookFlags(SWOOLE_HOOK_ALL);
|
||||
Runtime::enableCoroutine(SWOOLE_HOOK_ALL);
|
||||
|
||||
Console::log('Migrating: ' . $offset . ' / ' . $this->projectDB->getSum());
|
||||
\Co\run(function () use ($all, $callback) {
|
||||
Runtime::enableCoroutine(SWOOLE_HOOK_ALL);
|
||||
|
||||
foreach ($all as $document) {
|
||||
go(function () use ($document, $callback) {
|
||||
@@ -90,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;
|
||||
}
|
||||
|
||||
@@ -113,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.
|
||||
*/
|
||||
|
||||
@@ -26,10 +26,10 @@ class V07 extends Migration
|
||||
|
||||
switch ($document->getAttribute('$collection')) {
|
||||
case Database::SYSTEM_COLLECTION_USERS:
|
||||
/**
|
||||
* Remove deprecated OAuth2 properties in the Users Documents.
|
||||
*/
|
||||
foreach ($providers as $key => $provider) {
|
||||
/**
|
||||
* Remove deprecated OAuth2 properties in the Users Documents.
|
||||
*/
|
||||
if (!empty($document->getAttribute('oauth2' . \ucfirst($key)))) {
|
||||
$document->removeAttribute('oauth2' . \ucfirst($key));
|
||||
}
|
||||
@@ -37,17 +37,16 @@ class V07 extends Migration
|
||||
if (!empty($document->getAttribute('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;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,11 +33,6 @@ abstract class Format
|
||||
*/
|
||||
protected $keys;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $security;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
@@ -62,16 +57,14 @@ abstract class Format
|
||||
* @param Route[] $routes
|
||||
* @param Model[] $models
|
||||
* @param array $keys
|
||||
* @param array $security
|
||||
*/
|
||||
public function __construct(App $app, array $services, array $routes, array $models, array $keys, array $security)
|
||||
public function __construct(App $app, array $services, array $routes, array $models, array $keys)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->services = $services;
|
||||
$this->routes = $routes;
|
||||
$this->models = $models;
|
||||
$this->keys = $keys;
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -74,6 +74,10 @@ class OpenAPI3 extends Format
|
||||
if (isset($output['components']['securitySchemes']['Key'])) {
|
||||
$output['components']['securitySchemes']['Key']['x-appwrite'] = ['demo' => '919c2d18fb5d4...a2ae413da83346ad2'];
|
||||
}
|
||||
|
||||
if (isset($output['securityDefinitions']['JWT'])) {
|
||||
$output['securityDefinitions']['JWT']['x-appwrite'] = ['demo' => 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...'];
|
||||
}
|
||||
|
||||
if (isset($output['components']['securitySchemes']['Locale'])) {
|
||||
$output['components']['securitySchemes']['Locale']['x-appwrite'] = ['demo' => 'en'];
|
||||
@@ -83,7 +87,9 @@ class OpenAPI3 extends Format
|
||||
$output['components']['securitySchemes']['Mode']['x-appwrite'] = ['demo' => ''];
|
||||
}
|
||||
|
||||
foreach ($this->routes as $route) { /* @var $route \Utopia\Route */
|
||||
$usedModels = [];
|
||||
|
||||
foreach ($this->routes as $route) { /** @var \Utopia\Route $route */
|
||||
$url = \str_replace('/v1', '', $route->getURL());
|
||||
$scope = $route->getLabel('scope', '');
|
||||
$hide = $route->getLabel('sdk.hide', false);
|
||||
@@ -146,6 +152,7 @@ class OpenAPI3 extends Format
|
||||
// ],
|
||||
];
|
||||
} else {
|
||||
$usedModels[] = $model->getType();
|
||||
$temp['responses'][(string)$route->getLabel('sdk.response.code', '500')] = [
|
||||
'description' => $model->getName(),
|
||||
'content' => [
|
||||
@@ -164,7 +171,16 @@ class OpenAPI3 extends Format
|
||||
}
|
||||
|
||||
if ((!empty($scope))) { // && 'public' != $scope
|
||||
$temp['security'][] = $route->getLabel('sdk.security', $this->security);
|
||||
$securities = ['Project' => []];
|
||||
|
||||
foreach($route->getLabel('sdk.auth', []) as $security) {
|
||||
if(array_key_exists($security, $this->keys)) {
|
||||
$securities[$security] = [];
|
||||
}
|
||||
}
|
||||
|
||||
$temp['x-appwrite']['auth'] = array_slice($securities, 0, 2);
|
||||
$temp['security'][] = $securities;
|
||||
}
|
||||
|
||||
$body = [
|
||||
@@ -236,7 +252,7 @@ class OpenAPI3 extends Format
|
||||
$node['schema']['format'] = 'format';
|
||||
$node['schema']['x-example'] = 'password';
|
||||
break;
|
||||
case 'Utopia\Validator\Range': /* @var $validator \Utopia\Validator\Range */
|
||||
case 'Utopia\Validator\Range': /** @var \Utopia\Validator\Range $validator */
|
||||
$node['schema']['type'] = 'integer';
|
||||
$node['schema']['format'] = 'int32';
|
||||
$node['schema']['x-example'] = $validator->getMin();
|
||||
@@ -253,7 +269,7 @@ class OpenAPI3 extends Format
|
||||
$node['schema']['format'] = 'url';
|
||||
$node['schema']['x-example'] = 'https://example.com';
|
||||
break;
|
||||
case 'Utopia\Validator\WhiteList': /* @var $validator \Utopia\Validator\WhiteList */
|
||||
case 'Utopia\Validator\WhiteList': /** @var \Utopia\Validator\WhiteList $validator */
|
||||
$node['schema']['type'] = 'string';
|
||||
$node['schema']['x-example'] = $validator->getList()[0];
|
||||
break;
|
||||
@@ -307,8 +323,18 @@ class OpenAPI3 extends Format
|
||||
|
||||
$output['paths'][$url][\strtolower($route->getMethod())] = $temp;
|
||||
}
|
||||
|
||||
foreach ($this->models as $model) {
|
||||
foreach ($model->getRules() as $rule) {
|
||||
if (!in_array($rule['type'], ['string', 'integer', 'boolean', 'json', 'float'])) {
|
||||
$usedModels[] = $rule['type'];
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($this->models as $model) {
|
||||
if (!in_array($model->getType(), $usedModels) && $model->getType() !== 'error') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$required = $model->getRequired();
|
||||
$rules = $model->getRules();
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Appwrite\Specification\Format;
|
||||
|
||||
use Appwrite\Specification\Format;
|
||||
use Appwrite\Template\Template;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
use stdClass;
|
||||
|
||||
class Swagger2 extends Format
|
||||
@@ -73,6 +74,10 @@ class Swagger2 extends Format
|
||||
$output['securityDefinitions']['Key']['x-appwrite'] = ['demo' => '919c2d18fb5d4...a2ae413da83346ad2'];
|
||||
}
|
||||
|
||||
if (isset($output['securityDefinitions']['JWT'])) {
|
||||
$output['securityDefinitions']['JWT']['x-appwrite'] = ['demo' => 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ...'];
|
||||
}
|
||||
|
||||
if (isset($output['securityDefinitions']['Locale'])) {
|
||||
$output['securityDefinitions']['Locale']['x-appwrite'] = ['demo' => 'en'];
|
||||
}
|
||||
@@ -81,7 +86,9 @@ class Swagger2 extends Format
|
||||
$output['securityDefinitions']['Mode']['x-appwrite'] = ['demo' => ''];
|
||||
}
|
||||
|
||||
foreach ($this->routes as $route) { /* @var $route \Utopia\Route */
|
||||
$usedModels = [];
|
||||
|
||||
foreach ($this->routes as $route) { /** @var \Utopia\Route $route */
|
||||
$url = \str_replace('/v1', '', $route->getURL());
|
||||
$scope = $route->getLabel('scope', '');
|
||||
$hide = $route->getLabel('sdk.hide', false);
|
||||
@@ -148,6 +155,7 @@ class Swagger2 extends Format
|
||||
],
|
||||
];
|
||||
} else {
|
||||
$usedModels[] = $model->getType();
|
||||
$temp['responses'][(string)$route->getLabel('sdk.response.code', '500')] = [
|
||||
'description' => $model->getName(),
|
||||
'schema' => [
|
||||
@@ -162,7 +170,16 @@ class Swagger2 extends Format
|
||||
}
|
||||
|
||||
if ((!empty($scope))) { // && 'public' != $scope
|
||||
$temp['security'][] = $route->getLabel('sdk.security', $this->security);
|
||||
$securities = ['Project' => []];
|
||||
|
||||
foreach($route->getLabel('sdk.auth', []) as $security) {
|
||||
if(array_key_exists($security, $this->keys)) {
|
||||
$securities[$security] = [];
|
||||
}
|
||||
}
|
||||
|
||||
$temp['x-appwrite']['auth'] = array_slice($securities, 0, 2);
|
||||
$temp['security'][] = $securities;
|
||||
}
|
||||
|
||||
$body = [
|
||||
@@ -232,7 +249,7 @@ class Swagger2 extends Format
|
||||
$node['format'] = 'format';
|
||||
$node['x-example'] = 'password';
|
||||
break;
|
||||
case 'Utopia\Validator\Range': /* @var $validator \Utopia\Validator\Range */
|
||||
case 'Utopia\Validator\Range': /** @var \Utopia\Validator\Range $validator */
|
||||
$node['type'] = 'integer';
|
||||
$node['format'] = 'int32';
|
||||
$node['x-example'] = $validator->getMin();
|
||||
@@ -249,7 +266,7 @@ class Swagger2 extends Format
|
||||
$node['format'] = 'url';
|
||||
$node['x-example'] = 'https://example.com';
|
||||
break;
|
||||
case 'Utopia\Validator\WhiteList': /* @var $validator \Utopia\Validator\WhiteList */
|
||||
case 'Utopia\Validator\WhiteList': /** @var \Utopia\Validator\WhiteList $validator */
|
||||
$node['type'] = 'string';
|
||||
$node['x-example'] = $validator->getList()[0];
|
||||
break;
|
||||
@@ -308,8 +325,18 @@ class Swagger2 extends Format
|
||||
|
||||
$output['paths'][$url][\strtolower($route->getMethod())] = $temp;
|
||||
}
|
||||
|
||||
foreach ($this->models as $model) {
|
||||
foreach ($model->getRules() as $rule) {
|
||||
if (!in_array($rule['type'], ['string', 'integer', 'boolean', 'json', 'float'])) {
|
||||
$usedModels[] = $rule['type'];
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($this->models as $model) {
|
||||
if (!in_array($model->getType(), $usedModels) && $model->getType() !== 'error') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$required = $model->getRequired();
|
||||
$rules = $model->getRules();
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ use Appwrite\Utopia\Response\Model\Collection;
|
||||
use Appwrite\Utopia\Response\Model\Continent;
|
||||
use Appwrite\Utopia\Response\Model\Country;
|
||||
use Appwrite\Utopia\Response\Model\Currency;
|
||||
use Appwrite\Utopia\Response\Model\Document as ModelDocument;
|
||||
use Appwrite\Utopia\Response\Model\Domain;
|
||||
use Appwrite\Utopia\Response\Model\Error;
|
||||
use Appwrite\Utopia\Response\Model\ErrorDev;
|
||||
@@ -61,6 +62,7 @@ class Response extends SwooleResponse
|
||||
const MODEL_COLLECTION = 'collection';
|
||||
const MODEL_COLLECTION_LIST = 'collectionList';
|
||||
const MODEL_RULE = 'rule';
|
||||
const MODEL_DOCUMENT = 'document';
|
||||
const MODEL_DOCUMENT_LIST = 'documentList';
|
||||
|
||||
// Users
|
||||
@@ -145,7 +147,7 @@ class Response extends SwooleResponse
|
||||
->setModel(new ErrorDev())
|
||||
// Lists
|
||||
->setModel(new BaseList('Collections List', self::MODEL_COLLECTION_LIST, 'collections', self::MODEL_COLLECTION))
|
||||
->setModel(new BaseList('Documents List', self::MODEL_DOCUMENT_LIST, 'documents', self::MODEL_ANY))
|
||||
->setModel(new BaseList('Documents List', self::MODEL_DOCUMENT_LIST, 'documents', self::MODEL_DOCUMENT))
|
||||
->setModel(new BaseList('Users List', self::MODEL_USER_LIST, 'users', self::MODEL_USER))
|
||||
->setModel(new BaseList('Sessions List', self::MODEL_SESSION_LIST, 'sessions', self::MODEL_SESSION))
|
||||
->setModel(new BaseList('Logs List', self::MODEL_LOG_LIST, 'logs', self::MODEL_LOG, false))
|
||||
@@ -169,6 +171,7 @@ class Response extends SwooleResponse
|
||||
// Entities
|
||||
->setModel(new Permissions())
|
||||
->setModel(new Collection())
|
||||
->setModel(new ModelDocument())
|
||||
->setModel(new Rule())
|
||||
->setModel(new Log())
|
||||
->setModel(new User())
|
||||
|
||||
@@ -108,6 +108,7 @@ class V06 extends Filter {
|
||||
break;
|
||||
|
||||
case Response::MODEL_ANY :
|
||||
case Response::MODEL_DOCUMENT :
|
||||
$parsedResponse = $content;
|
||||
break;
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
|
||||
class Document extends Any
|
||||
{
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return 'Document';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Collection
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return Response::MODEL_DOCUMENT;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->addRule('$id', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Document ID.',
|
||||
'default' => '',
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('$collection', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Collection ID.',
|
||||
'default' => '',
|
||||
'example' => '5e5ea5c15117e',
|
||||
])
|
||||
->addRule('$permissions', [
|
||||
'type' => Response::MODEL_PERMISSIONS,
|
||||
'description' => 'Document permissions.',
|
||||
'default' => new \stdClass,
|
||||
'example' => new \stdClass,
|
||||
'array' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user