public function getLandingPage(&$configuration)
 {
     if (!count($this->getZones())) {
         return false;
     }
     $configuration['layouts'][$this->getLayout()] = ['identifier' => $this->getLayout(), 'name' => $this->getLayout(), 'description' => $this->getLayout(), 'thumbnail' => '/bundles/migrationbundle/images/layouts/' . $this->getLayout() . '.png', 'template' => 'MigrationBundle:layouts:' . $this->getLayout() . '.html.twig', 'zones' => []];
     $zones = [];
     Report::write(count($this->getZones()) . " in " . $this->getLayout() . " layout found");
     foreach ($this->getZones() as $zone) {
         $configuration['layouts'][$this->getLayout()]['zones'][$zone->getId()] = ['name' => $zone->getId()];
         $blocks = [];
         foreach ($zone->getBlocks() as $block) {
             Report::write("Trying to map {$block->getType()} block to one of used in eZ Studio");
             $studioBlock = $this->blockMapper->map($block);
             $legacyDefinition = $this->blockMapper->getLegacyBlockConfiguration()[$block->getType()];
             if (!$studioBlock) {
                 Report::write("Mapping not found, preparing placeholder block in: src/MigrationBundle/LandingPage/Block/Legacy{$block->getType()}Block.php");
                 $blockDefinition = $this->blockMapper->generateBlockClass($block->getType());
                 $blockRegistry = $this->container->get('ezpublish.landing_page.registry.block_type');
                 $blockRegistry->addBlockType('legacy_' . strtolower($block->getType()), $blockDefinition);
                 $studioBlock = new BlockValue($block->getId(), 'legacy_' . strtolower($block->getType()), $block->getView(), $block->getAttributes());
                 Report::write("Generate service configuration for new block type");
                 $configuration['services']['migration.landing_page.block.legacy_' . strtolower($block->getType())] = ['class' => 'MigrationBundle\\LandingPage\\Block\\Legacy' . $block->getType() . 'Block', 'arguments' => ['@ezpublish.api.service.content'], 'tags' => [['name' => 'landing_page_field_type.block_type', 'alias' => $studioBlock->getType()]]];
             } else {
                 Report::write("Mapping found, migrating block as " . $studioBlock->getType());
             }
             $studioBlock->setName($block->getName());
             if (!isset($configuration['blocks'][$studioBlock->getType()])) {
                 $configuration['blocks'][$studioBlock->getType()] = ['views' => []];
             }
             if (!isset($configuration['blocks'][$studioBlock->getType()]['views'][$studioBlock->getView()])) {
                 $configuration['blocks'][$studioBlock->getType()]['views'][$studioBlock->getView()] = ['template' => 'MigrationBundle:blocks:' . $studioBlock->getType() . '_' . $studioBlock->getView() . '.html.twig', 'name' => $studioBlock->getType() . ' ' . $studioBlock->getView() . ' view'];
                 if ($legacyDefinition['ManualAddingOfItems'] == 'enabled') {
                     $this->blockMapper->generateBlockView('schedule', $block->getType(), $block->getView());
                 } else {
                     $this->blockMapper->generateBlockView('block', $block->getType(), $block->getView());
                 }
             }
             $blocks[] = $studioBlock;
         }
         $zones[] = new LandingZone($zone->getId(), $zone->getId(), $blocks);
     }
     $landingPage = new LandingPage($this->getName(), $this->getLayout(), $zones);
     return $this->container->get('ezpublish.fieldtype.ezlandingpage.xml_converter')->toXml($landingPage);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $filesystem = new Filesystem();
     $formatter = $this->getHelper('formatter');
     try {
         Report::prepare($output, $formatter);
         $this->loginAsAdmin();
         $filesystem->mkdir('src/MigrationBundle');
         Report::write("Migrtion log: src/MigrationBundle/migration.log");
         $warning = new OutputFormatterStyle('yellow', 'red', array('bold', 'blink'));
         $output->getFormatter()->setStyle('warning', $warning);
         if ($filesystem->exists('src/MigrationBundle/MigrationBundle.php')) {
             $output->writeln($formatter->formatBlock(['', '  MigrationBundle already exists. Aborting...  ', ''], 'warning'));
             return false;
         }
         $dbname = $this->getContainer()->getParameter('database_name');
         $dbhost = $this->getContainer()->getParameter('database_host');
         $output->writeln($formatter->formatBlock(['', '     The migration script will operate on your current database.  ', '  Make sure to back up your database in case of an unexpected error.  ', ''], 'warning'));
         $helper = $this->getHelper('question');
         $output->writeln('');
         $output->writeln('Current database: ' . $dbname . '@' . $dbhost);
         $output->writeln('');
         $question = new Question('Are you sure? (yes/no) [default: no]  ', 'no');
         $answer = $helper->ask($input, $output, $question);
         $output->writeln('');
         if ($answer !== 'yes') {
             $output->writeln($formatter->formatBlock(['  Aborting...  '], 'warning'));
             return false;
         }
         $legacyPath = $input->getArgument('legacy_path');
         $legacyCustomConfiguration = $input->getOption('ini');
         Wrapper::initialize($legacyPath, $legacyCustomConfiguration ?: []);
         Wrapper::$handler = $this->getContainer()->get('ezpublish.api.storage_engine.legacy.dbhandler');
         $legacyWrapper = new Wrapper();
         $legacyModel = new Model(Wrapper::$handler);
         Report::write('Loading pages from database: ' . $dbname . '@' . $dbhost);
         $legacyPages = $legacyModel->getPages();
         Report::write('Reading legacy block configuration');
         $blockMapper = new BlockMapper($legacyWrapper->getBlockConfiguration(), $this->getContainer()->get('twig'));
         $configuration = ['layouts' => [], 'blocks' => [], 'services' => []];
         foreach ($legacyPages as $legacyPage) {
             Report::write("Migrating page...");
             Report::write("ContentId: {$legacyPage['contentobject_id']}, FieldId: {$legacyPage['id']}, Version: {$legacyPage['version']}");
             $legacyPage['name'] = 'Migrated Landing Page';
             $page = new Page($legacyPage, $this->getContainer(), $blockMapper);
             $landingPage = $page->getLandingPage($configuration);
             if ($landingPage) {
                 Report::write("Save page as Langin Page");
                 $legacyModel->updateEzPage($legacyPage['id'], $landingPage);
             } else {
                 Report::write("Not valid page field (empty or used as call-to-action). Ignoring...");
             }
         }
         $legacyModel->replacePageFieldType();
         $path = 'src/MigrationBundle/Resources/config';
         $filesystem->mkdir($path);
         $filesystem->mkdir('src/MigrationBundle/DependencyInjection');
         $dumper = new Dumper();
         $servicesYaml = $dumper->dump(['services' => $configuration['services']], 4);
         $layoutYaml = $dumper->dump(['layouts' => $configuration['layouts'], 'blocks' => $configuration['blocks']], 6);
         $path = 'src/MigrationBundle/Resources/views/layouts';
         $filesystem->mkdir($path);
         foreach ($configuration['layouts'] as $layout) {
             Report::write('Prepare placeholder layout (' . $layout['identifier'] . ') in: ' . "{$path}/{$layout['identifier']}.html.twig");
             $filesystem->dumpFile("{$path}/{$layout['identifier']}.html.twig", $this->getContainer()->get('twig')->render('@EzFlowMigrationToolkit/twig/layout.html.twig', ['zones' => $layout['zones']]));
         }
         $path = 'src/MigrationBundle/Resources/config';
         Report::write("Save service configuration: {$path}/services.yml");
         $filesystem->dumpFile("{$path}/services.yml", $servicesYaml);
         Report::write("Save layout configuration: {$path}/layouts.yml");
         $filesystem->dumpFile("{$path}/layouts.yml", $layoutYaml);
         Report::write("Prepare PHP classes for MigrationBundle");
         $filesystem->dumpFile("src/MigrationBundle/MigrationBundle.php", $this->getContainer()->get('twig')->render('@EzFlowMigrationToolkit/php/MigrationBundle.php.twig'));
         $filesystem->dumpFile("src/MigrationBundle/DependencyInjection/MigrationExtension.php", $this->getContainer()->get('twig')->render('@EzFlowMigrationToolkit/php/Extension.php.twig'));
         Report::write("Done!");
         $output->writeln($formatter->formatBlock(["  Success!  "], 'info'));
     } catch (\Exception $e) {
         $message = "ERROR: {$e->getMessage()}";
         Report::write($message);
         $output->writeln($formatter->formatBlock(["  {$message}  "], 'warning'));
     }
 }