/**
  * Compare current and expected database schemas and return the database differences
  *
  * @return array database differences
  */
 protected function getDatabaseDifferences()
 {
     $expectedSchema = $this->expectedSchemaService->getExpectedDatabaseSchema();
     $currentSchema = $this->schemaMigrationService->getFieldDefinitions_database();
     // Difference from expected to current
     return $this->schemaMigrationService->getDatabaseExtra($expectedSchema, $currentSchema);
 }
Exemplo n.º 2
0
 /**
  * Perform necessary database schema migrations
  *
  * @param SchemaUpdateType[] $schemaUpdateTypes List of permitted schema update types
  * @return SchemaUpdateResult Result of the schema update
  */
 public function updateSchema(array $schemaUpdateTypes)
 {
     $expectedSchema = $this->expectedSchemaService->getExpectedDatabaseSchema();
     $currentSchema = $this->schemaMigrationService->getFieldDefinitions_database();
     $addCreateChange = $this->schemaMigrationService->getDatabaseExtra($expectedSchema, $currentSchema);
     $dropRename = $this->schemaMigrationService->getDatabaseExtra($currentSchema, $expectedSchema);
     $updateStatements = array();
     ArrayUtility::mergeRecursiveWithOverrule($updateStatements, $this->schemaMigrationService->getUpdateSuggestions($addCreateChange));
     ArrayUtility::mergeRecursiveWithOverrule($updateStatements, $this->schemaMigrationService->getUpdateSuggestions($dropRename, 'remove'));
     $updateResult = new SchemaUpdateResult();
     foreach ($schemaUpdateTypes as $schemaUpdateType) {
         $statementTypes = $this->getStatementTypes($schemaUpdateType);
         foreach ($statementTypes as $statementType) {
             if (isset($updateStatements[$statementType])) {
                 $statements = $updateStatements[$statementType];
                 $result = $this->schemaMigrationService->performUpdateQueries($statements, array_combine(array_keys($statements), array_fill(0, count($statements), TRUE)));
                 if ($result === TRUE) {
                     $updateResult->addPerformedUpdates($schemaUpdateType, count($statements));
                 } elseif (is_array($result)) {
                     $updateResult->addErrors($schemaUpdateType, $result);
                 }
             }
         }
     }
     return $updateResult;
 }