<?php

namespace OfficeBrain\CustomBundle\MigrationBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use OfficeBrain\Bundle\FlyerBundle\Entity\Flyer;

class MigrateFlyerImportCommand extends ContainerAwareCommand {
	
	const COMMAND_NAME = 'goldstar_migration:migration:import-flyer';
	
	
	 /**
     * @see Command
     */
    protected function configure() {
        $this
                ->setName('goldstar_migration:migration:import-flyer')
                ->setDescription('Import Script For Flyer')
                ->addOption('categoryId', null, InputOption::VALUE_OPTIONAL, 'Enter category Id')
                ->addOption('limit', null, InputOption::VALUE_OPTIONAL, 'migrate data limit')
                ->setHelp(<<<EOT
The <info>goldstar_migration:migration:import-flyer</info> Migration Script For Flyer upload data:

  <info>php app/console goldstar_migration:migration:import-flyer --categoryId=1 --limit-1</info>
EOT
        );
    }

    public function init() {
        $this->container = $this->getContainer();
        $this->flyerManager = $this->container->get('office_brain_flyer_manager');
        $this->entityManager = $this->container->get('doctrine.orm.entity_manager');
    }
    
    /**
     * @see Command
     */
    protected function execute(InputInterface $input, OutputInterface $output) {
        $this->init();
        $categoryId = $input->getOption('categoryId', null);
        $limit = $input->getOption('limit', 500);
        
        if ($categoryId == '')
        {
            $output->writeln("Please provide a Category Id !");
            return;
        }
        $rootDir = $this->container->get('kernel')->getRootdir().'/../web';
        
        $this->flyerManager->importFlyer($categoryId,$rootDir,$limit);
        
        $output->writeln("Flyer import finished.");

        exit;
    }
}
		
		
		
?>