当前位置: 首页>>代码示例>>PHP>>正文


PHP Schema::getTables方法代码示例

本文整理汇总了PHP中Doctrine\DBAL\Schema\Schema::getTables方法的典型用法代码示例。如果您正苦于以下问题:PHP Schema::getTables方法的具体用法?PHP Schema::getTables怎么用?PHP Schema::getTables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\DBAL\Schema\Schema的用法示例。


在下文中一共展示了Schema::getTables方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: up

 public function up(Schema $schema)
 {
     // this up() migration is auto-generated, please modify it to your needs
     $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'.");
     $tables = $schema->getTables();
     foreach ($tables as $table) {
         if ($table->getName() === "os_user") {
             if ($table->hasForeignKey('FK_7BB0CD52BF396750')) {
                 $this->addSql("ALTER TABLE os_user DROP FOREIGN KEY FK_7BB0CD52BF396750");
             }
         } else {
             if ($table->getName() === "os_clock") {
                 if (!$table->hasColumn("uid")) {
                     $this->addSql("ALTER TABLE os_clock ADD uid INT DEFAULT NULL");
                     $this->addSql("UPDATE os_clock SET uid = id");
                 }
                 if (!$table->hasForeignKey('FK_34E85465539B0606')) {
                     $this->addSql("ALTER TABLE os_clock ADD CONSTRAINT FK_34E85465539B0606 FOREIGN KEY (uid) REFERENCES os_user (id)");
                 }
                 if (!$table->hasIndex('UNIQ_34E85465539B0606')) {
                     $this->addSql("CREATE UNIQUE INDEX UNIQ_34E85465539B0606 ON os_clock (uid)");
                 }
             }
         }
     }
 }
开发者ID:edubacco,项目名称:OpenSkedge,代码行数:26,代码来源:Version20130616122810.php

示例2: changePrimaryKeyType

 /**
  * @param Schema   $schema
  * @param QueryBag $queries
  * @param string   $tableName
  * @param string   $columnName
  * @param string   $type
  *
  * @throws \Exception
  */
 public function changePrimaryKeyType(Schema $schema, QueryBag $queries, $tableName, $columnName, $type)
 {
     $targetColumn = $schema->getTable($tableName)->getColumn($columnName);
     $type = Type::getType($type);
     if ($targetColumn->getType() === $type) {
         return;
     }
     /** @var ForeignKeyConstraint[] $foreignKeys */
     $foreignKeys = [];
     foreach ($schema->getTables() as $table) {
         /** @var ForeignKeyConstraint[] $tableForeignKeys */
         $tableForeignKeys = array_filter($table->getForeignKeys(), function (ForeignKeyConstraint $tableForeignKey) use($tableName, $columnName) {
             if ($tableForeignKey->getForeignTableName() !== $tableName) {
                 return false;
             }
             return $tableForeignKey->getForeignColumns() === [$columnName];
         });
         foreach ($tableForeignKeys as $tableForeignKey) {
             $foreignKeys[$tableForeignKey->getName()] = $tableForeignKey;
             $foreignKeyTableName = $tableForeignKey->getLocalTable()->getName();
             $foreignKeyColumnNames = $tableForeignKey->getLocalColumns();
             $queries->addPreQuery($this->platform->getDropForeignKeySQL($tableForeignKey, $foreignKeyTableName));
             $column = $schema->getTable($foreignKeyTableName)->getColumn(reset($foreignKeyColumnNames));
             if ($column instanceof ExtendColumn) {
                 $column->disableExtendOptions()->setType($type)->enableExtendOptions();
             } else {
                 $column->setType($type);
             }
         }
     }
     $targetColumn->setType($type);
     foreach ($foreignKeys as $foreignKey) {
         $queries->addPostQuery($this->platform->getCreateForeignKeySQL($foreignKey, $foreignKey->getLocalTable()));
     }
 }
开发者ID:Maksold,项目名称:platform,代码行数:44,代码来源:ChangeTypeExtension.php

示例3: assertSchemaTypes

 protected function assertSchemaTypes(Schema $schema)
 {
     foreach ($schema->getTables() as $table) {
         $this->assertInstanceOf('Oro\\Bundle\\EntityExtendBundle\\Migration\\Schema\\ExtendTable', $table);
         foreach ($table->getColumns() as $column) {
             $this->assertInstanceOf('Oro\\Bundle\\EntityExtendBundle\\Migration\\Schema\\ExtendColumn', $column);
         }
     }
 }
开发者ID:xamin123,项目名称:platform,代码行数:9,代码来源:ExtendSchemaTest.php

示例4: getTargetSchema

 /**
  * Return schema with Diamante tables
  * @param Schema $schema
  * @param array $entitiesTableName
  *
  * @return Schema
  */
 protected function getTargetSchema(Schema $schema, array $entitiesTableName)
 {
     $allTables = $schema->getTables();
     $targetTables = array();
     foreach ($allTables as $tableName => $table) {
         if (in_array($tableName, $entitiesTableName)) {
             $targetTables[$tableName] = $table;
         }
     }
     return new Schema($targetTables);
 }
开发者ID:northdakota,项目名称:diamantedesk-application,代码行数:18,代码来源:AbstractCommand.php

示例5: getExistingEnumTables

 /**
  * @param Schema $schema
  *
  * @return string[]
  */
 protected function getExistingEnumTables(Schema $schema)
 {
     $result = [];
     foreach ($schema->getTables() as $table) {
         $tableName = $table->getName();
         if (strrpos($tableName, 'oro_enum') === 0 && $tableName !== 'oro_enum_value_trans') {
             $result[] = $tableName;
         }
     }
     return $result;
 }
开发者ID:snorchel,项目名称:platform,代码行数:16,代码来源:MigrateOptionSetsToEnums.php

示例6: testRemoveNamespacedAssets

 /**
  * @group DBAL-204
  */
 public function testRemoveNamespacedAssets()
 {
     $config = new SchemaConfig();
     $config->setName("test");
     $schema = new Schema(array(), array(), $config);
     $schema->createTable("test.test");
     $schema->createTable("foo.bar");
     $schema->createTable("baz");
     $schema->visit(new RemoveNamespacedAssets());
     $tables = $schema->getTables();
     $this->assertEquals(array("test.test", "test.baz"), array_keys($tables), "Only 2 tables should be present, both in 'test' namespace.");
 }
开发者ID:Werelds,项目名称:FrameworkBenchmarks,代码行数:15,代码来源:RemoveNamespacedAssetsTest.php

示例7: renameCustomEntityTables

 protected function renameCustomEntityTables(Schema $schema, QueryBag $queries)
 {
     $tables = $schema->getTables();
     foreach ($tables as $table) {
         if (strpos($table->getName(), self::OLD_CUSTOM_TABLE_PREFIX) === 0) {
             $oldTableName = $table->getName();
             $oldTablePrefix = strpos($oldTableName, self::OLD_CUSTOM_TABLE_PREFIX . 'extendentity') === 0 ? self::OLD_CUSTOM_TABLE_PREFIX . 'extendentity' : self::OLD_CUSTOM_TABLE_PREFIX;
             $newTableName = ExtendDbIdentifierNameGenerator::CUSTOM_TABLE_PREFIX . substr($oldTableName, strlen($oldTablePrefix));
             $this->renameExtension->renameTable($schema, $queries, $oldTableName, $newTableName);
         }
     }
 }
开发者ID:Maksold,项目名称:platform,代码行数:12,代码来源:RenameExtendTablesAndColumns.php

示例8: up

 /**
  * @param Schema $schema
  */
 public function up(Schema $schema)
 {
     // Check if the tables already exist
     $tables = $schema->getTables();
     foreach ($tables as $table) {
         if ($table->getName() === 'tags') {
             return;
         }
     }
     $this->createTagsTable($schema);
     $this->createShortUrlsInTagsTable($schema);
 }
开发者ID:shlinkio,项目名称:shlink,代码行数:15,代码来源:Version20160820191203.php

示例9: testAddTable

 public function testAddTable()
 {
     $tableName = "public.foo";
     $table = new Table($tableName);
     $schema = new Schema(array($table));
     $this->assertTrue($schema->hasTable($tableName));
     $tables = $schema->getTables();
     $this->assertTrue(isset($tables[$tableName]));
     $this->assertSame($table, $tables[$tableName]);
     $this->assertSame($table, $schema->getTable($tableName));
     $this->assertTrue($schema->hasTable($tableName));
 }
开发者ID:selimcr,项目名称:servigases,代码行数:12,代码来源:SchemaTest.php

示例10: truncateTables

 /**
  * Truncate all known tables
  *
  * @param \Doctrine\ORM\EntityManager $entityManager
  * @return void
  */
 public function truncateTables($entityManager)
 {
     $connection = $entityManager->getConnection();
     $tables = self::$databaseSchema->getTables();
     switch ($connection->getDatabasePlatform()->getName()) {
         case 'mysql':
             $sql = 'SET FOREIGN_KEY_CHECKS=0;';
             foreach ($tables as $table) {
                 $sql .= 'TRUNCATE `' . $table->getName() . '`;';
             }
             $sql .= 'SET FOREIGN_KEY_CHECKS=1;';
             $connection->executeQuery($sql);
             break;
         case 'postgresql':
         default:
             foreach ($tables as $table) {
                 $sql = 'TRUNCATE ' . $table->getName() . ' CASCADE;';
                 $connection->executeQuery($sql);
             }
             break;
     }
 }
开发者ID:JupiterSky,项目名称:liketest,代码行数:28,代码来源:DatabaseContext.php

示例11: getDiff

 /**
  * @param Schema $targetSchema
  * @param \Doctrine\DBAL\Connection $connection
  * @return \Doctrine\DBAL\Schema\SchemaDiff
  */
 protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection)
 {
     $platform = $connection->getDatabasePlatform();
     $platform->registerDoctrineTypeMapping('tinyint unsigned', 'integer');
     $platform->registerDoctrineTypeMapping('smallint unsigned', 'integer');
     $platform->registerDoctrineTypeMapping('varchar ', 'string');
     // with sqlite autoincrement columns is of type integer
     foreach ($targetSchema->getTables() as $table) {
         foreach ($table->getColumns() as $column) {
             if ($column->getType() instanceof BigIntType && $column->getAutoincrement()) {
                 $column->setType(Type::getType('integer'));
             }
         }
     }
     return parent::getDiff($targetSchema, $connection);
 }
开发者ID:GitHubUser4234,项目名称:core,代码行数:21,代码来源:SQLiteMigrator.php

示例12: checkMigrate

 /**
  * @param Schema $targetSchema
  * @throws \OC\DB\MigrationException
  */
 public function checkMigrate(Schema $targetSchema)
 {
     /**
      * @var \Doctrine\DBAL\Schema\Table[] $tables
      */
     $tables = $targetSchema->getTables();
     $existingTables = $this->connection->getSchemaManager()->listTableNames();
     foreach ($tables as $table) {
         if (strpos($table->getName(), '.')) {
             list(, $tableName) = explode('.', $table->getName());
         } else {
             $tableName = $table->getName();
         }
         // don't need to check for new tables
         if (array_search($tableName, $existingTables) !== false) {
             $this->checkTableMigrate($table);
         }
     }
 }
开发者ID:Romua1d,项目名称:core,代码行数:23,代码来源:migrator.php

示例13: checkMigrate

 /**
  * @param Schema $targetSchema
  * @throws \OC\DB\MigrationException
  */
 public function checkMigrate(Schema $targetSchema)
 {
     /**
      * @var \Doctrine\DBAL\Schema\Table[] $tables
      */
     $tables = $targetSchema->getTables();
     $this->connection->getConfiguration()->setFilterSchemaAssetsExpression('/^' . $this->config->getSystemValue('dbtableprefix', 'oc_') . '/');
     $existingTables = $this->connection->getSchemaManager()->listTableNames();
     foreach ($tables as $table) {
         if (strpos($table->getName(), '.')) {
             list(, $tableName) = explode('.', $table->getName());
         } else {
             $tableName = $table->getName();
         }
         // don't need to check for new tables
         if (array_search($tableName, $existingTables) !== false) {
             $this->checkTableMigrate($table);
         }
     }
 }
开发者ID:riso,项目名称:owncloud-core,代码行数:24,代码来源:migrator.php

示例14: getForeignKeyHandlingSql

 /**
  * This serves a rather strange use case: renaming columns used in FK constraints.
  *
  * For a column that is used in a FK constraint to be renamed, the FK constraint has to be
  * dropped first, then the column can be renamed and last the FK constraint needs to be
  * added back (using the new name, of course).
  *
  * This method helps with the task of handling the FK constraints during this. Given a list
  * of tables that contain columns to be renamed and a search/replace pair for the column name,
  * it will return an array with arrays with drop and add SQL statements.
  *
  * Use them like this before and after renaming the affected fields:
  *
  * // collect foreign keys pointing to "our" tables
  * $tableNames = array(...);
  * $foreignKeyHandlingSql = $this->getForeignKeyHandlingSql($schema, $tableNames, 'old_name', 'new_name');
  *
  * // drop FK constraints
  * foreach ($foreignKeyHandlingSql['drop'] as $sql) {
  *     $this->addSql($sql);
  * }
  *
  * // rename columns now
  *
  * // add back FK constraints
  * foreach ($foreignKeyHandlingSql['add'] as $sql) {
  *     $this->addSql($sql);
  * }
  *
  * @param \Doctrine\DBAL\Schema\Schema $schema
  * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
  * @param array $tableNames
  * @param string $search
  * @param string $replace
  * @return array
  */
 public static function getForeignKeyHandlingSql(\Doctrine\DBAL\Schema\Schema $schema, \Doctrine\DBAL\Platforms\AbstractPlatform $platform, $tableNames, $search, $replace)
 {
     $foreignKeyHandlingSql = array('drop' => array(), 'add' => array());
     $tables = $schema->getTables();
     foreach ($tables as $table) {
         $foreignKeys = $table->getForeignKeys();
         foreach ($foreignKeys as $foreignKey) {
             if (!in_array($table->getName(), $tableNames) && !in_array($foreignKey->getForeignTableName(), $tableNames)) {
                 continue;
             }
             $localColumns = $foreignKey->getLocalColumns();
             $foreignColumns = $foreignKey->getForeignColumns();
             if (in_array($search, $foreignColumns) || in_array($search, $localColumns)) {
                 if (in_array($foreignKey->getLocalTableName(), $tableNames)) {
                     array_walk($localColumns, function (&$value) use($search, $replace) {
                         if ($value === $search) {
                             $value = $replace;
                         }
                     });
                 }
                 if (in_array($foreignKey->getForeignTableName(), $tableNames)) {
                     array_walk($foreignColumns, function (&$value) use($search, $replace) {
                         if ($value === $search) {
                             $value = $replace;
                         }
                     });
                 }
                 $identifierConstructorCallback = function ($columnName) {
                     return new Identifier($columnName);
                 };
                 $localColumns = array_map($identifierConstructorCallback, $localColumns);
                 $foreignColumns = array_map($identifierConstructorCallback, $foreignColumns);
                 $newForeignKey = clone $foreignKey;
                 \TYPO3\Flow\Reflection\ObjectAccess::setProperty($newForeignKey, '_localColumnNames', $localColumns, true);
                 \TYPO3\Flow\Reflection\ObjectAccess::setProperty($newForeignKey, '_foreignColumnNames', $foreignColumns, true);
                 $foreignKeyHandlingSql['drop'][] = $platform->getDropForeignKeySQL($foreignKey, $table);
                 $foreignKeyHandlingSql['add'][] = $platform->getCreateForeignKeySQL($newForeignKey, $table);
             }
         }
     }
     return $foreignKeyHandlingSql;
 }
开发者ID:patrickreck,项目名称:flow-development-collection,代码行数:78,代码来源:Service.php

示例15: getDropSchema

 /**
  * {@inheritdoc}
  */
 public function getDropSchema(Schema $dropSchema)
 {
     $visitor = new DropSchemaSqlCollector($this->platform);
     $sm = $this->conn->getSchemaManager();
     $fullSchema = $sm->createSchema();
     foreach ($fullSchema->getTables() as $table) {
         if ($dropSchema->hasTable($table->getName())) {
             $visitor->acceptTable($table);
         }
         foreach ($table->getForeignKeys() as $foreignKey) {
             if (!$dropSchema->hasTable($table->getName())) {
                 continue;
             }
             if (!$dropSchema->hasTable($foreignKey->getForeignTableName())) {
                 continue;
             }
             $visitor->acceptForeignKey($table, $foreignKey);
         }
     }
     if (!$this->platform->supportsSequences()) {
         return $visitor->getQueries();
     }
     foreach ($dropSchema->getSequences() as $sequence) {
         $visitor->acceptSequence($sequence);
     }
     foreach ($dropSchema->getTables() as $table) {
         if (!$table->hasPrimaryKey()) {
             continue;
         }
         $columns = $table->getPrimaryKey()->getColumns();
         if (count($columns) > 1) {
             continue;
         }
         $checkSequence = $table->getName() . "_" . $columns[0] . "_seq";
         if ($fullSchema->hasSequence($checkSequence)) {
             $visitor->acceptSequence($fullSchema->getSequence($checkSequence));
         }
     }
     return $visitor->getQueries();
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:43,代码来源:SingleDatabaseSynchronizer.php


注:本文中的Doctrine\DBAL\Schema\Schema::getTables方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。