Skip to content

Commit

Permalink
MIG-64: check the version of the destination PIM
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentPetard committed Dec 5, 2017
1 parent 8fbeb53 commit 8e85faf
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 22 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ This tool aims at helping you to migrate your *PIM 1.7 standard edition* (either

The 1.7 source PIM you will migrate from can be either installed locally or remotely.

The 2.0 destination PIM you will migrate to should be installed locally running on the port 80, you can install it following these [instructions](https://docs.akeneo.com/latest/install_pim/manual/system_requirements/system_requirements.html).
The 2.0 destination PIM you will migrate to should be installed locally running on the port 80, you can install it following these [instructions](https://docs.akeneo.com/latest/install_pim/manual/index.html).
We do not support the Docker installation yet regarding Transporteo.
The minimum version of the destination PIM is 2.0.3.

Both PIM should be functionnal and have a functionnal API with admin rights.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,23 @@ class DestinationPimConfigurationChecker
/** @var DestinationPimSystemRequirementsChecker */
private $destinationPimSystemRequirementsChecker;

public function __construct(DestinationPimEditionChecker $destinationPimEditionChecker, DestinationPimSystemRequirementsChecker $destinationPimSystemRequirementsChecker)
{
/** @var DestinationPimVersionChecker */
private $destinationPimVersionChecker;

public function __construct(
DestinationPimEditionChecker $destinationPimEditionChecker,
DestinationPimSystemRequirementsChecker $destinationPimSystemRequirementsChecker,
DestinationPimVersionChecker $destinationPimVersionChecker
) {
$this->destinationPimEditionChecker = $destinationPimEditionChecker;
$this->destinationPimSystemRequirementsChecker = $destinationPimSystemRequirementsChecker;
$this->destinationPimVersionChecker = $destinationPimVersionChecker;
}

public function check(SourcePim $sourcePim, DestinationPim $destinationPim): void
{
try {
$this->destinationPimEditionChecker->check($sourcePim, $destinationPim);
$this->destinationPimSystemRequirementsChecker->check($destinationPim);
} catch (\Exception $e) {
throw new DestinationPimCheckConfigurationException($e->getMessage(), $e->getCode(), $e);
}
$this->destinationPimEditionChecker->check($sourcePim, $destinationPim);
$this->destinationPimVersionChecker->check($destinationPim);
$this->destinationPimSystemRequirementsChecker->check($destinationPim);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace Akeneo\PimMigration\Domain\MigrationStep\s050_DestinationPimInstallation;

use Akeneo\PimMigration\Domain\Command\ChainedConsole;
use Akeneo\PimMigration\Domain\Command\SymfonyCommand;
use Akeneo\PimMigration\Domain\Pim\DestinationPim;

/**
* Checks that the version of the destination PIM is supported.
*
* @author Laurent Petard <[email protected]>
* @copyright 2017 Akeneo SAS (http://www.akeneo.com)
*/
class DestinationPimVersionChecker
{
const EXACT_MAJOR_VERSION = 2;
const EXACT_MINOR_VERSION = 0;
const MINIMUM_PATCH_VERSION = 3;

/** @var ChainedConsole */
private $console;

public function __construct(ChainedConsole $console)
{
$this->console = $console;
}

/**
* @throws DestinationPimCheckConfigurationException if the version of the destination PIM is not readable or is not at least 2.0.3
*/
public function check(DestinationPim $pim): void
{
$systemInformation = $this->console->execute(new SymfonyCommand('pim:system:information'), $pim)->getOutput();
$version = [];

if (1 !== preg_match('~Version\s+\| (?P<full>(?P<major>[0-9]+)\.(?P<minor>[0-9]+)\.(?P<patch>[0-9]+))\s+~i', $systemInformation, $version)) {
throw new DestinationPimCheckConfigurationException('Failed to read the destination PIM version.');
}

if ((int) $version['major'] !== self::EXACT_MAJOR_VERSION || (int) $version['minor'] !== self::EXACT_MINOR_VERSION) {
throw new DestinationPimCheckConfigurationException(sprintf(
'The current version of your destination PIM %s is not supported. The version should be %d.%d.x',
$version['full'],
self::EXACT_MAJOR_VERSION,
self::EXACT_MINOR_VERSION
));
}

if ((int) $version['patch'] < self::MINIMUM_PATCH_VERSION) {
throw new DestinationPimCheckConfigurationException(sprintf(
'The current version of your destination PIM %s is not supported. The minimum version of the destination PIM is %d.%d.%d',
$version['full'],
self::EXACT_MAJOR_VERSION,
self::EXACT_MINOR_VERSION,
self::MINIMUM_PATCH_VERSION
));
}
}
}
12 changes: 6 additions & 6 deletions src/Infrastructure/Common/config/transporteo_state_machine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ workflows:
- 'destination_pim_configured'
- 'destination_pim_api_configured'
- 'destination_pim_detected'
- 'destination_pim_system_requirements_installed'
- 'destination_pim_requirements_checked'
- 'destination_pim_system_requirements_installed'
- 'destination_pim_file_database_migrated'
- 'destination_pim_structure_migrated'
- 'destination_pim_family_migrated'
Expand Down Expand Up @@ -69,14 +69,14 @@ workflows:
destination_pim_detection:
from: 'destination_pim_api_configured'
to: 'destination_pim_detected'
local_destination_pim_system_requirements_installation:
from: 'destination_pim_detected'
to: 'destination_pim_system_requirements_installed'
destination_pim_check_requirements:
from: 'destination_pim_system_requirements_installed'
from: 'destination_pim_detected'
to: 'destination_pim_requirements_checked'
destination_pim_file_database_migration:
local_destination_pim_system_requirements_installation:
from: 'destination_pim_requirements_checked'
to: 'destination_pim_system_requirements_installed'
destination_pim_file_database_migration:
from: 'destination_pim_system_requirements_installed'
to: 'destination_pim_file_database_migrated'
destination_pim_structure_migration:
from: 'destination_pim_file_database_migrated'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function onDestinationPimCheckRequirements(Event $event)
try {
$this->destinationPimConfigurationChecker->check($stateMachine->getSourcePim(), $stateMachine->getDestinationPim());
} catch (\Exception $exception) {
throw new DestinationPimInstallationException($exception->getMessage(), $exception->getCode(), $exception);
throw new DestinationPimInstallationException($exception->getMessage(), $exception->getCode());
}

$this->logExit(__FUNCTION__);
Expand Down
12 changes: 6 additions & 6 deletions stateMachineTransporteo.dot
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ digraph workflow {
place_destination_pim_configured [label="destination_pim_configured", shape=circle];
place_destination_pim_api_configured [label="destination_pim_api_configured", shape=circle];
place_destination_pim_detected [label="destination_pim_detected", shape=circle];
place_destination_pim_system_requirements_installed [label="destination_pim_system_requirements_installed", shape=circle];
place_destination_pim_requirements_checked [label="destination_pim_requirements_checked", shape=circle];
place_destination_pim_system_requirements_installed [label="destination_pim_system_requirements_installed", shape=circle];
place_destination_pim_file_database_migrated [label="destination_pim_file_database_migrated", shape=circle];
place_destination_pim_structure_migrated [label="destination_pim_structure_migrated", shape=circle];
place_destination_pim_family_migrated [label="destination_pim_family_migrated", shape=circle];
Expand All @@ -40,8 +40,8 @@ digraph workflow {
transition_destination_pim_configuration [label="destination_pim_configuration", shape=box, shape="box", regular="1"];
transition_destination_pim_api_configuration [label="destination_pim_api_configuration", shape=box, shape="box", regular="1"];
transition_destination_pim_detection [label="destination_pim_detection", shape=box, shape="box", regular="1"];
transition_local_destination_pim_system_requirements_installation [label="local_destination_pim_system_requirements_installation", shape=box, shape="box", regular="1"];
transition_destination_pim_check_requirements [label="destination_pim_check_requirements", shape=box, shape="box", regular="1"];
transition_local_destination_pim_system_requirements_installation [label="local_destination_pim_system_requirements_installation", shape=box, shape="box", regular="1"];
transition_destination_pim_file_database_migration [label="destination_pim_file_database_migration", shape=box, shape="box", regular="1"];
transition_destination_pim_structure_migration [label="destination_pim_structure_migration", shape=box, shape="box", regular="1"];
transition_destination_pim_family_migration [label="destination_pim_family_migration", shape=box, shape="box", regular="1"];
Expand Down Expand Up @@ -78,11 +78,11 @@ digraph workflow {
transition_destination_pim_api_configuration -> place_destination_pim_api_configured [style="solid"];
place_destination_pim_api_configured -> transition_destination_pim_detection [style="solid"];
transition_destination_pim_detection -> place_destination_pim_detected [style="solid"];
place_destination_pim_detected -> transition_local_destination_pim_system_requirements_installation [style="solid"];
transition_local_destination_pim_system_requirements_installation -> place_destination_pim_system_requirements_installed [style="solid"];
place_destination_pim_system_requirements_installed -> transition_destination_pim_check_requirements [style="solid"];
place_destination_pim_detected -> transition_destination_pim_check_requirements [style="solid"];
transition_destination_pim_check_requirements -> place_destination_pim_requirements_checked [style="solid"];
place_destination_pim_requirements_checked -> transition_destination_pim_file_database_migration [style="solid"];
place_destination_pim_requirements_checked -> transition_local_destination_pim_system_requirements_installation [style="solid"];
transition_local_destination_pim_system_requirements_installation -> place_destination_pim_system_requirements_installed [style="solid"];
place_destination_pim_system_requirements_installed -> transition_destination_pim_file_database_migration [style="solid"];
transition_destination_pim_file_database_migration -> place_destination_pim_file_database_migrated [style="solid"];
place_destination_pim_file_database_migrated -> transition_destination_pim_structure_migration [style="solid"];
transition_destination_pim_structure_migration -> place_destination_pim_structure_migrated [style="solid"];
Expand Down
Binary file modified stateMachineTransporteo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

declare(strict_types=1);

namespace spec\Akeneo\PimMigration\Domain\MigrationStep\s050_DestinationPimInstallation;

use Akeneo\PimMigration\Domain\Command\ChainedConsole;
use Akeneo\PimMigration\Domain\Command\CommandResult;
use Akeneo\PimMigration\Domain\Command\SymfonyCommand;
use Akeneo\PimMigration\Domain\MigrationStep\s050_DestinationPimInstallation\DestinationPimCheckConfigurationException;
use Akeneo\PimMigration\Domain\MigrationStep\s050_DestinationPimInstallation\DestinationPimVersionChecker;
use Akeneo\PimMigration\Domain\Pim\DestinationPim;
use PhpSpec\ObjectBehavior;

/**
* @author Laurent Petard <[email protected]>
* @copyright 2017 Akeneo SAS (http://www.akeneo.com)
*/
class DestinationPimVersionCheckerSpec extends ObjectBehavior
{
public function let(ChainedConsole $console)
{
$this->beConstructedWith($console);
}

public function it_is_initializable()
{
$this->shouldHaveType(DestinationPimVersionChecker::class);
}

public function it_checks_an_acceptable_version(DestinationPim $pim, CommandResult $commandResult, $console)
{
$console->execute(new SymfonyCommand('pim:system:information'), $pim)->willReturn($commandResult);

$commandResult->getOutput()->willReturn('| Version | 2.0.3 ');

$this->check($pim);
}

public function it_throws_an_exception_if_the_version_it_fails_to_read_the_version(DestinationPim $pim, CommandResult $commandResult, $console)
{
$console->execute(new SymfonyCommand('pim:system:information'), $pim)->willReturn($commandResult);

$commandResult->getOutput()->willReturn('Version : unknown');

$this->shouldThrow(new DestinationPimCheckConfigurationException('Failed to read the destination PIM version.'))
->during('check', [$pim]);
}

public function it_throws_an_exception_if_the_version_is_not_supported(DestinationPim $pim, CommandResult $commandResult, $console)
{
$console->execute(new SymfonyCommand('pim:system:information'), $pim)->willReturn($commandResult);

$commandResult->getOutput()->willReturn('| Version | 2.1.0 ');

$this->shouldThrow(new DestinationPimCheckConfigurationException(sprintf(
'The current version of your destination PIM 2.1.0 is not supported. The version should be %d.%d.x',
DestinationPimVersionChecker::EXACT_MAJOR_VERSION,
DestinationPimVersionChecker::EXACT_MINOR_VERSION
)))->during('check', [$pim]);
}

public function it_throws_an_exception_if_the_version_patch_is_below_the_minimum(DestinationPim $pim, CommandResult $commandResult, $console)
{
$console->execute(new SymfonyCommand('pim:system:information'), $pim)->willReturn($commandResult);

$commandResult->getOutput()->willReturn('| Version | 2.0.2 ');

$this->shouldThrow(new DestinationPimCheckConfigurationException(sprintf(
'The current version of your destination PIM 2.0.2 is not supported. The minimum supported version is %d.%d.%d',
DestinationPimVersionChecker::EXACT_MAJOR_VERSION,
DestinationPimVersionChecker::EXACT_MINOR_VERSION,
DestinationPimVersionChecker::MINIMUM_PATCH_VERSION
)))->during('check', [$pim]);
}
}

0 comments on commit 8e85faf

Please sign in to comment.