Skip to content

Instantly share code, notes, and snippets.

@mishak87
Created June 18, 2014 22:43
Show Gist options
  • Save mishak87/7c1b560e3f5a4ab208fc to your computer and use it in GitHub Desktop.
Save mishak87/7c1b560e3f5a4ab208fc to your computer and use it in GitHub Desktop.
With <3 for Hosiplan
<?php
namespace Kdyby\Doctrine\Console;
use Kdyby;
use Kdyby\Doctrine\BatchImportException;
use Kdyby\Doctrine\Helpers;
use Rixxi;
use Symfony;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class DbalBatchFile extends Symfony\Component\Console\Command\Command
{
protected function configure()
{
$this->setName('dbal:batch-file');
$this->setAliases(['dbal:batch:file']);
$this->addArgument('file', InputArgument::REQUIRED, 'SQL batch file to run');
$this->setDescription('Self explanatory...');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
if (!is_readable($file = $input->getArgument('file'))) {
$output->writeLn(sprintf("<error>Cannot read file '%s'.</error>", $file));
return 1;
}
$emHelper = $this->getHelper('em');
/* @var $em \Doctrine\ORM\EntityManager */
$em = $emHelper->getEntityManager();
Helpers::loadFromFile($em->getConnection(), $file);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment