Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $selector = $input->getArgument('selector');
     if (!$selector) {
         $containers = $this->application->getController()->getContainers();
     } else {
         $containers = $this->application->getController()->selectContainers($selector);
     }
     $l = Formatter::calculateNamelength($containers) + 1;
     $FORMAT = "%{$l}s %s\n";
     printf($FORMAT, 'Name', 'Tags');
     array_walk($containers, function (&$container, $key) use($FORMAT) {
         $tags = $container->getTags();
         if (empty($tags)) {
             vprintf($FORMAT, array($container->getName(), '<none>'));
         }
         foreach ($tags as $key => $tag) {
             if ($key === 0) {
                 vprintf($FORMAT, array($container->getName(), $tag));
             } else {
                 vprintf($FORMAT, array('', $tag));
             }
         }
     });
 }
 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 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);
     }
 }
 /**
  * @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);
     }
 }
Exemplo n.º 6
0
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $selector = $input->getArgument('selector');
     $this->application->getController()->restart($selector, function ($message) {
         echo \Console_Color::convert(" %g>>%n ") . $message . "\n";
     });
 }
 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);
 }
Exemplo n.º 8
0
 /**
  * @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;
     }
 }
Exemplo n.º 9
0
 /**
  * @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));
     }
 }
Exemplo n.º 10
0
 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>');
     }
 }
Exemplo n.º 11
0
 /**
  * @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')));
     }
 }
Exemplo n.º 12
0
 /**
  * Runs the current application.
  *
  * @param InputInterface  $input  An Input instance
  * @param OutputInterface $output An Output instance
  *
  * @return integer 0 if everything went fine, or an error code
  */
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     if (true === $input->hasParameterOption(array('--shell', '-s'))) {
         $shell = new Shell($this);
         $shell->run();
         return 0;
     }
     return parent::doRun($input, $output);
 }
Exemplo n.º 13
0
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $selector = $input->getArgument('selector');
     $tag = $input->getArgument('tag');
     $containers = $this->application->getController()->selectContainers($selector);
     array_walk($containers, function (&$container, $key, $tag) {
         $container->addTag($tag);
     }, $tag);
 }
Exemplo n.º 14
0
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = $input->getArgument('name');
     $ip = $input->getArgument('ip');
     $container = $this->application->getController()->getContainer($name);
     if (!$container) {
         throw new \Exception('Container does not exists!');
     }
     $container->addAllowedIp($ip);
 }
 /**
  * @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);
 }
Exemplo n.º 16
0
 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);
     }
 }
Exemplo n.º 17
0
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = $input->getArgument('name');
     $container = $this->application->getController()->getContainer($name);
     if (!$container) {
         $output->writeln("<error>Container {$name} does not exists</error>");
     } else {
         $editor = $this->application->getController()->getExecutable('editor');
         \ContainerKit\Console\Launcher::launch("{$editor} {$container->getConfigPath()}");
     }
 }
Exemplo n.º 18
0
 /**
  * @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());
     }
 }
Exemplo n.º 19
0
 /**
  * @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;
 }
Exemplo n.º 20
0
 /**
  * @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'));
 }
Exemplo n.º 21
0
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $router = $this->container->getService('router');
     $routes = array();
     foreach ($router->getRouteCollection()->getRoutes() as $name => $route) {
         $routes[$name] = $route->compile();
     }
     if ($input->getArgument('name')) {
         $this->outputRoute($output, $routes, $input->getArgument('name'));
     } else {
         $this->outputRoutes($output, $routes);
     }
 }
Exemplo n.º 22
0
 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);
     }
 }
Exemplo n.º 23
0
 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);
     }
 }
Exemplo n.º 24
0
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = $input->getArgument('name');
     echo "  WARNING!\n";
     echo "  Selected archive must be created on system with same config and storage filesystem layout\n";
     echo "  Otherwise restore operation may damage your system!\n";
     if (readline("Proceed[Y/n]?") != 'n') {
         $this->application->getController()->restore($name, function ($message) {
             echo \Console_Color::convert(" %g>>%n ") . $message . "\n";
         });
     } else {
         echo "Aborted\n";
     }
 }
Exemplo n.º 25
0
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $selector = $input->getArgument('selector');
     echo "  Archive operation requires all selected containers to be stopped\n";
     echo "  Any running containers will be stopped before archiving\n";
     echo "  Archives will be created in current working directory\n";
     if (readline("Proceed[Y/n]?") != 'n') {
         $this->application->getController()->archive($selector, function ($message) {
             echo \Console_Color::convert(" %g>>%n ") . $message . "\n";
         });
     } else {
         echo "Aborted\n";
     }
 }
Exemplo n.º 26
0
 /**
  * @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);
     }
 }
Exemplo n.º 27
0
 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;
 }
Exemplo n.º 28
0
 /**
  * @see Console\Command\Command
  */
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $conn = $this->getHelper('db')->getConnection();
     if (($fileNames = $input->getArgument('file')) !== null) {
         foreach ((array) $fileNames as $fileName) {
             $fileName = realpath($fileName);
             if (!file_exists($fileName)) {
                 throw new \InvalidArgumentException(sprintf("SQL file '<info>%s</info>' does not exist.", $fileName));
             } else {
                 if (!is_readable($fileName)) {
                     throw new \InvalidArgumentException(sprintf("SQL file '<info>%s</info>' does not have read permissions.", $fileName));
                 }
             }
             $output->write(sprintf("Processing file '<info>%s</info>'... ", $fileName));
             $sql = file_get_contents($fileName);
             if ($conn instanceof \Doctrine\DBAL\Driver\PDOConnection) {
                 // PDO Drivers
                 try {
                     $lines = 0;
                     $stmt = $conn->prepare($sql);
                     $stmt->execute();
                     do {
                         // Required due to "MySQL has gone away!" issue
                         $stmt->fetch();
                         $stmt->closeCursor();
                         $lines++;
                     } while ($stmt->nextRowset());
                     $output->write(sprintf('%d statements executed!', $lines) . PHP_EOL);
                 } catch (\PDOException $e) {
                     $output->write('error!' . PHP_EOL);
                     throw new \RuntimeException($e->getMessage(), $e->getCode(), $e);
                 }
             } else {
                 // Non-PDO Drivers (ie. OCI8 driver)
                 $stmt = $conn->prepare($sql);
                 $rs = $stmt->execute();
                 if ($rs) {
                     $printer->writeln('OK!');
                 } else {
                     $error = $stmt->errorInfo();
                     $output->write('error!' . PHP_EOL);
                     throw new \RuntimeException($error[2], $error[0]);
                 }
                 $stmt->closeCursor();
             }
         }
     }
 }
Exemplo n.º 29
0
 /**
  * @see Command
  *
  * @throws \InvalidArgumentException When the target directory does not exist
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!is_dir($input->getArgument('target'))) {
         throw new \InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target')));
     }
     $filesystem = new Filesystem();
     foreach ($this->container->getKernelService()->getBundles() as $bundle) {
         if (is_dir($originDir = $bundle->getPath() . '/Resources/public')) {
             $output->writeln(sprintf('Installing assets for <comment>%s\\%s</comment>', $bundle->getNamespacePrefix(), $bundle->getName()));
             $targetDir = $input->getArgument('target') . '/bundles/' . preg_replace('/bundle$/', '', strtolower($bundle->getName()));
             $filesystem->remove($targetDir);
             mkdir($targetDir, 0777, true);
             $filesystem->mirror($originDir, $targetDir);
         }
     }
 }
Exemplo n.º 30
0
 /**
  * @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);
 }