/** * Compare a previous definition with the currently parsed definition * * @param string $table_name name of the table * @param array $current_definition multi dimensional array that contains the current definition * @param array $previous_definition multi dimensional array that contains the previous definition * @param array &$defined_tables table names in the schema * * @return array|MDB2_Error array of changes on success, or a error object * @access public */ function compareTableDefinitions($table_name, $current_definition, $previous_definition, &$defined_tables) { $changes = array(); if (is_array($current_definition)) { $was_table_name = $table_name; if (!empty($current_definition['was'])) { $was_table_name = $current_definition['was']; } if (!empty($previous_definition[$was_table_name])) { $changes['change'][$was_table_name] = array(); if ($was_table_name != $table_name) { $changes['change'][$was_table_name] = array('name' => $table_name); } if (!empty($defined_tables[$was_table_name])) { return $this->raiseError(MDB2_SCHEMA_ERROR_INVALID, null, null, 'the table "' . $was_table_name . '" was specified for more than one table of the database'); } $defined_tables[$was_table_name] = true; if (!empty($current_definition['fields']) && is_array($current_definition['fields'])) { $previous_fields = array(); if (isset($previous_definition[$was_table_name]['fields']) && is_array($previous_definition[$was_table_name]['fields'])) { $previous_fields = $previous_definition[$was_table_name]['fields']; } $change = $this->compareTableFieldsDefinitions($table_name, $current_definition['fields'], $previous_fields); if (PEAR::isError($change)) { return $change; } if (!empty($change)) { $changes['change'][$was_table_name] = MDB2_Schema::arrayMergeClobber($changes['change'][$was_table_name], $change); } } if (!empty($current_definition['indexes']) && is_array($current_definition['indexes'])) { $previous_indexes = array(); if (isset($previous_definition[$was_table_name]['indexes']) && is_array($previous_definition[$was_table_name]['indexes'])) { $previous_indexes = $previous_definition[$was_table_name]['indexes']; } $change = $this->compareTableIndexesDefinitions($table_name, $current_definition['indexes'], $previous_indexes); if (PEAR::isError($change)) { return $change; } if (!empty($change)) { $changes['change'][$was_table_name]['indexes'] = $change; } } if (empty($changes['change'][$was_table_name])) { unset($changes['change'][$was_table_name]); } if (empty($changes['change'])) { unset($changes['change']); } } else { if ($table_name != $was_table_name) { return $this->raiseError(MDB2_SCHEMA_ERROR_INVALID, null, null, 'it was specified a previous table name ("' . $was_table_name . '") for table "' . $table_name . '" that does not exist'); } $changes['add'][$table_name] = true; } } return $changes; }