Set/reset tenant on init
This commit is contained in:
parent
7b8e37b03d
commit
b9ac8e644d
1 changed files with 17 additions and 12 deletions
29
app/init.php
29
app/init.php
|
@ -953,9 +953,7 @@ App::setResource('clients', function ($request, $console, $project) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$clients = array_unique($clients);
|
return \array_unique($clients);
|
||||||
|
|
||||||
return $clients;
|
|
||||||
}, ['request', 'console', 'project']);
|
}, ['request', 'console', 'project']);
|
||||||
|
|
||||||
App::setResource('user', function ($mode, $project, $console, $request, $response, $dbForProject, $dbForConsole) {
|
App::setResource('user', function ($mode, $project, $console, $request, $response, $dbForProject, $dbForConsole) {
|
||||||
|
@ -1127,22 +1125,26 @@ App::setResource('dbForProject', function (Group $pools, Database $dbForConsole,
|
||||||
$database = new Database($dbAdapter, $cache);
|
$database = new Database($dbAdapter, $cache);
|
||||||
|
|
||||||
$database
|
$database
|
||||||
->setNamespace('_' . $project->getInternalId())
|
|
||||||
->setMetadata('host', \gethostname())
|
->setMetadata('host', \gethostname())
|
||||||
->setMetadata('project', $project->getId())
|
->setMetadata('project', $project->getId())
|
||||||
->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS);
|
->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS);
|
||||||
|
|
||||||
if ($project->getAttribute('shareTables')) {
|
if ($project->getAttribute('shareTables')) {
|
||||||
$database
|
$database
|
||||||
->setNamespace('')
|
|
||||||
->setShareTables(true)
|
->setShareTables(true)
|
||||||
->setTenant($project->getId());
|
->setTenant($project->getInternalId())
|
||||||
|
->setNamespace('');
|
||||||
|
} else {
|
||||||
|
$database
|
||||||
|
->setShareTables(false)
|
||||||
|
->setTenant(null)
|
||||||
|
->setNamespace('_' . $project->getInternalId());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $database;
|
return $database;
|
||||||
}, ['pools', 'dbForConsole', 'cache', 'project']);
|
}, ['pools', 'dbForConsole', 'cache', 'project']);
|
||||||
|
|
||||||
App::setResource('dbForConsole', function (Group $pools, Cache $cache, Document $project) {
|
App::setResource('dbForConsole', function (Group $pools, Cache $cache) {
|
||||||
$dbAdapter = $pools
|
$dbAdapter = $pools
|
||||||
->get('console')
|
->get('console')
|
||||||
->pop()
|
->pop()
|
||||||
|
@ -1151,14 +1153,13 @@ App::setResource('dbForConsole', function (Group $pools, Cache $cache, Document
|
||||||
$database = new Database($dbAdapter, $cache);
|
$database = new Database($dbAdapter, $cache);
|
||||||
|
|
||||||
$database
|
$database
|
||||||
->setTenant($project->getId())
|
|
||||||
->setNamespace('_console')
|
->setNamespace('_console')
|
||||||
->setMetadata('host', \gethostname())
|
->setMetadata('host', \gethostname())
|
||||||
->setMetadata('project', 'console')
|
->setMetadata('project', 'console')
|
||||||
->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS);
|
->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS);
|
||||||
|
|
||||||
return $database;
|
return $database;
|
||||||
}, ['pools', 'cache', 'project']);
|
}, ['pools', 'cache']);
|
||||||
|
|
||||||
App::setResource('getProjectDB', function (Group $pools, Database $dbForConsole, $cache) {
|
App::setResource('getProjectDB', function (Group $pools, Database $dbForConsole, $cache) {
|
||||||
$databases = []; // TODO: @Meldiron This should probably be responsibility of utopia-php/pools
|
$databases = []; // TODO: @Meldiron This should probably be responsibility of utopia-php/pools
|
||||||
|
@ -1172,16 +1173,20 @@ App::setResource('getProjectDB', function (Group $pools, Database $dbForConsole,
|
||||||
|
|
||||||
$configure = (function (Database $database) use ($project) {
|
$configure = (function (Database $database) use ($project) {
|
||||||
$database
|
$database
|
||||||
->setNamespace('_' . $project->getInternalId())
|
|
||||||
->setMetadata('host', \gethostname())
|
->setMetadata('host', \gethostname())
|
||||||
->setMetadata('project', $project->getId())
|
->setMetadata('project', $project->getId())
|
||||||
->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS);
|
->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS);
|
||||||
|
|
||||||
if ($project->getAttribute('shareTables')) {
|
if ($project->getAttribute('shareTables')) {
|
||||||
$database
|
$database
|
||||||
->setNamespace('')
|
|
||||||
->setShareTables(true)
|
->setShareTables(true)
|
||||||
->setTenant($project->getId());
|
->setTenant($project->getInternalId())
|
||||||
|
->setNamespace('');
|
||||||
|
} else {
|
||||||
|
$database
|
||||||
|
->setShareTables(false)
|
||||||
|
->setTenant(null)
|
||||||
|
->setNamespace('_' . $project->getInternalId());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue