コード例 #1
0
 public function onSchemaAlterTable(SchemaAlterTableEventArgs $args)
 {
     $platform = $args->getPlatform();
     $diff = $args->getTableDiff();
     $spatialIndexes = array();
     $addedIndexes = array();
     $changedIndexes = array();
     foreach ($diff->addedIndexes as $index) {
         if (!$index->hasFlag('SPATIAL')) {
             $addedIndexes[] = $index;
         } else {
             $spatialIndexes[] = $index;
         }
     }
     foreach ($diff->changedIndexes as $index) {
         if (!$index->hasFlag('SPATIAL')) {
             $changedIndexes[] = $index;
         } else {
             $diff->removedIndexes[] = $index;
             $spatialIndexes[] = $index;
         }
     }
     $diff->addedIndexes = $addedIndexes;
     $diff->changedIndexes = $changedIndexes;
     $spatialIndexSqlGenerator = new SpatialIndexSqlGenerator($platform);
     $sql = array();
     $table = new Identifier(false !== $diff->newName ? $diff->newName : $diff->name);
     $tableName = $table->getQuotedName($platform);
     foreach ($spatialIndexes as $index) {
         $sql[] = $spatialIndexSqlGenerator->getSql($index, $tableName);
     }
     $args->addSql($sql);
 }
コード例 #2
0
 /**
  * Listener for alter table events. This intercepts the building
  * of ALTER TABLE statements and adds the required statements to
  * change the ENGINE type on MySQL platforms if necessary.
  *
  * @param \Doctrine\DBAL\Event\SchemaAlterTableEventArgs $event
  * @return bool
  * @throws \Doctrine\DBAL\DBALException
  */
 public function onSchemaAlterTable(SchemaAlterTableEventArgs $event)
 {
     /** @var TableDiff $tableDiff */
     $tableDiff = $event->getTableDiff();
     // Original Doctrine TableDiff without table options, continue default processing
     if (!$tableDiff instanceof TableDiff) {
         return false;
     }
     // Table options are only supported on MySQL, continue default processing
     if (!$event->getPlatform() instanceof MySqlPlatform) {
         return false;
     }
     // No changes in table options, continue default processing
     if (count($tableDiff->getTableOptions()) === 0) {
         return false;
     }
     $quotedTableName = $tableDiff->getName($event->getPlatform())->getQuotedName($event->getPlatform());
     // Add an ALTER TABLE statement to change the table engine to the list of statements.
     if ($tableDiff->hasTableOption('engine')) {
         $statement = 'ALTER TABLE ' . $quotedTableName . ' ENGINE = ' . $tableDiff->getTableOption('engine');
         $event->addSql($statement);
     }
     // continue default processing for all other changes.
     return false;
 }
コード例 #3
0
 /**
  * Insures the name of the altered table is quoted according to the platform/
  * 
  * @param SchemaAlterTableEventArgs $args
  */
 public function onSchemaAlterTable(SchemaAlterTableEventArgs $args)
 {
     $tableDiff = $args->getTableDiff();
     $tableDiff->name = $tableDiff->fromTable->getQuotedName($args->getPlatform());
 }