Exemple #1
0
 /**
  * {@inheritDoc}
  */
 public function onBootstrap(EventInterface $e)
 {
     /* @var $app \Zend\Mvc\ApplicationInterface */
     $app = $e->getTarget();
     $events = $app->getEventManager()->getSharedManager();
     // Attach to helper set event and load the entity manager helper.
     $events->attach('doctrine', 'loadCli.post', function (EventInterface $e) {
         /* @var $cli \Symfony\Component\Console\Application */
         $cli = $e->getTarget();
         ConsoleRunner::addCommands($cli);
         $cli->addCommands(array(new DiffCommand(), new ExecuteCommand(), new GenerateCommand(), new MigrateCommand(), new StatusCommand(), new VersionCommand()));
         /* @var $sm ServiceLocatorInterface */
         $sm = $e->getParam('ServiceManager');
         /* @var $em \Doctrine\ORM\EntityManager */
         $em = $sm->get('doctrine.entitymanager.orm_default');
         $helperSet = $cli->getHelperSet();
         $helperSet->set(new DialogHelper(), 'dialog');
         $helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
         $helperSet->set(new EntityManagerHelper($em), 'em');
     });
     $config = $app->getServiceManager()->get('Config');
     $app->getServiceManager()->get('doctrine.entity_resolver.orm_default');
     if (isset($config['zenddevelopertools']['profiler']['enabled']) && $config['zenddevelopertools']['profiler']['enabled']) {
         $app->getServiceManager()->get('doctrine.sql_logger_collector.orm_default');
     }
 }
 /**
  * Constructor
  *
  * @param Application $console Console
  * @param ContainerInterface $container Container DI
  */
 public function __construct(Application $console, ContainerInterface $container)
 {
     $entityManager = $container->get('EntityManager');
     $helperSet = ConsoleRunner::createHelperSet($entityManager);
     $helperSet->set(new QuestionHelper(), 'dialog');
     $console->setHelperSet($helperSet);
     ConsoleRunner::addCommands($console);
 }
 public function registerCommands(Application $application)
 {
     parent::registerCommands($application);
     //include Doctrine ORM commands if exist
     if (class_exists('Doctrine\\ORM\\Version')) {
         ConsoleRunner::addCommands($application);
     }
 }
Exemple #4
0
 /**
  * Run console with the given helperset.  Use the in-built Doctrine commands, plus Flextrine specific ones.
  *
  * @param \Symfony\Component\Console\Helper\HelperSet $helperSet
  * @return void
  */
 public static function run(HelperSet $helperSet)
 {
     $cli = new Application('Doctrine Command Line Interface', \Doctrine\ORM\Version::VERSION);
     $cli->setCatchExceptions(true);
     $cli->setHelperSet($helperSet);
     parent::addCommands($cli);
     self::addCommands($cli);
     $cli->run();
 }
Exemple #5
0
 public function __construct()
 {
     parent::__construct(static::NAME, static::VERSION);
     //Add Doctrine support to console
     $em = Configuration::getEntityManager();
     $doctrineHelperSet = new HelperSet(['db' => new ConnectionHelper($em->getConnection()), 'em' => new EntityManagerHelper($em)]);
     $this->setHelperSet($doctrineHelperSet);
     ConsoleRunner::addCommands($this);
     $this->addCommands([new Command\ModuleUpdateCommand()]);
 }
 /**
  * @param $orm
  */
 public function ormCommands($orm)
 {
     if (is_array($orm) && in_array('doctrine', $orm)) {
         /** @var EntityManager $em */
         $em = Model::orm('doctrine')->getOrm();
         $helperSet = ConsoleRunner::createHelperSet($em);
         $this->cli->setCatchExceptions(true);
         $this->cli->setHelperSet($helperSet);
         ConsoleRunner::addCommands($this->cli);
     }
 }
 public function setupDoctrineCommands()
 {
     if (!Core::make('app')->isInstalled()) {
         return;
     }
     $helperSet = ConsoleRunner::createHelperSet(\ORM::entityManager('core'));
     $this->setHelperSet($helperSet);
     $migrationsConfiguration = new MigrationsConfiguration();
     /** @var \Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand[] $commands */
     $commands = array(new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand());
     foreach ($commands as $migrationsCommand) {
         $migrationsCommand->setMigrationConfiguration($migrationsConfiguration);
         $this->add($migrationsCommand);
     }
     ConsoleRunner::addCommands($this);
 }
Exemple #8
0
 /**
  * {@inheritDoc}
  */
 public function init(ModuleManager $e)
 {
     $events = $e->getEventManager()->getSharedManager();
     // Attach to helper set event and load the entity manager helper.
     $events->attach('doctrine', 'loadCli.post', function (EventInterface $e) {
         /* @var $cli \Symfony\Component\Console\Application */
         $cli = $e->getTarget();
         /* @var $sm ServiceLocatorInterface */
         $sm = $e->getParam('ServiceManager');
         $em = $sm->get('doctrine.entitymanager.orm_default');
         $paths = $sm->get('doctrine.configuration.fixtures');
         $importCommand = new ImportCommand();
         $importCommand->setEntityManager($em);
         $importCommand->setPath($paths);
         ConsoleRunner::addCommands($cli);
         $cli->addCommands(array($importCommand));
     });
 }
Exemple #9
0
 public function onBootstrap(EventInterface $e)
 {
     $app = $e->getTarget();
     $events = $app->getEventManager()->getSharedManager();
     // Attach to helper set event and load the entity manager helper.
     $events->attach('doctrine', 'loadCli.post', function (EventInterface $e) {
         $cli = $e->getTarget();
         ConsoleRunner::addCommands($cli);
         if (class_exists('Doctrine\\DBAL\\Migrations\\Versions')) {
             $cli->add(array(new DiffCommand(), new ExecuteCommand(), new GenerateCommand(), new MigrateCommand(), new StatusCommand(), new VersionCommand()));
         }
         $sm = $e->getParam('ServiceManager');
         $em = $sm->get('doctrine.entitymanager.orm_another');
         $helperSet = $cli->getHelperSet();
         $helperSet->set(new DialogHelper(), 'dialog');
         $helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
         $helperSet->set(new EntityManagerHelper($em), 'em');
     });
 }
Exemple #10
0
 /**
  * Add Doctrine commands
  *
  * @return $this
  */
 public function addOrmCommands()
 {
     ConsoleRunner::addCommands($this);
     return $this;
 }
use Symfony\Component\Console\Helper\HelperSet;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use MJanssen\Command\CacheClearCommand;
use MJanssen\Command\DocsCreateCommand;
use MJanssen\Command\LogClearCommand;
chdir(dirname(__DIR__));
$loader = (require_once 'vendor/autoload.php');
set_time_limit(0);
$app = new SilexApplication();
$cli = true;
require_once 'app/bootstrap.php';
$console = new ConsoleApplication('Silex - Rest API Edition', '1.0');
$console->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev'));
$command = new CacheClearCommand();
$command->setCachePath($app['cache.path']);
$console->add($command);
$command = new LogClearCommand();
$command->setLogPath($app['log.path']);
$console->add($command);
$command = new DocsCreateCommand();
$command->setApplicationPath($app['app.path']);
$console->add($command);
/*
 * Doctrine CLI
 */
$helperSet = new HelperSet(array('db' => new ConnectionHelper($app['orm.em']->getConnection()), 'em' => new EntityManagerHelper($app['orm.em'])));
$console->setHelperSet($helperSet);
ConsoleRunner::addCommands($console);
$console->run();
Exemple #12
0
 /**
  * @param OutputInterface $output
  */
 protected function registerCommands(OutputInterface $output)
 {
     //Wrap database related logic in a try-catch
     //so that non-db commands can still execute
     try {
         $em = $this->kernel->getContainer()->get('models');
         // setup doctrine commands
         $helperSet = $this->getHelperSet();
         $helperSet->set(new EntityManagerHelper($em), 'em');
         $helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
         DoctrineConsoleRunner::addCommands($this);
         $this->registerEventCommands();
     } catch (\Exception $e) {
         $formatter = $this->getHelperSet()->get('formatter');
         $output->writeln($formatter->formatBlock('WARNING! ' . $e->getMessage() . " in " . $e->getFile(), 'error'));
     }
     $this->registerFilesystemCommands();
 }
Exemple #13
0
        case 'yml':
        case 'yaml':
            //$driver = new YamlDriver( $mappingPaths );
            //$driver->setFileExtension('.yml');
            $ymlConfig = Setup::createYAMLMetadataConfiguration($mappingPaths, $env == 'dev');
            //$ymlConfig->setMetadataDriverImpl( $driver );
            $entityManager = EntityManager::create($dbParams, $ymlConfig);
            break;
        case 'annotation':
            $annotationConfig = Setup::createAnnotationMetadataConfiguration($mappingPaths, $env == 'dev');
            $entityManager = EntityManager::create($dbParams, $annotationConfig);
            break;
        default:
            throw new \Exception("Config: Unknown mapping type of '{$mappingType}'.");
    }
    if (empty($entityManager)) {
        throw new \Exception("Config: Unable to instantiate an entity manager. Please check the configuration.");
    }
    $helperSet = new HelperSet(array('db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($entityManager->getConnection()), 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($entityManager)));
    $app = new DoctrineConsole();
    $app->setCatchExceptions(false);
    $app->setDispatcher($dispatcher);
    $app->setHelperSet($helperSet);
    ConsoleRunner::addCommands($app);
    $commands = array(new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\LatestCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand());
    $app->addCommands($commands);
    $app->run();
} catch (\Exception $e) {
    $output = new \Symfony\Component\Console\Output\ConsoleOutput();
    $app->renderException($e, $output->getErrorOutput());
}
Exemple #14
0
 /**
  * @return RZ\Roadiz\Core\Kernel $this
  */
 public function runConsole()
 {
     /*
      * Define a request wide timezone
      */
     if (!empty($this->container['config']["timezone"])) {
         date_default_timezone_set($this->container['config']["timezone"]);
     } else {
         date_default_timezone_set("Europe/Paris");
     }
     $application = new Application('Roadiz Console Application', static::$cmsVersion);
     $helperSet = new HelperSet(['configuration' => new ConfigurationHelper($this->container['config']), 'db' => new ConnectionHelper($this->container['em']->getConnection()), 'em' => new EntityManagerHelper($this->container['em']), 'question' => new QuestionHelper(), 'solr' => new SolrHelper($this->container['solr']), 'ns-cache' => new CacheProviderHelper($this->container['nodesSourcesUrlCacheProvider']), 'mailer' => new MailerHelper($this->container['mailer']), 'templating' => new TemplatingHelper($this->container['twig.environment']), 'translator' => new TranslatorHelper($this->container['translator'])]);
     $application->setHelperSet($helperSet);
     $application->add(new \RZ\Roadiz\Console\TranslationsCommand());
     $application->add(new \RZ\Roadiz\Console\NodeTypesCommand());
     $application->add(new \RZ\Roadiz\Console\NodesSourcesCommand());
     $application->add(new \RZ\Roadiz\Console\NodesCommand());
     $application->add(new \RZ\Roadiz\Console\ThemesCommand());
     $application->add(new \RZ\Roadiz\Console\InstallCommand());
     $application->add(new \RZ\Roadiz\Console\UsersCommand());
     $application->add(new \RZ\Roadiz\Console\RequirementsCommand());
     $application->add(new \RZ\Roadiz\Console\SolrCommand());
     $application->add(new \RZ\Roadiz\Console\CacheCommand());
     $application->add(new \RZ\Roadiz\Console\ConfigurationCommand());
     $application->add(new \RZ\Roadiz\Console\ThemeInstallCommand());
     $application->add(new \RZ\Roadiz\Console\DocumentDownscaleCommand());
     /*
      * Register user defined Commands
      * Add them in your config.yml
      */
     if (isset($this->container['config']['additionalCommands'])) {
         foreach ($this->container['config']['additionalCommands'] as $commandClass) {
             if (class_exists($commandClass)) {
                 $application->add(new $commandClass());
             } else {
                 throw new \Exception("Command class does not exists (" . $commandClass . ")", 1);
             }
         }
     }
     // Use default Doctrine commands
     ConsoleRunner::addCommands($application);
     $application->run();
     $this->container['stopwatch']->stop('global');
     return $this;
 }
 protected function registerCommands()
 {
     //Wrap database related logic in a try-catch
     //so that non-db commands can still execute
     try {
         $em = $this->kernel->getContainer()->get('models');
         // setup doctrine commands
         $helperSet = $this->getHelperSet();
         $helperSet->set(new EntityManagerHelper($em), 'em');
         $helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
         DoctrineConsoleRunner::addCommands($this);
         $this->registerEventCommands();
     } catch (\Exception $e) {
     }
     $this->registerFilesystemCommands();
 }
Exemple #16
0
}
if (!array_key_exists($argv[1], $cfg['dsn'])) {
    exit(sprintf("Invalid dsn provided: '%s'\n", $argv[1]));
}
// extract dsn
$dsn = $argv[1];
array_splice($argv, 1, 1);
// Create the EntityManager
$config = \Doctrine\ORM\Tools\Setup::createXMLMetadataConfiguration(array(BUILD_DIR . '/config/' . $dsn), false, BUILD_DIR . '/proxies/' . $dsn);
$em = \Doctrine\ORM\EntityManager::create($cfg['dsn'][$dsn], $config);
// And run the console app
$helperSet = \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($em);
$cli = new \Symfony\Component\Console\Application('Haus23 Doctrine Command Line Interface', '1.0.0');
$cli->setCatchExceptions(true);
$cli->setHelperSet($helperSet);
\Doctrine\ORM\Tools\Console\ConsoleRunner::addCommands($cli);
$cli->run(new Symfony\Component\Console\Input\ArgvInput($argv));
// helper function to load and parse the configuration
function load_config()
{
    // json_last_error_msg? php >= 5.5.0
    if (!function_exists('json_last_error_msg')) {
        function json_last_error_msg()
        {
            static $errors = array(JSON_ERROR_NONE => null, JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch', JSON_ERROR_CTRL_CHAR => 'Unexpected control character found', JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON', JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded');
            $error = json_last_error();
            return array_key_exists($error, $errors) ? $errors[$error] : "Unknown error ({$error})";
        }
    }
    $filename = dirname(__DIR__) . '/config/config.json';
    if (!file_exists($filename)) {
Exemple #17
0
 /**
  * @return RZ\Roadiz\Core\Kernel $this
  */
 public function runConsole()
 {
     /*
      * Define a request wide timezone
      */
     if (!empty($this->container['config']["timezone"])) {
         date_default_timezone_set($this->container['config']["timezone"]);
     } else {
         date_default_timezone_set("Europe/Paris");
     }
     $application = new Application('Roadiz Console Application', static::$cmsVersion);
     $helperSet = new HelperSet(['db' => new ConnectionHelper($this->container['em']->getConnection()), 'em' => new EntityManagerHelper($this->container['em']), 'question' => new QuestionHelper(), 'solr' => new SolrHelper($this->container['solr']), 'ns-cache' => new CacheProviderHelper($this->container['nodesSourcesUrlCacheProvider'])]);
     $application->setHelperSet($helperSet);
     $application->add(new \RZ\Roadiz\Console\TranslationsCommand());
     $application->add(new \RZ\Roadiz\Console\NodeTypesCommand());
     $application->add(new \RZ\Roadiz\Console\NodesSourcesCommand());
     $application->add(new \RZ\Roadiz\Console\NodesCommand());
     $application->add(new \RZ\Roadiz\Console\ThemesCommand());
     $application->add(new \RZ\Roadiz\Console\InstallCommand());
     $application->add(new \RZ\Roadiz\Console\UsersCommand());
     $application->add(new \RZ\Roadiz\Console\RequirementsCommand());
     $application->add(new \RZ\Roadiz\Console\SolrCommand());
     $application->add(new \RZ\Roadiz\Console\CacheCommand());
     $application->add(new \RZ\Roadiz\Console\ConfigurationCommand());
     $application->add(new \RZ\Roadiz\Console\ThemeInstallCommand());
     // Use default Doctrine commands
     ConsoleRunner::addCommands($application);
     $application->run();
     $this->container['stopwatch']->stop('global');
     return $this;
 }
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Helper\QuestionHelper;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Doctrine\DBAL\Migrations\Configuration\Configuration;
use Doctrine\DBAL\Migrations\OutputWriter;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
require_once __DIR__ . "/../app/config/bootstrap.php";
$cli = new Application('Doctrine Command Line Interface', \Doctrine\ORM\Version::VERSION);
$helperSet = new HelperSet(array('db' => new ConnectionHelper($entityManager->getConnection()), 'em' => new EntityManagerHelper($entityManager), 'dialog' => new QuestionHelper()));
$cli->setHelperSet($helperSet);
$outputWriter = new OutputWriter(function ($message) {
    $output = new ConsoleOutput();
    $output->writeln($message);
});
$config = new Configuration($entityManager->getConnection(), $outputWriter);
$config->setMigrationsDirectory(__DIR__ . $configuration['migrations']['directory']);
$config->setName($configuration['migrations']['name']);
$config->setMigrationsNamespace($configuration['migrations']['namespace']);
$config->setMigrationsTableName($configuration['migrations']['table_name']);
$config->registerMigrationsFromDirectory(__DIR__ . $configuration['migrations']['directory']);
$commands = array(new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand());
foreach ($commands as $command) {
    $command->setMigrationConfiguration($config);
    $cli->add($command);
}
ConsoleRunner::addCommands($cli);
$cli->run();
 public function register(Application $app)
 {
     $self = $this;
     $app["orm.proxy_dir"] = NULL;
     $app["orm.cache"] = NULL;
     $app["orm.is_dev_mode"] = $app["debug"];
     $app['orm.driver.configs'] = array();
     $app["orm.chain_driver"] = $app->share(function () {
         return new MappingDriverChain();
     });
     /**
      * EN : create entity manager config
      * FR : creer la configuration de l'entity mananger
      */
     $app["orm.config"] = $app->share(function ($app) {
         $config = Setup::createConfiguration($app["orm.is_dev_mode"], $app["orm.proxy_dir"], $app["orm.cache"]);
         $config->setMetadataDriverImpl($app["orm.chain_driver"]);
         if (isset($app["orm.logger"])) {
             $config->setSQLLogger($app["orm.logger"]);
         }
         $config->addCustomDatetimeFunction("DATE", 'Mparaiso\\Doctrine\\ORM\\Functions\\Date');
         return $config;
     });
     /**
      * EN : create the entity manager
      * FR : créer l'entity manager
      */
     $app["orm.em"] = $app->share(function ($app) use($self) {
         foreach ($app["orm.driver.configs"] as $key => $config) {
             if (!is_array($config['paths'])) {
                 throw new Exception(' $config["paths"] must be an array of paths ');
             }
             if ($key == "default") {
                 $app["orm.chain_driver"]->setDefaultDriver($self->getDriver($config['type'], $config['paths'], $app["orm.config"]));
             }
             $app["orm.chain_driver"]->addDriver($self->getDriver($config['type'], $config['paths'], $app["orm.config"]), $config["namespace"]);
         }
         if (!isset($app["orm.connection"]) && $app["db"]) {
             $app["orm.connection"] = $app["db"];
         }
         $em = EntityManager::create($app["orm.connection"], $app["orm.config"]);
         return $em;
     });
     $app['orm.manager_registry'] = $app->share(function ($app) {
         return new DoctrineManagerRegistry("manager_registry", array("default" => $app['orm.em']->getConnection()), array("default" => $app['orm.em']));
     });
     /* call this to install Doctrine orm's commands $app['orm.console.boot_commands']() */
     $app['orm.console.boot_commands'] = $app->protect(function () use($app) {
         if (isset($app["console"])) {
             $em = $app['orm.em'];
             /* @var $console \Symfony\Component\Console\Application */
             $console = $app["console"];
             $console->getHelperSet()->set(new EntityManagerHelper($em), "em");
             $console->getHelperSet()->set(new ConnectionHelper($em->getConnection()), "db");
             ConsoleRunner::addCommands($app["console"]);
             $console->add(new ImportMappingDoctrineCommand());
             $console->add(new LoadFixturesCommand());
         }
     });
 }