0

I want to update a Magento installation with sample data from 2.0.2 to 2.0.7, so I am following the instructions here to update the sample data.

When running

bin/magento sampledata:reset

I get the following error message:

[ErrorException]
file_get_contents(/path/to/magento/src/Vendor/Module/src/composer.json): failed to open stream: No such file or directory

The directory /path/to/magento/src/Vendor/Module/src/ contains the source code of a custom module which is not installed via composer.

The module registration file lies in /path/to/magento/src/Vendor/Module/registration.php with the following content:

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Vendor_Module',
    __DIR__ . '/src'
);

The module has a composer.json file in /path/to/magento/src/Vendor/Module/composer.json, so if I can tell Magento to use that one it will be fine, but I wonder where the assumption is made that a composer.json is in the module source directory even if it has not been installed with composer.

The sampledata:reset command is the first one where I ran into trouble with this setup. What can I do to make it work?

0

I found the culprit: Magento\SampleData\Model\Dependency::getSuggestsFromModules() looks for a composer.json in all module directories but does not verify if it exists.

foreach ($this->componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleDir) {
    $file = $moduleDir . '/composer.json';
    ...

This only affects the sample data module and IMHO is a bug because local modules that are not installed via composer are a real thing.

I also found a relatively new GitHub issue about it: https://github.com/magento/magento2/issues/4636 (MX label for "Merchant Experience")

Until this is fixed, you can add the following line after the code from above to ignore missing composer.json files:

if (! \file_exists($file)) continue;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.