Exemplo n.º 1
0
 /**
  * Returns a ezcDbSchemaDiff object containing the differences between the schemas $fromSchema and $toSchema.
  *
  * The returned diferences are returned in such a way that they contain the
  * operations to change the schema stored in $fromSchema to the schema that is
  * stored in $toSchema.
  *
  * @param ezcDbSchema $fromSchema
  * @param ezcDbSchema $toSchema
  *
  * @return ezcDbSchemaDiff
  */
 public static final function compareSchemas(ezcDbSchema $fromSchema, ezcDbSchema $toSchema)
 {
     $diff = new ezcDbSchemaDiff();
     $fromSchema = $fromSchema->getSchema();
     $toSchema = $toSchema->getSchema();
     foreach ($toSchema as $tableName => $tableDefinition) {
         if (!isset($fromSchema[$tableName])) {
             $diff->newTables[$tableName] = $tableDefinition;
         } else {
             $tableDifferences = ezcDbSchemaComparator::diffTable($fromSchema[$tableName], $tableDefinition);
             if ($tableDifferences !== false) {
                 $diff->changedTables[$tableName] = $tableDifferences;
             }
         }
     }
     /* Check if there are tables removed */
     foreach ($fromSchema as $tableName => $tableDefinition) {
         if (!isset($toSchema[$tableName])) {
             $diff->removedTables[$tableName] = true;
         }
     }
     return $diff;
 }