當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Schema\Comparator類代碼示例

本文整理匯總了PHP中Doctrine\DBAL\Schema\Comparator的典型用法代碼示例。如果您正苦於以下問題:PHP Comparator類的具體用法?PHP Comparator怎麽用?PHP Comparator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Comparator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: runActivityLists

 /**
  * @param LoggerInterface $logger
  * @param bool            $dryRun
  */
 protected function runActivityLists(LoggerInterface $logger, $dryRun = false)
 {
     // @todo: this workaround should be removed in BAP-9156
     $this->configManager->clear();
     $targetEntities = $this->provider->getTargetEntityClasses(false);
     $toSchema = clone $this->schema;
     $hasSchemaChanges = false;
     foreach ($targetEntities as $targetEntity) {
         $associationName = ExtendHelper::buildAssociationName($targetEntity, ActivityListEntityConfigDumperExtension::ASSOCIATION_KIND);
         $relationTableName = $this->nameGenerator->generateManyToManyJoinTableName(ActivityListEntityConfigDumperExtension::ENTITY_CLASS, $associationName, $targetEntity);
         if (!$toSchema->hasTable($relationTableName)) {
             $hasSchemaChanges = true;
             $this->activityListExtension->addActivityListAssociation($toSchema, $this->metadataHelper->getTableNameByEntityClass($targetEntity));
         }
     }
     if ($hasSchemaChanges) {
         $comparator = new Comparator();
         $platform = $this->connection->getDatabasePlatform();
         $schemaDiff = $comparator->compare($this->schema, $toSchema);
         $queries = $schemaDiff->toSql($platform);
         foreach ($queries as $query) {
             $this->logQuery($logger, $query);
             if (!$dryRun) {
                 $this->connection->executeQuery($query);
             }
         }
     }
 }
開發者ID:woei66,項目名稱:platform,代碼行數:32,代碼來源:ActivityListMigrationQuery.php

示例2: updateDbSchema

 /**
  * Updates DB Schema. Changes from Diamante only will be applied for current schema. Other bundles updating skips
  * @throws \Exception if there are no changes in entities
  */
 protected function updateDbSchema()
 {
     /**
      * @var $em \Doctrine\ORM\EntityManager
      */
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     $event = $em->getEventManager();
     $sm = $em->getConnection()->getSchemaManager();
     $allMetadata = $em->getMetadataFactory()->getAllMetadata();
     $schemaTool = new SchemaTool($em);
     $entitiesMetadata = array($em->getClassMetadata(\Diamante\DeskBundle\Entity\Branch::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\Ticket::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\Comment::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\Attachment::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\BranchEmailConfiguration::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\MessageReference::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\TicketHistory::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\WatcherList::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\TicketTimeline::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\Audit::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\AuditField::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\Article::getClassName()));
     $event->disableListeners();
     $currentSchema = $sm->createSchema();
     $schemaFromMetadata = $schemaTool->getSchemaFromMetadata($allMetadata);
     $entitiesSchema = $schemaTool->getSchemaFromMetadata($entitiesMetadata);
     $entitiesTables = $entitiesSchema->getTables();
     $entitiesTableName = array_keys($entitiesTables);
     $currentDiamanteSchema = $this->getTargetSchema($currentSchema, $entitiesTableName);
     $diamanteSchemaFromMetadata = $this->getTargetSchema($schemaFromMetadata, $entitiesTableName);
     $comparator = new Comparator();
     $diff = $comparator->compare($currentDiamanteSchema, $diamanteSchemaFromMetadata);
     $toUpdate = $diff->toSql($em->getConnection()->getDatabasePlatform());
     if (empty($toUpdate)) {
         throw new \Exception('No new updates found. DiamanteDesk is up to date!');
     }
     $conn = $em->getConnection();
     foreach ($toUpdate as $sql) {
         $conn->executeQuery($sql);
     }
 }
開發者ID:northdakota,項目名稱:diamantedesk-application,代碼行數:34,代碼來源:AbstractCommand.php

示例3: createOrUpdateTable

 /**
  * Generates code for creating or updating a database table.
  * @param Doctrine\DBAL\Schema\Table $updatedTable Specifies the updated table schema.
  * @param Doctrine\DBAL\Schema\Table $existingTable Specifies the existing table schema, if applicable.
  * @param string $newTableName An updated name of the theme. 
  * @return string|boolean Returns the migration up() and down() methods code. 
  * Returns false if there the table was not changed.
  */
 public function createOrUpdateTable($updatedTable, $existingTable, $newTableName)
 {
     $tableDiff = false;
     if ($existingTable !== null) {
         // The table already exists
         //
         $comparator = new Comparator();
         $tableDiff = $comparator->diffTable($existingTable, $updatedTable);
         if ($newTableName !== $existingTable->getName()) {
             if (!$tableDiff) {
                 $tableDiff = new TableDiff($existingTable->getName());
             }
             $tableDiff->newName = $newTableName;
         }
     } else {
         // The table doesn't exist
         //
         $tableDiff = new TableDiff($updatedTable->getName(), $updatedTable->getColumns(), [], [], $updatedTable->getIndexes());
         $tableDiff->fromTable = $updatedTable;
     }
     if (!$tableDiff) {
         return false;
     }
     if (!$this->tableHasNameOrColumnChanges($tableDiff) && !$this->tableHasPrimaryKeyChanges($tableDiff)) {
         return false;
     }
     return $this->generateCreateOrUpdateCode($tableDiff, !$existingTable, $updatedTable);
 }
開發者ID:sms-system,項目名稱:builder-plugin,代碼行數:36,代碼來源:TableMigrationCodeGenerator.php

示例4: updateDbSchema

 /**
  * Updates DB Schema.
  * @throws \Exception if there are no changes in entities
  */
 protected function updateDbSchema()
 {
     /**
      * @var $em \Doctrine\ORM\EntityManager
      */
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     $event = $em->getEventManager();
     $sm = $em->getConnection()->getSchemaManager();
     $allMetadata = $em->getMetadataFactory()->getAllMetadata();
     $schemaTool = new SchemaTool($em);
     $entitiesMetadata = array($em->getClassMetadata(ApiUser::getClassName()), $em->getClassMetadata(DiamanteUser::getClassName()));
     $event->disableListeners();
     $currentSchema = $sm->createSchema();
     $schemaFromMetadata = $schemaTool->getSchemaFromMetadata($allMetadata);
     $entitiesSchema = $schemaTool->getSchemaFromMetadata($entitiesMetadata);
     $entitiesTables = $entitiesSchema->getTables();
     $entitiesTableName = array_keys($entitiesTables);
     $currentDiamanteSchema = $this->getTargetSchema($currentSchema, $entitiesTableName);
     $diamanteSchemaFromMetadata = $this->getTargetSchema($schemaFromMetadata, $entitiesTableName);
     $comparator = new Comparator();
     $diff = $comparator->compare($currentDiamanteSchema, $diamanteSchemaFromMetadata);
     $toUpdate = $diff->toSql($em->getConnection()->getDatabasePlatform());
     if (empty($toUpdate)) {
         throw new \Exception('No new updates found. Diamante Api Bundle is up to date!');
     }
     $conn = $em->getConnection();
     foreach ($toUpdate as $sql) {
         $conn->executeQuery($sql);
     }
 }
開發者ID:gitter-badger,項目名稱:diamantedesk-application,代碼行數:34,代碼來源:SchemaCommand.php

示例5: execute

 public function execute(InputInterface $input, OutputInterface $output)
 {
     $dumpSql = $input->getOption('dump-sql');
     $force = $input->getOption('force');
     $manager = $this->connection->getSchemaManager();
     $this->connection->connect();
     $fromSchema = $manager->createSchema();
     $toSchema = new Schema();
     $comparator = new Comparator();
     $schemaDiff = $comparator->compare($fromSchema, $toSchema);
     $sql = $schemaDiff->toSaveSql($this->connection->getDatabasePlatform());
     if (!$dumpSql && !$force) {
         $output->writeln(sprintf('%d sql statements would be executed. Use `--dump-sql` to show them and `--force` to execute them on the database.', count($sql)));
         return;
     }
     if ($dumpSql) {
         foreach ($sql as $line) {
             $output->writeln($line);
         }
     }
     if ($force) {
         $output->writeln('Updating database schema');
         foreach ($sql as $line) {
             $this->connection->exec($line);
         }
         $output->writeln(sprintf('%d sql statements executed.', count($sql)));
     }
 }
開發者ID:dantleech,項目名稱:phpbench,代碼行數:28,代碼來源:MigrateCommand.php

示例6: handle

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->info('Retrieving schema differences...' . PHP_EOL);
     $this->createInMemoryDatabase();
     $defaultSm = $this->getSchemaManager();
     $inMemorySm = $this->getSchemaManager(self::CONNECTION_NAME);
     $fromSchema = $defaultSm->createSchema();
     $toSchema = $inMemorySm->createSchema();
     $comparator = new Comparator();
     $schemaDiff = $comparator->compare($fromSchema, $toSchema);
     $diffStatements = $schemaDiff->toSql($this->getDatabasePlatform());
     if (count($diffStatements) > 0) {
         $this->info('Statements that will be executed:' . PHP_EOL);
         foreach ($diffStatements as $statement) {
             $this->info('- ' . $statement);
         }
     } else {
         $this->info('The schema is up to date with the migrations.' . PHP_EOL);
     }
     if ($this->option('force')) {
         DB::transaction(function () use($diffStatements) {
             foreach ($diffStatements as $statement) {
                 DB::statement($statement);
             }
         });
     } else {
         $this->info(PHP_EOL . 'To apply diff statements use the --force option');
     }
 }
開發者ID:ablunier,項目名稱:laravel-database,代碼行數:34,代碼來源:SchemaUpdate.php

示例7: getSchemaDiff

 /**
  * @param array $classes
  *
  * @return \Doctrine\DBAL\Schema\SchemaDiff
  * @throws \Doctrine\ORM\ORMException
  */
 protected function getSchemaDiff(array $classes)
 {
     $sm = $this->getConnection()->getSchemaManager();
     $fromSchema = $sm->createSchema();
     $toSchema = $this->getSchemaFromMetadata($classes);
     $comparator = new Comparator();
     return $comparator->compare($fromSchema, $toSchema);
 }
開發者ID:Maksold,項目名稱:platform,代碼行數:14,代碼來源:SaveSchemaTool.php

示例8: getSchemaDiff

 public function getSchemaDiff()
 {
     $diff = new SchemaDiff();
     $comparator = new Comparator();
     $tableDiff = $comparator->diffTable($this->conn->getSchemaManager()->createSchema()->getTable($this->tableName), $this->schema->getTable($this->tableName));
     if (false !== $tableDiff) {
         $diff->changedTables[$this->tableName] = $tableDiff;
     }
     return $diff;
 }
開發者ID:BlueTM,項目名稱:LexikMonologBrowserBundle,代碼行數:10,代碼來源:SchemaBuilder.php

示例9: getUpdateSchema

 /**
  * {@inheritdoc}
  */
 public function getUpdateSchema(Schema $toSchema, $noDrops = false)
 {
     $comparator = new Comparator();
     $sm = $this->conn->getSchemaManager();
     $fromSchema = $sm->createSchema();
     $schemaDiff = $comparator->compare($fromSchema, $toSchema);
     if ($noDrops) {
         return $schemaDiff->toSaveSql($this->platform);
     }
     return $schemaDiff->toSql($this->platform);
 }
開發者ID:BusinessCookies,項目名稱:CoffeeMachineProject,代碼行數:14,代碼來源:SingleDatabaseSynchronizer.php

示例10: testSearchPathSchemaChanges

 public function testSearchPathSchemaChanges()
 {
     $table = new Table("dbal510tbl");
     $table->addColumn('id', 'integer');
     $table->setPrimaryKey(array('id'));
     $this->_conn->getSchemaManager()->createTable($table);
     $onlineTable = $this->_conn->getSchemaManager()->listTableDetails('dbal510tbl');
     $comparator = new Comparator();
     $diff = $comparator->diffTable($onlineTable, $table);
     $this->assertFalse($diff);
 }
開發者ID:llinder,項目名稱:FrameworkBenchmarks,代碼行數:11,代碼來源:DBAL510Test.php

示例11: execute

 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $url = $input->getArgument('url');
     $filename = $input->getArgument('filename');
     $apply = $input->getOption('apply');
     $dbmanager = new DatabaseManager();
     $databaseConfig = $dbmanager->getDatabaseConfig($url);
     $config = $databaseConfig->getConnectionConfig('default');
     $dsn = sprintf('%s:host=%s;port=%d', $config->getDriver(), $config->getHost(), $config->getPort());
     $dbname = $config->getDatabaseName();
     try {
         $pdo = new PDO($dsn, $config->getUsername(), $config->getPassword());
     } catch (\Exception $e) {
         throw new RuntimeException("Can't connect to server with provided address and credentials");
     }
     $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     $stmt = $pdo->query("SELECT COUNT(*) FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '" . $dbname . "'");
     if (!$stmt->fetchColumn()) {
         $output->writeln("<info>Creating database</info>");
         $stmt = $pdo->query("CREATE DATABASE " . $dbname . "");
     } else {
         $output->writeln("<error>Database exists...</error>");
     }
     $loader = LoaderFactory::getInstance()->getLoader($filename);
     $toSchema = $loader->loadSchema($filename);
     $config = new Configuration();
     $connectionParams = array('url' => $dbmanager->getUrlByDatabaseName($url));
     $connection = DriverManager::getConnection($connectionParams, $config);
     $connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
     $output->writeln(sprintf('<info>Loading file <comment>`%s`</comment> into database <comment>`%s`</comment></info>', $filename, $url));
     $schemaManager = $connection->getSchemaManager();
     $fromSchema = $schemaManager->createSchema();
     $comparator = new Comparator();
     $schemaDiff = $comparator->compare($fromSchema, $toSchema);
     $platform = $connection->getDatabasePlatform();
     $queries = $schemaDiff->toSaveSql($platform);
     if (!count($queries)) {
         $output->writeln("<info>No schema changes required</info>");
         return;
     }
     if ($apply) {
         $output->writeln("<info>APPLYING...</info>");
         foreach ($queries as $query) {
             $output->writeln(sprintf('<info>Running: <comment>%s</comment></info>', $query));
             $stmt = $connection->query($query);
         }
     } else {
         $output->writeln("<info>CHANGES: The following SQL statements need to be executed to synchronise the schema (use <comment>--apply</comment>)</info>");
         foreach ($queries as $query) {
             $output->writeln($query);
         }
     }
 }
開發者ID:dbtk,項目名稱:schema-loader,代碼行數:56,代碼來源:SchemaLoadCommand.php

示例12: updateSchema

 /**
  * Update database schema
  * @param bool $sqlOnly
  * @return array|null
  */
 public function updateSchema($sqlOnly = false)
 {
     $comparator = new Comparator();
     $schemaDiff = $comparator->compare($this->getCurrentSchema(), $this->getDesiredSchema());
     $sqls = $schemaDiff->toSql($this->getDBALPlatform());
     if ($sqlOnly) {
         return $sqls;
     }
     foreach ($sqls as $sql) {
         $this->connection->exec($sql);
     }
 }
開發者ID:echo511,項目名稱:leanmapper,代碼行數:17,代碼來源:DatabaseSchemaManipulator.php

示例13: update

 /**
  * Update all tables.
  *
  * @param array $metadata
  * @param boolean $saveMode
  * @return array
  */
 public function update(array $metadata, $saveMode = false)
 {
     $fromSchema = $this->schemaManager->createSchema();
     $toSchema = $this->getSchemaFromMetadata($metadata);
     $comparator = new Comparator();
     $schemaDiff = $comparator->compare($fromSchema, $toSchema);
     if ($saveMode) {
         $statements = $schemaDiff->toSaveSql($this->platform);
     } else {
         $statements = $schemaDiff->toSql($this->platform);
     }
     $this->build($statements);
     return $statements;
 }
開發者ID:proai,項目名稱:laravel-datamapper,代碼行數:21,代碼來源:Builder.php

示例14: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $sm = $this->connection->getSchemaManager();
     $schema = $this->schema->getSchema();
     $existing = new DoctrineSchema($sm->listTables(), []);
     $comparator = new Comparator();
     $difference = $comparator->compare($existing, $schema);
     $count = 0;
     if ($statements = $difference->toSql($sm->getDatabasePlatform())) {
         foreach ($statements as $statement) {
             $this->connection->exec($statement);
             $count++;
         }
         $output->writeln(sprintf('Executed <info>%d</info> queries', $count));
     } else {
         $output->writeln('<comment>Schema is already up to date.</comment>');
     }
 }
開發者ID:nickschuch,項目名稱:tl,代碼行數:21,代碼來源:Install.php

示例15: up

 public function up(Schema $schema)
 {
     \Database::query('UPDATE Config SET configNamespace="" WHERE configNamespace IS NULL');
     $config = $schema->getTable('Config');
     $fromConfig = clone $config;
     $db = \Database::get();
     $platform = $db->getDatabasePlatform();
     $config->dropPrimaryKey();
     $config->setPrimaryKey(array('configNamespace', 'configGroup', 'configItem'));
     $comparator = new Comparator();
     $diff = $comparator->diffTable($fromConfig, $config);
     $sql = $platform->getAlterTableSQL($diff);
     if (is_array($sql) && count($sql)) {
         foreach ($sql as $q) {
             $db->query($q);
         }
     }
 }
開發者ID:vipkailiai,項目名稱:FCVOVA,代碼行數:18,代碼來源:Version5704.php


注:本文中的Doctrine\DBAL\Schema\Comparator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。