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

Remove wrong '_setup' replace when getting DB connection #9121

Closed

Conversation

jalogut
Copy link
Contributor

@jalogut jalogut commented Apr 4, 2017

If a custom database resource contains '_setup', default is returned as resourceName does not match after replacement.

… database resource contains '_setup', default is returned as resourceName does not match after replacement
@okorshenko
Copy link
Contributor

@jalogut thank you for your contribution.
Could you please provide more details about your use case?
Currently in Magento 2 we have separate connection for Setup application. Frontend or Backend of the application should not use setup connection to do their logic. Why do you need to user smth_setup connection on frontend?

@okorshenko
Copy link
Contributor

Closing this PR due to inactivity

@jalogut
Copy link
Contributor Author

jalogut commented May 12, 2017

Hi @okorshenko ,

Sorry for the delay in my reply, I did not see you answer.
Our case is simply to add a second custom database into etc/env.php like that:

array (
    'table_prefix' => '',
    'connection' => 
    array (
      'custom' => 
      array (
        'host' => 'localhost',
        'dbname' => '<db_custom>',
        'username' => '<user>',
        'password' => '<pass>',
        'engine' => 'innodb',
        'initStatements' => 'SET NAMES utf8;',
        'active' => '1',
      ),
      'default' => 
      array (
        'host' => 'localhost',
        'dbname' => '<db_default>',
        'username' => '<user>',
        'password' => '<pass>',
        'model' => 'mysql4',
        'engine' => 'innodb',
        'initStatements' => 'SET NAMES utf8;',
        'active' => '1',
      ),
    ),
  ),
  'resource' => 
  array (
    'custom_setup' => 
    array (
      'connection' => 'custom',
    ),
    'default_setup' => 
    array (
      'connection' => 'default',
    ),
  ),

After that I would expect to use the custom database by resource name custom_setup. However, as _setup is always replaced, the system does not find any resource with this name. Then, I need to use a different name without _setup. From my point of view, there is no need to replace that. In fact, the only reason why default_setup database works is because default connection is the fall back. When calling resource default_setup is also not found but it falls back to default.

So my question here. What is exactly the purpose of replacing _setup? I checked the code and I do not see any need to have that.

@jalogut
Copy link
Contributor Author

jalogut commented May 12, 2017

Could you please open the PR again and have another look after my comment?

Thanks

@jalogut
Copy link
Contributor Author

jalogut commented May 22, 2017

I created a new PR with my last comment. I am not sure if someone has checked out my explanation as the PR was already closed.

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

Successfully merging this pull request may close these issues.

2 participants