コード例 #1
0
 /**
  * Perform add/change/create operations on tables and fields in an
  * optimized, non-interactive, mode using the original doctrine
  * SchemaManager ->toSaveSql() method.
  *
  * @param bool $createOnly
  * @return array
  */
 public function install(bool $createOnly = false) : array
 {
     $result = [];
     $schemaDiff = $this->buildSchemaDiff(false);
     $schemaDiff->removedTables = [];
     foreach ($schemaDiff->changedTables as $key => $changedTable) {
         $schemaDiff->changedTables[$key]->removedColumns = [];
         $schemaDiff->changedTables[$key]->removedIndexes = [];
         // With partial ext_tables.sql files the SchemaManager is detecting
         // existing columns as false positives for a column rename. In this
         // context every rename is actually a new column.
         foreach ($changedTable->renamedColumns as $columnName => $renamedColumn) {
             $changedTable->addedColumns[$renamedColumn->getName()] = GeneralUtility::makeInstance(Column::class, $renamedColumn->getName(), $renamedColumn->getType(), array_diff_key($renamedColumn->toArray(), ['name', 'type']));
             unset($changedTable->renamedColumns[$columnName]);
         }
         if ($createOnly) {
             $schemaDiff->changedTables[$key]->changedColumns = [];
             $schemaDiff->changedTables[$key]->renamedIndexes = [];
         }
     }
     $statements = $schemaDiff->toSaveSql($this->connection->getDatabasePlatform());
     foreach ($statements as $statement) {
         try {
             $this->connection->executeUpdate($statement);
             $result[$statement] = '';
         } catch (DBALException $e) {
             $result[$statement] = $e->getPrevious()->getMessage();
         }
     }
     return $result;
 }