/**
  * 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);
 }
Example #2
0
 /**
  * {@inheritDoc}
  */
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     $this->setHelperSet(ConsoleRunner::createHelperSet($this->app->get('doctrine.orm.entity_manager')));
     $this->getHelperSet()->set(new QuestionHelper());
     $this->getHelperSet()->set(new DialogHelper());
     $this->registerCommands();
     $this->io = new ConsoleIO($input, $output, $this->getHelperSet());
     return parent::doRun($input, $output);
 }
 private function registerEntityManager(Application $app, $serviceName, Connection $connection, Configuration $metadataConfig)
 {
     $app[$serviceName] = $app->share(function () use($app, $connection, $metadataConfig) {
         return EntityManager::create($connection, $metadataConfig);
     });
     // create a console for every manager
     $consoleServiceName = sprintf('%s.console', $serviceName);
     $app[$consoleServiceName] = $app->share(function () use($app, $serviceName) {
         return ConsoleRunner::createApplication(ConsoleRunner::createHelperSet($app[$serviceName]));
     });
 }
Example #4
0
 /**
  * @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);
     }
 }
 protected function _before()
 {
     $credentials = new DbCredentials();
     $container = ContainerService::getInstance()->setDbCredentials($credentials)->addEntityPath('src/Entity')->getContainer();
     $em = $container['doctrine.entity_manager'];
     $helperSet = ConsoleRunner::createHelperSet($em);
     $helperSet->set(new DialogHelper(), 'dialog');
     $this->app = new Application();
     $gen = new GenerateProxy();
     $gen->setHelperSet($helperSet);
     $this->app->add($gen);
     $this->app->add(new VersionCommand());
 }
Example #6
0
 protected function _before()
 {
     $credentials = new DbCredentials();
     $container = ContainerService::getInstance()->setDbCredentials($credentials)->addEntityPath('src/Entity')->getContainer();
     $em = $container['doctrine.entity_manager'];
     $helperSet = ConsoleRunner::createHelperSet($em);
     $helperSet->set(new DialogHelper(), 'dialog');
     $configuration = new Configuration($em->getConnection());
     $configuration->setMigrationsNamespace('Migrations');
     $configuration->setMigrationsTableName('Migration');
     $this->app = new Application();
     $mig = new Migration();
     $mig->setMigrationConfiguration($configuration);
     $this->app->add($mig);
     $this->app->add(new VersionCommand());
 }
 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);
 }
Example #8
0
 public function indexAction()
 {
     if ($this->getRequest() instanceof ConsoleRequest) {
         $params = $this->params()->fromRoute();
         switch ($params['api']) {
             case 'doctrine':
                 global $argv;
                 array_shift($argv);
                 // index.php
                 array_shift($argv);
                 // external
                 $_SERVER['argv'] = $argv;
                 $helperSet = ConsoleRunner::createHelperSet($this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'));
                 ConsoleRunner::run($helperSet, array());
                 break;
             default:
                 return 'Could not find an option for external tool: ' . $params['api'];
         }
         return '';
     }
     return new ViewModel();
 }
Example #9
0
 public function actionIndex()
 {
     unset($_SERVER['argv'][1]);
     $option = '--' . \yii\console\Application::OPTION_APPCONFIG . '=';
     foreach ($_SERVER['argv'] as $key => $param) {
         if (strpos($param, $option) === 0) {
             $keyToUnset = $key;
             break;
         }
     }
     if (isset($keyToUnset)) {
         unset($_SERVER['argv'][$keyToUnset]);
         unset($keyToUnset);
     }
     // Currently, symfony application uses a deprecated class (DialogHelper).
     // Don't throw an exception.
     $currentLevel = error_reporting();
     error_reporting($currentLevel ^ E_USER_DEPRECATED);
     $doctrine = $this->getDoctrineComponent();
     $entityManager = $doctrine->getEntityManager();
     $helperSet = ConsoleRunner::createHelperSet($entityManager);
     $result = ConsoleRunner::run($helperSet);
     return $result;
 }
<?php

require dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
use Doctrine\ORM\Tools\Console\ConsoleRunner;
//create database if not exists
$mysqlConfig = NwApi\Libraries\Config::getInstance('mysql');
$mysqli = new mysqli($mysqlConfig->host, $mysqlConfig->user, $mysqlConfig->password, '', $mysqlConfig->port);
if (!$mysqli->query('CREATE DATABASE IF NOT EXISTS ' . $mysqli->real_escape_string($mysqlConfig->database))) {
    throw new Exception('Unable to create database');
}
return ConsoleRunner::createHelperSet(NwApi\Di::getInstance()->em);
Example #11
0
<?php

require_once __DIR__ . '/../bootstrap.php';
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Nucleus\Config;
use Nucleus\EntityManager;
return ConsoleRunner::createHelperSet((new EntityManager(new Config()))->getEntityManager());
Example #12
0
<?php

require_once "bootstrap.php";
return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($container->get('entityManager'));
<?php

require_once "bootstrap.php";
$sm = \Updashd\ServiceManager::getInstance();
return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($sm->get('\\Updashd\\Service\\Doctrine\\EntityManagerService')->getEntityManager());
Example #14
0
<?php

$entityManager = (require __DIR__ . '/../bootstrap.php');
return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($entityManager);
Example #15
0
<?php

require_once __DIR__ . '/vendor/autoload.php';
$app = new Domora\TvGuide\Application();
\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists');
return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($app['orm.em']);
 /**
  * @Route('/console/createhelpers')
  * @Method('GET')
  * @Name('console.createhelpers')
  */
 public function CreateHelpers()
 {
     ConsoleRunner::createHelperSet($this->getApp()->getEntityManager());
 }
Example #17
0
//$diff->setMigrationConfiguration($configuration);
//$exec->setMigrationConfiguration($configuration);
//$gen->setMigrationConfiguration($configuration);
//$migrate->setMigrationConfiguration($configuration);
//$status->setMigrationConfiguration($configuration);
//$ver->setMigrationConfiguration($configuration);
//
//$cli = ConsoleRunner::createApplication($helperSet,[
//    $diff, $exec, $gen, $migrate, $status, $ver
//]);
//
//return $cli->run();
use Del\Common\Command\Migration;
use Doctrine\DBAL\Migrations\Configuration\Configuration;
use Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand;
use Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand;
use Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand;
use Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand;
use Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand;
use Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Del\Common\ContainerService;
use Del\Common\Config\DbCredentials;
$credentials = new DbCredentials();
$container = ContainerService::getInstance()->setDbCredentials($credentials)->addEntityPath('src/Entity')->getContainer();
/** @var Doctrine\ORM\EntityManager $em*/
$em = $container['doctrine.entity_manager'];
$helperSet = ConsoleRunner::createHelperSet($em);
$helperSet->set(new \Symfony\Component\Console\Helper\DialogHelper(), 'dialog');
$cli = ConsoleRunner::createApplication($helperSet, []);
return $cli->run();
Example #18
0
<?php

/*
 * Copyright 2015 Jack Sleight <http://jacksleight.com/>
 * This source file is subject to the MIT license that is bundled with this package in the file LICENCE.md. 
 */
use Doctrine\ORM\Tools\Console\ConsoleRunner;
require_once 'app.php';
return ConsoleRunner::createHelperSet($app->entity->em);
 /**
  * Create Doctrine's console application
  *
  * @return void
  */
 public function buildConsole($key = null)
 {
     $em = $this->proxyEntityManager->on($key);
     $helperSet = ConsoleRunner::createHelperSet($em);
     return $this->console = ConsoleRunner::createApplication($helperSet);
 }
<?php

require_once __DIR__ . "/../../vendor/autoload.php";
\asm\core\Config::init(__DIR__ . "/../config.ini", __DIR__ . "/../internal.ini");
return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet(\asm\core\Repositories::getEntityManager());
Example #21
0
<?php

use Doctrine\ORM\Tools\Console\ConsoleRunner;
define('EXECUTION_DISABLED', true);
require_once __DIR__ . '/../app.php';
$entityManager = $framework->getInstance('\\Zepi\\DataSourceDriver\\Doctrine\\Manager\\EntityManager');
return ConsoleRunner::createHelperSet($entityManager->getDoctrineEntityManager());
<?php

/**
 * Interface for Doctrine command line, accessed using "vendor/bin/doctrine"
 *
 * @author Timur Kuzhagaliyev <*****@*****.**>
 * @copyright 2016
 * @license http://opensource.org/licenses/mit-license.php MIT License
 * @version 0.0.1
 */
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Apollo\Components\DB;
require_once 'vendor/autoload.php';
return ConsoleRunner::createHelperSet(DB::getEntityManager());
Example #23
0
<?php

namespace Project;

use Doctrine\ORM\Tools\Console\ConsoleRunner;
chdir(__DIR__);
$autoloader = (require 'vendor/autoload.php');
$app = new Application($autoloader);
$app->loadConfig('app/config');
ob_start();
$app->run();
ob_get_clean();
$em = $app->getServicesFactory()->get('doctrine.em.default');
return ConsoleRunner::createHelperSet($em);
<?php

return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet(require __DIR__ . '/bootstrap-entitymanager.php');
Example #25
0
<?php

use Doctrine\ORM\Tools\Console\ConsoleRunner;
// replace with file to your own project bootstrap
$app = (include "core/app.php");
return ConsoleRunner::createHelperSet($app['em']);
Example #26
0
<?php

/**
 * Sky Framework
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @package		Sky Framework
 * @author		Hansen Wong
 * @copyright	Copyright (c) 2015, Rockbeat.
 * @license		http://www.opensource.org/licenses/mit-license.php MIT License
 * @link		http://rockbeat.web.id
 * @since		Version 1.0
 */
/**
This is CLI CONFIG for Doctrine 
**/
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Sky\doctrine\ORM;
require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
$orm = new ORM();
return ConsoleRunner::createHelperSet($orm->entity);
Example #27
0
<?php

require_once __DIR__ . '/vendor/autoload.php';
return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet((new Lw\Infrastructure\Ui\Web\Silex\Application())->bootstrap()['em']);
Example #28
0
 /**
  * Starts a migration
  *
  * @param array $courseList
  * @param string $path
  * @param string $toVersion
  * @param bool $dryRun
  * @param OutputInterface $output
  * @param bool $removeUnusedTables
  * @param InputInterface $mainInput
  *
  * @return bool
  * @throws \Exception
  */
 public function startMigration($courseList, $path, $toVersion, $dryRun, OutputInterface $output, $removeUnusedTables = false, InputInterface $mainInput, $runFixIds = true, $onlyUpdateDatabase = false)
 {
     // Cleaning query list.
     $this->queryList = array();
     // Main DB connection.
     $conn = $this->getConnection($mainInput);
     $_configuration = $this->getHelper('configuration')->getConfiguration($path);
     $versionInfo = $this->getAvailableVersionInfo($toVersion);
     $installPath = $this->getInstallationFolder() . $toVersion . '/';
     // Filling sqlList array with "pre" db changes.
     if (isset($versionInfo['pre']) && !empty($versionInfo['pre'])) {
         $sqlToInstall = $installPath . $versionInfo['pre'];
         $this->fillQueryList($sqlToInstall, $output, 'pre');
         // Processing sql query list depending of the section (course, main, user).
         $this->processQueryList($courseList, $output, $path, $toVersion, $dryRun, 'pre');
     }
     try {
         if (isset($versionInfo['hook_to_doctrine_version'])) {
             // Doctrine migrations:
             $em = $this->setDoctrineSettings($this->getHelperSet());
             $output->writeln('');
             $output->writeln("<comment>You have to select 'yes' for the 'Chamilo Migrations'<comment>");
             // Setting migrations temporal ymls
             $tempFolder = '/tmp';
             require_once $_configuration['root_sys'] . 'app/Migrations/AbstractMigrationChamilo.php';
             $migrationsFolder = $tempFolder . '/Migrations/';
             $fs = new Filesystem();
             if (!$fs->exists($migrationsFolder)) {
                 $fs->mkdir($migrationsFolder);
             }
             $migrations = array('name' => 'Chamilo Migrations', 'migrations_namespace' => $versionInfo['migrations_namespace'], 'table_name' => 'version', 'migrations_directory' => $versionInfo['migrations_directory']);
             $dumper = new Dumper();
             $yaml = $dumper->dump($migrations, 1);
             $file = $migrationsFolder . $versionInfo['migrations_yml'];
             if (file_exists($file)) {
                 unlink($file);
             }
             file_put_contents($file, $yaml);
             //$command = $this->getApplication()->find('migrations:migrate');
             $command = new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand();
             // Creates the helper set
             $helperSet = \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($em);
             $dialog = $this->getHelperSet()->get('dialog');
             $helperSet->set($dialog, 'dialog');
             $command->setHelperSet($helperSet);
             $arguments = array('--configuration' => $file, '--dry-run' => $dryRun, 'version' => $versionInfo['hook_to_doctrine_version']);
             $output->writeln("<comment>Executing migrations:migrate " . $versionInfo['hook_to_doctrine_version'] . " --configuration=" . $file . "<comment>");
             $input = new ArrayInput($arguments);
             $command->run($input, $output);
             $output->writeln("<comment>Migration ended successfully</comment>");
         }
         // Processing "db" changes.
         if (isset($versionInfo['update_db']) && !empty($versionInfo['update_db'])) {
             $sqlToInstall = $installPath . $versionInfo['update_db'];
             if (is_file($sqlToInstall) && file_exists($sqlToInstall)) {
                 if ($dryRun) {
                     $output->writeln("<comment>File to be executed but not fired because of dry-run option: <info>'{$sqlToInstall}'</info>");
                 } else {
                     $output->writeln("<comment>Executing update db: <info>'{$sqlToInstall}'</info>");
                 }
                 require $sqlToInstall;
                 if (!empty($update)) {
                     $update($_configuration, $conn, $courseList, $dryRun, $output, $this, $removeUnusedTables);
                 }
             } else {
                 $output->writeln(sprintf("File doesn't exist: '<info>%s</info>'", $sqlToInstall));
             }
         }
         // Processing "update file" changes.
         if (isset($versionInfo['update_files']) && !empty($versionInfo['update_files']) && $onlyUpdateDatabase == false) {
             $sqlToInstall = $installPath . $versionInfo['update_files'];
             if (is_file($sqlToInstall) && file_exists($sqlToInstall)) {
                 if ($dryRun) {
                     $output->writeln("<comment>Files to be executed but dry-run is on: <info>'{$sqlToInstall}'</info>");
                 } else {
                     $output->writeln("<comment>Executing update files: <info>'{$sqlToInstall}'</info>");
                     require $sqlToInstall;
                     if (!empty($updateFiles)) {
                         $updateFiles($_configuration, $conn, $courseList, $dryRun, $output, $this);
                     }
                 }
             } else {
                 $output->writeln(sprintf("File doesn't exist: '<info>%s</info>'", $sqlToInstall));
             }
         }
         // Filling sqlList array with "post" db changes.
         if (isset($versionInfo['post']) && !empty($versionInfo['post'])) {
             $sqlToInstall = $installPath . $versionInfo['post'];
             $this->fillQueryList($sqlToInstall, $output, 'post');
             // Processing sql query list depending of the section.
             $this->processQueryList($courseList, $output, $path, $toVersion, $dryRun, 'post');
         }
         if ($runFixIds) {
             require_once $this->getRootSys() . '/main/inc/lib/database.constants.inc.php';
             require_once $this->getRootSys() . '/main/inc/lib/system/session.class.php';
             require_once $this->getRootSys() . '/main/inc/lib/chamilo_session.class.php';
             require_once $this->getRootSys() . '/main/inc/lib/api.lib.php';
             require_once $this->getRootSys() . '/main/inc/lib/database.lib.php';
             require_once $this->getRootSys() . '/main/inc/lib/custom_pages.class.php';
             require_once $this->getRootSys() . '/main/install/install.lib.php';
             require_once $this->getRootSys() . '/main/inc/lib/display.lib.php';
             require_once $this->getRootSys() . '/main/inc/lib/group_portal_manager.lib.php';
             require_once $this->getRootSys() . '/main/inc/lib/model.lib.php';
             require_once $this->getRootSys() . '/main/inc/lib/events.lib.php';
             require_once $this->getRootSys() . '/main/inc/lib/extra_field.lib.php';
             require_once $this->getRootSys() . '/main/inc/lib/extra_field_value.lib.php';
             require_once $this->getRootSys() . '/main/inc/lib/urlmanager.lib.php';
             require_once $this->getRootSys() . '/main/inc/lib/usermanager.lib.php';
             require_once $this->getRootSys() . '/src/Chamilo/CoreBundle/Entity/ExtraField.php';
             require_once $this->getRootSys() . '/src/Chamilo/CoreBundle/Entity/ExtraFieldOptions.php';
             fixIds($em);
         }
     } catch (\Exception $e) {
         $output->write(sprintf('<error>Migration failed. Error %s</error>', $e->getMessage()));
         throw $e;
     }
     return false;
 }
<?php

// replace with file to your own project bootstrap
require_once "vendor/autoload.php";
use Doctrine\ORM\Tools\Console\ConsoleRunner;
$dbParams = array('driver' => 'pdo_mysql', 'user' => 'blockchain', 'password' => 'blockchain', 'dbname' => 'blockchain', 'host' => 'multichain-mysql.docker');
$isDevMode = true;
$paths = array("./yml");
$config = \Doctrine\ORM\Tools\Setup::createYAMLMetadataConfiguration($paths, $isDevMode);
$entityManager = \Doctrine\ORM\EntityManager::create($dbParams, $config);
return ConsoleRunner::createHelperSet($entityManager);
Example #30
0
 /**
  * @param string $name
  * @return HelperSet
  */
 public function getHelperSet($name = null)
 {
     if (null === $name) {
         $name = $this->getDefautName();
     }
     if (null === $this->helperSet) {
         $this->helperSet = ConsoleRunner::createHelperSet($this->getEntityManager($name));
     }
     return $this->helperSet;
 }