Skip to content

Fixed issue #19481: After composer installation sample data can't be installed from command line #27481

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

Merged
merged 8 commits into from
Jun 5, 2020

Conversation

andrewbess
Copy link
Contributor

@andrewbess andrewbess commented Mar 28, 2020

Description (*)

This PR fixes the problem when sample data aren't deploying if the field "version" has removed from composer.json.

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes Magento 2.3.0: After composer installation sampledata can't be installed from command line #19481: Magento 2.3.0: After composer installation sampledata can't be installed from command line

Manual testing scenarios (*)

  1. Install Magento with the composer;
  2. Remove the version number from the composer.json file in the root of the project;
  3. Try to deploy sample data using bin/magento sampledata:deploy

Actual result

  1. Command throws the following error:
bin/magento sampledata:deploy
Git installations must deploy sample data from GitHub; see https://devdocs.magento.com/guides/v2.3/install-gde/install/sample-data-after-clone.html for more information.

console-output-before-fix

  1. The sample data haven't deployed.

Result after fix

  1. Command throws the following message:
bin/magento sampledata:deploy
We don't recommend to remove the "version" field from your composer.json; see https://getcomposer.org/doc/02-libraries.md#library-versioning for more information.
The field "version" has been restored.

console-output-after-fix

  1. The field "version" has been restored in composer.json;

  2. The sample data have been deployed successfully.

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

… sampledata can't be installed from command line
@m2-assistant
Copy link

m2-assistant bot commented Mar 28, 2020

Hi @andrewbess. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@magento-engcom-team magento-engcom-team added Component: SampleData Release Line: 2.4 Partner: Atwix Pull Request is created by partner Atwix partners-contribution Pull Request is created by Magento Partner labels Mar 28, 2020
Copy link
Contributor

@lbajsarowicz lbajsarowicz left a comment

Choose a reason for hiding this comment

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

There's just a minor change + code lint that is going to be detected by Static Tests.
Logic and the approach is - in my opinion - correct. Especially taking into consideration additional notice about missing version node.

Comment on lines 99 to 103
$rootJson = json_decode(
$this->filesystem->getDirectoryRead(
DirectoryList::ROOT
)->readFile("composer.json")
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you use Json Serializer from Magento package?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello @lbajsarowicz
Thank you for your review.
I fixed it. Please check.
Thank you in advance.

$output->writeln('<info>' . 'Git installations must deploy sample data from GitHub; see https://devdocs.magento.com/guides/v2.3/install-gde/install/sample-data-after-clone.html for more information.' . '</info>');
return;
$magentoProductPackage = array_filter(
(array) $rootJson->require,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if you linted your code properly (let's wait for Static tests)

@magento-engcom-team
Copy link
Contributor

Hi @lbajsarowicz, thank you for the review.
ENGCOM-7219 has been created to process this Pull Request
✳️ @lbajsarowicz, could you please add one of the following labels to the Pull Request?

Label Description
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests

Copy link
Contributor

@lbajsarowicz lbajsarowicz left a comment

Choose a reason for hiding this comment

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

The only issue I see is the serializer interface. That should be explicit JSON, as Magento is going to - sooner or later - replace the serializer preference.

*/
public function __construct(
Filesystem $filesystem,
Dependency $sampleDataDependency,
ArrayInputFactory $arrayInputFactory,
ApplicationFactory $applicationFactory
ApplicationFactory $applicationFactory,
SerializerInterface $serializer
Copy link
Contributor

Choose a reason for hiding this comment

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

I think Magento is not the guy you'd like to trust when it comes to Serializer interface :-P
Use the one \Magento\Framework\Serialize\Serializer\Json

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello @lbajsarowicz
Thank you for your review.
I changed SerializerInterface to Serializer\Json. Please check.
Thank you in advance.

Comment on lines 192 to 197
return [
'command' => 'config',
'setting-key' => 'version',
'setting-value' => ['0.0.1'],
'--quiet' => 1
];
Copy link
Contributor

Choose a reason for hiding this comment

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

That can be just private const STUB_EXPECTED_COMPOSER_CONFIG

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello @lbajsarowicz
Thank you for your review.
I fixed it. Please check.
Thank you in advance.

@magento-engcom-team
Copy link
Contributor

Hi @lbajsarowicz, thank you for the review.
ENGCOM-7219 has been created to process this Pull Request
✳️ @lbajsarowicz, could you please add one of the following labels to the Pull Request?

Label Description
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests

@andrewbess andrewbess force-pushed the issue-19481 branch 2 times, most recently from 6bbeb54 to 05b1190 Compare March 28, 2020 21:11
* @return void
*/
private function updateMemoryLimit()
{
if (function_exists('ini_set')) {
@ini_set('display_errors', 1);
Copy link
Contributor Author

@andrewbess andrewbess Mar 29, 2020

Choose a reason for hiding this comment

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

Hello @lbajsarowicz
I changed @ini_set to ini_alter (that's the alias of ini_set) and added throwing an exception when ini_set returns an error.
Please check it.
Thank you in advance.

@lbajsarowicz lbajsarowicz added the Auto-Tests: Covered All changes in Pull Request is covered by auto-tests label Apr 2, 2020
* @return void
*/
private function updateMemoryLimit()
{
if (function_exists('ini_set')) {
@ini_set('display_errors', 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use // phpcs:ignore Magento2.Functions.DiscouragedFunction for the legacy code. ini_alter should be added to the discouraged list as well https://github.com/magento/magento-coding-standard/blob/develop/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello @lenaorobei
Thank you for your remark.
I have reverted ini_alter to ini_set (without @).
Also, today I am going to add all alias to discouraged functions

@ghost ghost assigned lenaorobei Apr 3, 2020
@magento-engcom-team
Copy link
Contributor

Hi @slavvka, thank you for the review.
ENGCOM-7219 has been created to process this Pull Request

@slavvka
Copy link
Member

slavvka commented May 27, 2020

@magento run all tests

Copy link
Member

@slavvka slavvka left a comment

Choose a reason for hiding this comment

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

My mistake

@magento-engcom-team
Copy link
Contributor

Hi @slavvka, thank you for the review.
ENGCOM-7219 has been created to process this Pull Request

@m2-assistant
Copy link

m2-assistant bot commented Jun 5, 2020

Hi @andrewbess, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@andrewbess andrewbess deleted the issue-19481 branch June 5, 2020 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: bug fix Award: test coverage Component: Exception Component: SampleData Partner: Atwix Pull Request is created by partner Atwix partners-contribution Pull Request is created by Magento Partner Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: accept QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope QA: Ready to add to Regression Scope Should be analyzed and added to Regression Testing Scope(if applicable) Release Line: 2.4 Severity: S1 Affects critical data or functionality and forces users to employ a workaround.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Magento 2.3.0: After composer installation sampledata can't be installed from command line
9 participants