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 (2) #9726

Merged
merged 2 commits into from
Jun 29, 2017

Conversation

jalogut
Copy link
Contributor

@jalogut jalogut commented May 22, 2017

Description

I a second custom database into etc/env.php is added like that, it is not possible to get the database connection using custom_setup as $resourceName:

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.

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

Fixed Issue

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

… database resource contains '_setup', default is returned as resourceName does not match after replacement
@jalogut jalogut changed the title Remove wrong '_setup' replace when getting DB connection. If a custom… Remove wrong '_setup' replace when getting DB connection (2) May 22, 2017
@fooman
Copy link
Contributor

fooman commented May 30, 2017

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

To me this looks like it would rely on the functionality that is removed. As to why this is implemented in such a way I don't know.

@jalogut
Copy link
Contributor Author

jalogut commented Jun 8, 2017

Hi @fooman ,

Actually the code that you mention has nothing to do with that. This 2 lines of code are simply creating a new instance of Magento\Quote\Setup\QuoteSetup and Magento\Sales\Setup\SalesSetup. The resourceName parameter is not even used as there is not such argument on the __construct of these classes. See this and this

I have checked all calls to the method edited in this pull request and the only $resourceName passed to this function containing the word _setup is default_setup. Even in this case the logic will not find a connectionName for resourceName = default, so the default connection \Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION is always used.

For me there is no such need to replace _setup. This only prevents a custom database to use _setup in the resourceName. That is a bit weird, if we want to be consistent with Magento and use custom_setup same Magento uses default_setup

@fooman fooman self-assigned this Jun 8, 2017
@fooman fooman added this to the June 2017 milestone Jun 8, 2017
@fooman fooman added the develop label Jun 8, 2017
@fooman
Copy link
Contributor

fooman commented Jun 8, 2017

Thanks @jalogut for the explanation. I'll progress this PR along (this will run tests on the EE version as well) and will try to get someone from the Magento side to let us know why this was done in the first place.

@fooman
Copy link
Contributor

fooman commented Jun 22, 2017

@jalogut apologies for the delay. The internal testsuite looks all good for your proposed changes. Would you mind quickly addressing this mini style issue highlighted by codacy here https://www.codacy.com/app/antonkril/magento2/pullRequest?prid=592044

@jalogut
Copy link
Contributor Author

jalogut commented Jun 28, 2017

Hi @fooman,

Done.

@fooman
Copy link
Contributor

fooman commented Jun 28, 2017

@jalogut good stuff - will keep you posted.

@magento-team magento-team merged commit bb7d3ef into magento:develop Jun 29, 2017
@fooman
Copy link
Contributor

fooman commented Jun 30, 2017

Thank you @jalogut for your contribution - it's been merged.

@jalogut jalogut deleted the fix-db-connection-setup-replace branch July 25, 2017 11:44
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.

None yet

3 participants