Skip to content

Commit

Permalink
EZP-23949: Refactored installers out of kernel
Browse files Browse the repository at this point in the history
Added service tag ezplatform.installer, with 'type' key.
PlatformInstallerBundle contains 'clean' install by default.
'demo' and 'demo-clean' installers are in the demobundle itself.
  • Loading branch information
Bertrand Dunogier committed Feb 13, 2015
1 parent c4342b4 commit d2ca6e0
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 1,851 deletions.
486 changes: 0 additions & 486 deletions data/demo_clean_data.sql

This file was deleted.

1,188 changes: 0 additions & 1,188 deletions data/demo_data.sql

This file was deleted.

Expand Up @@ -8,6 +8,7 @@
namespace EzSystems\PlatformInstallerBundle\Command;

use Doctrine\DBAL\Exception\ConnectionException;
use EzSystems\PlatformInstallerBundle\Installer\Installer;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -30,7 +31,8 @@ class InstallPlatformCommand extends ContainerAwareCommand
protected function configure()
{
$this->setName( 'ezplatform:install' );
$this->addArgument( 'type', InputArgument::REQUIRED, "The type of install, one of: clean, demo-clean or demo" );

$this->addArgument( 'type', InputArgument::REQUIRED, "The type of install" );
}

protected function execute( InputInterface $input, OutputInterface $output )
Expand All @@ -40,19 +42,11 @@ protected function execute( InputInterface $input, OutputInterface $output )
$this->checkParameters();
$this->checkDatabase();

switch ( $type = $input->getArgument( 'type' ) )
$type = $input->getArgument( 'type' );
$installer = $this->getInstaller( $type );
if ( $installer === false )
{
case 'clean':
$installer = $this->getContainer()->get( 'ezplatform.installer.clean_installer' );
break;
case 'demo':
$installer = $this->getContainer()->get( 'ezplatform.installer.demo_installer' );
break;
case 'demo-clean':
$installer = $this->getContainer()->get( 'ezplatform.installer.democlean_installer' );
break;
default:
$output->writeln( "Unknown install type '$type''" );
$output->writeln( "Unknown install type '$type'" );
exit( self::EXIT_UNKNOWN_INSTALL_TYPE );
}

Expand Down Expand Up @@ -128,4 +122,28 @@ private function checkDatabase()
exit( self::EXIT_GENERAL_DATABASE_ERROR );
}
}

/**
* @return array
*/
private function getAvailableInstallers()
{
return array_keys( $this->getContainer()->getParameter( 'ezplatform.installers' ) );
}

/**
* @param $type
*
* @return \EzSystems\PlatformInstallerBundle\Installer\Installer
*/
private function getInstaller( $type )
{
$installers = $this->getContainer()->getParameter( 'ezplatform.installers' );
if ( !isset( $installers[$type] ) )
{
return false;
}

return $this->getContainer()->get( $installers[$type] );
}
}
@@ -0,0 +1,42 @@
<?php
/**
* This file is part of the ezpublish-kernel package.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/

namespace EzSystems\PlatformInstallerBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

/**
* Compiles services tagged as ezplatform.installer to %ezplatform.installers%
*/
class InstallerTagPass implements CompilerPassInterface
{
public function process( ContainerBuilder $container )
{
$installers = [];

foreach ( $container->findTaggedServiceIds( 'ezplatform.installer' ) as $id => $tags )
{
foreach ( $tags as $tag )
{
if ( !isset( $tag['type'] ) )
throw new \LogicException( "ezplatform.installer service tag needs a 'type' attribute to identify the installer. None given for $id." );

$installers[$tag['type']] = $id;
}
}

if ( count( $installers ) == 0 )
{
return;
}

$container->setParameter( 'ezplatform.installers', $installers );
}
}
Expand Up @@ -7,9 +7,15 @@
*/
namespace EzSystems\PlatformInstallerBundle;

use EzSystems\PlatformInstallerBundle\DependencyInjection\Compiler\InstallerTagPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class EzSystemsPlatformInstallerBundle extends Bundle
{
public function build( ContainerBuilder $container )
{
parent::build( $container );
$container->addCompilerPass( new InstallerTagPass() );
}
}

This file was deleted.

56 changes: 0 additions & 56 deletions eZ/Bundle/PlatformInstallerBundle/src/Installer/DemoInstaller.php

This file was deleted.

@@ -1,23 +1,15 @@
parameters:
ezplatform.installer.db_based_installer.class: EzSystems\PlatformInstallerBundle\Installer\DbBasedInstaller
ezplatform.installer.clean_installer.class: EzSystems\PlatformInstallerBundle\Installer\CleanInstaller
ezplatform.installer.democlean_installer.class: EzSystems\PlatformInstallerBundle\Installer\DemoCleanInstaller
ezplatform.installer.demo_installer.class: EzSystems\PlatformInstallerBundle\Installer\DemoInstaller

services:
ezplatform.installer.db_based_installer:
abstract: true
class: %ezplatform.installer.db_based_installer.class%
arguments: [@database_connection]

ezplatform.installer.democlean_installer:
class: %ezplatform.installer.democlean_installer.class%
parent: ezplatform.installer.db_based_installer

ezplatform.installer.clean_installer:
class: %ezplatform.installer.clean_installer.class%
parent: ezplatform.installer.db_based_installer

ezplatform.installer.demo_installer:
class: %ezplatform.installer.demo_installer.class%
parent: ezplatform.installer.db_based_installer
tags:
- {name: ezplatform.installer, type: clean}

This file was deleted.

0 comments on commit d2ca6e0

Please sign in to comment.