diff --git a/.gitattributes b/.gitattributes index f0e613c..16bba7b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,7 +3,4 @@ /.php_cs export-ignore /.gitattributes export-ignore /.gitignore export-ignore -/.travis.yml export-ignore -/tests export-ignore -/travis.ini export-ignore -/phpunit.xml.dist export-ignore + diff --git a/.gitignore b/.gitignore index b252b69..8b7ef35 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ -/build /vendor - -composer.lock \ No newline at end of file +composer.lock diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ebd4aae..0000000 --- a/.travis.yml +++ /dev/null @@ -1,48 +0,0 @@ -language: php - -sudo: false - -php: - - 5.4 - - 5.5 - - 5.6 - - 7.0 - - hhvm - -cache: - directories: - - $HOME/.composer/cache - -env: - global: - - TIMEZONE="Europe/Berlin" - -matrix: - fast_finish: true - include: - - php: 5.4 - env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"' - -before_install: - - composer config --quiet github-oauth.github.com $GITHUB_TOKEN - - composer self-update - -install: - - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction - -before_script: - - if [ "$TRAVIS_PHP_VERSION" = "hhv*" ]; then cat tests/fixtures/travis.ini >> /etc/hhvm/php.ini; fi; - - if [ "$TRAVIS_PHP_VERSION" = "php*" ]; then phpenv config-add tests/fixtures/travis.ini ; fi; - -script: vendor/bin/phpunit --coverage-clover=coverage.clover - -after_script: - - if [[ $TRAVIS_PHP_VERSION != '7.0' ]] && [[ $TRAVIS_PHP_VERSION != 'hhvm' ]]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi - -notifications: - email: - - jerome@kreait.com - webhooks: - urls: - - https://webhooks.gitter.im/e/81fafa2c4f2eb03e552e - diff --git a/CHANGELOG.md b/CHANGELOG.md index 9dde0e5..00d3373 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # CHANGELOG +## Unreleased + +- This bundle is now based on the [DoctrineMigrationsBundle](https://github.com/doctrine/DoctrineMigrationsBundle) and + eZ Platform ready. +- All commands except the `ezpublish:migrations:generate` have been removed - + use the `doctrine:migrations:*` commands instead +- The following deprecated methods have been removed: + - `Kreait\EzPublish\MigrationsBundle\Migrations\AbstractMigration::getContainer()` +- If you want to upgrade an existing project using version 1.x/2.x to the latest release, please follow the + [upgrade guide](UPGRADE.md) + ## 2.0.3 - 2015-12-13 - Added support for Symfony 3 and PHPUnit 5 diff --git a/LICENSE b/LICENSE index a5ed853..535af1b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ The MIT License (MIT) -Copyright (c) 2014-2105 kreait GmbH +Copyright (c) Jérôme Gamez +Copyright (c) kreait GmbH Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index d9b0ca9..4c04fe4 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,19 @@ -# eZ Publish 5 Migrations +# eZ Publish/Platform Migrations [![Latest Stable Version](https://img.shields.io/packagist/v/kreait/ezpublish-migrations-bundle.svg)](https://packagist.org/packages/kreait/ezpublish-migrations-bundle) [![License](http://img.shields.io/badge/Licence-MIT-blue.svg)](https://packagist.org/packages/kreait/ezpublish-migrations-bundle) -[![Build Status](https://img.shields.io/travis/kreait/ezpublish-migrations-bundle.svg)](http://travis-ci.org/kreait/ezpublish-migrations-bundle) -[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/kreait/ezpublish-migrations-bundle.svg)](https://scrutinizer-ci.com/g/kreait/ezpublish-migrations-bundle/?branch=master) -[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/kreait/ezpublish-migrations-bundle.svg)](https://scrutinizer-ci.com/g/kreait/ezpublish-migrations-bundle/?branch=master) [![Gitter](https://img.shields.io/badge/gitter-join%20chat-ff69b4.svg)](https://gitter.im/kreait/ezpublish-migrations-bundle) -Migrations for eZ Publish 5, based on [Doctrine Migrations](https://github.com/doctrine/migrations), very similar to Symfony's -[DoctrineMigrationsBundle](https://github.com/doctrine/DoctrineMigrationsBundle). +Migrations for eZ Publish/Platform. +## Features +This bundle gives you an additional `ezpublish:migrations:generate` command, which generates a Migration that eases +eZ Publish/Platform related changes + +- Automatically sets the active eZ user performing the changes (default: `admin`) +- Allows the quick change of the currently active user, e.g. for creating new content in the name of a certain user. +- Adds a shorthand method to create new content ## Installation @@ -18,53 +21,45 @@ Migrations for eZ Publish 5, based on [Doctrine Migrations](https://github.com/d composer require kreait/ezpublish-migrations-bundle ``` -## Configuration - - -Enable the bundle in EzPublishKernel.php by including the following: +Enable the DoctrineMigrationsBundle and the KreaitEzPublishMigrationsBundle +in `AppKernel.php` (eZ Platform) or `EzPublishKernel.php` (eZ Publish 5): ```php -// ezpublish/EzPublishKernel.php public function registerBundles() { $bundles = array( //... + new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(), new Kreait\EzPublish\MigrationsBundle\KreaitEzPublishMigrationsBundle(), ); } ``` -You can configure the path, namespace, table_name and name in your config.yml. -The examples below are the default values. +### Configuration + +You can configure the bundles in your `config.yml`. The examples below are the default values. ``` -// ezpublish/config/config.yml -ezpublish_migrations: - dir_name: "%kernel.root_dir%/EzPublishMigrations" +doctrine_migrations: + dir_name: "%kernel.root_dir%/DoctrineMigrations" namespace: Application\Migrations - table_name: ezmigration_versions + table_name: migration_versions name: Application Migrations - ez_user: admin + +ezpublish_migrations: + # The login name of the user performing the migrations. + ez_migrations_user: admin ``` ## Usage -All of the migrations functionality is contained in the following commands: +The usage is [identical to Symfony's DoctrineMigrationBundle](http://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html), +with the addition of the following command: ``` -ezpublish:migrations - :execute Execute a single migration version up or down manually. - :generate Generate a blank migration class. - :migrate Execute a migration to a specified version or the latest available version. - :status View the status of a set of migrations. - :version Manually add and delete migration versions from the version table. +ezpublish:migrations:generate # Generate a blank eZ Publish/Platform enabled migration class ``` -The usage is identical to Symfony's DoctrineMigrationBundle, except for the missing `:diff` command. -Please have a look at the -[official documentation](http://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html) -for further information. - ### Changing the current migration user during a migration You can change the current eZ Publish user inside a migration by issuing the following command: @@ -79,12 +74,13 @@ and restore the default Migration user by using: $this->restoreDefaultMigrationUser(); ``` -## Usage examples +See [src/Resources/doc/examples](src/Resources/doc/examples) for more usage examples. -See [src/Resources/doc/examples](src/Resources/doc/examples) for some usage examples. +## Known issues -## Acknowledgments +When you create a migration using only eZ Publish's API methods, no SQL statements are executed in terms of the +DoctrineMigrationsBundle. This results in the following message: -- [Doctrine Project](http://www.doctrine-project.org/) for the [Doctrine Database Migrations](https://github.com/doctrine/migrations) providing the underlying migration functionality -- [Symfony](http://symfony.com/) for the [DoctrineMigrationsBundle](https://github.com/doctrine/DoctrineMigrationsBundle) being the blueprint for this bundle -- [Magic Internet GmbH](http://www.magicinternet.de/), especially [@m-keil](https://github.com/m-keil) for the initial methodical blueprint +``` +Migration was executed but did not result in any SQL statements. +``` diff --git a/UPGRADE.md b/UPGRADE.md new file mode 100644 index 0000000..0a65bcb --- /dev/null +++ b/UPGRADE.md @@ -0,0 +1,73 @@ +# eZ Publish/Platform Migrations Upgrade + +## From 2.0 to 3.0 + +### Project dependencies + +This bundle now requires the [`DoctrineMigrationsBundle`](https://github.com/doctrine/DoctrineMigrationsBundle): + +```php +// ezpublish/EzPublishKernel.php (eZ Publish 5) +// or +// app/AppKernel.php (eZ Platform) +public function registerBundles() +{ + $bundles = array( + //... + new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(), + new Kreait\EzPublish\MigrationsBundle\KreaitEzPublishMigrationsBundle(), + ); +} +``` + +### Configuration changes + +The configuration has changed as described in the following table: + +2.0 | 3.0 +----------------------------------- | ------------------------------------------- +**ezpublish_migrations**.dir_name | **doctrine_migrations**.dir_name +**ezpublish_migrations**.namespace | **doctrine_migrations**.namespace +**ezpublish_migrations**.table_name | **doctrine_migrations**.table_name +**ezpublish_migrations**.name | **doctrine_migrations**.name +ezpublish_migrations.**ez_user** | ezpublish_migrations.**ez_migrations_user** + +So, the following 2.0 configuration + +```yaml +# ezpublish/config/config.yml (eZ Publish 5) +# app/config/config.yml (eZ Platform) +ezpublish_migrations: + dir_name: "%kernel.root_dir%/EzPublishMigrations" + namespace: Application\Migrations + table_name: ezmigration_versions + name: Application Migrations + ez_user: admin +``` + +would become + +```yaml +# ezpublish/config/config.yml (eZ Publish 5) +# app/config/config.yml (eZ Platform) +doctrine_migrations: + dir_name: "%kernel.root_dir%/EzPublishMigrations" + namespace: Application\Migrations + table_name: ezmigration_versions + name: Application Migrations + +ezpublish_migrations: + ez_migrations_user: admin +``` + +### Console command changes + +The `ezpublish:migrations:generate` commands remains unchanged. + +2.0 | 3.0 +---------------------------------| ------------------------------- +**ezpublish**:migrations:execute | **doctrine**:migrations:execute +**ezpublish**:migrations:latest | **doctrine**:migrations:latest +**ezpublish**:migrations:migrate | **doctrine**:migrations:migrate +**ezpublish**:migrations:status | **doctrine**:migrations:status +**ezpublish**:migrations:version | **doctrine**:migrations:version diff --git a/composer.json b/composer.json index e0941e0..63c3c82 100644 --- a/composer.json +++ b/composer.json @@ -1,31 +1,31 @@ { "name": "kreait/ezpublish-migrations-bundle", - "description": "Migrations for eZ Publish 5", - "keywords": ["migrations", "ezpublish"], + "description": "Migrations for eZ Publish/eZ Platform", + "keywords": ["migrations", "ezpublish", "ezplatform", "ezpublish"], "homepage": "https://github.com/kreait/ezpublish-migrations-bundle", "license": "MIT", "authors": [ - {"name": "Jérôme Gamez", "email": "jerome@kreait.com"} + { + "name": "Jérôme Gamez", + "email": "jerome@gamez.name", + "homepage": "https://github.com/jeromegamez" + } ], "require": { - "php": ">=5.4", - "doctrine/migrations": "^1.0" + "doctrine/doctrine-migrations-bundle": "^1.1" }, "require-dev": { - "symfony/config": "^2.4|^3.0", - "symfony/console": "^2.4|^3.0", - "symfony/dependency-injection": "^2.4|^3.0", - "symfony/framework-bundle": "^2.4|^3.0", - "symfony/finder": "^2.4|^3.0", - "symfony/http-kernel": "^2.4|^3.0", - "symfony/expression-language": "^2.4|^3.0", "ezsystems/ezpublish-api": "^5.3|^6.0", - "ezsystems/ezpublish-spi": "^5.3|^6.0", - "phpunit/phpunit": "^4.5|^5.0" + "ezsystems/ezpublish-spi": "^5.3|^6.0" }, "autoload": { "psr-4": { "Kreait\\EzPublish\\MigrationsBundle\\": "src" } + }, + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist deleted file mode 100644 index 1f73074..0000000 --- a/phpunit.xml.dist +++ /dev/null @@ -1,26 +0,0 @@ - - - - - tests - - - - - - . - - src/Resources - tests - vendor - - - bootstrap.php - - - - \ No newline at end of file diff --git a/src/Command/ExecuteCommand.php b/src/Command/ExecuteCommand.php deleted file mode 100644 index ce9fedc..0000000 --- a/src/Command/ExecuteCommand.php +++ /dev/null @@ -1,46 +0,0 @@ -setName('ezpublish:migrations:execute'); - } - - public function execute(InputInterface $input, OutputInterface $output) - { - /** @var \Symfony\Bundle\FrameworkBundle\Console\Application $app */ - $app = $this->getApplication(); - /** @var ContainerInterface $container */ - $container = $app->getKernel()->getContainer(); - - $this->setMigrationConfiguration($this->getBasicConfiguration($container, $output)); - - $configuration = $this->getMigrationConfiguration($input, $output); - $this->configureMigrations($container, $configuration); - - parent::execute($input, $output); - } -} diff --git a/src/Command/GenerateCommand.php b/src/Command/GenerateCommand.php index b5be0ea..0e848cb 100644 --- a/src/Command/GenerateCommand.php +++ b/src/Command/GenerateCommand.php @@ -9,25 +9,21 @@ namespace Kreait\EzPublish\MigrationsBundle\Command; -use Doctrine\DBAL\Migrations\Configuration\Configuration; -use Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand as BaseGenerateCommand; -use Kreait\EzPublish\MigrationsBundle\Traits\CommandTrait; +use Doctrine\Bundle\MigrationsBundle\Command\MigrationsGenerateDoctrineCommand; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Doctrine\DBAL\Migrations\Configuration\Configuration; +use Doctrine\DBAL\Migrations\Tools\Console\Helper\MigrationDirectoryHelper; /** * Command for generating new blank migration classes. */ -class GenerateCommand extends BaseGenerateCommand +class GenerateCommand extends MigrationsGenerateDoctrineCommand { - use CommandTrait; - - protected $template = + protected $ezMigrationTemplate = '; -use Kreait\EzPublish\MigrationsBundle\Migrations\AbstractMigration as EzPublishMigration; +use Kreait\EzPublish\MigrationsBundle\Migrations\EzPublishMigration; use Doctrine\DBAL\Schema\Schema; /** @@ -64,21 +60,7 @@ protected function configure() parent::configure(); $this->setName('ezpublish:migrations:generate'); - } - - public function execute(InputInterface $input, OutputInterface $output) - { - /** @var \Symfony\Bundle\FrameworkBundle\Console\Application $app */ - $app = $this->getApplication(); - /** @var ContainerInterface $container */ - $container = $app->getKernel()->getContainer(); - - $this->setMigrationConfiguration($this->getBasicConfiguration($container, $output)); - - $configuration = $this->getMigrationConfiguration($input, $output); - $this->configureMigrations($container, $configuration); - - parent::execute($input, $output); + $this->setDescription('Generate a blank eZ Publish/Platform enabled migration class'); } protected function generateMigration(Configuration $configuration, InputInterface $input, $version, $up = null, $down = null) @@ -92,25 +74,19 @@ protected function generateMigration(Configuration $configuration, InputInterfac $replacements = [ $configuration->getMigrationsNamespace(), $version, - $up ? ' '.implode("\n ", explode("\n", $up)) : null, - $down ? ' '.implode("\n ", explode("\n", $down)) : null, + $up ? " " . implode("\n ", explode("\n", $up)) : null, + $down ? " " . implode("\n ", explode("\n", $down)) : null ]; - $code = str_replace($placeHolders, $replacements, $this->template); - $dir = $configuration->getMigrationsDirectory(); - $dir = $dir ? $dir : getcwd(); - $dir = rtrim($dir, '/'); - $path = $dir.'/Version'.$version.'.php'; - - if (!file_exists($dir)) { - // @codeCoverageIgnoreStart - throw new \InvalidArgumentException(sprintf('Migrations directory "%s" does not exist.', $dir)); - // @codeCoverageIgnoreEnd - } + $code = str_replace($placeHolders, $replacements, $this->ezMigrationTemplate); + $code = preg_replace('/^ +$/m', '', $code); + $migrationDirectoryHelper = new MigrationDirectoryHelper($configuration); + $dir = $migrationDirectoryHelper->getMigrationDirectory(); + $path = $dir . '/Version' . $version . '.php'; file_put_contents($path, $code); if ($editorCmd = $input->getOption('editor-cmd')) { - shell_exec($editorCmd.' '.escapeshellarg($path)); + proc_open($editorCmd . ' ' . escapeshellarg($path), [], $pipes); } return $path; diff --git a/src/Command/LatestCommand.php b/src/Command/LatestCommand.php deleted file mode 100644 index 76ae183..0000000 --- a/src/Command/LatestCommand.php +++ /dev/null @@ -1,46 +0,0 @@ -setName('ezpublish:migrations:latest'); - } - - public function execute(InputInterface $input, OutputInterface $output) - { - /** @var \Symfony\Bundle\FrameworkBundle\Console\Application $app */ - $app = $this->getApplication(); - /** @var ContainerInterface $container */ - $container = $app->getKernel()->getContainer(); - - $this->setMigrationConfiguration($this->getBasicConfiguration($container, $output)); - - $configuration = $this->getMigrationConfiguration($input, $output); - $this->configureMigrations($container, $configuration); - - parent::execute($input, $output); - } -} diff --git a/src/Command/MigrateCommand.php b/src/Command/MigrateCommand.php deleted file mode 100644 index b8fe881..0000000 --- a/src/Command/MigrateCommand.php +++ /dev/null @@ -1,46 +0,0 @@ -setName('ezpublish:migrations:migrate'); - } - - public function execute(InputInterface $input, OutputInterface $output) - { - /** @var \Symfony\Bundle\FrameworkBundle\Console\Application $app */ - $app = $this->getApplication(); - /** @var ContainerInterface $container */ - $container = $app->getKernel()->getContainer(); - - $this->setMigrationConfiguration($this->getBasicConfiguration($container, $output)); - - $configuration = $this->getMigrationConfiguration($input, $output); - $this->configureMigrations($container, $configuration); - - parent::execute($input, $output); - } -} diff --git a/src/Command/StatusCommand.php b/src/Command/StatusCommand.php deleted file mode 100644 index e682d8e..0000000 --- a/src/Command/StatusCommand.php +++ /dev/null @@ -1,46 +0,0 @@ -setName('ezpublish:migrations:status'); - } - - public function execute(InputInterface $input, OutputInterface $output) - { - /** @var \Symfony\Bundle\FrameworkBundle\Console\Application $app */ - $app = $this->getApplication(); - /** @var ContainerInterface $container */ - $container = $app->getKernel()->getContainer(); - - $this->setMigrationConfiguration($this->getBasicConfiguration($container, $output)); - - $configuration = $this->getMigrationConfiguration($input, $output); - $this->configureMigrations($container, $configuration); - - parent::execute($input, $output); - } -} diff --git a/src/Command/VersionCommand.php b/src/Command/VersionCommand.php deleted file mode 100644 index 949567c..0000000 --- a/src/Command/VersionCommand.php +++ /dev/null @@ -1,46 +0,0 @@ -setName('ezpublish:migrations:version'); - } - - public function execute(InputInterface $input, OutputInterface $output) - { - /** @var \Symfony\Bundle\FrameworkBundle\Console\Application $app */ - $app = $this->getApplication(); - /** @var ContainerInterface $container */ - $container = $app->getKernel()->getContainer(); - - $this->setMigrationConfiguration($this->getBasicConfiguration($container, $output)); - - $configuration = $this->getMigrationConfiguration($input, $output); - $this->configureMigrations($container, $configuration); - - parent::execute($input, $output); - } -} diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 2563e60..6f66114 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -39,11 +39,11 @@ public function getConfigTreeBuilder() $rootNode ->children() - ->scalarNode('dir_name')->defaultValue('%kernel.root_dir%/EzPublishMigrations')->cannotBeEmpty()->end() - ->scalarNode('namespace')->defaultValue('Application\Migrations')->cannotBeEmpty()->end() - ->scalarNode('table_name')->defaultValue('ezmigration_versions')->cannotBeEmpty()->end() - ->scalarNode('name')->defaultValue('Application Migrations')->end() - ->scalarNode('ez_user')->defaultValue('admin')->cannotBeEmpty()->end() + ->scalarNode('ez_migrations_user') + ->info('The login name of the user performing the migrations.') + ->defaultValue('admin') + ->cannotBeEmpty() + ->end() ->end(); return $treeBuilder; diff --git a/src/DependencyInjection/EzPublishMigrationsExtension.php b/src/DependencyInjection/EzPublishMigrationsExtension.php index 8999847..9bf199a 100644 --- a/src/DependencyInjection/EzPublishMigrationsExtension.php +++ b/src/DependencyInjection/EzPublishMigrationsExtension.php @@ -33,4 +33,9 @@ public function getAlias() { return 'ezpublish_migrations'; } + + public function getConfiguration(array $config, ContainerBuilder $container) + { + return new Configuration($this->getAlias()); + } } diff --git a/src/Migrations/AbstractMigration.php b/src/Migrations/EzPublishMigration.php similarity index 76% rename from src/Migrations/AbstractMigration.php rename to src/Migrations/EzPublishMigration.php index a486ecb..9f28a9d 100644 --- a/src/Migrations/AbstractMigration.php +++ b/src/Migrations/EzPublishMigration.php @@ -9,7 +9,7 @@ namespace Kreait\EzPublish\MigrationsBundle\Migrations; -use Doctrine\DBAL\Migrations\AbstractMigration as BaseAbstractMigration; +use Doctrine\DBAL\Migrations\AbstractMigration; use Doctrine\DBAL\Schema\Schema; use eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException; use eZ\Publish\API\Repository\Exceptions\ContentValidationException; @@ -17,9 +17,8 @@ use eZ\Publish\API\Repository\Values\Content\Content; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerAwareTrait; -use Symfony\Component\DependencyInjection\ContainerInterface; -abstract class AbstractMigration extends BaseAbstractMigration implements ContainerAwareInterface +abstract class EzPublishMigration extends AbstractMigration implements ContainerAwareInterface { use ContainerAwareTrait; @@ -42,22 +41,14 @@ abstract class AbstractMigration extends BaseAbstractMigration implements Contai */ protected $repository; - /** - * @var \eZ\Publish\API\Repository\UserService - */ - private $userService; - /** * Initializes eZ Publish related service shortcuts. - * - * @param Schema $schema */ - protected function pre(Schema $schema) + protected function pre() { $this->repository = $this->container->get('ezpublish.api.repository'); - $this->userService = $this->repository->getUserService(); - $this->defaultMigrationUser = $this->container->getParameter('ezpublish_migrations.ez_user'); + $this->defaultMigrationUser = $this->container->getParameter('ezpublish_migrations.ez_migrations_user'); $this->currentMigrationUser = $this->defaultMigrationUser; $this->setDefaultMigrationUser(); @@ -66,13 +57,13 @@ protected function pre(Schema $schema) public function preUp(Schema $schema) { parent::preUp($schema); - $this->pre($schema); + $this->pre(); } public function preDown(Schema $schema) { parent::preDown($schema); - $this->pre($schema); + $this->pre(); } /** @@ -93,19 +84,6 @@ protected function restoreDefaultMigrationUser() $this->setDefaultMigrationUser(); } - /** - * Returns the container. - * - * @deprecated 1.0.1 Use $this->container instead - * @codeCoverageIgnore - * - * @return ContainerInterface - */ - protected function getContainer() - { - return $this->container; - } - /** * Sets the current ez user the the default migration user. */ @@ -122,7 +100,7 @@ private function setDefaultMigrationUser() private function setMigrationUser($username) { $this->repository->setCurrentUser( - $this->userService->loadUserByLogin($username) + $this->repository->getUserService()->loadUserByLogin($username) ); } @@ -151,11 +129,9 @@ private function setMigrationUser($username) */ protected function createContent($parentLocationId, $contentTypeIdentifier, $languageCode, array $fields) { - /** @var $repository \eZ\Publish\API\Repository\Repository */ - $repository = $this->container->get('ezpublish.api.repository'); - $contentService = $repository->getContentService(); - $locationService = $repository->getLocationService(); - $contentTypeService = $repository->getContentTypeService(); + $contentService = $this->repository->getContentService(); + $locationService = $this->repository->getLocationService(); + $contentTypeService = $this->repository->getContentTypeService(); $contentType = $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier); $contentCreateStruct = $contentService->newContentCreateStruct($contentType, $languageCode); diff --git a/src/Resources/doc/examples/01-add-policy-to-role.md b/src/Resources/doc/examples/01-add-policy-to-role.md index 26d1a7f..526d6b1 100644 --- a/src/Resources/doc/examples/01-add-policy-to-role.md +++ b/src/Resources/doc/examples/01-add-policy-to-role.md @@ -2,19 +2,13 @@ ##### Enable users with the 'Anonymous' role to access the siteacess 'mysiteaccess' without having to log in -```bash -$ ezpublish/console ezpublish:migrations:generate -Generated new migration class to "/var/www/ezpublish/EzPublishMigrations/Version20140507140029.php" -``` - ```php -// ezpublish/EzPublishMigrations/Version20140507140029.php namespace Application\Migrations; use eZ\Publish\API\Repository\RoleService; use eZ\Publish\API\Repository\Values\User\Limitation\SiteAccessLimitation; use eZ\Publish\API\Repository\Values\User\Role; -use Kreait\EzPublish\MigrationsBundle\Migrations\AbstractMigration as EzPublishMigration; +use Kreait\EzPublish\MigrationsBundle\Migrations\EzPublishMigration; use Doctrine\DBAL\Schema\Schema; /** @@ -25,7 +19,7 @@ class Version20140507140029 extends EzPublishMigration /** * @var string */ - private $siteAccessIdentifier = 'mysiteaccess'; + private $siteAccessIdentifier = 'site'; /** * @param Schema $schema diff --git a/src/Resources/doc/examples/02-create-contenttype-group.md b/src/Resources/doc/examples/02-create-contenttype-group.md index 3abcf0e..c1bdfea 100644 --- a/src/Resources/doc/examples/02-create-contenttype-group.md +++ b/src/Resources/doc/examples/02-create-contenttype-group.md @@ -2,18 +2,10 @@ ##### Create a ContentType group -```bash -$ ezpublish/console ezpublish:migrations:generate -Generated new migration class to "/var/www/ezpublish/EzPublishMigrations/Version20140508144959.php" -``` - ```php -// ezpublish/EzPublishMigrations/Version20140508144959.php -getParameter('ezpublish_migrations.dir_name'); - if (!file_exists($dir)) { - mkdir($dir, 0777, true); - } - - $configuration->setMigrationsNamespace($container->getParameter('ezpublish_migrations.namespace')); - $configuration->setMigrationsDirectory($dir); - $configuration->registerMigrationsFromDirectory($dir); - $configuration->setName($container->getParameter('ezpublish_migrations.name')); - $configuration->setMigrationsTableName($container->getParameter('ezpublish_migrations.table_name')); - - self::injectContainerToMigrations($container, $configuration->getMigrations()); - } - - /** - * Injects the container to migrations aware of it. - * - * @param ContainerInterface $container - * @param Version[] $versions - */ - protected function injectContainerToMigrations(ContainerInterface $container, array $versions) - { - foreach ($versions as $version) { - $migration = $version->getMigration(); - if ($migration instanceof ContainerAwareInterface) { - $migration->setContainer($container); - } - } - } - - /** - * Generates a doctrine configuration object with eZ Publish's database connection. - * - * @param ContainerInterface $container - * @param OutputInterface $output - * - * @return \Doctrine\DBAL\Migrations\Configuration\Configuration - */ - protected function getBasicConfiguration(ContainerInterface $container, OutputInterface $output) - { - $outputWriter = new OutputWriter( - function ($message) use ($output) { - // @codeCoverageIgnoreStart - if (!(stripos($message, 'but did not result in any sql statements') !== false)) { - return $output->writeln($message); - } - return null; - // @codeCoverageIgnoreEnd - } - ); - - return new Configuration($container->get('ezpublish.connection')->getConnection(), $outputWriter); - } -} diff --git a/tests/Tests/Command/ExecuteCommandTest.php b/tests/Tests/Command/ExecuteCommandTest.php deleted file mode 100644 index a8712ac..0000000 --- a/tests/Tests/Command/ExecuteCommandTest.php +++ /dev/null @@ -1,44 +0,0 @@ -generateMigrationAndReturnVersionString(); - - $command = new ExecuteCommand(); - $this->application->add($command); - - $tester = new CommandTester($command); - $tester->execute( - [ - 'command' => $command->getName(), - 'version' => $versionString, - '--no-interaction' => true, - ], - [ - 'interactive' => false, - ] - ); - - $output = $tester->getDisplay(); - - $this->assertRegExp('/\+\+ migrated/', $output); - } -} diff --git a/tests/Tests/Command/GenerateCommandTest.php b/tests/Tests/Command/GenerateCommandTest.php deleted file mode 100644 index 7cd623f..0000000 --- a/tests/Tests/Command/GenerateCommandTest.php +++ /dev/null @@ -1,92 +0,0 @@ -getApplication(); - - $command = new GenerateCommand(); - $application->add($command); - - $commandInputs = array_merge( - [ - 'command' => $command->getName(), - ], $commandInputs - ); - - $tester = new CommandTester($command); - $tester->execute($commandInputs); - - $output = $tester->getDisplay(); - $versionString = $this->getVersionFromString($output); - - $expectedPath = $this->container->getParameter('ezpublish_migrations.dir_name'); - $this->assertFileExists($expectedPath); - - $finder = new Finder(); - // A new file should have been created with the following attributes: - // - The file name starts with 'Version' - // - The file contains a use statement using our AbstractMigration - $files = $finder - ->in($expectedPath) - ->files() - ->name("Version{$versionString}.php") - ->contains('use Kreait\EzPublish\MigrationsBundle\Migrations\AbstractMigration as EzPublishMigration;'); - - // Used for generating fixtures during development - // $this->writeFixtures($files); - - $this->assertEquals(1, $files->count()); - } - - public function commandInputsProvider() - { - return [ - [ - [], - ], - [ - ['--editor-cmd' => 'echo '], - ], - ]; - } - - /** - * Copies generated fixtures into the _fixtures dir. Only used during development. - * - * @param Finder $files - */ - protected function writeFixtures(Finder $files) - { - $fs = new Filesystem(); - foreach ($files as $file) { - /* @var SplFileInfo $file */ - $fs->copy($file->getRealPath(), __DIR__.'../_fixtures/'.$file->getBasename()); - } - } -} diff --git a/tests/Tests/Command/LatestCommandTest.php b/tests/Tests/Command/LatestCommandTest.php deleted file mode 100644 index 16068aa..0000000 --- a/tests/Tests/Command/LatestCommandTest.php +++ /dev/null @@ -1,40 +0,0 @@ -generateMigrationAndReturnVersionString(); - - $command = new LatestCommand(); - $this->application->add($command); - - $tester = new CommandTester($command); - $tester->execute( - [ - 'command' => $command->getName(), - ] - ); - - $this->assertEquals($versionString, $this->getVersionFromString($tester->getDisplay())); - } -} diff --git a/tests/Tests/Command/MigrateCommandTest.php b/tests/Tests/Command/MigrateCommandTest.php deleted file mode 100644 index 4f84f6d..0000000 --- a/tests/Tests/Command/MigrateCommandTest.php +++ /dev/null @@ -1,43 +0,0 @@ -generateMigrationAndReturnVersionString(); - - $command = new MigrateCommand(); - $this->application->add($command); - - $tester = new CommandTester($command); - $tester->execute( - [ - 'command' => $command->getName(), - '--no-interaction' => true, - ], - [ - 'interactive' => false, - ] - ); - - $output = $tester->getDisplay(); - - $this->assertRegExp('/1 migrations executed/', $output); - } -} diff --git a/tests/Tests/Command/StatusCommandTest.php b/tests/Tests/Command/StatusCommandTest.php deleted file mode 100644 index 2af56f0..0000000 --- a/tests/Tests/Command/StatusCommandTest.php +++ /dev/null @@ -1,73 +0,0 @@ -generateMigrationAndReturnVersionString(); - if ($numberOfVersions > 1) { - sleep(1); // We have to wait for one second to get a new version :) - } - } - - $command = new StatusCommand(); - $this->application->add($command); - - $tester = new CommandTester($command); - $tester->execute(['command' => $command->getName()]); - - $output = $tester->getDisplay(); - - $pattern = sprintf('/Name:\s+(%s)/', preg_quote($this->container->getParameter('ezpublish_migrations.name'))); - $this->assertRegExp($pattern, $output); - - $pattern = sprintf('/Version Table Name:\s+(%s)/', preg_quote($this->container->getParameter('ezpublish_migrations.table_name'))); - $this->assertRegExp($pattern, $output); - - $pattern = sprintf('/Migrations Namespace:\s+(%s)/', preg_quote($this->container->getParameter('ezpublish_migrations.namespace'), '/')); - $this->assertRegExp($pattern, $output); - - $pattern = sprintf('/Migrations Directory:\s+(%s)/', preg_quote($this->container->getParameter('ezpublish_migrations.dir_name'), '/')); - $this->assertRegExp($pattern, $output); - - if (count($versions)) { - $pattern = sprintf('/Latest Version:(.+)\(%s\)/', preg_quote(end($versions))); - } else { - $pattern = '/Latest Version:(.+)0/'; - } - $this->assertRegExp($pattern, $output); - - $pattern = sprintf('/New Migrations:\s+(%s)/', preg_quote(count($versions), '/')); - $this->assertRegExp($pattern, $output); - } - - public function commandInputsProvider() - { - return [ - [0], - [1], - ]; - } -} diff --git a/tests/Tests/Command/VersionCommandTest.php b/tests/Tests/Command/VersionCommandTest.php deleted file mode 100644 index 49c25ae..0000000 --- a/tests/Tests/Command/VersionCommandTest.php +++ /dev/null @@ -1,45 +0,0 @@ -generateMigrationAndReturnVersionString(); - - $command = new VersionCommand(); - $this->application->add($command); - - $tester = new CommandTester($command); - $tester->execute( - [ - 'command' => $command->getName(), - 'version' => $versionString, - '--add' => true, - '--no-interaction' => true, - ], - [ - 'interactive' => false, - ] - ); - - $output = $tester->getDisplay(); - - $this->assertNotEmpty($output); - } -} diff --git a/tests/Tests/DependencyInjection/EzPublishMigrationsExtensionTest.php b/tests/Tests/DependencyInjection/EzPublishMigrationsExtensionTest.php deleted file mode 100644 index 5ffdc90..0000000 --- a/tests/Tests/DependencyInjection/EzPublishMigrationsExtensionTest.php +++ /dev/null @@ -1,34 +0,0 @@ - $this->rootDir.'/EzPublishMigrations', - 'namespace' => $this->migrationsNamespace, - 'table_name' => 'ezmigration_versions', - 'name' => 'Application Migrations', - 'ez_user' => $this->migrationUser, - ]; - - foreach ($checks as $key => $value) { - $this->assertEquals($value, $this->container->getParameter("{$this->extension->getAlias()}.{$key}")); - } - } -} diff --git a/tests/Tests/Fixtures/Version1.php b/tests/Tests/Fixtures/Version1.php deleted file mode 100644 index 32b78b0..0000000 --- a/tests/Tests/Fixtures/Version1.php +++ /dev/null @@ -1,25 +0,0 @@ -createContent(2, 'folder', 'ger-DE', ['title' => 'Title']); - } - - public function down(Schema $schema) - { - } -} diff --git a/tests/Tests/KreaitEzPublishMigrationsBundleTest.php b/tests/Tests/KreaitEzPublishMigrationsBundleTest.php deleted file mode 100644 index 2a565b2..0000000 --- a/tests/Tests/KreaitEzPublishMigrationsBundleTest.php +++ /dev/null @@ -1,25 +0,0 @@ -assertInstanceOf( - 'Kreait\EzPublish\MigrationsBundle\DependencyInjection\EzPublishMigrationsExtension', - $bundle->getContainerExtension() - ); - } -} diff --git a/tests/Tests/Migrations/EzPublishMigrationTest.php b/tests/Tests/Migrations/EzPublishMigrationTest.php deleted file mode 100644 index 86e0a6f..0000000 --- a/tests/Tests/Migrations/EzPublishMigrationTest.php +++ /dev/null @@ -1,140 +0,0 @@ -generateMigrationAndReturnVersionString(); - $namespace = $this->container->getParameter('ezpublish_migrations.namespace'); - $config = $this->getSqliteConfiguration(); - - $fullClassName = $namespace.'\\Version'.$versionString; - $filePath = $this->container->getParameter('ezpublish_migrations.dir_name').'/Version'.$versionString.'.php'; - - $this->assertTrue($this->fs->exists($filePath)); - - require $filePath; - - $version = new Version($config, $versionString, $fullClassName); - - $migration = $version->getMigration(); - if ($migration instanceof ContainerAwareInterface) { - $migration->setContainer($this->container); - } - - $version->execute($direction, true); - - $this->assertAttributeEquals($this->migrationUser, 'defaultMigrationUser', $migration); - $this->assertAttributeEquals($this->migrationUser, 'currentMigrationUser', $migration); - } - - /** - * @param string $direction "up" or "down" - * @dataProvider directionProvider - */ - public function testMigration($direction) - { - $versionString = $this->generateMigrationAndReturnVersionString(); - $namespace = $this->container->getParameter('ezpublish_migrations.namespace'); - $config = $this->getSqliteConfiguration(); - - $fullClassName = $namespace.'\\Version'.$versionString; - $filePath = $this->container->getParameter('ezpublish_migrations.dir_name').'/Version'.$versionString.'.php'; - - $this->assertTrue($this->fs->exists($filePath)); - - require $filePath; - - $version = new Version($config, $versionString, $fullClassName); - - $migration = $version->getMigration(); - if ($migration instanceof ContainerAwareInterface) { - $migration->setContainer($this->container); - } - - $version->execute($direction, true); - - $this->assertInstanceOf($fullClassName, $migration); - } - - public function testCreateContent() - { - $config = $this->getSqliteConfiguration(); - - $version = new Version($config, '1', 'Kreait\EzPublish\MigrationsBundle\Tests\Fixtures\Version1'); - $migration = $version->getMigration(); - if ($migration instanceof ContainerAwareInterface) { - $migration->setContainer($this->container); - } - - $createStruct = $this->getMock('eZ\Publish\API\Repository\Values\Content\ContentCreateStruct'); - $contentType = $this->getMock('eZ\Publish\API\Repository\Values\ContentType\ContentType'); - $versionInfo = $this->getMock('eZ\Publish\API\Repository\Values\Content\VersionInfo'); - $content = $this->getMock('eZ\Publish\API\Repository\Values\Content\Content'); - - $content - ->expects($this->once()) - ->method('getVersionInfo') - ->willReturn($versionInfo); - - /** @var \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\API\Repository\Repository $repository */ - $repository = $this->container->get('ezpublish.api.repository'); - - /** @var \eZ\Publish\API\Repository\ContentTypeService|\PHPUnit_Framework_MockObject_MockObject $contentTypeService */ - $contentTypeService = $repository->getContentTypeService(); - - $contentTypeService - ->expects($this->any()) - ->method('loadContentTypeByIdentifier') - ->willReturn($contentType); - - /** @var \eZ\Publish\API\Repository\ContentService|\PHPUnit_Framework_MockObject_MockObject $contentService */ - $contentService = $repository->getContentService(); - $contentService - ->expects($this->once()) - ->method('newContentCreateStruct') - ->willReturn($createStruct); - - $contentService - ->expects($this->once()) - ->method('createContent') - ->willReturn($content); - - $contentService - ->expects($this->once()) - ->method('publishVersion') - ->willReturn($content); - - $createStruct - ->expects($this->once()) - ->method('setField') - ->with('title', 'Title'); - - $version->execute('up', true); - } - - public function directionProvider() - { - return [ - ['up'], - ['down'], - ]; - } -} diff --git a/tests/Tests/TestCase.php b/tests/Tests/TestCase.php deleted file mode 100644 index 6865933..0000000 --- a/tests/Tests/TestCase.php +++ /dev/null @@ -1,315 +0,0 @@ -fs = new Filesystem(); - - $uniqId = uniqid(); - $this->rootDir = __DIR__.'/Temporary'.$uniqId; - $this->migrationsNamespace = 'Kreait\EzPublish\MigrationsBundle\Tests\Temporary'.$uniqId; - $this->migrationUser = $uniqId; - - $this->extension = new EzPublishMigrationsExtension(); - $this->container = new ContainerBuilder(); - - $this->container->registerExtension($this->extension); - $this->container->setParameter('kernel.root_dir', $this->rootDir); - - $this->container->set('ezpublish.connection', $this->getEzPersistenceHandler()); - $this->container->set('ezpublish.api.repository', $this->getEzRepository()); - - $this->container->loadFromExtension($this->extension->getAlias()); - $this->container->setParameter('ezpublish_migrations.namespace', $this->migrationsNamespace); - $this->container->setParameter('ezpublish_migrations.ez_user', $this->migrationUser); - $this->container->compile(); - - $this->application = $this->getApplication(); - } - - protected function tearDown() - { - $this->fs->remove($this->rootDir); - } - - /** - * Mocked repository - we don't need to test it, we just have to call its methods. - * - * @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\API\Repository\Repository - */ - protected function getEzRepository() - { - $repository = $this->getMock('eZ\Publish\API\Repository\Repository'); - - $repository - ->expects($this->any()) - ->method('getUserService') - ->willReturn($this->getEzUserService()); - - $repository - ->expects($this->any()) - ->method('getContentService') - ->willReturn($this->getEzContentService()); - - $repository - ->expects($this->any()) - ->method('getContentTypeService') - ->willReturn($this->getEzContentTypeService()); - - $repository - ->expects($this->any()) - ->method('getLocationService') - ->willReturn($this->getEzLocationService()); - - $repository - ->expects($this->any()) - ->method('setCurrentUser'); - - return $repository; - } - - /** - * @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\API\Repository\UserService - */ - protected function getEzUserService() - { - $userService = $this->getMock('eZ\Publish\API\Repository\UserService'); - - $userService - ->expects($this->any()) - ->method('loadUserByLogin') - ->willReturn($this->getEzUser()); - - return $userService; - } - - /** - * @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\API\Repository\Values\User\User - */ - protected function getEzUser() - { - $user = $this->getMockBuilder('eZ\Publish\API\Repository\Values\User\User') - ->getMock(); - - return $user; - } - - /** - * @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\API\Repository\ContentService - */ - protected function getEzContentService() - { - $service = $this->getMock('eZ\Publish\API\Repository\ContentService'); - - return $service; - } - - /** - * @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\API\Repository\ContentTypeService - */ - protected function getEzContentTypeService() - { - return $this->getMock('eZ\Publish\API\Repository\ContentTypeService'); - } - - /** - * @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\API\Repository\LocationService - */ - protected function getEzLocationService() - { - return $this->getMock('eZ\Publish\API\Repository\LocationService'); - } - - /** - * @throws \Doctrine\DBAL\DBALException - * - * @return \Doctrine\DBAL\Connection - */ - public function getSqliteConnection() - { - $params = ['driver' => 'pdo_sqlite', 'memory' => true]; - - return DriverManager::getConnection($params); - } - - /** - * @return Configuration - */ - public function getSqliteConfiguration() - { - return new Configuration($this->getSqliteConnection()); - } - - public function getEzPersistenceHandler() - { - $handler = $this->getMockBuilder('eZ\Publish\SPI\Persistence\Handler') - ->setMethods(['getConnection']) - ->getMockForAbstractClass(); - - $handler - ->expects($this->any()) - ->method('getConnection') - ->willReturn($this->getSqliteConnection()); - - return $handler; - } - - /** - * Returns the an application mock which returns a mocked kernel. - * - * @return Application - */ - protected function getApplication() - { - /** @var \PHPUnit_Framework_MockObject_MockObject|\Symfony\Component\HttpKernel\KernelInterface $kernel */ - $kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface'); - - $kernel - ->expects($this->any()) - ->method('getContainer') - ->willReturn($this->container); - - $app = new Application($kernel); - - return $app; - } - - /** - * @throws \Exception - * - * @return string - */ - protected function generateMigrationAndReturnVersionString() - { - $command = new GenerateCommand(); - if (!$this->application->has($command->getName())) { - $this->application->add($command); - } - - $params = [[]]; - - $input = new ArrayInput($params); - $output = new BufferedOutput(); - - $command->run($input, $output); - - $text = $output->fetch(); - - $versionString = $this->getVersionFromString($text); - - return $versionString; - } - - /** - * @param array $variables - * - * @return string - */ - protected function generateMigrationClassFileFromTemplate(array $variables) - { - $placeholders = ['namespace', 'version', 'up', 'down']; - - if (!array_key_exists('version', $variables)) { - $variables['version'] = rand(1, 999999); - } - - $generateCommand = new GenerateCommand(); - $reflection = new \ReflectionClass($generateCommand); - $templateProperty = $reflection->getProperty('template'); - $templateProperty->setAccessible(true); - - $template = $templateProperty->getValue($generateCommand); - - foreach ($placeholders as $placeholder) { - if (array_key_exists($placeholder, $variables)) { - $template = str_replace('<'.$placeholder.'>', $variables[$placeholder], $template); - } else { - $template = str_replace('<'.$placeholder.'>', '', $template); - } - } - - $fileName = $this->container->getParameter('ezpublish_migrations.dir_name').'/Version'.$variables['version']; - $this->fs->dumpFile($fileName, $template); - - $this->assertFileExists($fileName); - } - - /** - * Returns the version number from a string. - * - * @param string $string - * - * @throws \RuntimeException - * - * @return string - */ - protected function getVersionFromString($string) - { - if (preg_match('/(Version)(\d+)(.php)?/m', $string, $matches)) { - return $matches[2]; - } - - if (preg_match('/^\d+$/m', $string, $matches)) { - return $matches[0]; - } - - throw new \RuntimeException("Couldn't find version in string. Please check your tests."); - } -} diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index 6742db5..0000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,12 +0,0 @@ -add('Doctrine\DBAL\Migrations\Tests', __DIR__.'/../vendor/doctrine/migrations/tests'); -$loader->addPsr4('Kreait\\EzPublish\\MigrationsBundle\\Tests\\', __DIR__.'/Tests'); diff --git a/travis.ini b/travis.ini deleted file mode 100644 index 2e67c29..0000000 --- a/travis.ini +++ /dev/null @@ -1 +0,0 @@ -date.timezone = "UTC" \ No newline at end of file