Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken setupDriverConfig #23

Closed
duckzland opened this issue Apr 1, 2016 · 11 comments
Closed

Broken setupDriverConfig #23

duckzland opened this issue Apr 1, 2016 · 11 comments
Labels

Comments

@duckzland
Copy link

I'm not sure if this will affect normal installation of tenanti since I'm using it in more complex way than the standard behavior. But judging from the code in the TenantiManager::connection

the array set for the $this->config will never have driver key thus when TenantiSetupDriverConfig is called it will always return null

        // This will always return null since there are no array key by driver name ever set
        if (isset($this->config[$driver])) {
            return;
        }

        // this will also always return null since no drivers key ever set
        if (is_null($config = Arr::pull($this->config, "drivers.{$driver}"))) {
            return;
        }

When changed to :

        if (is_null($config = Arr::get($this->config, "connection.template"))) {
            return;
        }

it will work again as expected.

not sure if this is a bug or just my installation that need this, so I didnt make proper fork and pull request.

Thank you for the great plugin btw

@crynobone
Copy link
Member

@duckzland
Copy link
Author

I saw the commit code aside from the user observer (I'm using other logic) everything is the same and the array has 'container' as the key instead of 'tenants' which causes it to break.

Sorry if cannot test apple to apple.

@crynobone
Copy link
Member

container? Where is this exactly?

@duckzland
Copy link
Author

$this->config will have $this->config['container']

@duckzland
Copy link
Author

oh sorry it is $this->config['connection']

array(1) { ["connection"]=> array(4) { ["name"]=> string(12) "tenants_{id}" ["template"]=> array(10) { ["driver"]=> string(5) "mysql" ["host"]=> string(9) "127.0.0.1" ["port"]=> string(4) "3307" ["username"]=> string(4) "root" ["password"]=> string(7) "12duckz" ["charset"]=> string(4) "utf8" ["collation"]=> string(15) "utf8_unicode_ci" ["prefix"]=> string(0) "" ["strict"]=> bool(false) ["engine"]=> NULL } ["resolver"]=> object(Closure)#104 (2) { ["this"]=> object(App\Tenants)#106 (23) { ["table":protected]=> string(7) "tenants" ["fillable":protected]=> array(5) { [0]=> string(4) "name" [1]=> string(6) "domain" [2]=> string(5) "email" [3]=> string(6) "active" [4]=> string(6) "dbname" } ["hidden":protected]=> array(2) { [0]=> string(8) "password" [1]=> string(14) "remember_token" } ["connection":protected]=> NULL ["primaryKey":protected]=> string(2) "id" ["perPage":protected]=> int(15) ["incrementing"]=> bool(true) ["timestamps"]=> bool(true) ["attributes":protected]=> array(9) { ["id"]=> int(33) ["name"]=> string(14) "Brand New Site" ["domain"]=> string(15) "test2.ticket.io" ["email"]=> string(22) "jason.xie@victheme.com" ["active"]=> int(1) ["remember_token"]=> NULL ["created_at"]=> string(19) "2016-01-29 20:02:55" ["updated_at"]=> string(19) "2016-01-29 12:02:55" ["dbname"]=> string(10) "tenants_33" } ["original":protected]=> array(9) { ["id"]=> int(33) ["name"]=> string(14) "Brand New Site" ["domain"]=> string(15) "test2.ticket.io" ["email"]=> string(22) "jason.xie@victheme.com" ["active"]=> int(1) ["remember_token"]=> NULL ["created_at"]=> string(19) "2016-01-29 20:02:55" ["updated_at"]=> string(19) "2016-01-29 12:02:55" ["dbname"]=> string(10) "tenants_33" } ["relations":protected]=> array(0) { } ["visible":protected]=> array(0) { } ["appends":protected]=> array(0) { } ["guarded":protected]=> array(1) { [0]=> string(1) "*" } ["dates":protected]=> array(0) { } ["dateFormat":protected]=> NULL ["casts":protected]=> array(0) { } ["touches":protected]=> array(0) { } ["observables":protected]=> array(0) { } ["with":protected]=> array(0) { } ["morphClass":protected]=> NULL ["exists"]=> bool(true) ["wasRecentlyCreated"]=> bool(false) } ["parameter"]=> array(2) { ["$entity"]=> string(10) "" ["$config"]=> string(10) "" } } ["options"]=> array(0) { } } }

@crynobone
Copy link
Member

$this->config will get the drivers (tenants) value from https://github.com/orchestral/tenanti/blob/master/src/TenantiServiceProvider.php#L46

@duckzland
Copy link
Author

ok seems that the problem is registerConfigurationForManager is called after the app boot method so the database driver is not registered yet. is there a way to call it before boot?

@crynobone
Copy link
Member

It is not safe to set it before boot, orchestra.tenanti is bind on register(), while config is merge and set during boot(). Therefore in situation where you somehow resolve orchestra.tenanti (on other service provider) before boot, the config might not be available yet.

@duckzland
Copy link
Author

is it safe to redirect after register() coz I'm using this to switch database based on detected domain not user

@crynobone
Copy link
Member

That should use/set as a middleware, not service provider.

@duckzland
Copy link
Author

ok thanks for the information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants