Example #1
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')));
     }
 }
 /**
  * @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);
 }
 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');
     }
 }
 /**
  * @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);
 }
 /**
  * @see Command
  */
 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';
     }
     // adjust so file naming works
     if ($type === 'yaml') {
         $type = 'yml';
     }
     $cme = new ClassMetadataExporter();
     $exporter = $cme->getExporter($type);
     if ($type === 'annotation') {
         $entityGenerator = $this->getEntityGenerator();
         $exporter->setEntityGenerator($entityGenerator);
     }
     $converter = new ConvertDoctrine1Schema($input->getArgument('d1-schema'));
     $metadata = $converter->getMetadata();
     if ($metadata) {
         $output->writeln(sprintf('Converting Doctrine 1 schema "<info>%s</info>"', $input->getArgument('d1-schema')));
         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.' . $type;
             }
             $output->writeln(sprintf('  > writing <comment>%s</comment>', $path));
             $code = $exporter->exportClassMetadata($class);
             if (!is_dir($dir = dirname($path))) {
                 mkdir($dir, 0777, true);
             }
             file_put_contents($path, $code);
         }
     } else {
         $output->writeln('Database does not have any mapping information.' . PHP_EOL, 'ERROR');
     }
 }
Example #7
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);
     }
 }
 /**
  * @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();
     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();
     $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');
     $this->application->getController()->restart($selector, function ($message) {
         echo \Console_Color::convert(" %g>>%n ") . $message . "\n";
     });
 }
 /**
  * @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 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);
         }
     }
 }
 /**
  * @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));
             }
         }
     });
 }
 /**
  * @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)
 {
     $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()}");
     }
 }
Example #17
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());
     }
 }
Example #18
0
 /**
  * @see Command
  */
 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();
     $dirs = $this->container->getKernelService()->getBundleDirs();
     foreach ($this->container->getKernelService()->getBundles() as $bundle) {
         $tmp = dirname(str_replace('\\', '/', get_class($bundle)));
         $namespace = dirname($tmp);
         $class = basename($tmp);
         if (isset($dirs[$namespace]) && is_dir($originDir = $dirs[$namespace] . '/' . $class . '/Resources/public')) {
             $output->writeln(sprintf('Installing assets for <comment>%s\\%s</comment>', $namespace, $class));
             $targetDir = $input->getArgument('target') . '/bundles/' . preg_replace('/bundle$/', '', strtolower($class));
             $filesystem->remove($targetDir);
             mkdir($targetDir, 0755, true);
             $filesystem->mirror($originDir, $targetDir);
         }
     }
 }
Example #19
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);
     }
 }
 /**
  * @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";
     }
 }
 /**
  * @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";
     }
 }
 /**
  * @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();
             }
         }
     }
 }
Example #23
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);
 }
Example #24
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 {
         $confirmation = $this->getHelper('dialog')->askConfirmation($output, '<question>WARNING! You are about to execute a database migration that could result in schema changes and data lost. Are you sure you wish to continue? (y/n)</question>', 'y');
         if ($confirmation === true) {
             $version->execute($direction, $input->getOption('dry-run') ? true : false);
         } else {
             $output->writeln('<error>Migration cancelled!</error>');
         }
     }
 }
Example #25
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $version = $input->getArgument('version');
     $configuration = $this->_getMigrationConfiguration($input, $output);
     $migration = new Migration($configuration);
     if ($path = $input->getOption('write-sql')) {
         $path = is_bool($path) ? getcwd() : $path;
         $migration->writeSqlFile($path, $version);
     } else {
         $confirmation = $this->getHelper('dialog')->askConfirmation($output, '<question>Are you sure you wish to continue?</question>', 'y');
         if ($confirmation === true) {
             $migration->migrate($version, $input->getOption('dry-run') ? true : false);
         } else {
             $output->writeln('<info>Migration cancelled...</info>');
             return 1;
         }
     }
 }
Example #26
0
 /**
  * @see Command
  *
  * @throws \InvalidArgumentException When namespace doesn't end with Bundle
  * @throws \RuntimeException         When bundle can't be executed
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!preg_match('/Bundle$/', $namespace = $input->getArgument('namespace'))) {
         throw new \InvalidArgumentException('The namespace must end with Bundle.');
     }
     $dirs = $this->container->getKernelService()->getBundleDirs();
     $tmp = str_replace('\\', '/', $namespace);
     $namespace = str_replace('/', '\\', dirname($tmp));
     $bundle = basename($tmp);
     if (!isset($dirs[$namespace])) {
         throw new \InvalidArgumentException(sprintf('Unable to initialize the bundle (%s not defined).', $namespace));
     }
     $dir = $dirs[$namespace];
     $output->writeln(sprintf('Initializing bundle "<info>%s</info>" in "<info>%s</info>"', $bundle, realpath($dir)));
     if (file_exists($targetDir = $dir . '/' . $bundle)) {
         throw new \RuntimeException(sprintf('Bundle "%s" already exists.', $bundle));
     }
     $filesystem = new Filesystem();
     $filesystem->mirror(__DIR__ . '/../Resources/skeleton/bundle', $targetDir);
     Mustache::renderDir($targetDir, array('namespace' => $namespace, 'bundle' => $bundle));
 }
 /**
  * @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('yaml') ? 'yaml' : 'xml';
     $filesystem = new Filesystem();
     $filesystem->mirror(__DIR__ . '/../Resources/skeleton/application/' . $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);
 }
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!preg_match('/Bundle$/', $class = $input->getArgument('bundle'))) {
         throw new \InvalidArgumentException('The namespace of a bundle must end with Bundle.');
     }
     $dirs = $this->container->getKernelService()->getBundleDirs();
     $tmp = str_replace('\\', '/', $class);
     $namespace = dirname($tmp);
     $bundle = basename($tmp);
     if (!isset($dirs[$namespace])) {
         throw new \InvalidArgumentException('Unable to find the bundle.');
     }
     //$dir = str_replace(str_replace('\\', '/', $namespace), '', $dirs[$namespace]);
     $dir = $dirs[$namespace];
     $pharFile = $dir . '/' . $bundle . '.phar';
     if (file_exists($pharFile)) {
         unlink($pharFile);
     }
     $phar = new \Phar($pharFile, 0, $bundle);
     $phar->setSignatureAlgorithm(\Phar::SHA1);
     $phar->startBuffering();
     foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dirs[$namespace] . '/' . $bundle), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
         if (preg_match('/^\\./', $file)) {
             continue;
         }
         //$name = str_replace(realpath($dir).'/', '', realpath($file));
         $name = str_replace(realpath($dir) . '/', 'Bundle/', realpath($file));
         $this->addPhpFile($phar, $name, file_get_contents($file));
     }
     // Stubs
     $phar['_cli_stub.php'] = $this->getCliStub();
     $phar['_web_stub.php'] = $this->getWebStub();
     $phar->setDefaultStub('_cli_stub.php', '_web_stub.php');
     $phar->stopBuffering();
     // does not seem to work if set before adding files
     //$phar->compressFiles(\Phar::GZ);
     unset($phar);
 }
 /**
  * @see Console\Command\Command
  */
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $em = $this->getHelper('em')->getEntityManager();
     $cmf = new DisconnectedClassMetadataFactory($em);
     $metadatas = $cmf->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)) {
         // Create EntityGenerator
         $entityGenerator = new EntityGenerator();
         $entityGenerator->setGenerateAnnotations($input->getOption('generate-annotations'));
         $entityGenerator->setGenerateStubMethods($input->getOption('generate-methods'));
         $entityGenerator->setRegenerateEntityIfExists($input->getOption('regenerate-entities'));
         $entityGenerator->setUpdateEntityIfExists($input->getOption('update-entities'));
         $entityGenerator->setNumSpaces($input->getOption('num-spaces'));
         if (($extend = $input->getOption('extend')) !== null) {
             $entityGenerator->setClassToExtend($extend);
         }
         foreach ($metadatas as $metadata) {
             $output->write(sprintf('Processing entity "<info>%s</info>"', $metadata->name) . PHP_EOL);
         }
         // Generating Entities
         $entityGenerator->generate($metadatas, $destPath);
         // Outputting information message
         $output->write(PHP_EOL . sprintf('Entity classes generated to "<info>%s</INFO>"', $destPath) . PHP_EOL);
     } else {
         $output->write('No Metadata Classes to process.' . PHP_EOL);
     }
 }
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($selector = $input->getArgument('selector')) {
         $containers = $this->application->getController()->selectContainers($selector);
     } else {
         $containers = $this->application->getController()->getContainers();
     }
     $namelength = Formatter::calculateNamelength($containers) + 1;
     $FORMAT = "%2s %{$namelength}s %6s %8s %12s %12s %12s %18s %10s %10s\n";
     printf($FORMAT, ' ', 'Name', 'Tasks', 'Rss', 'User time', 'System time', 'Uptime', 'IP', 'Upload', 'Download');
     foreach ($containers as $container) {
         $r = array('state' => '', 'name' => '', 'tasks' => 'n/a', 'rss' => 'n/a', 'usertime' => 'n/a', 'systemtime' => 'n/a', 'uptime' => 'n/a', 'ip' => 'n/a', 'upload' => 'n/a', 'download' => 'n/a');
         $r['name'] = $container->getName();
         $state = $container->getState();
         if ($state == 'RUNNING') {
             $r['state'] = \Console_Color::convert(' %g>>%n');
         } else {
             if ($state == 'STOPPED') {
                 $r['state'] = \Console_Color::convert(' %b--%n');
             }
         }
         if ($state == 'RUNNING') {
             $r['tasks'] = count($container->getTasks());
             $r['rss'] = Formatter::formatBytes($container->getRss());
             $r['uptime'] = Formatter::formatTime($container->getUptime());
             $times = $container->getCpuTimes();
             $r['systemtime'] = Formatter::formatTime($times['system']);
             $r['usertime'] = Formatter::formatTime($times['user']);
             $r['ip'] = $container->getIp();
             $traffic = $container->getTraffic();
             $r['upload'] = Formatter::formatBytes($traffic['upload']);
             $r['download'] = Formatter::formatBytes($traffic['download']);
         }
         vprintf($FORMAT, $r);
     }
 }