Skip to content

[BACKPORT 2.2] [BUGFIX] check if currentStoreId === '' so report isn't generated if … #11915

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

Conversation

lewisvoncken
Copy link
Contributor

same as magento-partners/magento2ce#60

Description

When you try to switch to a non-existing or empty store code you the request will result in an Exception.

Fixed Issues (if relevant)

  1. Accessing url with ___store= creates exception #9433: Accessing url with ___store= creates exception

Manual testing scenarios

  1. Try to switch to http://www.example.com/?___store=
  2. This will result in an Exception
  3. Try to switch to http://www.example.com/?___store=nonexistingcode

@dmanners
Copy link
Contributor

dmanners commented Nov 1, 2017

There is also a problem with 1 of the integration tests.

There was 1 failure:
1) Magento\Config\Console\Command\ConfigSetCommandTest::testConfigSetValidationError with data set #7 ('general/locale/code', 'en_UK', 'The "wrong_store_code" value ...value.', 'store', 'wrong_store_code')
Symfony\Component\Console\Output\OutputInterface::writeln('<error>Expectation failed for...error>', 0) was not expected to be called more than once.
/home/travis/build/magento/magento2/app/code/Magento/Config/Console/Command/ConfigSetCommand.php:162
/home/travis/build/magento/magento2/vendor/symfony/console/Command/Command.php:266
/home/travis/build/magento/magento2/dev/tests/integration/testsuite/Magento/Config/Console/Command/ConfigSetCommandTest.php:504
/home/travis/build/magento/magento2/dev/tests/integration/testsuite/Magento/Config/Console/Command/ConfigSetCommandTest.php:465
/home/travis/build/magento/magento2/dev/tests/integration/testsuite/Magento/Config/Console/Command/ConfigSetCommandTest.php:304

Copy link
Contributor

@dmanners dmanners left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a couple of questions but nothing too major here.


return $store;
}

/**
* @return int
*/
public function getCurrentStoreId()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this method need to be public? I can only see it being used currently inside this class.

} elseif (key_exists($storeId, $this->storeRepository->getList())) {
$store = $this->storeRepository->get($storeId);
} else {
$store = $this->storeRepository->getById($this->getCurrentStoreId());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit curious about this else. From what I can see $storeId will be the result of $this->getCurrentStoreId(). Is there any reason you have not just used $storeId here rather than calling $this->getCurrentStoreId()?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also from what I can see this thing could be done with:

if (is_numeric($storeId) || !key_exists($storeId, $this->storeRepository->getList())) {
    $store = $this->storeRepository->getById($storeId);
} else {
    $store = $this->storeRepository->get($storeId);
}

Or have I missed something out here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmanners $storeId may be passed from outside as a method parameter. And this is actually the issue, as there are several places where ___store query parameter just fetched from a query object and passed to store manager. Store resolver already implements a logic for correct handling of the invalid store code or id.

I'm worrying about this implementation as at this point we do not know exactly that $storeId value comes from ___store query parameter so any code issue will be silently handled without any notification and may lead to unpredictable result and hard to detect bugs.

I think we should find a solution in which only value of ___store query parameter will be affected.

@dmanners
Copy link
Contributor

@lewisvoncken have you had any chance to look into this feedback and the tests?

@lewisvoncken
Copy link
Contributor Author

lewisvoncken commented Nov 11, 2017 via email


return $store;
}

/**
* @return int
*/
public function getCurrentStoreId()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @dmanners mentioned there are no reasons to make this method public. For patch releases (2.1-develop and 2.2-develop) we should avoid introduction of new public methods to existing class even if they look as a good addition to a class public interface.

} elseif (key_exists($storeId, $this->storeRepository->getList())) {
$store = $this->storeRepository->get($storeId);
} else {
$store = $this->storeRepository->getById($this->getCurrentStoreId());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmanners $storeId may be passed from outside as a method parameter. And this is actually the issue, as there are several places where ___store query parameter just fetched from a query object and passed to store manager. Store resolver already implements a logic for correct handling of the invalid store code or id.

I'm worrying about this implementation as at this point we do not know exactly that $storeId value comes from ___store query parameter so any code issue will be silently handled without any notification and may lead to unpredictable result and hard to detect bugs.

I think we should find a solution in which only value of ___store query parameter will be affected.

@lewisvoncken
Copy link
Contributor Author

@dmanners working on it #magetestfest

@dmanners
Copy link
Contributor

HI @lewisvoncken do you need any help with this PR?

@okorshenko okorshenko removed the 2.2.x label Dec 14, 2017
@okorshenko okorshenko modified the milestones: December 2017, January 2018 Jan 8, 2018
@magento-engcom-team magento-engcom-team added the Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release label Jan 8, 2018
@dmanners
Copy link
Contributor

Hi @lewisvoncken I am going to close this PR due to inactivity. If you feel like getting back into this code feel free to re-raise this PR at a later date.

@dmanners dmanners closed this Jan 19, 2018
@lewisvoncken lewisvoncken reopened this Oct 30, 2018
@sivaschenko
Copy link
Member

Hi @lewisvoncken, can you please provide some update on this PR, as you reopened it after a year of inactivity.

@sivaschenko sivaschenko self-assigned this Nov 19, 2018
@sivaschenko
Copy link
Member

Closing due to inactivity. Feel free to contact me if you'd like to continue work on this pull request. Thanks for the collaboration!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report bugfix Progress: needs update Release Line: 2.2 Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants