From b1ef60027ac91f695caf9c6604e732bf83ee6745 Mon Sep 17 00:00:00 2001 From: Hasham Ahmad Date: Mon, 1 Aug 2016 22:24:47 +0000 Subject: [PATCH] Support app level migration scaffolding --- .../Fixture/Generate/GenerateAction.class.php | 2 - .../Fixture/Import/ImportAction.class.php | 2 - .../Migrate/Create/CouchDbMigration.tpl.twig | 2 +- .../Create/CreateSuccessView.class.php | 26 ++++++---- .../Create/ElasticsearchMigration.tpl.twig | 2 +- .../Migrate/Create/RabbitMqMigration.tpl.twig | 48 +++++++++++++++++++ .../BuildConfig/BuildConfigAction.class.php | 2 - .../ReplayEvents/ReplayEventsAction.class.php | 1 - .../WebSockets/Server/ServerAction.class.php | 1 - .../impl/Worker/Start/StartAction.class.php | 1 - 10 files changed, 67 insertions(+), 20 deletions(-) create mode 100644 app/modules/Honeybee_Core/impl/Migrate/Create/RabbitMqMigration.tpl.twig diff --git a/app/modules/Honeybee_Core/impl/Fixture/Generate/GenerateAction.class.php b/app/modules/Honeybee_Core/impl/Fixture/Generate/GenerateAction.class.php index d1c8b6aa..596f69ea 100644 --- a/app/modules/Honeybee_Core/impl/Fixture/Generate/GenerateAction.class.php +++ b/app/modules/Honeybee_Core/impl/Fixture/Generate/GenerateAction.class.php @@ -1,8 +1,6 @@ getAttribute('migration_dir'); // Bit of a hack to build namespace - if (!preg_match('#.+/app/modules/(\w+_?)/.+#', $migration_dir, $matches)) { + if (!preg_match('#.+/app/(?:modules|migration)/(\w+_?)(?:$|/.+)#', $migration_dir, $matches)) { throw new RuntimeError(sprintf('Could not find namespace info in path %s', $migration_dir)); } + $namespace_parts = explode('_', $matches[1]); + if (count($namespace_parts) == 1) { + // @todo app migration - introduce a project root namespace setting + $namespace_parts = [ 'Your', 'Application' ]; + } + // And a hack to determine the technology namespace - if (strpos($request_data->getParameter('target'), 'event_source')) { + $target = $request_data->getParameter('target'); + if (strpos($target, 'event_source')) { $technology = 'CouchDb'; - } else { + } elseif (strpos($target, 'view_store')) { $technology = 'Elasticsearch'; + } else { + $technology = 'RabbitMq'; } $migration_filepath = sprintf( @@ -35,11 +44,9 @@ public function executeConsole(AgaviRequestDataHolder $request_data) $migration_slug ); - $twig_renderer = TwigRenderer::create( - [ - 'template_paths' => [ __DIR__ ] - ] - ); + $twig_renderer = TwigRenderer::create([ + 'template_paths' => [ __DIR__ ] + ]); $twig_renderer->renderToFile( $technology . 'Migration.tpl.twig', @@ -52,7 +59,8 @@ public function executeConsole(AgaviRequestDataHolder $request_data) 'filepath' => $migration_filepath, 'vendor_prefix' => $namespace_parts[0], 'package_prefix' => $namespace_parts[1], - 'technology' => $technology + 'technology' => $technology, + 'project_prefix' => AgaviConfig::get('core.project_prefix') ] ); diff --git a/app/modules/Honeybee_Core/impl/Migrate/Create/ElasticsearchMigration.tpl.twig b/app/modules/Honeybee_Core/impl/Migrate/Create/ElasticsearchMigration.tpl.twig index 0ac05c31..ffdeb034 100644 --- a/app/modules/Honeybee_Core/impl/Migrate/Create/ElasticsearchMigration.tpl.twig +++ b/app/modules/Honeybee_Core/impl/Migrate/Create/ElasticsearchMigration.tpl.twig @@ -3,8 +3,8 @@ namespace {{ vendor_prefix }}\{{ package_prefix }}\Migration\Elasticsearch; use Honeybee\Infrastructure\Migration\ElasticsearchMigration; -use Honeybee\Infrastructure\Migration\MigrationTargetInterface; use Honeybee\Infrastructure\Migration\MigrationInterface; +use Honeybee\Infrastructure\Migration\MigrationTargetInterface; class Migration_{{ timestamp }}_{{ name }} extends ElasticsearchMigration { diff --git a/app/modules/Honeybee_Core/impl/Migrate/Create/RabbitMqMigration.tpl.twig b/app/modules/Honeybee_Core/impl/Migrate/Create/RabbitMqMigration.tpl.twig new file mode 100644 index 00000000..ac5fd339 --- /dev/null +++ b/app/modules/Honeybee_Core/impl/Migrate/Create/RabbitMqMigration.tpl.twig @@ -0,0 +1,48 @@ +createVersionList($migration_target, '{{ project_prefix }}.domain.version_list'); + * $this->createExchangePipeline($migration_target, '{{ project_prefix }}.domain.events'); + */ + + /* + * Create a queue and register on an exchange. Event bus events for an async channel will be sent + * as messages routed to the given queue. + * + * Add a configuration in jobs.xml and register the job to an event handler, then run a worker + * to process the messages according to configured retry/fail strategies. + * + * $this->createQueue($migration_target, '{{ project_prefix }}.domain.events', 'my.queue', 'my_routing_key'); + */ + } + + public function down(MigrationTargetInterface $migration_target) + { + // @todo implement + } +} diff --git a/app/modules/Honeybee_Core/impl/Util/BuildConfig/BuildConfigAction.class.php b/app/modules/Honeybee_Core/impl/Util/BuildConfig/BuildConfigAction.class.php index 7d2063b1..5cb45e41 100644 --- a/app/modules/Honeybee_Core/impl/Util/BuildConfig/BuildConfigAction.class.php +++ b/app/modules/Honeybee_Core/impl/Util/BuildConfig/BuildConfigAction.class.php @@ -1,10 +1,8 @@