DeployCommand.php 3.11 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
<?php

/**
 * Composer Magento Installer
 */

namespace MagentoHackathon\Composer\Magento\Command;

use MagentoHackathon\Composer\Magento\Deploy\Manager\Entry;
use MagentoHackathon\Composer\Magento\DeployManager;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Composer\Downloader\VcsDownloader;
use MagentoHackathon\Composer\Magento\Installer;

/**
 * @author Tiago Ribeiro <tiago.ribeiro@seegno.com>
 * @author Rui Marinho <rui.marinho@seegno.com>
 */
class DeployCommand extends \Composer\Command\Command
{
    protected function configure()
    {
        $this
            ->setName('magento-module-deploy')
            ->setDescription('Deploy all Magento modules loaded via composer.json')
            ->setDefinition(array(
            // we dont need to define verbose, because composer already defined it internal
            //new InputOption('verbose', 'v', InputOption::VALUE_NONE, 'Show modified files for each directory that contains changes.'),
        ))
            ->setHelp(<<<EOT
This command deploys all magento Modules

EOT
        )
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        // init repos
        $composer = $this->getComposer();
        $installedRepo = $composer->getRepositoryManager()->getLocalRepository();

        $dm = $composer->getDownloadManager();
        $im = $composer->getInstallationManager();

        /**
         * @var $moduleInstaller \MagentoHackathon\Composer\Magento\Installer
         */
        $moduleInstaller = $im->getInstaller("magento-module");


        $deployManager = new DeployManager( $this->getIO() );

        $extra          = $composer->getPackage()->getExtra();
        $sortPriority   = isset($extra['magento-deploy-sort-priority']) ? $extra['magento-deploy-sort-priority'] : array();
        $deployManager->setSortPriority( $sortPriority );



        $moduleInstaller->setDeployManager( $deployManager );
        

        foreach ($installedRepo->getPackages() as $package) {

            if ($input->getOption('verbose')) {
                $output->writeln( $package->getName() );
                $output->writeln( $package->getType() );
            }

            if( $package->getType() != "magento-module" ){
                continue;
            }
            if ($input->getOption('verbose')) {
                $output->writeln("package {$package->getName()} recognized");
            }

            $strategy = $moduleInstaller->getDeployStrategy($package);
            if ($input->getOption('verbose')) {
                $output->writeln("used " . get_class($strategy) . " as deploy strategy");
            }
            $strategy->setMappings($moduleInstaller->getParser($package)->getMappings());

            $deployManagerEntry = new Entry();
            $deployManagerEntry->setPackageName($package->getName());
            $deployManagerEntry->setDeployStrategy($strategy);
            $deployManager->addPackage($deployManagerEntry);
            
        }

        $deployManager->doDeploy();

        return;
    }
}