1
0
Fork 0
mirror of synced 2024-06-03 03:14:50 +12:00

Merge branch '0.9.x' of github.com:appwrite/appwrite into feat-db-refactor-routes

This commit is contained in:
kodumbeats 2021-07-01 12:51:07 -04:00
commit d68f7254be
27 changed files with 270 additions and 242 deletions

View file

@ -16,7 +16,7 @@ FROM php:8.0-cli-alpine as step1
ENV PHP_REDIS_VERSION=5.3.4 \ ENV PHP_REDIS_VERSION=5.3.4 \
PHP_MONGODB_VERSION=1.9.1 \ PHP_MONGODB_VERSION=1.9.1 \
PHP_SWOOLE_VERSION=v4.6.6 \ PHP_SWOOLE_VERSION=v4.6.7 \
PHP_IMAGICK_VERSION=master \ PHP_IMAGICK_VERSION=master \
PHP_YAML_VERSION=2.2.1 \ PHP_YAML_VERSION=2.2.1 \
PHP_MAXMINDDB_VERSION=v1.10.1 PHP_MAXMINDDB_VERSION=v1.10.1

View file

@ -1,6 +1,6 @@
<?php <?php
require_once __DIR__.'/init.php'; require_once __DIR__.'/workers.php';
use Utopia\App; use Utopia\App;
use Utopia\CLI\CLI; use Utopia\CLI\CLI;

View file

@ -111,7 +111,7 @@ return [
[ [
'key' => 'android', 'key' => 'android',
'name' => 'Android', 'name' => 'Android',
'version' => '0.0.0-SNAPSHOT', 'version' => '0.0.1',
'url' => 'https://github.com/appwrite/sdk-for-android', 'url' => 'https://github.com/appwrite/sdk-for-android',
'package' => 'https://repo1.maven.org/maven2/io/appwrite/sdk-for-android/', 'package' => 'https://repo1.maven.org/maven2/io/appwrite/sdk-for-android/',
'enabled' => true, 'enabled' => true,
@ -346,6 +346,23 @@ return [
'gitRepoName' => 'sdk-for-cli', 'gitRepoName' => 'sdk-for-cli',
'gitUserName' => 'appwrite', 'gitUserName' => 'appwrite',
], ],
[
'key' => 'kotlin',
'name' => 'Kotlin',
'version' => '0.0.1',
'url' => 'https://github.com/appwrite/sdk-for-kotlin',
'package' => 'https://repo1.maven.org/maven2/io/appwrite/sdk-for-kotlin/',
'enabled' => true,
'beta' => true,
'dev' => false,
'hidden' => false,
'family' => APP_PLATFORM_SERVER,
'prism' => 'kotlin',
'source' => \realpath(__DIR__ . '/../sdks/server-kotlin'),
'gitUrl' => 'git@github.com:appwrite/sdk-for-kotlin.git',
'gitRepoName' => 'sdk-for-kotlin',
'gitUserName' => 'appwrite',
],
], ],
], ],
]; ];

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -42,12 +42,11 @@ App::get('/v1/health/db')
->label('sdk.method', 'getDB') ->label('sdk.method', 'getDB')
->label('sdk.description', '/docs/references/health/get-db.md') ->label('sdk.description', '/docs/references/health/get-db.md')
->inject('response') ->inject('response')
->inject('register') ->inject('app')
->action(function ($response, $register) { ->action(function ($response, $app) {
/** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Registry\Registry $register */ /** @var Utopia\App $app */
$app->getResource('db');
$register->get('db'); /* @var $db PDO */
$response->json(['status' => 'OK']); $response->json(['status' => 'OK']);
}); });
@ -61,11 +60,11 @@ App::get('/v1/health/cache')
->label('sdk.method', 'getCache') ->label('sdk.method', 'getCache')
->label('sdk.description', '/docs/references/health/get-cache.md') ->label('sdk.description', '/docs/references/health/get-cache.md')
->inject('response') ->inject('response')
->inject('register') ->inject('app')
->action(function ($response, $register) { ->action(function ($response, $app) {
/** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Registry\Registry $register */ /** @var Utopia\App $register */
$register->get('cache'); /* @var $cache Predis\Client */ $app->getResource('cache');
$response->json(['status' => 'OK']); $response->json(['status' => 'OK']);
}); });

View file

@ -218,12 +218,11 @@ App::get('/v1/users/:userId/logs')
->inject('geodb') ->inject('geodb')
->action(function ($userId, $response, $dbForInternal, $locale, $geodb) { ->action(function ($userId, $response, $dbForInternal, $locale, $geodb) {
/** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Registry\Registry $register */
/** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Document $project */
/** @var Utopia\Database\Database $dbForInternal */ /** @var Utopia\Database\Database $dbForInternal */
/** @var Utopia\Locale\Locale $locale */ /** @var Utopia\Locale\Locale $locale */
/** @var MaxMind\Db\Reader $geodb */ /** @var MaxMind\Db\Reader $geodb */
$user = $dbForInternal->getDocument('users', $userId); $user = $dbForInternal->getDocument('users', $userId);
if ($user->isEmpty()) { if ($user->isEmpty()) {

View file

@ -137,18 +137,22 @@ $http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swo
return; return;
} }
$app = new App('UTC');
$db = $register->get('dbPool')->get(); $db = $register->get('dbPool')->get();
$redis = $register->get('redisPool')->get(); $redis = $register->get('redisPool')->get();
$register->set('db', function () use (&$db) { App::setResource('db', function () use (&$db) {
return $db; return $db;
}); });
$register->set('cache', function () use (&$redis) { App::setResource('cache', function () use (&$redis) {
return $redis; return $redis;
}); });
$app = new App('UTC'); App::setResource('app', function() use (&$app) {
return $app;
});
try { try {
Authorization::cleanRoles(); Authorization::cleanRoles();

View file

@ -24,8 +24,6 @@ use Appwrite\Database\Database;
use Appwrite\Database\Adapter\MySQL as MySQLAdapter; use Appwrite\Database\Adapter\MySQL as MySQLAdapter;
use Appwrite\Database\Adapter\Redis as RedisAdapter; use Appwrite\Database\Adapter\Redis as RedisAdapter;
use Appwrite\Database\Document; use Appwrite\Database\Document;
use Appwrite\Database\Pool\PDOPool;
use Appwrite\Database\Pool\RedisPool;
use Appwrite\Database\Validator\Authorization; use Appwrite\Database\Validator\Authorization;
use Appwrite\Event\Event; use Appwrite\Event\Event;
use Appwrite\OpenSSL\OpenSSL; use Appwrite\OpenSSL\OpenSSL;
@ -42,6 +40,10 @@ use Utopia\Database\Adapter\MariaDB;
use Utopia\Database\Document as Document2; use Utopia\Database\Document as Document2;
use Utopia\Database\Database as Database2; use Utopia\Database\Database as Database2;
use Utopia\Database\Validator\Authorization as Authorization2; use Utopia\Database\Validator\Authorization as Authorization2;
use Swoole\Database\PDOConfig;
use Swoole\Database\PDOPool;
use Swoole\Database\RedisConfig;
use Swoole\Database\RedisPool;
const APP_NAME = 'Appwrite'; const APP_NAME = 'Appwrite';
const APP_DOMAIN = 'appwrite.io'; const APP_DOMAIN = 'appwrite.io';
@ -54,7 +56,7 @@ const APP_PAGING_LIMIT = 12;
const APP_LIMIT_COUNT = 5000; const APP_LIMIT_COUNT = 5000;
const APP_LIMIT_USERS = 10000; const APP_LIMIT_USERS = 10000;
const APP_CACHE_BUSTER = 148; const APP_CACHE_BUSTER = 148;
const APP_VERSION_STABLE = '0.8.0'; const APP_VERSION_STABLE = '0.9.0';
const APP_STORAGE_UPLOADS = '/storage/uploads'; const APP_STORAGE_UPLOADS = '/storage/uploads';
const APP_STORAGE_FUNCTIONS = '/storage/functions'; const APP_STORAGE_FUNCTIONS = '/storage/functions';
const APP_STORAGE_CACHE = '/storage/cache'; const APP_STORAGE_CACHE = '/storage/cache';
@ -188,10 +190,21 @@ Database2::addFilter('encrypt',
*/ */
$register->set('dbPool', function () { // Register DB connection $register->set('dbPool', function () { // Register DB connection
$dbHost = App::getEnv('_APP_DB_HOST', ''); $dbHost = App::getEnv('_APP_DB_HOST', '');
$dbPort = App::getEnv('_APP_DB_PORT', '');
$dbUser = App::getEnv('_APP_DB_USER', ''); $dbUser = App::getEnv('_APP_DB_USER', '');
$dbPass = App::getEnv('_APP_DB_PASS', ''); $dbPass = App::getEnv('_APP_DB_PASS', '');
$dbScheme = App::getEnv('_APP_DB_SCHEMA', ''); $dbScheme = App::getEnv('_APP_DB_SCHEMA', '');
$pool = new PDOPool(10, $dbHost, $dbScheme, $dbUser, $dbPass);
$pool = new PDOPool((new PDOConfig())
->withHost($dbHost)
->withPort($dbPort)
// ->withUnixSocket('/tmp/mysql.sock')
->withDbName($dbScheme)
->withCharset('utf8mb4')
->withUsername($dbUser)
->withPassword($dbPass)
);
return $pool; return $pool;
}); });
@ -200,16 +213,18 @@ $register->set('redisPool', function () {
$redisPort = App::getEnv('_APP_REDIS_PORT', ''); $redisPort = App::getEnv('_APP_REDIS_PORT', '');
$redisUser = App::getEnv('_APP_REDIS_USER', ''); $redisUser = App::getEnv('_APP_REDIS_USER', '');
$redisPass = App::getEnv('_APP_REDIS_PASS', ''); $redisPass = App::getEnv('_APP_REDIS_PASS', '');
$redisAuth = []; $redisAuth = '';
if ($redisUser) { if ($redisUser && $redisPass) {
$redisAuth[] = $redisUser; $redisAuth = $redisUser.':'.$redisPass;
}
if ($redisPass) {
$redisAuth[] = $redisPass;
} }
$pool = new RedisPool(10, $redisHost, $redisPort, $redisAuth); $pool = new RedisPool((new RedisConfig)
->withHost($redisHost)
->withPort($redisPort)
->withAuth($redisAuth)
->withDbIndex(0)
);
return $pool; return $pool;
}); });
@ -567,23 +582,23 @@ App::setResource('console', function() {
]); ]);
}, []); }, []);
App::setResource('consoleDB', function($register) { App::setResource('consoleDB', function($db, $cache) {
$consoleDB = new Database(); $consoleDB = new Database();
$consoleDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register)); $consoleDB->setAdapter(new RedisAdapter(new MySQLAdapter($db, $cache), $cache));
$consoleDB->setNamespace('app_console'); // Should be replaced with param if we want to have parent projects $consoleDB->setNamespace('app_console'); // Should be replaced with param if we want to have parent projects
$consoleDB->setMocks(Config::getParam('collections', [])); $consoleDB->setMocks(Config::getParam('collections', []));
return $consoleDB; return $consoleDB;
}, ['register']); }, ['db', 'cache']);
App::setResource('projectDB', function($register, $project) { App::setResource('projectDB', function($db, $cache, $project) {
$projectDB = new Database(); $projectDB = new Database();
$projectDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register)); $projectDB->setAdapter(new RedisAdapter(new MySQLAdapter($db, $cache), $cache));
$projectDB->setNamespace('app_'.$project->getId()); $projectDB->setNamespace('app_'.$project->getId());
$projectDB->setMocks(Config::getParam('collections', [])); $projectDB->setMocks(Config::getParam('collections', []));
return $projectDB; return $projectDB;
}, ['register', 'project']); }, ['db', 'cache', 'project']);
App::setResource('dbForInternal', function($register, $project) { App::setResource('dbForInternal', function($register, $project) {
$cache = new Cache(new RedisCache($register->get('cache'))); $cache = new Cache(new RedisCache($register->get('cache')));

View file

@ -14,16 +14,18 @@ $cli
->task('migrate') ->task('migrate')
->action(function () use ($register) { ->action(function () use ($register) {
Console::success('Starting Data Migration'); Console::success('Starting Data Migration');
$db = $register->get('db', true);
$cache = $register->get('cache', true);
$consoleDB = new Database(); $consoleDB = new Database();
$consoleDB $consoleDB
->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register)) ->setAdapter(new RedisAdapter(new MySQLAdapter($db, $cache), $cache))
->setNamespace('app_console') // Main DB ->setNamespace('app_console') // Main DB
->setMocks(Config::getParam('collections', [])); ->setMocks(Config::getParam('collections', []));
$projectDB = new Database(); $projectDB = new Database();
$projectDB $projectDB
->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register)) ->setAdapter(new RedisAdapter(new MySQLAdapter($db, $cache), $cache))
->setMocks(Config::getParam('collections', [])); ->setMocks(Config::getParam('collections', []));
$console = $consoleDB->getDocument('console'); $console = $consoleDB->getDocument('console');
@ -36,7 +38,7 @@ $cli
$projects = [$console]; $projects = [$console];
$count = 0; $count = 0;
$migration = new Version\V07($register->get('db')); //TODO: remove hardcoded version and move to dynamic migration $migration = new Version\V08($register->get('db')); //TODO: remove hardcoded version and move to dynamic migration
while ($sum > 0) { while ($sum > 0) {
foreach ($projects as $project) { foreach ($projects as $project) {

View file

@ -16,6 +16,7 @@ use Appwrite\SDK\Language\DotNet;
use Appwrite\SDK\Language\Flutter; use Appwrite\SDK\Language\Flutter;
use Appwrite\SDK\Language\Go; use Appwrite\SDK\Language\Go;
use Appwrite\SDK\Language\Kotlin; use Appwrite\SDK\Language\Kotlin;
use Appwrite\SDK\Language\Android;
use Appwrite\SDK\Language\Swift; use Appwrite\SDK\Language\Swift;
$cli $cli
@ -142,6 +143,9 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
$config = new DotNet(); $config = new DotNet();
break; break;
case 'android': case 'android':
$config = new Android();
break;
case 'kotlin':
$config = new Kotlin(); $config = new Kotlin();
break; break;
default: default:
@ -179,7 +183,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
->setTwitter(APP_SOCIAL_TWITTER_HANDLE) ->setTwitter(APP_SOCIAL_TWITTER_HANDLE)
->setDiscord(APP_SOCIAL_DISCORD_CHANNEL, APP_SOCIAL_DISCORD) ->setDiscord(APP_SOCIAL_DISCORD_CHANNEL, APP_SOCIAL_DISCORD)
->setDefaultHeaders([ ->setDefaultHeaders([
'X-Appwrite-Response-Format' => '0.8.0', 'X-Appwrite-Response-Format' => '0.9.0',
]) ])
; ;

View file

@ -28,8 +28,11 @@ class CertificatesV1 extends Worker
{ {
global $register; global $register;
$db = $register->get('db');
$cache = $register->get('cache');
$consoleDB = new Database(); $consoleDB = new Database();
$consoleDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register)); $consoleDB->setAdapter(new RedisAdapter(new MySQLAdapter($db, $cache), $cache));
$consoleDB->setNamespace('app_console'); // Main DB $consoleDB->setNamespace('app_console'); // Main DB
$consoleDB->setMocks(Config::getParam('collections', [])); $consoleDB->setMocks(Config::getParam('collections', []));

View file

@ -179,7 +179,6 @@ class DeletesV1 extends Worker
throw new Exception('Failed to delete audit logs. No timestamp provided'); throw new Exception('Failed to delete audit logs. No timestamp provided');
} }
$this->deleteForProjectIds(function($projectId) use ($timestamp){ $this->deleteForProjectIds(function($projectId) use ($timestamp){
$timeLimit = new TimeLimit("", 0, 1, $this->getInternalDB($projectId)); $timeLimit = new TimeLimit("", 0, 1, $this->getInternalDB($projectId));
$abuse = new Abuse($timeLimit); $abuse = new Abuse($timeLimit);
@ -356,9 +355,12 @@ class DeletesV1 extends Worker
{ {
global $register; global $register;
$db = $register->get('db');
$cache = $register->get('cache');
if($this->consoleDB === null) { if($this->consoleDB === null) {
$this->consoleDB = new Database(); $this->consoleDB = new Database();
$this->consoleDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register)); $this->consoleDB->setAdapter(new RedisAdapter(new MySQLAdapter($db, $cache), $cache));;
$this->consoleDB->setNamespace('app_console'); // Main DB $this->consoleDB->setNamespace('app_console'); // Main DB
$this->consoleDB->setMocks(Config::getParam('collections', [])); $this->consoleDB->setMocks(Config::getParam('collections', []));
} }
@ -372,9 +374,12 @@ class DeletesV1 extends Worker
protected function getProjectDB($projectId): Database protected function getProjectDB($projectId): Database
{ {
global $register; global $register;
$db = $register->get('db');
$cache = $register->get('cache');
$projectDB = new Database(); $projectDB = new Database();
$projectDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register)); $projectDB->setAdapter(new RedisAdapter(new MySQLAdapter($db, $cache), $cache));
$projectDB->setNamespace('app_'.$projectId); // Main DB $projectDB->setNamespace('app_'.$projectId); // Main DB
$projectDB->setMocks(Config::getParam('collections', [])); $projectDB->setMocks(Config::getParam('collections', []));

View file

@ -2,6 +2,7 @@
use Appwrite\Event\Event; use Appwrite\Event\Event;
use Appwrite\Resque\Worker; use Appwrite\Resque\Worker;
use Appwrite\Utopia\Response\Model\Execution;
use Cron\CronExpression; use Cron\CronExpression;
use Swoole\Runtime; use Swoole\Runtime;
use Utopia\App; use Utopia\App;
@ -138,6 +139,9 @@ class FunctionsV1 extends Worker
{ {
global $register; global $register;
$db = $register->get('db');
$cache = $register->get('cache');
$projectId = $this->args['projectId'] ?? ''; $projectId = $this->args['projectId'] ?? '';
$functionId = $this->args['functionId'] ?? ''; $functionId = $this->args['functionId'] ?? '';
$webhooks = $this->args['webhooks'] ?? []; $webhooks = $this->args['webhooks'] ?? [];
@ -461,6 +465,7 @@ class FunctionsV1 extends Worker
Authorization::reset(); Authorization::reset();
$executionModel = new Execution();
$executionUpdate = new Event('v1-webhooks', 'WebhooksV1'); $executionUpdate = new Event('v1-webhooks', 'WebhooksV1');
$executionUpdate $executionUpdate
@ -468,17 +473,7 @@ class FunctionsV1 extends Worker
->setParam('userId', $userId) ->setParam('userId', $userId)
->setParam('webhooks', $webhooks) ->setParam('webhooks', $webhooks)
->setParam('event', 'functions.executions.update') ->setParam('event', 'functions.executions.update')
->setParam('eventData', [ ->setParam('eventData', $execution->getArrayCopy(array_keys($executionModel->getRules())));
'$id' => $execution['$id'],
'functionId' => $execution['functionId'],
'dateCreated' => $execution['dateCreated'],
'trigger' => $execution['trigger'],
'status' => $execution['status'],
'exitCode' => $execution['exitCode'],
'stdout' => $execution['stdout'],
'stderr' => $execution['stderr'],
'time' => $execution['time']
]);
$executionUpdate->trigger(); $executionUpdate->trigger();

View file

@ -30,8 +30,11 @@ class TasksV1 extends Worker
{ {
global $register; global $register;
$db = $register->get('db');
$cache = $register->get('cache');
$consoleDB = new Database(); $consoleDB = new Database();
$consoleDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register)); $consoleDB->setAdapter(new RedisAdapter(new MySQLAdapter($db, $cache), $cache));
$consoleDB->setNamespace('app_console'); // Main DB $consoleDB->setNamespace('app_console'); // Main DB
$consoleDB->setMocks(Config::getParam('collections', [])); $consoleDB->setMocks(Config::getParam('collections', []));

View file

@ -54,13 +54,13 @@
"utopia-php/storage": "0.5.*", "utopia-php/storage": "0.5.*",
"utopia-php/image": "0.5.*", "utopia-php/image": "0.5.*",
"resque/php-resque": "1.3.6", "resque/php-resque": "1.3.6",
"matomo/device-detector": "4.2.2", "matomo/device-detector": "4.2.3",
"dragonmantank/cron-expression": "3.1.0", "dragonmantank/cron-expression": "3.1.0",
"influxdb/influxdb-php": "1.15.2", "influxdb/influxdb-php": "1.15.2",
"phpmailer/phpmailer": "6.5.0", "phpmailer/phpmailer": "6.5.0",
"chillerlan/php-qrcode": "4.3.0", "chillerlan/php-qrcode": "4.3.0",
"adhocore/jwt": "1.1.2", "adhocore/jwt": "1.1.2",
"slickdeals/statsd": "3.0.2" "slickdeals/statsd": "3.1.0"
}, },
"repositories": [ "repositories": [
{ {
@ -73,9 +73,9 @@
} }
], ],
"require-dev": { "require-dev": {
"appwrite/sdk-generator": "0.10.11", "appwrite/sdk-generator": "0.11.0",
"swoole/ide-helper": "4.6.6", "swoole/ide-helper": "4.6.7",
"phpunit/phpunit": "9.5.4", "phpunit/phpunit": "9.5.6",
"vimeo/psalm": "4.7.2" "vimeo/psalm": "4.7.2"
}, },
"provide": { "provide": {

77
composer.lock generated
View file

@ -848,16 +848,16 @@
}, },
{ {
"name": "matomo/device-detector", "name": "matomo/device-detector",
"version": "4.2.2", "version": "4.2.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/matomo-org/device-detector.git", "url": "https://github.com/matomo-org/device-detector.git",
"reference": "dc270e7645d286d6f01d516a6634aba8b31ad668" "reference": "d879f07496d6e6ee89cef5bcd925383d9b0c2cc0"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/matomo-org/device-detector/zipball/dc270e7645d286d6f01d516a6634aba8b31ad668", "url": "https://api.github.com/repos/matomo-org/device-detector/zipball/d879f07496d6e6ee89cef5bcd925383d9b0c2cc0",
"reference": "dc270e7645d286d6f01d516a6634aba8b31ad668", "reference": "d879f07496d6e6ee89cef5bcd925383d9b0c2cc0",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -913,7 +913,7 @@
"source": "https://github.com/matomo-org/matomo", "source": "https://github.com/matomo-org/matomo",
"wiki": "https://dev.matomo.org/" "wiki": "https://dev.matomo.org/"
}, },
"time": "2021-02-26T07:31:42+00:00" "time": "2021-05-12T14:14:25+00:00"
}, },
{ {
"name": "mongodb/mongodb", "name": "mongodb/mongodb",
@ -1448,31 +1448,33 @@
}, },
{ {
"name": "slickdeals/statsd", "name": "slickdeals/statsd",
"version": "3.0.2", "version": "3.1.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/Slickdeals/statsd-php.git", "url": "https://github.com/Slickdeals/statsd-php.git",
"reference": "393c6565efbfb23c8296ae3099a62fb6366c6ce3" "reference": "225588a0a079e145359049f6e5e23eedb1b4c17f"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/Slickdeals/statsd-php/zipball/393c6565efbfb23c8296ae3099a62fb6366c6ce3", "url": "https://api.github.com/repos/Slickdeals/statsd-php/zipball/225588a0a079e145359049f6e5e23eedb1b4c17f",
"reference": "393c6565efbfb23c8296ae3099a62fb6366c6ce3", "reference": "225588a0a079e145359049f6e5e23eedb1b4c17f",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">= 7.2" "php": ">= 7.3 || ^8"
},
"replace": {
"domnikl/statsd": "self.version"
}, },
"require-dev": { "require-dev": {
"flyeralarm/php-code-validator": "^2.2", "friendsofphp/php-cs-fixer": "^3.0",
"phpunit/phpunit": "~8.0", "phpunit/phpunit": "^9",
"vimeo/psalm": "^3.4" "vimeo/psalm": "^4.6"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Domnikl\\Statsd\\": "src/", "Domnikl\\Statsd\\": "src/"
"Domnikl\\Test\\Statsd\\": "tests/unit"
} }
}, },
"notification-url": "https://packagist.org/downloads/", "notification-url": "https://packagist.org/downloads/",
@ -1486,7 +1488,7 @@
} }
], ],
"description": "a PHP client for statsd", "description": "a PHP client for statsd",
"homepage": "https://domnikl.github.com/statsd-php", "homepage": "https://github.com/Slickdeals/statsd-php",
"keywords": [ "keywords": [
"Metrics", "Metrics",
"monitoring", "monitoring",
@ -1495,9 +1497,10 @@
"udp" "udp"
], ],
"support": { "support": {
"source": "https://github.com/Slickdeals/statsd-php/tree/3.0.2" "issues": "https://github.com/Slickdeals/statsd-php/issues",
"source": "https://github.com/Slickdeals/statsd-php/tree/3.1.0"
}, },
"time": "2020-01-03T14:24:58+00:00" "time": "2021-06-04T20:33:46+00:00"
}, },
{ {
"name": "symfony/polyfill-ctype", "name": "symfony/polyfill-ctype",
@ -2723,16 +2726,16 @@
}, },
{ {
"name": "appwrite/sdk-generator", "name": "appwrite/sdk-generator",
"version": "0.10.11", "version": "0.11.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/appwrite/sdk-generator.git", "url": "https://github.com/appwrite/sdk-generator.git",
"reference": "f73391d482660798f4077d54760d67e633bdde1e" "reference": "96c41c44f930a4d40184cd0f3c7dca76d2cca7e1"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/f73391d482660798f4077d54760d67e633bdde1e", "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/96c41c44f930a4d40184cd0f3c7dca76d2cca7e1",
"reference": "f73391d482660798f4077d54760d67e633bdde1e", "reference": "96c41c44f930a4d40184cd0f3c7dca76d2cca7e1",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2766,9 +2769,9 @@
"description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms",
"support": { "support": {
"issues": "https://github.com/appwrite/sdk-generator/issues", "issues": "https://github.com/appwrite/sdk-generator/issues",
"source": "https://github.com/appwrite/sdk-generator/tree/0.10.11" "source": "https://github.com/appwrite/sdk-generator/tree/0.11.0"
}, },
"time": "2021-06-07T11:37:50+00:00" "time": "2021-07-01T13:51:23+00:00"
}, },
{ {
"name": "composer/semver", "name": "composer/semver",
@ -4127,16 +4130,16 @@
}, },
{ {
"name": "phpunit/phpunit", "name": "phpunit/phpunit",
"version": "9.5.4", "version": "9.5.6",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git", "url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "c73c6737305e779771147af66c96ca6a7ed8a741" "reference": "fb9b8333f14e3dce976a60ef6a7e05c7c7ed8bfb"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c73c6737305e779771147af66c96ca6a7ed8a741", "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fb9b8333f14e3dce976a60ef6a7e05c7c7ed8bfb",
"reference": "c73c6737305e779771147af66c96ca6a7ed8a741", "reference": "fb9b8333f14e3dce976a60ef6a7e05c7c7ed8bfb",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -4166,7 +4169,7 @@
"sebastian/global-state": "^5.0.1", "sebastian/global-state": "^5.0.1",
"sebastian/object-enumerator": "^4.0.3", "sebastian/object-enumerator": "^4.0.3",
"sebastian/resource-operations": "^3.0.3", "sebastian/resource-operations": "^3.0.3",
"sebastian/type": "^2.3", "sebastian/type": "^2.3.4",
"sebastian/version": "^3.0.2" "sebastian/version": "^3.0.2"
}, },
"require-dev": { "require-dev": {
@ -4214,7 +4217,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues", "issues": "https://github.com/sebastianbergmann/phpunit/issues",
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.4" "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.6"
}, },
"funding": [ "funding": [
{ {
@ -4226,7 +4229,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2021-03-23T07:16:29+00:00" "time": "2021-06-23T05:14:38+00:00"
}, },
{ {
"name": "psr/container", "name": "psr/container",
@ -5242,16 +5245,16 @@
}, },
{ {
"name": "swoole/ide-helper", "name": "swoole/ide-helper",
"version": "4.6.6", "version": "4.6.7",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/swoole/ide-helper.git", "url": "https://github.com/swoole/ide-helper.git",
"reference": "d29d71267f8ed4e4993dc057ca53ffdb5d2703b7" "reference": "0d1409b8274117addfe64d3ea412812a69807411"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/swoole/ide-helper/zipball/d29d71267f8ed4e4993dc057ca53ffdb5d2703b7", "url": "https://api.github.com/repos/swoole/ide-helper/zipball/0d1409b8274117addfe64d3ea412812a69807411",
"reference": "d29d71267f8ed4e4993dc057ca53ffdb5d2703b7", "reference": "0d1409b8274117addfe64d3ea412812a69807411",
"shasum": "" "shasum": ""
}, },
"require-dev": { "require-dev": {
@ -5274,7 +5277,7 @@
"description": "IDE help files for Swoole.", "description": "IDE help files for Swoole.",
"support": { "support": {
"issues": "https://github.com/swoole/ide-helper/issues", "issues": "https://github.com/swoole/ide-helper/issues",
"source": "https://github.com/swoole/ide-helper/tree/4.6.6" "source": "https://github.com/swoole/ide-helper/tree/4.6.7"
}, },
"funding": [ "funding": [
{ {
@ -5290,7 +5293,7 @@
"type": "open_collective" "type": "open_collective"
} }
], ],
"time": "2021-04-22T16:38:11+00:00" "time": "2021-05-14T16:05:16+00:00"
}, },
{ {
"name": "symfony/console", "name": "symfony/console",

View file

@ -2,13 +2,12 @@
namespace Appwrite\Database\Adapter; namespace Appwrite\Database\Adapter;
use Utopia\Registry\Registry;
use Appwrite\Database\Adapter; use Appwrite\Database\Adapter;
use Appwrite\Database\Exception\Duplicate; use Appwrite\Database\Exception\Duplicate;
use Appwrite\Database\Validator\Authorization; use Appwrite\Database\Validator\Authorization;
use Exception; use Exception;
use PDO; use PDO;
use Redis as Client; use Redis;
class MySQL extends Adapter class MySQL extends Adapter
{ {
@ -23,11 +22,6 @@ class MySQL extends Adapter
const OPTIONS_LIMIT_ATTRIBUTES = 1000; const OPTIONS_LIMIT_ATTRIBUTES = 1000;
/**
* @var Registry
*/
protected $register;
/** /**
* Last modified. * Last modified.
* *
@ -42,16 +36,28 @@ class MySQL extends Adapter
*/ */
protected $debug = []; protected $debug = [];
/**
* @var PDO
*/
protected $pdo;
/**
* @var Redis
*/
protected $redis;
/** /**
* Constructor. * Constructor.
* *
* Set connection and settings * Set connection and settings
* *
* @param Registry $register * @param PDO $pdo
* @param Redis $redis
*/ */
public function __construct(Registry $register) public function __construct($pdo, Redis $redis)
{ {
$this->register = $register; $this->pdo = $pdo;
$this->redis = $redis;
} }
/** /**
@ -87,8 +93,8 @@ class MySQL extends Adapter
ORDER BY `order` ORDER BY `order`
'); ');
$st->bindParam(':documentUid', $document['uid'], PDO::PARAM_STR); $st->bindParam(':documentUid', $document['uid'], PDO::PARAM_STR, 32);
$st->bindParam(':documentRevision', $document['revision'], PDO::PARAM_STR); $st->bindParam(':documentRevision', $document['revision'], PDO::PARAM_STR, 32);
$st->execute(); $st->execute();
@ -116,8 +122,8 @@ class MySQL extends Adapter
ORDER BY `order` ORDER BY `order`
'); ');
$st->bindParam(':start', $document['uid'], PDO::PARAM_STR); $st->bindParam(':start', $document['uid'], PDO::PARAM_STR, 32);
$st->bindParam(':revision', $document['revision'], PDO::PARAM_STR); $st->bindParam(':revision', $document['revision'], PDO::PARAM_STR, 32);
$st->execute(); $st->execute();
@ -933,18 +939,18 @@ class MySQL extends Adapter
* *
* @throws Exception * @throws Exception
*/ */
protected function getPDO(): PDO protected function getPDO()
{ {
return $this->register->get('db'); return $this->pdo;
} }
/** /**
* @throws Exception * @throws Exception
* *
* @return Client * @return Redis
*/ */
protected function getRedis(): Client protected function getRedis(): Redis
{ {
return $this->register->get('cache'); return $this->redis;
} }
} }

View file

@ -2,7 +2,6 @@
namespace Appwrite\Database\Adapter; namespace Appwrite\Database\Adapter;
use Utopia\Registry\Registry;
use Appwrite\Database\Adapter; use Appwrite\Database\Adapter;
use Exception; use Exception;
use Redis as Client; use Redis as Client;
@ -10,9 +9,9 @@ use Redis as Client;
class Redis extends Adapter class Redis extends Adapter
{ {
/** /**
* @var Registry * @var Client
*/ */
protected $register; protected $redis;
/** /**
* @var Adapter * @var Adapter
@ -23,11 +22,11 @@ class Redis extends Adapter
* Redis constructor. * Redis constructor.
* *
* @param Adapter $adapter * @param Adapter $adapter
* @param Registry $register * @param Client $redis
*/ */
public function __construct(Adapter $adapter, Registry $register) public function __construct(Adapter $adapter, Client $redis)
{ {
$this->register = $register; $this->redis = $redis;
$this->adapter = $adapter; $this->adapter = $adapter;
} }
@ -261,7 +260,7 @@ class Redis extends Adapter
*/ */
protected function getRedis(): Client protected function getRedis(): Client
{ {
return $this->register->get('cache'); return $this->redis;
} }
/** /**
@ -281,4 +280,4 @@ class Redis extends Adapter
return parent::setNamespace($namespace); return parent::setNamespace($namespace);
} }
} }

View file

@ -1,20 +0,0 @@
<?php
namespace Appwrite\Database;
abstract class Pool
{
protected $available = true;
protected $pool;
protected $size = 5;
abstract public function get();
public function destruct()
{
$this->available = false;
while (!$this->pool->isEmpty()) {
$this->pool->pop();
}
}
}

View file

@ -1,49 +0,0 @@
<?php
namespace Appwrite\Database\Pool;
use Appwrite\Database\Pool;
use Appwrite\Extend\PDO;
use SplQueue;
class PDOPool extends Pool
{
public function __construct(int $size, string $host = 'localhost', string $schema = 'appwrite', string $user = '', string $pass = '', string $charset = 'utf8mb4')
{
$this->pool = new SplQueue;
$this->size = $size;
for ($i = 0; $i < $this->size; $i++) {
$pdo = new PDO(
"mysql:" .
"host={$host};" .
"dbname={$schema};" .
"charset={$charset}",
$user,
$pass,
[
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4',
PDO::ATTR_TIMEOUT => 3, // Seconds
PDO::ATTR_PERSISTENT => true,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true
]
);
$this->pool->enqueue($pdo);
}
}
public function put(PDO $pdo)
{
$this->pool->enqueue($pdo);
}
public function get(): PDO
{
if ($this->available && count($this->pool) > 0) {
return $this->pool->dequeue();
}
sleep(0.01);
return $this->get();
}
}

View file

@ -1,42 +0,0 @@
<?php
namespace Appwrite\Database\Pool;
use Appwrite\Database\Pool;
use SplQueue;
use Redis;
class RedisPool extends Pool
{
public function __construct(int $size, string $host, int $port, array $auth = [])
{
$this->pool = new SplQueue;
$this->size = $size;
for ($i = 0; $i < $this->size; $i++) {
$redis = new Redis();
$redis->pconnect($host, $port);
$redis->setOption(Redis::OPT_READ_TIMEOUT, -1);
if ($auth) {
$redis->auth($auth);
}
$this->pool->enqueue($redis);
}
}
public function put(Redis $redis)
{
$this->pool->enqueue($redis);
}
public function get(): Redis
{
if ($this->available && !$this->pool->isEmpty()) {
return $this->pool->dequeue();
}
sleep(0.1);
return $this->get();
}
}

View file

@ -13,7 +13,6 @@ class V07 extends Migration
{ {
public function execute(): void public function execute(): void
{ {
$db = $this->db;
$project = $this->project; $project = $this->project;
Console::log('Migrating project: ' . $project->getAttribute('name') . ' (' . $project->getId() . ')'); Console::log('Migrating project: ' . $project->getAttribute('name') . ' (' . $project->getId() . ')');

View file

@ -0,0 +1,53 @@
<?php
namespace Appwrite\Migration\Version;
use Appwrite\Migration\Migration;
use Utopia\Config\Config;
use Utopia\CLI\Console;
use Appwrite\Database\Database;
use Appwrite\Database\Document;
class V08 extends Migration
{
public function execute(): void
{
$project = $this->project;
Console::log('Migrating project: ' . $project->getAttribute('name') . ' (' . $project->getId() . ')');
$this->forEachDocument([$this, 'fixDocument']);
}
protected function fixDocument(Document $document)
{
switch ($document->getAttribute('$collection')) {
/**
* Rename env attribute to runtime.
*/
case Database::SYSTEM_COLLECTION_FUNCTIONS:
if ($document->isSet('env')) {
$document
->setAttribute('runtime', $document->getAttribute('env', $document->getAttribute('env', '')))
->removeAttribute('env');
}
break;
}
foreach ($document as &$attr) {
if ($attr instanceof Document) {
$attr = $this->fixDocument($attr);
}
if (\is_array($attr)) {
foreach ($attr as &$child) {
if ($child instanceof Document) {
$child = $this->fixDocument($child);
}
}
}
}
return $document;
}
}

View file

@ -48,13 +48,13 @@ class Execution extends Model
]) ])
->addRule('stdout', [ ->addRule('stdout', [
'type' => self::TYPE_STRING, 'type' => self::TYPE_STRING,
'description' => 'The script stdout output string.', 'description' => 'The script stdout output string. Logs the last 4,000 characters of the execution stdout output.',
'default' => '', 'default' => '',
'example' => '', 'example' => '',
]) ])
->addRule('stderr', [ ->addRule('stderr', [
'type' => self::TYPE_STRING, 'type' => self::TYPE_STRING,
'description' => 'The script stderr output string.', 'description' => 'The script stderr output string. Logs the last 4,000 characters of the execution stderr output',
'default' => '', 'default' => '',
'example' => '', 'example' => '',
]) ])

View file

@ -0,0 +1,33 @@
<?php
namespace Appwrite\Tests;
use ReflectionClass;
use Appwrite\Database\Database;
use Appwrite\Database\Document;
use Appwrite\Auth\Auth;
use Appwrite\Migration\Version\V08;
class MigrationV08Test extends MigrationTest
{
public function setUp(): void
{
$this->pdo = new \PDO('sqlite::memory:');
$this->migration = new V08($this->pdo);
$reflector = new ReflectionClass('Appwrite\Migration\Version\V08');
$this->method = $reflector->getMethod('fixDocument');
$this->method->setAccessible(true);
}
public function testMigration()
{
$document = $this->fixDocument(new Document([
'$id' => 'unique',
'$collection' => Database::SYSTEM_COLLECTION_FUNCTIONS,
'env' => 'node-16'
]));
$this->assertEquals($document->getAttribute('env', null), null);
$this->assertEquals($document->getAttribute('runtime', null), 'node-16');
}
}