0

Following that guide

https://devdocs.magento.com/guides/v2.3/migration/migration-tool-configure.html

I choose to configure migration in a separate module as recommended.

But when run

bin/magento migrate:settings -r app/code/Bileamara/Migration/etc/opensource-to-opensource/1.9.4.0/config.xml

I got the following error:

Invalid map filename: /mnt/vdb/vhosts/example.com/subdomains/dev/vendor/magento/data-migration-tool/etc/opensource-to-opensource/settings.xml

but what is expected is that the script looking for files first in the custom module than in the vendor folder.

Any help?

0

I managed to make it works in the following way:

app/code/Vendor/Migration/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
  <preference for="Migration\Reader\Map" type="Vendor\Migration\Reader\Map" />
  <preference for="Migration\Reader\Groups" type="Vendor\Migration\Reader\Groups" />
  <preference for="Migration\Reader\ClassMap" type="Vendor\Migration\Reader\ClassMap" />
  <preference for="Migration\Reader\Settings" type="Vendor\Migration\Reader\Settings" />
</config>

app/code/Vendor/Migration/Reader/ClassMap.php

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Vendor\Migration\Reader;

/**
 * Class ClassMap
 */
class ClassMap extends \Migration\Reader\ClassMap
{

    /**
     * Validating xml file
     *
     * @return $this
     * @throws Exception
     */
    protected function validate()
    {
        $mapFile = $this->config->getOption(self::MAP_FILE_OPTION);
        $rootDir = dirname(__DIR__) . DIRECTORY_SEPARATOR;
        $configFile = $rootDir . $mapFile;
        if (!is_file($configFile)) {
            return parent::validate();
        }
        $xml = file_get_contents($configFile);
        $document = new \Magento\Framework\Config\Dom($xml, $this->validationState);

        if (!$document->validate($rootDir .'etc/' . self::CONFIGURATION_SCHEMA)) {
            throw new Exception('XML file is invalid.');
        }

        $this->xml = new \DOMXPath($document->getDom());
        return $this;
    }
}

app/code/Vendor/Migration/Reader/Groups.php

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Vendor\Migration\Reader;

/**
 * Class Groups
 */
class Groups extends \Migration\Reader\Groups
{
    /**
     * Init configuration
     *
     * @param string $groupsFile
     * @return $this
     * @throws Exception
     */
    public function init($groupsFile)
    {
        $xmlFile = $this->getThisRootDir() . $groupsFile;
        if (!is_file($xmlFile)) {
            return parent::init($groupsFile);
        }

        $xml = file_get_contents($xmlFile);
        $document = new \Magento\Framework\Config\Dom($xml, $this->validationState);

        if (!$document->validate($this->getRootDir() .'etc/' . self::CONFIGURATION_SCHEMA)) {
            throw new Exception('XML file is invalid.');
        }

        $this->xml = new \DOMXPath($document->getDom());
        return $this;
    }

    /**
     * Get Migration Tool Configuration Dir
     *
     * @return string
     */
    protected function getThisRootDir()
    {
        return dirname(__DIR__) . DIRECTORY_SEPARATOR;
    }
}

app/code/Vendor/Migration/Reader/Map.php

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Vendor\Migration\Reader;

/**
 * Class Map
 */
class Map extends \Migration\Reader\Map
{

    /**
     * Init configuration
     *
     * @param string $mapFile
     * @return $this
     * @throws Exception
     */
    protected function init($mapFile)
    {
        $this->ignoredDocuments = [];
        $this->wildcards = null;

        $configFile = $this->getThisRootDir() . $mapFile;
        if (!is_file($configFile)) {
            return parent::init($mapFile);
        }

        $xml = file_get_contents($configFile);
        $document = new \Magento\Framework\Config\Dom($xml, $this->validationState);

        if (!$document->validate($this->getRootDir() .'etc/' . self::CONFIGURATION_SCHEMA)) {
            throw new Exception('XML file is invalid.');
        }

        $this->xml = new \DOMXPath($document->getDom());
        return $this;
    }

    /**
     * Get Migration Tool Configuration Dir
     *
     * @return string
     */
    protected function getThisRootDir()
    {
        return dirname(__DIR__) . DIRECTORY_SEPARATOR;
    }

}

app/code/Vendor/Migration/Reader/Settings.php

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Vendor\Migration\Reader;

use Migration\Exception;

/**
 * Class Settings
 */
class Settings extends \Migration\Reader\Settings
{

    /**
     * Validating xml file
     *
     * @return $this
     * @throws Exception
     */
    protected function validate()
    {
        $mapFile = $this->config->getOption(self::MAP_FILE_OPTION);
        $rootDir = dirname(__DIR__) . DIRECTORY_SEPARATOR;
        $configFile = $rootDir . $mapFile;
        if (!is_file($configFile)) {
            return parent::validate();
        }

        $xml = file_get_contents($configFile);
        $document = new \Magento\Framework\Config\Dom($xml, $this->validationState);

        if (!$document->validate($rootDir .'etc/' . self::CONFIGURATION_SCHEMA)) {
            throw new Exception('XML file is invalid.');
        }

        $this->xml = new \DOMXPath($document->getDom());
        return $this;
    }
}

I hope will help someone.

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.