diff --git a/app/controllers/general.php b/app/controllers/general.php index dcf205ce52..4f483e4055 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -22,7 +22,7 @@ Config::setParam('domainVerification', false); Config::setParam('cookieDomain', 'localhost'); Config::setParam('cookieSamesite', Response::COOKIE_SAMESITE_NONE); -App::init(function ($utopia, $request, $response, $console, $project, $user, $locale, $clients, $dbForConsole) { +App::init(function ($utopia, $request, $response, $console, $project, $user, $locale, $clients) { /** @var Utopia\Swoole\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $console */ @@ -30,37 +30,6 @@ App::init(function ($utopia, $request, $response, $console, $project, $user, $lo /** @var Appwrite\Database\Document $user */ /** @var Utopia\Locale\Locale $locale */ /** @var array $clients */ - /** @var Utopia\Database\Database $dbForConsole */ - - if(!$dbForConsole->exists()) { - - Console::success('init database!!'); - - $collections = Config::getParam('collections2', []); /** @var array $collections */ - - $dbForConsole->create(); - - foreach ($collections as $key => $collection) { - $dbForConsole->createCollection($key); - - foreach ($collection['attributes'] as $i => $attribute) { - $dbForConsole->createAttribute( - $key, - $attribute['$id'], - $attribute['type'], - $attribute['size'], - $attribute['required'], - $attribute['signed'], - $attribute['array'], - $attribute['filters'], - ); - } - - foreach ($collection['indexes'] as $i => $index) { - - } - } - } $localeParam = (string)$request->getParam('locale', $request->getHeader('x-appwrite-locale', '')); @@ -260,7 +229,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $user, $lo throw new Exception('Password reset is required', 412); } -}, ['utopia', 'request', 'response', 'console', 'project', 'user', 'locale', 'clients', 'dbForConsole']); +}, ['utopia', 'request', 'response', 'console', 'project', 'user', 'locale', 'clients']); App::options(function ($request, $response) { /** @var Utopia\Swoole\Request $request */ diff --git a/app/http.php b/app/http.php index 23679a90bb..ec8fffd025 100644 --- a/app/http.php +++ b/app/http.php @@ -12,6 +12,7 @@ use Swoole\Http\Request as SwooleRequest; use Swoole\Http\Response as SwooleResponse; use Utopia\App; use Utopia\CLI\Console; +use Utopia\Config\Config; use Utopia\Database\Validator\Authorization as Authorization2; // xdebug_start_trace('/tmp/trace'); @@ -51,6 +52,41 @@ $http->on('AfterReload', function($serv, $workerId) { $http->on('start', function (Server $http) use ($payloadSize) { + /** @var Utopia\Database\Database $dbForConsole */ + $app = new App('UTC'); + $dbForConsole = $app->getResource('dbForConsole'); + + if(!$dbForConsole->exists()) { + Console::success('[Setup] - Server database init started...'); + + $collections = Config::getParam('collections2', []); /** @var array $collections */ + + $dbForConsole->create(); + + foreach ($collections as $key => $collection) { + $dbForConsole->createCollection($key); + + foreach ($collection['attributes'] as $i => $attribute) { + $dbForConsole->createAttribute( + $key, + $attribute['$id'], + $attribute['type'], + $attribute['size'], + $attribute['required'], + $attribute['signed'], + $attribute['array'], + $attribute['filters'], + ); + } + + foreach ($collection['indexes'] as $i => $index) { + + } + } + + Console::success('[Setup] - Server database init completed...'); + } + Console::success('Server started succefully (max payload is '.number_format($payloadSize).' bytes)'); Console::info("Master pid {$http->master_pid}, manager pid {$http->manager_pid}"); diff --git a/app/init.php b/app/init.php index d874b05394..666bf59f56 100644 --- a/app/init.php +++ b/app/init.php @@ -527,14 +527,14 @@ App::setResource('dbForExternal', function($register, $project) { return $database; }, ['register', 'project']); -App::setResource('dbForConsole', function($register, $project) { +App::setResource('dbForConsole', function($register) { $cache = new Cache(new RedisCache($register->get('cache'))); $database = new DatabaseDatabase(new MariaDB($register->get('db')), $cache); - $database->setNamespace('project_console_internal'); + $database->setNamespace('project_console'); return $database; -}, ['register', 'project']); +}, ['register']); App::setResource('mode', function($request) { /** @var Utopia\Swoole\Request $request */