protected function _getMigrationConfiguration(InputInterface $input, OutputInterface $output) { if (!$this->_configuration) { $outputWriter = new OutputWriter(function ($message) use($output) { return $output->writeln($message); }); $em = $this->getHelper('em')->getEntityManager(); if ($input->getOption('configuration')) { $info = pathinfo($input->getOption('configuration')); $class = $info['extension'] === 'xml' ? 'Doctrine\\DBAL\\Migrations\\Configuration\\XmlConfiguration' : 'Doctrine\\DBAL\\Migrations\\Configuration\\YamlConfiguration'; $configuration = new $class($em->getConnection(), $outputWriter); $configuration->load($input->getOption('configuration')); } else { if (file_exists('migrations.xml')) { $configuration = new XmlConfiguration($em->getConnection(), $outputWriter); $configuration->load('migrations.xml'); } else { if (file_exists('migrations.yml')) { $configuration = new YamlConfiguration($em->getConnection(), $outputWriter); $configuration->load('migrations.yml'); } else { $configuration = new Configuration($em->getConnection(), $outputWriter); } } } $this->_configuration = $configuration; } return $this->_configuration; }
protected function execute(InputInterface $input, OutputInterface $output) { $filterBundle = $input->getOption('bundle') ? str_replace('/', '\\', $input->getOption('bundle')) : false; $filterEntity = $filterBundle ? $filterBundle . '\\Entities\\' . str_replace('/', '\\', $input->getOption('entity')) : false; if (!isset($filterBundle) && isset($filterEntity)) { throw new \InvalidArgumentException(sprintf('Unable to specify an entity without also specifying a bundle.')); } $entityGenerator = $this->getEntityGenerator(); $bundleDirs = $this->container->getKernelService()->getBundleDirs(); foreach ($this->container->getKernelService()->getBundles() as $bundle) { $tmp = dirname(str_replace('\\', '/', get_class($bundle))); $namespace = str_replace('/', '\\', dirname($tmp)); $class = basename($tmp); if ($filterBundle && $filterBundle != $namespace . '\\' . $class) { continue; } if (isset($bundleDirs[$namespace])) { $destination = realpath($bundleDirs[$namespace] . '/..'); if ($metadatas = $this->getBundleMetadatas($bundle)) { $output->writeln(sprintf('Generating entities for "<info>%s</info>"', $class)); foreach ($metadatas as $metadata) { if ($filterEntity && strpos($metadata->name, $filterEntity) !== 0) { continue; } $output->writeln(sprintf(' > generating <comment>%s</comment>', $metadata->name)); $entityGenerator->generate(array($metadata), $destination); } } } } }
/** * @see Command */ protected function execute(InputInterface $input, OutputInterface $output) { if ($input->getOption('re-create')) { $input->setOption('drop', true); $input->setOption('create', true); } if (!$input->getOption('drop') && !$input->getOption('create')) { throw new \InvalidArgumentException('You must specify one of the --drop and --create options or both.'); } $found = false; $connections = $this->getDoctrineConnections(); foreach ($connections as $name => $connection) { if ($input->getOption('connection') && $name != $input->getOption('connection')) { continue; } if ($input->getOption('drop')) { $this->dropDatabaseForConnection($connection, $output); } if ($input->getOption('create')) { $this->createDatabaseForConnection($connection, $output); } $found = true; } if ($found === false) { if ($input->getOption('connection')) { throw new \InvalidArgumentException(sprintf('<error>Could not find a connection named <comment>%s</comment></error>', $input->getOption('connection'))); } else { throw new \InvalidArgumentException(sprintf('<error>Could not find any configured connections</error>', $input->getOption('connection'))); } } }
/** * @see Console\Command\Command */ protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) { $em = $this->getHelper('em')->getEntityManager(); if (($dql = $input->getArgument('dql')) === null) { throw new \RuntimeException("Argument 'DQL' is required in order to execute this command correctly."); } $depth = $input->getOption('depth'); if (!is_numeric($depth)) { throw new \LogicException("Option 'depth' must contains an integer value"); } $hydrationModeName = $input->getOption('hydrate'); $hydrationMode = 'Doctrine\\ORM\\Query::HYDRATE_' . strtoupper(str_replace('-', '_', $hydrationModeName)); if (!defined($hydrationMode)) { throw new \RuntimeException("Hydration mode '{$hydrationModeName}' does not exist. It should be either: object. array, scalar or single-scalar."); } $query = $em->createQuery($dql); if (($firstResult = $input->getOption('first-result')) !== null) { if (!is_numeric($firstResult)) { throw new \LogicException("Option 'first-result' must contains an integer value"); } $query->setFirstResult((int) $firstResult); } if (($maxResult = $input->getOption('max-result')) !== null) { if (!is_numeric($maxResult)) { throw new \LogicException("Option 'max-result' must contains an integer value"); } $query->setMaxResult((int) $maxResult); } $resultSet = $query->execute(array(), constant($hydrationMode)); \Doctrine\Common\Util\Debug::dump($resultSet, $input->getOption('depth')); }
/** * @see Console\Command\Command */ protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) { $em = $this->getHelper('em')->getEntityManager(); $cacheDriver = $em->getConfiguration()->getResultCacheImpl(); if (!$cacheDriver) { throw new \InvalidArgumentException('No Result cache driver is configured on given EntityManager.'); } $outputed = false; // Removing based on --id if (($ids = $input->getOption('id')) !== null && $ids) { foreach ($ids as $id) { $output->write($outputed ? PHP_EOL : ''); $output->write(sprintf('Clearing Result cache entries that match the id "<info>%s</info>"', $id) . PHP_EOL); $deleted = $cacheDriver->delete($id); if (is_array($deleted)) { $this->_printDeleted($output, $deleted); } else { if (is_bool($deleted) && $deleted) { $this->_printDeleted($output, array($id)); } } $outputed = true; } } // Removing based on --regex if (($regexps = $input->getOption('regex')) !== null && $regexps) { foreach ($regexps as $regex) { $output->write($outputed ? PHP_EOL : ''); $output->write(sprintf('Clearing Result cache entries that match the regular expression "<info>%s</info>"', $regex) . PHP_EOL); $this->_printDeleted($output, $cacheDriver->deleteByRegex('/' . $regex . '/')); $outputed = true; } } // Removing based on --prefix if (($prefixes = $input->getOption('prefix')) !== null & $prefixes) { foreach ($prefixes as $prefix) { $output->write($outputed ? PHP_EOL : ''); $output->write(sprintf('Clearing Result cache entries that have the prefix "<info>%s</info>"', $prefix) . PHP_EOL); $this->_printDeleted($output, $cacheDriver->deleteByPrefix($prefix)); $outputed = true; } } // Removing based on --suffix if (($suffixes = $input->getOption('suffix')) !== null && $suffixes) { foreach ($suffixes as $suffix) { $output->write($outputed ? PHP_EOL : ''); $output->write(sprintf('Clearing Result cache entries that have the suffix "<info>%s</info>"', $suffix) . PHP_EOL); $this->_printDeleted($output, $cacheDriver->deleteBySuffix($suffix)); $outputed = true; } } // Removing ALL entries if (!$ids && !$regexps && !$prefixes && !$suffixes) { $output->write($outputed ? PHP_EOL : ''); $output->write('Clearing ALL Result cache entries' . PHP_EOL); $this->_printDeleted($output, $cacheDriver->deleteAll()); $outputed = true; } }
protected function execute(Input\InputInterface $input, Output\OutputInterface $output) { try { $output->writeln('<info>' . $this->runIndexUpdates($input->getOption('mode'), $input->getOption('class')) . '</info>'); } catch (\Exception $e) { $output->writeln('<error>' . $e->getMessage() . '</error>'); } }
protected function execute(InputInterface $input, OutputInterface $output) { $bundleClass = null; $bundleDirs = $this->container->getKernelService()->getBundleDirs(); foreach ($this->container->getKernelService()->getBundles() as $bundle) { if (strpos(get_class($bundle), $input->getArgument('bundle')) !== false) { $tmp = dirname(str_replace('\\', '/', get_class($bundle))); $namespace = str_replace('/', '\\', dirname($tmp)); $class = basename($tmp); if (isset($bundleDirs[$namespace])) { $destPath = realpath($bundleDirs[$namespace]) . '/' . $class; $bundleClass = $class; break; } } } $type = $input->getArgument('mapping-type') ? $input->getArgument('mapping-type') : 'xml'; if ($type === 'annotation') { $destPath .= '/Entities'; } else { $destPath .= '/Resources/config/doctrine/metadata'; } $cme = new ClassMetadataExporter(); $exporter = $cme->getExporter($type); if ($type === 'annotation') { $entityGenerator = $this->getEntityGenerator(); $exporter->setEntityGenerator($entityGenerator); } $emName = $input->getOption('em') ? $input->getOption('em') : 'default'; $emServiceName = sprintf('doctrine.orm.%s_entity_manager', $emName); $em = $this->container->getService($emServiceName); $databaseDriver = new DatabaseDriver($em->getConnection()->getSchemaManager()); $em->getConfiguration()->setMetadataDriverImpl($databaseDriver); $cmf = new DisconnectedClassMetadataFactory($em); $metadata = $cmf->getAllMetadata(); if ($metadata) { $output->writeln(sprintf('Importing mapping information from "<info>%s</info>" entity manager', $emName)); $filesystem = new Filesystem(); foreach ($metadata as $class) { $className = $class->name; $class->name = $namespace . '\\' . $bundleClass . '\\Entities\\' . $className; if ($type === 'annotation') { $path = $destPath . '/' . $className . '.php'; } else { $path = $destPath . '/' . str_replace('\\', '.', $class->name) . '.dcm.xml'; } $output->writeln(sprintf(' > writing <comment>%s</comment>', $path)); $code = $exporter->exportClassMetadata($class); if (!is_dir($dir = dirname($path))) { $filesystem->mkdirs($dir); } file_put_contents($path, $code); } } else { $output->writeln('Database does not have any mapping information.' . PHP_EOL, 'ERROR'); } }
/** * @throws \InvalidArgumentException When the bundle doesn't end with Bundle (Example: "Bundle\MySampleBundle") */ protected function execute(InputInterface $input, OutputInterface $output) { if (!preg_match('/Bundle$/', $bundle = $input->getArgument('bundle'))) { throw new \InvalidArgumentException('The bundle name must end with Bundle. Example: "Bundle\\MySampleBundle".'); } $dirs = $this->container->getKernelService()->getBundleDirs(); $tmp = str_replace('\\', '/', $bundle); $namespace = str_replace('/', '\\', dirname($tmp)); $bundle = basename($tmp); if (!isset($dirs[$namespace])) { throw new \InvalidArgumentException(sprintf('Unable to initialize the bundle entity (%s not defined).', $namespace)); } $entity = $input->getArgument('entity'); $entityNamespace = $namespace . '\\' . $bundle . '\\Entities'; $fullEntityClassName = $entityNamespace . '\\' . $entity; $tmp = str_replace('\\', '/', $fullEntityClassName); $tmp = str_replace('/', '\\', dirname($tmp)); $className = basename($tmp); $mappingType = $input->getOption('mapping-type'); $mappingType = $mappingType ? $mappingType : 'xml'; $class = new ClassMetadataInfo($fullEntityClassName); $class->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true)); $class->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); // Map the specified fields $fields = $input->getOption('fields'); if ($fields) { $e = explode(' ', $fields); foreach ($e as $value) { $e = explode(':', $value); $name = $e[0]; $type = isset($e[1]) ? $e[1] : 'string'; preg_match_all('/(.*)\\((.*)\\)/', $type, $matches); $type = isset($matches[1][0]) ? $matches[1][0] : 'string'; $length = isset($matches[2][0]) ? $matches[2][0] : null; $class->mapField(array('fieldName' => $name, 'type' => $type, 'length' => $length)); } } // Setup a new exporter for the mapping type specified $cme = new ClassMetadataExporter(); $exporter = $cme->getExporter($mappingType); if ($mappingType === 'annotation') { $path = $dirs[$namespace] . '/' . $bundle . '/Entities/' . str_replace($entityNamespace . '\\', null, $fullEntityClassName) . '.php'; $exporter->setEntityGenerator($this->getEntityGenerator()); } else { $mappingType = $mappingType == 'yaml' ? 'yml' : $mappingType; $path = $dirs[$namespace] . '/' . $bundle . '/Resources/config/doctrine/metadata/' . str_replace('\\', '.', $fullEntityClassName) . '.dcm.' . $mappingType; } $code = $exporter->exportClassMetadata($class); if (!is_dir($dir = dirname($path))) { mkdir($dir, 0777, true); } $output->writeln(sprintf('Generating entity for "<info>%s</info>"', $bundle)); $output->writeln(sprintf(' > generating <comment>%s</comment>', $fullEntityClassName)); file_put_contents($path, $code); }
/** * @param InputInterface $input * @param OutputInterface $output * @return Configuration */ protected function _getMigrationConfiguration(InputInterface $input, OutputInterface $output) { if (!$this->_configuration) { $outputWriter = new OutputWriter(function ($message) use($output) { return $output->writeln($message); }); if ($this->application->getHelperSet()->has('db')) { $conn = $this->getHelper('db')->getConnection(); } else { if ($input->getOption('db-configuration')) { if (!file_exists($input->getOption('db-configuration'))) { throw new \InvalidArgumentException("The specified connection file is a valid file."); } $params = (include $input->getOption('db-configuration')); if (!is_array($params)) { throw new \InvalidArgumentException('The connection file has to return an array with database configuration parameters.'); } $conn = \Doctrine\DBAL\DriverManager::getConnection($params); } else { if (file_exists('migrations-db.php')) { $params = (include "migrations-db.php"); if (!is_array($params)) { throw new \InvalidArgumentException('The connection file has to return an array with database configuration parameters.'); } $conn = \Doctrine\DBAL\DriverManager::getConnection($params); } else { throw new \InvalidArgumentException('You have to specify a --db-configuration file or pass a Database Connection as a dependency to the Migrations.'); } } } if ($input->getOption('configuration')) { $info = pathinfo($input->getOption('configuration')); $class = $info['extension'] === 'xml' ? 'Doctrine\\DBAL\\Migrations\\Configuration\\XmlConfiguration' : 'Doctrine\\DBAL\\Migrations\\Configuration\\YamlConfiguration'; $configuration = new $class($conn, $outputWriter); $configuration->load($input->getOption('configuration')); } else { if (file_exists('migrations.xml')) { $configuration = new XmlConfiguration($conn, $outputWriter); $configuration->load('migrations.xml'); } else { if (file_exists('migrations.yml')) { $configuration = new YamlConfiguration($conn, $outputWriter); $configuration->load('migrations.yml'); } else { $configuration = new Configuration($conn, $outputWriter); } } } $this->_configuration = $configuration; } return $this->_configuration; }
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas) { // Defining if update is complete or not (--complete not defined means $saveMode = true) $saveMode = $input->getOption('complete') === true; if ($input->getOption('dump-sql') === true) { $sqls = $schemaTool->getUpdateSchemaSql($metadatas, $saveMode); $output->write(implode(';' . PHP_EOL, $sqls) . PHP_EOL); } else { $output->write('Updating database schema...' . PHP_EOL); $schemaTool->updateSchema($metadatas, $saveMode); $output->write('Database schema updated successfully!' . PHP_EOL); } }
/** * @see Console\Command\Command */ protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) { $em = $this->getHelper('em')->getEntityManager(); // Process source directories $fromPaths = array_merge(array($input->getArgument('from-path')), $input->getOption('from')); foreach ($fromPaths as &$dirName) { $dirName = realpath($dirName); if (!file_exists($dirName)) { throw new \InvalidArgumentException(sprintf("Doctrine 1.X schema directory '<info>%s</info>' does not exist.", $dirName)); } else { if (!is_readable($dirName)) { throw new \InvalidArgumentException(sprintf("Doctrine 1.X schema directory '<info>%s</info>' does not have read permissions.", $dirName)); } } } // Process destination directory $destPath = realpath($input->getArgument('dest-path')); if (!file_exists($destPath)) { throw new \InvalidArgumentException(sprintf("Doctrine 2.X mapping destination directory '<info>%s</info>' does not exist.", $destPath)); } else { if (!is_writable($destPath)) { throw new \InvalidArgumentException(sprintf("Doctrine 2.X mapping destination directory '<info>%s</info>' does not have write permissions.", $destPath)); } } $toType = $input->getArgument('to-type'); $cme = new ClassMetadataExporter(); $exporter = $cme->getExporter($toType, $destPath); if (strtolower($toType) === 'annotation') { $entityGenerator = new EntityGenerator(); $exporter->setEntityGenerator($entityGenerator); $entityGenerator->setNumSpaces($input->getOption('num-spaces')); if (($extend = $input->getOption('extend')) !== null) { $entityGenerator->setClassToExtend($extend); } } $converter = new ConvertDoctrine1Schema($fromPaths); $metadata = $converter->getMetadata(); if ($metadata) { $output->write(PHP_EOL); foreach ($metadata as $class) { $output->write(sprintf('Processing entity "<info>%s</info>"', $class->name) . PHP_EOL); } $exporter->setMetadata($metadata); $exporter->export(); $output->write(PHP_EOL . sprintf('Converting Doctrine 1.X schema to "<info>%s</info>" mapping type in "<info>%s</info>"', $toType, $destPath)); } else { $output->write('No Metadata Classes to process.' . PHP_EOL); } }
/** * @see Console\Command\Command */ protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) { $em = $this->getHelper('em')->getEntityManager(); $metadatas = $em->getMetadataFactory()->getAllMetadata(); $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter')); // Process destination directory if (($destPath = $input->getArgument('dest-path')) === null) { $destPath = $em->getConfiguration()->getProxyDir(); } if (!is_dir($destPath)) { mkdir($destPath, 0777, true); } $destPath = realpath($destPath); if (!file_exists($destPath)) { throw new \InvalidArgumentException(sprintf("Proxies destination directory '<info>%s</info>' does not exist.", $destPath)); } else { if (!is_writable($destPath)) { throw new \InvalidArgumentException(sprintf("Proxies destination directory '<info>%s</info>' does not have write permissions.", $destPath)); } } if (count($metadatas)) { foreach ($metadatas as $metadata) { $output->write(sprintf('Processing entity "<info>%s</info>"', $metadata->name) . PHP_EOL); } // Generating Proxies $em->getProxyFactory()->generateProxyClasses($metadatas, $destPath); // Outputting information message $output->write(PHP_EOL . sprintf('Proxy classes generated to "<info>%s</INFO>"', $destPath) . PHP_EOL); } else { $output->write('No Metadata Classes to process.' . PHP_EOL); } }
public function execute(InputInterface $input, OutputInterface $output) { DoctrineCommand::setApplicationEntityManager($this->application, $input->getOption('em')); $configuration = $this->_getMigrationConfiguration($input, $output); DoctrineCommand::configureMigrationsForBundle($this->application, $input->getOption('bundle'), $configuration); parent::execute($input, $output); }
/** * @see Console\Command\Command */ protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) { $em = $this->getHelper('em')->getEntityManager(); $metadatas = $em->getMetadataFactory()->getAllMetadata(); $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter')); // Process destination directory $destPath = realpath($input->getArgument('dest-path')); if (!file_exists($destPath)) { throw new \InvalidArgumentException(sprintf("Entities destination directory '<info>%s</info>' does not exist.", $destPath)); } else { if (!is_writable($destPath)) { throw new \InvalidArgumentException(sprintf("Entities destination directory '<info>%s</info>' does not have write permissions.", $destPath)); } } if (count($metadatas)) { $numRepositories = 0; $generator = new EntityRepositoryGenerator(); foreach ($metadatas as $metadata) { if ($metadata->customRepositoryClassName) { $output->write(sprintf('Processing repository "<info>%s</info>"', $metadata->customRepositoryClassName) . PHP_EOL); $generator->writeEntityRepositoryClass($metadata->customRepositoryClassName, $destPath); $numRepositories++; } } if ($numRepositories) { // Outputting information message $output->write(PHP_EOL . sprintf('Repository classes generated to "<info>%s</INFO>"', $destPath) . PHP_EOL); } else { $output->write('No Repository classes were found to be processed.' . PHP_EOL); } } else { $output->write('No Metadata Classes to process.' . PHP_EOL); } }
/** * @see Command */ protected function execute(InputInterface $input, OutputInterface $output) { $selector = $input->getArgument('selector'); $hard = $input->getOption('hard'); $this->application->getController()->stop($selector, $hard, function ($message) { echo \Console_Color::convert(" %g>>%n ") . $message . "\n"; }); }
/** * @see Command */ protected function initialize(InputInterface $input, OutputInterface $output) { $this->container = $this->application->getKernel()->getContainer(); $this->server = $this->container->getServerService(); if (!$input->getOption('verbose')) { $this->server->setConsole(new Console($output)); } }
/** * @see Command */ protected function execute(InputInterface $input, OutputInterface $output) { if ($input->getOption('xml')) { $output->writeln($this->application->asXml($input->getArgument('namespace')), Output::OUTPUT_RAW); } else { $output->writeln($this->application->asText($input->getArgument('namespace'))); } }
/** * @see Console\Command\Command */ protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) { $em = $this->getHelper('em')->getEntityManager(); if ($input->getOption('from-database') === true) { $em->getConfiguration()->setMetadataDriverImpl(new \Doctrine\ORM\Mapping\Driver\DatabaseDriver($em->getConnection()->getSchemaManager())); } $cmf = new DisconnectedClassMetadataFactory($em); $metadata = $cmf->getAllMetadata(); $metadata = MetadataFilter::filter($metadata, $input->getOption('filter')); // Process destination directory if (!is_dir($destPath = $input->getArgument('dest-path'))) { mkdir($destPath, 0777, true); } $destPath = realpath($destPath); if (!file_exists($destPath)) { throw new \InvalidArgumentException(sprintf("Mapping destination directory '<info>%s</info>' does not exist.", $destPath)); } else { if (!is_writable($destPath)) { throw new \InvalidArgumentException(sprintf("Mapping destination directory '<info>%s</info>' does not have write permissions.", $destPath)); } } $toType = strtolower($input->getArgument('to-type')); $cme = new ClassMetadataExporter(); $exporter = $cme->getExporter($toType, $destPath); if ($toType == 'annotation') { $entityGenerator = new EntityGenerator(); $exporter->setEntityGenerator($entityGenerator); $entityGenerator->setNumSpaces($input->getOption('num-spaces')); if (($extend = $input->getOption('extend')) !== null) { $entityGenerator->setClassToExtend($extend); } } if (count($metadata)) { foreach ($metadata as $class) { $output->write(sprintf('Processing entity "<info>%s</info>"', $class->name) . PHP_EOL); } $exporter->setMetadata($metadata); $exporter->export(); $output->write(PHP_EOL . sprintf('Exporting "<info>%s</info>" mapping information to "<info>%s</info>"' . PHP_EOL, $toType, $destPath)); } else { $output->write('No Metadata Classes to process.' . PHP_EOL); } }
/** * @see Command */ protected function execute(InputInterface $input, OutputInterface $output) { if (!preg_match('/Bundle$/', $bundle = $input->getOption('bundle'))) { throw new \InvalidArgumentException('The bundle must end with Bundle.'); } $dirs = $this->container->getKernelService()->getBundleDirs(); $tmp = str_replace('\\', '/', $bundle); $namespace = str_replace('/', '\\', dirname($tmp)); $bundle = basename($tmp); if (!isset($dirs[$namespace])) { throw new \InvalidArgumentException(sprintf('Could not find namespace "%s" for bundle "%s".', $namespace, $bundle)); } $path = $dirs[$namespace] . '/' . $bundle . '/Resources/config/doctrine/metadata'; if (!is_dir($path)) { mkdir($path, 0777, true); } $this->em = $this->container->getService(sprintf('doctrine.orm.%s_entity_manager', $input->getOption('connection'))); $this->runCommand('doctrine:convert-mapping', array('--from' => 'database', '--to' => $input->getOption('type'), '--dest' => $path)); }
protected function execute(InputInterface $input, OutputInterface $output) { $found = false; $connections = $this->getDoctrineConnections(); foreach ($connections as $name => $connection) { if ($input->getOption('connection') && $name != $input->getOption('connection')) { continue; } $this->dropDatabaseForConnection($connection, $output); $found = true; } if ($found === false) { if ($input->getOption('connection')) { throw new \InvalidArgumentException(sprintf('<error>Could not find a connection named <comment>%s</comment></error>', $input->getOption('connection'))); } else { throw new \InvalidArgumentException(sprintf('<error>Could not find any configured connections</error>', $input->getOption('connection'))); } } }
/** * @see Command */ protected function execute(InputInterface $input, OutputInterface $output) { if (null === $this->command) { $this->command = $this->application->getCommand($input->getArgument('command_name')); } if ($input->getOption('xml')) { $output->writeln($this->command->asXml(), Output::OUTPUT_RAW); } else { $output->writeln($this->command->asText()); } }
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas) { if ($input->getOption('dump-sql') === true) { $sqls = $schemaTool->getDropSchemaSql($metadatas); $output->write(implode(';' . PHP_EOL, $sqls) . PHP_EOL); } else { $output->write('Dropping database schema...' . PHP_EOL); $schemaTool->dropSchema($metadatas); $output->write('Database schema dropped successfully!' . PHP_EOL); } }
/** * @see Command */ protected function execute(InputInterface $input, OutputInterface $output) { if (!preg_match('/Bundle$/', $bundle = $input->getOption('bundle'))) { throw new \InvalidArgumentException('The bundle name must end with Bundle. Example: "Bundle\\MySampleBundle".'); } $dirs = $this->container->getKernelService()->getBundleDirs(); $tmp = str_replace('\\', '/', $bundle); $namespace = str_replace('/', '\\', dirname($tmp)); $bundle = basename($tmp); if (!isset($dirs[$namespace])) { throw new \InvalidArgumentException(sprintf('Unable to initialize the bundle entity (%s not defined).', $namespace)); } $entity = $input->getOption('entity'); $entityNamespace = $namespace . '\\' . $bundle . '\\Entities'; $fullEntityClassName = $entityNamespace . '\\' . $entity; $tmp = str_replace('\\', '/', $fullEntityClassName); $tmp = str_replace('/', '\\', dirname($tmp)); $className = basename($tmp); $extends = null; $path = $dirs[$namespace] . '/' . $bundle . '/Resources/config/doctrine/metadata/' . str_replace('\\', '.', $fullEntityClassName) . '.dcm.xml'; $xml = sprintf('<?xml version="1.0" encoding="UTF-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="%s" table="%s"> <id name="id" type="integer" column="id"> <generator strategy="AUTO"/> </id> </entity> </doctrine-mapping>', $fullEntityClassName, str_replace('\\', '_', strtolower($entity))); if (!is_dir($dir = dirname($path))) { mkdir($dir, 0777, true); } file_put_contents($path, $xml); $this->runCommand('doctrine:build-entities'); }
public function execute(InputInterface $input, OutputInterface $output) { $version = $input->getArgument('version'); $direction = $input->getOption('down') ? 'down' : 'up'; $configuration = $this->_getMigrationConfiguration($input, $output); $version = $configuration->getVersion($version); if ($path = $input->getOption('write-sql')) { $path = is_bool($path) ? getcwd() : $path; $version->writeSqlFile($path, $direction); } else { $version->execute($direction, $input->getOption('dry-run') ? true : false); } }
/** * @see Command */ protected function execute(InputInterface $input, OutputInterface $output) { /** * @TODO implement mongrel_rails like runtime configuration * @link http://github.com/fauna/mongrel/blob/master/bin/mongrel_rails#L22 * * Sequence * 1) runtime configuration [-defaults] * 2) config.yml * 3) server.xml */ $this->server->start($input->getOption('daemonize')); }
/** * @see Command */ protected function execute(InputInterface $input, OutputInterface $output) { if (file_exists($targetDir = $input->getArgument('path'))) { throw new \RuntimeException(sprintf('The directory "%s" already exists.', $targetDir)); } if (!file_exists($webDir = $input->getArgument('web_path'))) { mkdir($webDir, 0777, true); } $parameters = array('class' => $input->getArgument('name'), 'application' => strtolower($input->getArgument('name')), 'format' => $input->getOption('format')); $filesystem = new Filesystem(); $filesystem->mirror(__DIR__ . '/../Resources/skeleton/application/generic', $targetDir); $filesystem->mirror(__DIR__ . '/../Resources/skeleton/application/' . $input->getOption('format'), $targetDir); Mustache::renderDir($targetDir, $parameters); $filesystem->chmod($targetDir . '/console', 0777); $filesystem->chmod($targetDir . '/logs', 0777); $filesystem->chmod($targetDir . '/cache', 0777); $filesystem->rename($targetDir . '/Kernel.php', $targetDir . '/' . $input->getArgument('name') . 'Kernel.php'); $filesystem->rename($targetDir . '/Cache.php', $targetDir . '/' . $input->getArgument('name') . 'Cache.php'); $filesystem->copy(__DIR__ . '/../Resources/skeleton/web/front_controller.php', $file = $webDir . '/' . (file_exists($webDir . '/index.php') ? strtolower($input->getArgument('name')) : 'index') . '.php'); Mustache::renderFile($file, $parameters); $filesystem->copy(__DIR__ . '/../Resources/skeleton/web/front_controller_debug.php', $file = $webDir . '/' . strtolower($input->getArgument('name')) . '_dev.php'); Mustache::renderFile($file, $parameters); }
protected function _generateMigration(Configuration $configuration, InputInterface $input, $version, $up = null, $down = null) { $placeHolders = array('<namespace>', '<version>', '<up>', '<down>'); $replacements = array($configuration->getMigrationsNamespace(), $version, $up ? " " . implode("\n ", explode("\n", $up)) : null, $down ? " " . implode("\n ", explode("\n", $down)) : null); $code = str_replace($placeHolders, $replacements, self::$_template); $dir = $configuration->getMigrationsDirectory(); $dir = $dir ? $dir : getcwd(); $dir = rtrim($dir, '/'); $path = $dir . '/Version' . $version . '.php'; file_put_contents($path, $code); if ($editorCmd = $input->getOption('editor-cmd')) { shell_exec($editorCmd . ' ' . escapeshellarg($path)); } return $path; }
/** * @see Command * * @throws \InvalidArgumentException When the target directory does not exist */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$input->getOption('sql')) { $output->writeln('<info>Building model classes</info>'); $modelCommand = new BuildModelCommand(); $modelCommand->setApplication($this->application); $modelCommand->execute($input, $output); } if (!$input->getOption('classes')) { $output->writeln('<info>Building model sql</info>'); $sqlCommand = new BuildSQLCommand(); $sqlCommand->setApplication($this->application); $sqlCommand->execute($input, $output); } }
/** * @see Console\Command\Command */ protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) { $em = $this->getHelper('em')->getEntityManager(); $error = false; try { $em->getConfiguration()->ensureProductionSettings(); if ($input->getOption('complete') !== null) { $em->getConnection()->connect(); } } catch (\Exception $e) { $error = true; $output->writeln('<error>' . $e->getMessage() . '</error>'); } if ($error === false) { $output->write('<info>Environment is correctly configured for production.</info>' . PHP_EOL); } }
/** * @see Console\Command\Command */ protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) { $conn = $this->getHelper('db')->getConnection(); if (($sql = $input->getArgument('sql')) === null) { throw new \RuntimeException("Argument 'SQL' is required in order to execute this command correctly."); } $depth = $input->getOption('depth'); if (!is_numeric($depth)) { throw new \LogicException("Option 'depth' must contains an integer value"); } if (preg_match('/^select/i', $sql)) { $resultSet = $conn->fetchAll($sql); } else { $resultSet = $em->getConnection()->executeUpdate($sql); } \Doctrine\Common\Util\Debug::dump($resultSet, (int) $depth); }