本文整理汇总了PHP中Doctrine\ORM\Tools\SchemaTool::getSchemaFromMetadata方法的典型用法代码示例。如果您正苦于以下问题:PHP SchemaTool::getSchemaFromMetadata方法的具体用法?PHP SchemaTool::getSchemaFromMetadata怎么用?PHP SchemaTool::getSchemaFromMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Tools\SchemaTool
的用法示例。
在下文中一共展示了SchemaTool::getSchemaFromMetadata方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
示例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);
}
}
示例3: getTaggingSchema
protected function getTaggingSchema($em)
{
$tool = new \Doctrine\ORM\Tools\SchemaTool($em);
$classes = array($em->getClassMetadata('Poc\\PocPlugins\\Tagging\\Driver\\Doctrine2\\Entities\\Cache'), $em->getClassMetadata('Poc\\PocPlugins\\Tagging\\Driver\\Doctrine2\\Entities\\CacheTag'), $em->getClassMetadata('Poc\\PocPlugins\\Tagging\\Driver\\Doctrine2\\Entities\\Tag'));
$schema = $tool->getSchemaFromMetadata($classes);
return $schema;
}
示例4: down
/**
* Down method
*
* @param Schema $schema
*/
public function down(Schema $schema)
{
if (Version::isSupportGetInstanceFunction()) {
$app = Application::getInstance();
$meta = $this->getMetadata($app['orm.em']);
$tool = new SchemaTool($app['orm.em']);
$schemaFromMetadata = $tool->getSchemaFromMetadata($meta);
// テーブル削除
foreach ($schemaFromMetadata->getTables() as $table) {
if ($schema->hasTable($table->getName())) {
$schema->dropTable($table->getName());
}
}
// シーケンス削除
foreach ($schemaFromMetadata->getSequences() as $sequence) {
if ($schema->hasSequence($sequence->getName())) {
$schema->dropSequence($sequence->getName());
}
}
} else {
if ($schema->hasTable(self::MAKER)) {
$schema->dropTable(self::MAKER);
}
if ($schema->hasTable(self::PRODUCTMAKER)) {
$schema->dropTable(self::PRODUCTMAKER);
}
}
if ($this->connection->getDatabasePlatform()->getName() == 'postgresql') {
foreach ($this->sequence as $sequence) {
if ($schema->hasSequence($sequence)) {
$schema->dropSequence($sequence);
}
}
}
}
示例5: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$configuration = $this->_getMigrationConfiguration($input, $output);
$em = $this->getHelper('em')->getEntityManager();
$conn = $em->getConnection();
$platform = $conn->getDatabasePlatform();
$metadata = $em->getMetadataFactory()->getAllMetadata();
if (empty($metadata)) {
$output->writeln('No mapping information to process.', 'ERROR');
return;
}
$tool = new SchemaTool($em);
$fromSchema = $conn->getSchemaManager()->createSchema();
$toSchema = $tool->getSchemaFromMetadata($metadata);
$up = $this->_buildCodeFromSql($configuration, $fromSchema->getMigrateToSql($toSchema, $platform));
$down = $this->_buildCodeFromSql($configuration, $fromSchema->getMigrateFromSql($toSchema, $platform));
if ( ! $up && ! $down) {
$output->writeln('No changes detected in your mapping information.', 'ERROR');
return;
}
$version = date('YmdHis');
$path = $this->_generateMigration($configuration, $input, $version, $up, $down);
$output->writeln(sprintf('Generated new migration class to "<info>%s</info>" from schema differences.', $path));
}
示例6: down
/**
* remove table.
*
* @param Schema $schema
*/
public function down(Schema $schema)
{
//current version >= 3.0.9
if (Version::isSupportGetInstanceFunction()) {
$app = Application::getInstance();
$meta = $this->getMetadata($app['orm.em']);
$tool = new SchemaTool($app['orm.em']);
$schemaFromMetadata = $tool->getSchemaFromMetadata($meta);
// テーブル削除
foreach ($schemaFromMetadata->getTables() as $table) {
if ($schema->hasTable($table->getName())) {
$schema->dropTable($table->getName());
}
}
// シーケンス削除
foreach ($schemaFromMetadata->getSequences() as $sequence) {
if ($schema->hasSequence($sequence->getName())) {
$schema->dropSequence($sequence->getName());
}
}
//for delete sequence in postgresql
if ($this->connection->getDatabasePlatform()->getName() == 'postgresql') {
$schema->dropSequence('plg_related_product_id_seq');
}
} else {
// this down() migration is auto-generated, please modify it to your needs
$schema->dropTable(self::NAME);
$schema->dropSequence('plg_related_product_id_seq');
}
}
示例7: down
/**
* Remove data.
*
* @param Schema $schema
*/
public function down(Schema $schema)
{
if (Version::isSupportGetInstanceFunction()) {
$app = Application::getInstance();
$meta = $this->getMetadata($app['orm.em']);
$tool = new SchemaTool($app['orm.em']);
$schemaFromMetadata = $tool->getSchemaFromMetadata($meta);
// テーブル削除
foreach ($schemaFromMetadata->getTables() as $table) {
if ($schema->hasTable($table->getName())) {
$schema->dropTable($table->getName());
}
}
// シーケンス削除
foreach ($schemaFromMetadata->getSequences() as $sequence) {
if ($schema->hasSequence($sequence->getName())) {
$schema->dropSequence($sequence->getName());
}
}
} else {
// this down() migration is auto-generated, please modify it to your needs
$schema->dropTable(self::NAME);
$schema->dropSequence('plg_recommend_product_recommend_product_id_seq');
}
}
示例8: testNullDefaultNotAddedToCustomSchemaOptions
public function testNullDefaultNotAddedToCustomSchemaOptions()
{
$em = $this->_getTestEntityManager();
$schemaTool = new SchemaTool($em);
$classes = array($em->getClassMetadata('Doctrine\\Tests\\Models\\NullDefault\\NullDefaultColumn'));
$customSchemaOptions = $schemaTool->getSchemaFromMetadata($classes)->getTable('NullDefaultColumn')->getColumn('nullDefault')->getCustomSchemaOptions();
$this->assertSame(array(), $customSchemaOptions);
}
示例9: createSchema
/**
* {@inheritdoc}
*/
public function createSchema()
{
$metadata = $this->entityManager->getMetadataFactory()->getAllMetadata();
if (empty($metadata)) {
throw new \UnexpectedValueException('No mapping information to process');
}
$tool = new SchemaTool($this->entityManager);
return $tool->getSchemaFromMetadata($metadata);
}
示例10: testPostGenerateEvents
/**
* @group DDC-283
*/
public function testPostGenerateEvents()
{
$listener = new GenerateSchemaEventListener();
$em = $this->_getTestEntityManager();
$em->getEventManager()->addEventListener(array(ToolEvents::postGenerateSchemaTable, ToolEvents::postGenerateSchema), $listener);
$schemaTool = new SchemaTool($em);
$classes = array($em->getClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsAddress'), $em->getClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsArticle'), $em->getClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsComment'), $em->getClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsEmployee'), $em->getClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsGroup'), $em->getClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsPhonenumber'), $em->getClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser'));
$schema = $schemaTool->getSchemaFromMetadata($classes);
$this->assertEquals(count($classes), $listener->tableCalls);
$this->assertTrue($listener->schemaCalled);
}
示例11: execute
/**
* Generate sql queries and create new migration class
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @return null
* @throws \InvalidArgumentException
*/
public function execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output)
{
$isDbalOld = DbalVersion::compare('2.2.0') > 0;
$configuration = $this->getMigrationConfiguration($input, $output);
$em = $this->getHelper('em')->getEntityManager();
$conn = $em->getConnection();
$platform = $conn->getDatabasePlatform();
$metadata = $em->getMetadataFactory()->getAllMetadata();
if (empty($metadata)) {
$output->writeln('No mapping information to process.', 'ERROR');
return;
}
if ($filterExpr = $input->getOption('filter-expression')) {
if ($isDbalOld) {
throw new \InvalidArgumentException('The "--filter-expression" option can only be used as of Doctrine DBAL 2.2');
}
$conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpr);
}
$tool = new SchemaTool($em);
$fromSchema = $conn->getSchemaManager()->createSchema();
$toSchema = $tool->getSchemaFromMetadata($metadata);
foreach ($fromSchema->getTables() as $tableName => $table) {
if (!$toSchema->hasTable($tableName)) {
// if drop the table from the $fromSchema, could not generate the DROP TABLE sql
$fromSchema->dropTable($tableName);
}
}
//Not using value from options, because filters can be set from config.yml
if (!$isDbalOld && ($filterExpr = $conn->getConfiguration()->getFilterSchemaAssetsExpression())) {
$tableNames = $toSchema->getTableNames();
foreach ($tableNames as $tableName) {
$tableName = substr($tableName, strpos($tableName, '.') + 1);
if (!preg_match($filterExpr, $tableName)) {
$toSchema->dropTable($tableName);
}
}
}
$up = $this->buildCodeFromSql($configuration, $fromSchema->getMigrateToSql($toSchema, $platform));
$down = $this->buildCodeFromSql($configuration, $fromSchema->getMigrateFromSql($toSchema, $platform));
if (!$up && !$down) {
$output->writeln('No changes detected in your mapping information.', 'ERROR');
return;
}
$version = date('YmdHis');
$path = $this->generateMigration($configuration, $input, $version, $up, $down);
$output->writeln(sprintf('Generated new migration class to "<info>%s</info>" from schema differences.', $path));
}
示例12: assertCreatedSchemaNeedsNoUpdates
public function assertCreatedSchemaNeedsNoUpdates($classes)
{
$classMetadata = array();
foreach ($classes as $class) {
$classMetadata[] = $this->_em->getClassMetadata($class);
}
$schemaTool = new Tools\SchemaTool($this->_em);
$schemaTool->dropSchema($classMetadata);
$schemaTool->createSchema($classMetadata);
$sm = $this->_em->getConnection()->getSchemaManager();
$fromSchema = $sm->createSchema();
$toSchema = $schemaTool->getSchemaFromMetadata($classMetadata);
$comparator = new \Doctrine\DBAL\Schema\Comparator();
$schemaDiff = $comparator->compare($fromSchema, $toSchema);
$sql = $schemaDiff->toSql($this->_em->getConnection()->getDatabasePlatform());
$this->assertEquals(0, count($sql));
}
示例13: down
/**
* Down method.
*
* @param Schema $schema
*/
public function down(Schema $schema)
{
if (Version::isSupportMethod()) {
$app = Application::getInstance();
$meta = $this->getMetadata($app['orm.em']);
$tool = new SchemaTool($app['orm.em']);
$schemaFromMetadata = $tool->getSchemaFromMetadata($meta);
// テーブル削除
foreach ($schemaFromMetadata->getTables() as $table) {
if ($schema->hasTable($table->getName())) {
$schema->dropTable($table->getName());
}
}
} else {
if ($schema->hasTable(self::TABLE)) {
$schema->dropTable(self::TABLE);
}
}
}
示例14: generateDatabaseVersionTable
/**
* Generates table for entity DatabaseVersion. Does not check if this table already exists.
*
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\ORM\ORMException
* @throws \Exception
*/
private function generateDatabaseVersionTable()
{
$metadata = $this->entityManager->getMetadataFactory()->getAllMetadata();
$tool = new SchemaTool($this->entityManager);
$schema = $tool->getSchemaFromMetadata($metadata);
$versionTable = null;
foreach ($schema->getTables() as $table) {
if ($table->getShortestName($schema->getName()) == self::VERSION_TABLE) {
$versionTable = $table;
break;
}
}
if ($versionTable) {
$platform = $this->entityManager->getConnection()->getDatabasePlatform();
$sql = $platform->getCreateTableSQL($versionTable, AbstractPlatform::CREATE_INDEXES);
$this->entityManager->getConnection()->executeQuery($sql[0]);
} else {
throw new \Exception('Error: Couldn\'t find database version entity definition.');
}
}
示例15: testForeignKeyOnSTIWithMultipleMapping
/**
* @group DDC-2138
*/
public function testForeignKeyOnSTIWithMultipleMapping()
{
$em = $this->_em;
$schemaTool = new SchemaTool($em);
$classes = array($em->getClassMetadata(__NAMESPACE__ . '\\DDC2138User'), $em->getClassMetadata(__NAMESPACE__ . '\\DDC2138Structure'), $em->getClassMetadata(__NAMESPACE__ . '\\DDC2138UserFollowedObject'), $em->getClassMetadata(__NAMESPACE__ . '\\DDC2138UserFollowedStructure'), $em->getClassMetadata(__NAMESPACE__ . '\\DDC2138UserFollowedUser'));
$schema = $schemaTool->getSchemaFromMetadata($classes);
$this->assertTrue($schema->hasTable('users_followed_objects'), "Table users_followed_objects should exist.");
/* @var $table \Doctrine\DBAL\Schema\Table */
$table = $schema->getTable('users_followed_objects');
$this->assertTrue($table->columnsAreIndexed(array('object_id')));
$this->assertTrue($table->columnsAreIndexed(array('user_id')));
$foreignKeys = $table->getForeignKeys();
$this->assertCount(1, $foreignKeys, 'user_id column has to have FK, but not object_id');
/* @var $fk \Doctrine\DBAL\Schema\ForeignKeyConstraint */
$fk = reset($foreignKeys);
$this->assertEquals('users', $fk->getForeignTableName());
$localColumns = $fk->getLocalColumns();
$this->assertContains('user_id', $localColumns);
$this->assertCount(1, $localColumns);
}