Merge branch 'refactor-usage-sn' into fix-deployment-not-found-error
This commit is contained in:
commit
7f038ec704
5 changed files with 83 additions and 67 deletions
|
@ -639,7 +639,7 @@ return [
|
||||||
Exception::PROJECT_PROVIDER_UNSUPPORTED => [
|
Exception::PROJECT_PROVIDER_UNSUPPORTED => [
|
||||||
'name' => Exception::PROJECT_PROVIDER_UNSUPPORTED,
|
'name' => Exception::PROJECT_PROVIDER_UNSUPPORTED,
|
||||||
'description' => 'The chosen OAuth provider is unsupported. Please check the <a href="/docs/client/account?sdk=web-default#accountCreateOAuth2Session">Create OAuth2 Session docs</a> for the complete list of supported OAuth providers.',
|
'description' => 'The chosen OAuth provider is unsupported. Please check the <a href="/docs/client/account?sdk=web-default#accountCreateOAuth2Session">Create OAuth2 Session docs</a> for the complete list of supported OAuth providers.',
|
||||||
'code' => 501,
|
'code' => 400,
|
||||||
],
|
],
|
||||||
Exception::PROJECT_INVALID_SUCCESS_URL => [
|
Exception::PROJECT_INVALID_SUCCESS_URL => [
|
||||||
'name' => Exception::PROJECT_INVALID_SUCCESS_URL,
|
'name' => Exception::PROJECT_INVALID_SUCCESS_URL,
|
||||||
|
|
|
@ -4,6 +4,7 @@ use Appwrite\Auth\Auth;
|
||||||
use Appwrite\Event\Delete;
|
use Appwrite\Event\Delete;
|
||||||
use Appwrite\Event\Validator\Event;
|
use Appwrite\Event\Validator\Event;
|
||||||
use Appwrite\Extend\Exception;
|
use Appwrite\Extend\Exception;
|
||||||
|
use Appwrite\Hooks\Hooks;
|
||||||
use Appwrite\Network\Validator\Email;
|
use Appwrite\Network\Validator\Email;
|
||||||
use Appwrite\Network\Validator\Origin;
|
use Appwrite\Network\Validator\Origin;
|
||||||
use Appwrite\Template\Template;
|
use Appwrite\Template\Template;
|
||||||
|
@ -75,7 +76,8 @@ App::post('/v1/projects')
|
||||||
->inject('dbForConsole')
|
->inject('dbForConsole')
|
||||||
->inject('cache')
|
->inject('cache')
|
||||||
->inject('pools')
|
->inject('pools')
|
||||||
->action(function (string $projectId, string $name, string $teamId, string $region, string $description, string $logo, string $url, string $legalName, string $legalCountry, string $legalState, string $legalCity, string $legalAddress, string $legalTaxId, Response $response, Database $dbForConsole, Cache $cache, Group $pools) {
|
->inject('hooks')
|
||||||
|
->action(function (string $projectId, string $name, string $teamId, string $region, string $description, string $logo, string $url, string $legalName, string $legalCountry, string $legalState, string $legalCity, string $legalAddress, string $legalTaxId, Response $response, Database $dbForConsole, Cache $cache, Group $pools, Hooks $hooks) {
|
||||||
|
|
||||||
|
|
||||||
$team = $dbForConsole->getDocument('teams', $teamId);
|
$team = $dbForConsole->getDocument('teams', $teamId);
|
||||||
|
@ -217,6 +219,8 @@ App::post('/v1/projects')
|
||||||
$dbForProject->createCollection($key, $attributes, $indexes);
|
$dbForProject->createCollection($key, $attributes, $indexes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$hooks->trigger('afterProjectCreation', [ $project, $pools, $cache ]);
|
||||||
|
|
||||||
$response
|
$response
|
||||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||||
->dynamic($project, Response::MODEL_PROJECT);
|
->dynamic($project, Response::MODEL_PROJECT);
|
||||||
|
|
133
app/realtime.php
133
app/realtime.php
|
@ -36,74 +36,83 @@ require_once __DIR__ . '/init.php';
|
||||||
|
|
||||||
Runtime::enableCoroutine(SWOOLE_HOOK_ALL);
|
Runtime::enableCoroutine(SWOOLE_HOOK_ALL);
|
||||||
|
|
||||||
function getConsoleDB(): Database
|
// Allows overriding
|
||||||
{
|
if (!function_exists("getConsoleDB")) {
|
||||||
global $register;
|
function getConsoleDB(): Database
|
||||||
|
{
|
||||||
|
global $register;
|
||||||
|
|
||||||
/** @var \Utopia\Pools\Group $pools */
|
/** @var \Utopia\Pools\Group $pools */
|
||||||
$pools = $register->get('pools');
|
$pools = $register->get('pools');
|
||||||
|
|
||||||
$dbAdapter = $pools
|
$dbAdapter = $pools
|
||||||
->get('console')
|
->get('console')
|
||||||
->pop()
|
|
||||||
->getResource()
|
|
||||||
;
|
|
||||||
|
|
||||||
$database = new Database($dbAdapter, getCache());
|
|
||||||
|
|
||||||
$database
|
|
||||||
->setNamespace('_console')
|
|
||||||
->setMetadata('host', \gethostname())
|
|
||||||
->setMetadata('project', '_console');
|
|
||||||
|
|
||||||
return $database;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getProjectDB(Document $project): Database
|
|
||||||
{
|
|
||||||
global $register;
|
|
||||||
|
|
||||||
/** @var \Utopia\Pools\Group $pools */
|
|
||||||
$pools = $register->get('pools');
|
|
||||||
|
|
||||||
if ($project->isEmpty() || $project->getId() === 'console') {
|
|
||||||
return getConsoleDB();
|
|
||||||
}
|
|
||||||
|
|
||||||
$dbAdapter = $pools
|
|
||||||
->get($project->getAttribute('database'))
|
|
||||||
->pop()
|
|
||||||
->getResource()
|
|
||||||
;
|
|
||||||
|
|
||||||
$database = new Database($dbAdapter, getCache());
|
|
||||||
|
|
||||||
$database
|
|
||||||
->setNamespace('_' . $project->getInternalId())
|
|
||||||
->setMetadata('host', \gethostname())
|
|
||||||
->setMetadata('project', $project->getId());
|
|
||||||
|
|
||||||
return $database;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getCache(): Cache
|
|
||||||
{
|
|
||||||
global $register;
|
|
||||||
|
|
||||||
$pools = $register->get('pools'); /** @var \Utopia\Pools\Group $pools */
|
|
||||||
|
|
||||||
$list = Config::getParam('pools-cache', []);
|
|
||||||
$adapters = [];
|
|
||||||
|
|
||||||
foreach ($list as $value) {
|
|
||||||
$adapters[] = $pools
|
|
||||||
->get($value)
|
|
||||||
->pop()
|
->pop()
|
||||||
->getResource()
|
->getResource()
|
||||||
;
|
;
|
||||||
}
|
|
||||||
|
|
||||||
return new Cache(new Sharding($adapters));
|
$database = new Database($dbAdapter, getCache());
|
||||||
|
|
||||||
|
$database
|
||||||
|
->setNamespace('_console')
|
||||||
|
->setMetadata('host', \gethostname())
|
||||||
|
->setMetadata('project', '_console');
|
||||||
|
|
||||||
|
return $database;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allows overriding
|
||||||
|
if (!function_exists("getProjectDB")) {
|
||||||
|
function getProjectDB(Document $project): Database
|
||||||
|
{
|
||||||
|
global $register;
|
||||||
|
|
||||||
|
/** @var \Utopia\Pools\Group $pools */
|
||||||
|
$pools = $register->get('pools');
|
||||||
|
|
||||||
|
if ($project->isEmpty() || $project->getId() === 'console') {
|
||||||
|
return getConsoleDB();
|
||||||
|
}
|
||||||
|
|
||||||
|
$dbAdapter = $pools
|
||||||
|
->get($project->getAttribute('database'))
|
||||||
|
->pop()
|
||||||
|
->getResource()
|
||||||
|
;
|
||||||
|
|
||||||
|
$database = new Database($dbAdapter, getCache());
|
||||||
|
|
||||||
|
$database
|
||||||
|
->setNamespace('_' . $project->getInternalId())
|
||||||
|
->setMetadata('host', \gethostname())
|
||||||
|
->setMetadata('project', $project->getId());
|
||||||
|
|
||||||
|
return $database;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allows overriding
|
||||||
|
if (!function_exists("getCache")) {
|
||||||
|
function getCache(): Cache
|
||||||
|
{
|
||||||
|
global $register;
|
||||||
|
|
||||||
|
$pools = $register->get('pools'); /** @var \Utopia\Pools\Group $pools */
|
||||||
|
|
||||||
|
$list = Config::getParam('pools-cache', []);
|
||||||
|
$adapters = [];
|
||||||
|
|
||||||
|
foreach ($list as $value) {
|
||||||
|
$adapters[] = $pools
|
||||||
|
->get($value)
|
||||||
|
->pop()
|
||||||
|
->getResource()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Cache(new Sharding($adapters));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$realtime = new Realtime();
|
$realtime = new Realtime();
|
||||||
|
|
2
composer.lock
generated
2
composer.lock
generated
|
@ -5169,5 +5169,5 @@
|
||||||
"platform-overrides": {
|
"platform-overrides": {
|
||||||
"php": "8.0"
|
"php": "8.0"
|
||||||
},
|
},
|
||||||
"plugin-api-version": "2.6.0"
|
"plugin-api-version": "2.3.0"
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,14 @@ class Hooks
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed[] $params
|
* @param mixed[] $params
|
||||||
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function trigger(string $name, array $params = [])
|
public function trigger(string $name, array $params = []): mixed
|
||||||
{
|
{
|
||||||
if (isset(self::$hooks[$name])) {
|
if (isset(self::$hooks[$name])) {
|
||||||
call_user_func_array(self::$hooks[$name], $params);
|
return call_user_func_array(self::$hooks[$name], $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue