Skip to content

Commit

Permalink
Merge branch 'future-4.x' of github.com:kaliop-uk/ezmigrationbundle
Browse files Browse the repository at this point in the history
# Conflicts:
#	Command/MigrateCommand.php
#	WHATSNEW.md
  • Loading branch information
gggeek committed May 13, 2017
2 parents ac3b8b7 + 813e042 commit 3c857d7
Show file tree
Hide file tree
Showing 103 changed files with 3,868 additions and 1,573 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/composer
/composer.phar
/composer.lock
/Tests/dsl/good/references/test_refs_generated.yml
24 changes: 15 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,35 @@ sudo: false
# We limit the matrix to one version of eZPublish for each version of PHP
matrix:
include:
# ezpublish-community 2014.3 corresponds to enterprise 5.3, still supported, installs via composer
- php: 5.4
env: EZ_PACKAGES='ezsystems/ezpublish-community:~2014.3.2' EZ_VERSION=ezpublish-community EZ_APP_DIR=ezpublish EZ_KERNEL=EzPublishKernel CODE_COVERAGE=0 INSTALL_TAGSBUNDLE=0
# ezpublish-community 2014.3 corresponds to enterprise 5.3, not supported any more since end of May 2017.
#- php: 5.4
# env: EZ_PACKAGES='ezsystems/ezpublish-community:~2014.3.2' EZ_VERSION=ezpublish-community EZ_APP_DIR=ezpublish EZ_KERNEL=EzPublishKernel CODE_COVERAGE=0 INSTALL_TAGSBUNDLE=0
#- php: 5.5
# env: EZ_PACKAGES='ezsystems/ezpublish-community:~2014.3.2 netgen/tagsbundle:1.O' EZ_VERSION=ezpublish-community EZ_APP_DIR=ezpublish EZ_KERNEL=EzPublishKernel CODE_COVERAGE=0 INSTALL_TAGSBUNDLE=0
# the last version of eZPublish Community Project, aka eZPublish 5, corresponds to eZPublish Platform (Enterprise) 5.4

# The last version of eZPublish Community Project, aka eZPublish 5, corresponds to eZPublish Platform (Enterprise) 5.4
# About php versions:
# - php 5.6 can be installed on RHEL/CentOS 6, which is the oldest currently supported
# - current Debian Stable comes with php 5.6 too (Debian 7 has php 5.4 but it is only in LTS support by now)
# We thus only test on php 5.6
#- php: 5.4
# env: EZ_PACKAGES='ezsystems/ezpublish-community:~2014.11.0 ezsystems/behatbundle:~5.4 netgen/tagsbundle:~2.0' EZ_VERSION=ezpublish-community EZ_APP_DIR=ezpublish EZ_KERNEL=EzPublishKernel CODE_COVERAGE=0 INSTALL_TAGSBUNDLE=1
- php: 5.5
env: EZ_PACKAGES='ezsystems/ezpublish-community:~2014.11.0 ezsystems/behatbundle:~5.4 netgen/tagsbundle:~2.0' EZ_VERSION=ezpublish-community EZ_APP_DIR=ezpublish EZ_KERNEL=EzPublishKernel CODE_COVERAGE=0 INSTALL_TAGSBUNDLE=1
#- php: 5.5
# env: EZ_PACKAGES='ezsystems/ezpublish-community:~2014.11.0 ezsystems/behatbundle:~5.4 netgen/tagsbundle:~2.0' EZ_VERSION=ezpublish-community EZ_APP_DIR=ezpublish EZ_KERNEL=EzPublishKernel CODE_COVERAGE=0 INSTALL_TAGSBUNDLE=1
- php: 5.6
env: EZ_PACKAGES='ezsystems/ezpublish-community:~2014.11.0 ezsystems/behatbundle:~5.4 netgen/tagsbundle:~2.0' EZ_VERSION=ezpublish-community EZ_APP_DIR=ezpublish EZ_KERNEL=EzPublishKernel CODE_COVERAGE=1 INSTALL_TAGSBUNDLE=1

# latest version currently available of eZPlatform aka eZPublish 6
#- php: 5.6
# env: EZ_PACKAGES='ezsystems/ezplatform:~1.7.0 ezsystems/behatbundle:^6.3 netgen/tagsbundle:~2.0' EZ_VERSION=ezplatform EZ_APP_DIR=app EZ_KERNEL=AppKernel CODE_COVERAGE=0 INSTALL_TAGSBUNDLE=1
# env: EZ_PACKAGES='ezsystems/ezplatform:~1.8.0 ezsystems/ezplatform-xmltext-fieldtype:^1.1 ezsystems/behatbundle:^6.3 netgen/tagsbundle:~2.0' EZ_VERSION=ezplatform EZ_APP_DIR=app EZ_KERNEL=AppKernel CODE_COVERAGE=0 INSTALL_TAGSBUNDLE=1
- php: 7.0
env: EZ_PACKAGES='ezsystems/ezplatform:~1.7.0 ezsystems/ezplatform-xmltext-fieldtype:^1.1 ezsystems/behatbundle:^6.3 netgen/tagsbundle:~2.0' EZ_VERSION=ezplatform EZ_APP_DIR=app EZ_KERNEL=AppKernel CODE_COVERAGE=0 INSTALL_TAGSBUNDLE=1
- php: 7.1
env: EZ_PACKAGES='ezsystems/ezplatform:~1.7.0 ezsystems/ezplatform-xmltext-fieldtype:^1.1 ezsystems/behatbundle:^6.3 netgen/tagsbundle:~2.0' EZ_VERSION=ezplatform EZ_APP_DIR=app EZ_KERNEL=AppKernel CODE_COVERAGE=0 INSTALL_TAGSBUNDLE=1

#allow_failures:
# this currently fails because of eZPublish services.yml not quoting usage of @, despite it being tested with Sf 2.8...
#- php: 7.0
# this currently fails because of the refactoring of location matcher
#- php: 5.4

before_install:
# No need for a web server, until we start testing using Selenium
Expand Down
19 changes: 0 additions & 19 deletions API/ComplexFieldInterface.php

This file was deleted.

24 changes: 24 additions & 0 deletions API/ContextProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Kaliop\eZMigrationBundle\API;

use Kaliop\eZMigrationBundle\API\Value\MigrationDefinition;
use Kaliop\eZMigrationBundle\API\Value\Migration;

/**
* Implemented by classes which have 'context' data that should be stored/restored when migrations are suspended
*/
interface ContextProviderInterface
{
/**
* @param string $migrationName
* @return array|null
*/
public function getCurrentContext($migrationName);

/**
* @param string $migrationName
* @param array $context
*/
public function restoreContext($migrationName, array $context);
}
34 changes: 34 additions & 0 deletions API/ContextStorageHandlerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Kaliop\eZMigrationBundle\API;

/**
* Implemented by classes which store details of the executing migrations contexts
*/
interface ContextStorageHandlerInterface
{
/**
* @param string $migrationName
* @return array|null
*/
public function loadMigrationContext($migrationName);

/**
* Stores a migration context
* @param string $migrationName
* @param array $context
*/
public function storeMigrationContext($migrationName, array $context);

/**
* Removes a migration context from storage (regardless of the migration status)
*
* @param string $migrationName
*/
public function deleteMigrationContext($migrationName);

/**
* Removes all migration contexts from storage (regardless of the migration status)
*/
public function deleteMigrationContexts();
}
16 changes: 16 additions & 0 deletions API/EnumerableReferenceResolverInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Kaliop\eZMigrationBundle\API;

/**
* Used to identify those reference resolvers which can enumerate their references injected.
*/
interface EnumerableReferenceResolverInterface
{
/**
* Lists all existing references
*
* @return array key: ref identifier, value: reference value
*/
public function listReferences();
}
35 changes: 35 additions & 0 deletions API/Event/MigrationSuspendedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Kaliop\eZMigrationBundle\API\Event;

use Symfony\Component\EventDispatcher\Event;
use Kaliop\eZMigrationBundle\API\Value\MigrationStep;
use Kaliop\eZMigrationBundle\API\Exception\MigrationSuspendedException;

class MigrationSuspendedEvent extends Event
{
protected $step;
protected $exception;

public function __construct(MigrationStep $step, MigrationSuspendedException $exception)
{
$this->step = $step;
$this->exception = $exception;
}

/**
* @return MigrationStep
*/
public function getStep()
{
return $this->step;
}

/**
* @return MigrationSuspendedException
*/
public function getException()
{
return $this->exception;
}
}
14 changes: 14 additions & 0 deletions API/Exception/MigrationSuspendedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Kaliop\eZMigrationBundle\API\Exception;

/**
* Throw this exception in any step to suspend the migration
*/
class MigrationSuspendedException extends \Exception
{
public function __construct($message = "", $code = 0, \Exception $previous = null)
{
parent::__construct($message, $code, $previous);
}
}
3 changes: 3 additions & 0 deletions API/LanguageAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Kaliop\eZMigrationBundle\API;

/**
* @deprecated
*/
interface LanguageAwareInterface
{
/**
Expand Down
3 changes: 2 additions & 1 deletion API/MigrationGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ interface MigrationGeneratorInterface
*
* @param array $matchCondition
* @param string $mode
* @param array $context
* @return array Migration data
* @throws \Exception
*/
public function generateMigration(array $matchCondition, $mode);
public function generateMigration(array $matchCondition, $mode, array $context = array());
}
3 changes: 2 additions & 1 deletion API/ReferenceBagInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace Kaliop\eZMigrationBundle\API;

/**
* Used for those reference resolvers which can have their references injected
* Used to identify those reference resolvers which can have references injected.
* Most of the time one would implement directly ReferenceResolverBagInterface.
*/
interface ReferenceBagInterface
{
Expand Down
10 changes: 10 additions & 0 deletions API/ReferenceResolverBagInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Kaliop\eZMigrationBundle\API;

/**
* A Reference Resolver that allows references to be added to it
*/
interface ReferenceResolverBagInterface extends ReferenceResolverInterface, ReferenceBagInterface
{
}
23 changes: 21 additions & 2 deletions API/StorageHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,24 @@
use Kaliop\eZMigrationBundle\API\Value\Migration;

/**
* Implemented by classes which store details of the executed migrations
* Implemented by classes which store details of the executing/executed migrations
*/
interface StorageHandlerInterface
{
/**
* @param int $limit 0 or below will be treated as 'no limit'
* @param int $offset
* @return MigrationCollection sorted from oldest to newest
*/
public function loadMigrations();
public function loadMigrations($limit = null, $offset = null);

/**
* @param int $status see the STATUS_ constants
* @param int $limit 0 or below will be treated as 'no limit'
* @param int $offset
* @return MigrationCollection sorted from oldest to newest
*/
public function loadMigrationsByStatus($status, $limit = null, $offset = null);

/**
* @param string $migrationName
Expand Down Expand Up @@ -70,4 +80,13 @@ public function deleteMigrations();
*/
public function skipMigration(MigrationDefinition $migrationDefinition);

/**
* Resumes a migration (updates it, from SUSPENDED to status STARTED)
*
* @param Migration $migration
* @return Migration
* @throws \Exception If the migration was not present or not suspended
*/
public function resumeMigration(Migration $migration);

}
1 change: 1 addition & 0 deletions API/Value/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Migration extends AbstractValue
const STATUS_DONE = 2;
const STATUS_FAILED = 3;
const STATUS_SKIPPED = 4;
const STATUS_SUSPENDED = 6;
// the ones below are not yet supported
const STATUS_PARTIALLY_DONE = 5;

Expand Down
8 changes: 4 additions & 4 deletions Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Symfony\Component\Yaml\Yaml;
use Kaliop\eZMigrationBundle\API\MigrationGeneratorInterface;
use Kaliop\eZMigrationBundle\API\MatcherInterface;
use Kaliop\eZMigrationBundle\API\LanguageAwareInterface;

class GenerateCommand extends AbstractCommand
{
Expand Down Expand Up @@ -242,15 +241,16 @@ protected function generateMigrationFile($path, $fileType, $migrationType, array
}
$executor = $this->getMigrationService()->getExecutor($migrationType);

if ($executor instanceof LanguageAwareInterface) {
$executor->setLanguageCode($parameters['lang']);
$context = array();
if (isset($parameters['lang']) && $parameters['lang'] != '') {
$context['defaultLanguageCode'] = $parameters['lang'];
}

$matchCondition = array($parameters['matchType'] => $parameters['matchValue']);
if ($parameters['matchExcept']) {
$matchCondition = array(MatcherInterface::MATCH_NOT => $matchCondition);
}
$data = $executor->generateMigration($matchCondition, $parameters['mode']);
$data = $executor->generateMigration($matchCondition, $parameters['mode'], $context);

if (!is_array($data) || !count($data)) {
$warning = 'Note: the generated migration is empty';
Expand Down
11 changes: 4 additions & 7 deletions Command/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,10 @@ protected function configure()
->setName(self::COMMAND_NAME)
->setAliases(array('kaliop:migration:update'))
->setDescription('Execute available migration definitions.')
->addOption(
'path',
null,
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
"The directory or file to load the migration definitions from"
)
->addOption('path', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, "The directory or file to load the migration definitions from")
// nb: when adding options, remember to forward them to sub-commands executed in 'separate-process' mode
->addOption('default-language', 'l', InputOption::VALUE_REQUIRED, "Default language code that will be used if no language is provided in migration steps")
->addOption('admin-login', 'a', InputOption::VALUE_REQUIRED, "Login of admin account used whenever elevated privileges are needed (user id 14 used by default)")
->addOption('ignore-failures', 'i', InputOption::VALUE_NONE, "Keep executing migrations even if one fails")
->addOption('clear-cache', 'c', InputOption::VALUE_NONE, "Clear the cache after the command finishes")
->addOption('no-interaction', 'n', InputOption::VALUE_NONE, "Do not ask any interactive question")
Expand Down Expand Up @@ -201,7 +197,8 @@ function($type, $buffer) {
$migrationService->executeMigration(
$migrationDefinition,
!$input->getOption('no-transactions'),
$input->getOption('default-language')
$input->getOption('default-language'),
$input->getOption('admin-login')
);
$executed++;
} catch (\Exception $e) {
Expand Down
Loading

0 comments on commit 3c857d7

Please sign in to comment.