diff --git a/Command/MigrateCommand.php b/Command/MigrateCommand.php index ca215d4d..3066453e 100644 --- a/Command/MigrateCommand.php +++ b/Command/MigrateCommand.php @@ -80,6 +80,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->setVerbosity(self::VERBOSITY_CHILD); } + $this->getContainer()->get('ez_migration_bundle.step_executed_listener.tracing')->setOutput($output); + $migrationService = $this->getMigrationService(); $paths = $input->getOption('path'); diff --git a/Core/EventListener/TracingStepExecutedListener.php b/Core/EventListener/TracingStepExecutedListener.php new file mode 100644 index 00000000..f9440488 --- /dev/null +++ b/Core/EventListener/TracingStepExecutedListener.php @@ -0,0 +1,112 @@ +output = $output; + } + + /** + * NB: only works when using an OutputInterface to echo output + * @param int $level + */ + public function setMinVerbosity($level) + { + $this->minVerbosityLevel = $level; + } + + public function onStepExecuted(StepExecutedEvent $event) + { + $obj = $event->getResult(); + $type = $event->getStep()->type; + $dsl = $event->getStep()->dsl; + $action = isset($dsl['mode']) ? ($dsl['mode'] . 'd') : 'acted upon'; + + switch($type) { + case 'content': + case 'content_type': + case 'language': + case 'location': + case 'object_state': + case 'object_state_group': + case 'role': + case 'tag': + case 'user': + case 'user_group': + $out = $type . ' '. $this->getObjectIdentifierAsString($obj). ' has been ' . $action; + break; + case 'sql': + $out = 'sql has been executed'; + break; + case 'php': + $out = "class '{$dsl['class']}' has been executed"; + break; + default: + // custom migration step types... + $out = "migration step '$type' has been executed"; + } + + if ($this->output) { + if ($this->output->getVerbosity() >= $this->minVerbosityLevel) { + $this->output->writeln($out); + } + } else { + echo $out . "\n"; + } + } + + protected function getObjectIdentifierAsString($objOrCollection) + { + if ($objOrCollection instanceof AbstractCollection || is_array($objOrCollection)) { + $out = array(); + foreach($objOrCollection as $obj) { + $out[] = $this->getObjectIdentifierAsString($obj); + } + return implode(", ", $out) ; + } + + switch(gettype($objOrCollection)) { + + case 'object': + if ($objOrCollection instanceof \eZ\Publish\API\Repository\Values\Content\Content || + $objOrCollection instanceof \eZ\Publish\API\Repository\Values\User\UserGroup) + return "'" . $objOrCollection->contentInfo->name . "'"; + if ($objOrCollection instanceof \eZ\Publish\API\Repository\Values\ContentType\ContentType || + $objOrCollection instanceof \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup || + $objOrCollection instanceof \eZ\Publish\API\Repository\Values\ObjectState\ObjectState || + $objOrCollection instanceof \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup || + $objOrCollection instanceof \eZ\Publish\API\Repository\Values\User\Role || + $objOrCollection instanceof \eZ\Publish\API\Repository\Values\Content\Section) + return "'" . $objOrCollection->identifier . "'"; + if ($objOrCollection instanceof \eZ\Publish\API\Repository\Values\Content\Location) + return "'" . $objOrCollection->pathString . "'"; + if ($objOrCollection instanceof \eZ\Publish\API\Repository\Values\Content\Language) + return "'" . $objOrCollection->languageCode . "'"; + if ($objOrCollection instanceof \eZ\Publish\API\Repository\Values\User\User) + return "'" . $objOrCollection->login . "'"; + // unknown objects - we can't know what the desired identifier is... + return ''; + + default: + // scalars: the identifier is the value... + /// @todo make readable NULL, true/false + return "'" . $objOrCollection . "'"; + } + } +} diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 84a9e811..3b3fff52 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -75,6 +75,8 @@ parameters: ez_migration_bundle.helper.limitation_converter.class: Kaliop\eZMigrationBundle\Core\Helper\LimitationConverter ez_migration_bundle.helper.console_io.class: Kaliop\eZMigrationBundle\Core\Helper\ConsoleIO + ez_migration_bundle.step_executed_listener.tracing.class: Kaliop\eZMigrationBundle\Core\EventListener\TracingStepExecutedListener + services: ez_migration_bundle.migration_service: @@ -424,6 +426,12 @@ services: ### misc + # This service is used for the verbose mode when executing migrations on the command line + ez_migration_bundle.step_executed_listener.tracing: + class: '%ez_migration_bundle.step_executed_listener.tracing.class%' + tags: + - { name: kernel.event_listener, event: ez_migration.step_executed, method: onStepExecuted } + ez_migration_bundle.helper.limitation_converter: class: '%ez_migration_bundle.helper.limitation_converter.class%' arguments: diff --git a/WHATSNEW.md b/WHATSNEW.md index ada54d46..799cbed6 100644 --- a/WHATSNEW.md +++ b/WHATSNEW.md @@ -7,6 +7,8 @@ Version 3.0.0-beta3 * New: the 'migrate' command learned a `--separate-process` option, to run each migration it its own separate php process. This should help when running many migrations in a single pass, and there are f.e. memory leaks. +* New: the 'migrate' command learned to give information ion the executed steps when using the `-v` option + * New: the 'migration' command learned a `--skip` option, to tag migrations as to be skipped * New: it is now possible to create, update and delete Object States and Object State Groups @@ -36,13 +38,14 @@ Version 3.0.0-beta3 * New: the content_type_group tags in ContentType creation will accept a Content Type Group identifier besides an id -* New: added 2 events to which you can listen to implement custom logic just-before and just-after migration steps are executed: +* New: added 2 events to which you can listen to implement custom logic just-before and just-after migration steps are + executed: * ez_migration.before_execution => listeners receive a BeforeStepExecutionEvent event instance * ez_migration.step_executed => listeners receive a StepExecutedEvent event instance -* Fixed: migrations will not silently swallow any more errors when creating users or assigning roles and an inexisting +* Fix: migrations will not silently swallow any more errors when creating users or assigning roles and a non-existing group is specified * Fix: (issue 78) when using transactions, do not report 'Migration can not be ended' if there is an error during the