Beispiel #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;
 }
Beispiel #2
0
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $em = $this->getHelper('em')->getEntityManager();
     // Delete first
     $query = $em->createQuery('delete from BBM\\Play');
     $query->execute();
     $query = $em->createQuery('delete from BBM\\Game');
     $query->execute();
     $count = 0;
     $gameFactory = new GameFactory($em);
     $currec = array();
     if (($handle = fopen(DATADIR . "/game_events/2008ATL.EVN", "r")) !== FALSE) {
         while (($data = fgetcsv($handle)) !== FALSE) {
             if ($data[0] === 'id' && sizeof($currec) !== 0) {
                 $game = $gameFactory->createGameFromRetrosheetRecords($currec);
                 $em->persist($game);
                 if ($count % 10 == 0) {
                     $em->flush();
                     $em->clear();
                 }
                 $output->writeln($game);
                 unset($currec);
                 $count++;
             }
             $currec[] = $data;
         }
     }
     fclose($handle);
     $em->flush();
 }
Beispiel #3
0
  protected function execute(InputInterface $input, OutputInterface $output)
  {
    $this->input = $input;
    $this->output = $output;

    $output->writeln('called');
  }
 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
     $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 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);
     }
 }
 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>');
     }
 }
Beispiel #8
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')));
     }
 }
 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)
 {
     $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');
     }
 }
Beispiel #11
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());
     }
 }
 /**
  * @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()}");
     }
 }
 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);
     }
 }
 protected function dropDatabaseForConnection(Connection $connection, OutputInterface $output)
 {
     $params = $connection->getParams();
     $name = isset($params['path']) ? $params['path'] : $params['dbname'];
     try {
         $connection->getSchemaManager()->dropDatabase($name);
         $output->writeln(sprintf('<info>Dropped database for connection named <comment>%s</comment></info>', $name));
     } catch (\Exception $e) {
         $output->writeln(sprintf('<error>Could not drop database for connection named <comment>%s</comment></error>', $name));
         $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
     }
 }
 /**
  * @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 Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $kernel = $this->container->getKernelService();
     $container = new Builder($kernel->getDefaultParameters());
     $configuration = new BuilderConfiguration();
     foreach ($kernel->getBundles() as $bundle) {
         $configuration->merge($bundle->buildContainer($container));
     }
     $configuration->merge($kernel->registerContainerConfiguration());
     $container->merge($configuration);
     $kernel->optimizeContainer($container);
     $container->setService('kernel', $kernel);
     $dumper = new GraphvizDumper($container);
     $output->write($dumper->dump(), Output::OUTPUT_RAW);
 }
Beispiel #18
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);
     }
 }
 protected function createDatabaseForConnection(Connection $connection, OutputInterface $output)
 {
     $params = $connection->getParams();
     $name = isset($params['path']) ? $params['path'] : $params['dbname'];
     unset($params['dbname']);
     $tmpConnection = \Doctrine\DBAL\DriverManager::getConnection($params);
     try {
         $tmpConnection->getSchemaManager()->createDatabase($name);
         $output->writeln(sprintf('<info>Created database for connection named <comment>%s</comment></info>', $name));
     } catch (\Exception $e) {
         $output->writeln(sprintf('<error>Could not create database for connection named <comment>%s</comment></error>', $name));
         $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
     }
     $tmpConnection->close();
 }
Beispiel #20
0
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $em = $this->getHelper('em')->getEntityManager();
     if (($handle = fopen(DATADIR . "/teams/TEAMABR.TXT", "r")) !== FALSE) {
         while (($data = fgetcsv($handle)) !== FALSE) {
             $team = new \BBM\Team($data[0]);
             $team->setLeague($data[1]);
             $team->setCity($data[2]);
             $team->setNickname($data[3]);
             $output->writeln($team);
             $em->persist($team);
         }
     }
     $em->flush();
 }
 /**
  * @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();
             }
         }
     }
 }
 /**
  * @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);
         }
     }
 }
Beispiel #23
0
 /**
  * Asks for a value and validates the response.
  *
  * @param OutputInterface $output
  * @param string|array    $question
  * @param Closure         $validator
  * @param integer         $attempts Max number of times to ask before giving up (false by default, which means infinite)
  *
  * @return mixed
  *
  * @throws \Exception When any of the validator returns an error
  */
 public function askAndValidate(OutputInterface $output, $question, \Closure $validator, $attempts = false)
 {
     // @codeCoverageIgnoreStart
     $error = null;
     while (false === $attempts || $attempts--) {
         if (null !== $error) {
             $output->writeln($this->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
         }
         $value = $this->ask($output, $question, null);
         try {
             return $validator($value);
         } catch (\Exception $error) {
         }
     }
     throw $error;
     // @codeCoverageIgnoreEnd
 }
 /**
  * @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);
     }
 }
Beispiel #25
0
 /**
  * @see Command
  *
  * @throws \InvalidArgumentException When the target directory does not exist
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->callPhing('sql', array('propel.packageObjectModel' => false));
     $filesystem = new Filesystem();
     $basePath = $this->application->getKernel()->getRootDir() . DIRECTORY_SEPARATOR . 'propel' . DIRECTORY_SEPARATOR . 'sql';
     $sqlMap = file_get_contents($basePath . DIRECTORY_SEPARATOR . 'sqldb.map');
     foreach ($this->tempSchemas as $schemaFile => $schemaDetails) {
         $sqlFile = str_replace('.xml', '.sql', $schemaFile);
         $targetSqlFile = $schemaDetails['bundle'] . '-' . str_replace('.xml', '.sql', $schemaDetails['basename']);
         $targetSqlFilePath = $basePath . DIRECTORY_SEPARATOR . $targetSqlFile;
         $sqlMap = str_replace($sqlFile, $targetSqlFile, $sqlMap);
         $filesystem->remove($targetSqlFilePath);
         $filesystem->rename($basePath . DIRECTORY_SEPARATOR . $sqlFile, $targetSqlFilePath);
         $output->writeln(sprintf('Wrote SQL file for bundle "<info>%s</info>" in "<info>%s</info>"', $schemaDetails['bundle'], $targetSqlFilePath));
     }
     file_put_contents($basePath . DIRECTORY_SEPARATOR . 'sqldb.map', $sqlMap);
 }
 /**
  * @see Console\Command\Command
  */
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $em = $this->getHelper('em')->getEntityManager();
     $cacheDriver = $em->getConfiguration()->getQueryCacheImpl();
     if (!$cacheDriver) {
         throw new \InvalidArgumentException('No Query cache driver is configured on given EntityManager.');
     }
     $output->write('Clearing ALL Query cache entries' . PHP_EOL);
     $cacheIds = $cacheDriver->deleteAll();
     if ($cacheIds) {
         foreach ($cacheIds as $cacheId) {
             $output->write(' - ' . $cacheId . PHP_EOL);
         }
     } else {
         $output->write('No entries to be deleted.' . PHP_EOL);
     }
 }
 /**
  * @see Console\Command\Command
  */
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $em = $this->getHelper('em')->getEntityManager();
     $validator = new \Doctrine\ORM\Tools\SchemaValidator($em);
     $errors = $validator->validateMapping();
     $exit = 0;
     if ($errors) {
         foreach ($errors as $className => $errorMessages) {
             $output->write("<error>[Mapping]  FAIL - The entity-class '" . $className . "' mapping is invalid:</error>\n");
             foreach ($errorMessages as $errorMessage) {
                 $output->write('* ' . $errorMessage . "\n");
             }
             $output->write("\n");
         }
         $exit += 1;
     } else {
         $output->write('<info>[Mapping]  OK - The mapping files are correct.</info>' . "\n");
     }
     if (!$validator->schemaInSyncWithMetadata()) {
         $output->write('<error>[Database] FAIL - The database schema is not in sync with the current mapping file.</error>' . "\n");
         $exit += 2;
     } else {
         $output->write('<info>[Database] OK - The database schema is in sync with the mapping files.</info>' . "\n");
     }
     exit($exit);
 }
 /**
  * @throws \InvalidArgumentException When route does not exist
  */
 protected function outputRoute(OutputInterface $output, $routes, $name)
 {
     $output->writeln($this->getHelper('formatter')->formatSection('router', sprintf('Route "%s"', $name)));
     if (!isset($routes[$name])) {
         throw new \InvalidArgumentException(sprintf('The route "%s" does not exist.', $name));
     }
     $route = $routes[$name];
     $output->writeln(sprintf('<comment>Name</comment>         %s', $name));
     $output->writeln(sprintf('<comment>Pattern</comment>      %s', $route->getPattern()));
     $output->writeln(sprintf('<comment>Class</comment>        %s', get_class($route)));
     $defaults = '';
     $d = $route->getDefaults();
     ksort($d);
     foreach ($d as $name => $value) {
         $defaults .= ($defaults ? "\n" . str_repeat(' ', 13) : '') . $name . ': ' . $this->formatValue($value);
     }
     $output->writeln(sprintf('<comment>Defaults</comment>     %s', $defaults));
     $requirements = '';
     $r = $route->getRequirements();
     ksort($r);
     foreach ($r as $name => $value) {
         $requirements .= ($requirements ? "\n" . str_repeat(' ', 13) : '') . $name . ': ' . $this->formatValue($value);
     }
     $output->writeln(sprintf('<comment>Requirements</comment> %s', $requirements));
     $options = '';
     $o = $route->getOptions();
     ksort($o);
     foreach ($o as $name => $value) {
         $options .= ($options ? "\n" . str_repeat(' ', 13) : '') . $name . ': ' . $this->formatValue($value);
     }
     $output->writeln(sprintf('<comment>Options</comment>      %s', $options));
     $output->write('<comment>Regex</comment>        ');
     $output->writeln(preg_replace('/^             /', '', preg_replace('/^/m', '             ', $route->getRegex())), Output::OUTPUT_RAW);
     $tokens = '';
     foreach ($route->getTokens() as $token) {
         if (!$tokens) {
             $tokens = $this->displayToken($token);
         } else {
             $tokens .= "\n" . str_repeat(' ', 13) . $this->displayToken($token);
         }
     }
     $output->writeln(sprintf('<comment>Tokens</comment>       %s', $tokens));
 }
 /**
  * @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);
     }
 }
 /**
  * @param InputInterface $input
  * @param OutputInterface $output 
  */
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $emHelper = $this->getHelper('em');
     /* @var $em \Doctrine\ORM\EntityManager */
     $em = $emHelper->getEntityManager();
     $metadatas = $em->getMetadataFactory()->getAllMetadata();
     if (!empty($metadatas)) {
         // Create SchemaTool
         $tool = new \Doctrine\ORM\Tools\SchemaTool($em);
         $updateSql = $tool->getUpdateSchemaSql($metadatas, false);
         if (count($updateSql) == 0) {
             $output->write("[Database] OK - Metadata schema exactly matches the database schema.");
         } else {
             $output->write("[Database] FAIL - There are differences between metadata and database schema.");
         }
     } else {
         $output->write("No metadata mappings found");
     }
 }