cvs: pear /MDB2_Schema/MDB2 Schema.php
| From: | Lukas Smith | Date: | Thu, 13 Apr 2006 15:27:21 +0000 |
| Subject: | cvs: pear /MDB2_Schema/MDB2 Schema.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-39597@lists.php.net to get a copy of this message | ||
lsmith Thu Apr 13 15:27:21 2006 UTC
Modified files:
/pear/MDB2_Schema/MDB2 Schema.php
Log:
- fixed schema comparing
http://cvs.php.net/viewcvs.cgi/pear/MDB2_Schema/MDB2/Schema.php?r1=1.67&r2=1.68&diff_format=u
Index: pear/MDB2_Schema/MDB2/Schema.php
diff -u pear/MDB2_Schema/MDB2/Schema.php:1.67 pear/MDB2_Schema/MDB2/Schema.php:1.68
--- pear/MDB2_Schema/MDB2/Schema.php:1.67 Fri Apr 7 16:41:45 2006
+++ pear/MDB2_Schema/MDB2/Schema.php Thu Apr 13 15:27:21 2006
@@ -42,7 +42,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
-// $Id: Schema.php,v 1.67 2006/04/07 16:41:45 lsmith Exp $
+// $Id: Schema.php,v 1.68 2006/04/13 15:27:21 lsmith Exp $
//
require_once 'MDB2.php';
@@ -105,6 +105,31 @@
return '0.4.3';
}
+ /**
+ * Clobbers two arrays together.
+ *
+ * @param array array that should be clobbered
+ * @param array array that should be clobbered
+ * @return array|false array on success and false on error
+ *
+ * @access public
+ * @author kc@hireability.com
+ */
+ function arrayMergeClobber($a1, $a2)
+ {
+ if (!is_array($a1) || !is_array($a2)) {
+ return false;
+ }
+ foreach ($a2 as $key => $val) {
+ if (is_array($val) && array_key_exists($key, $a1) &&
is_array($a1[$key])) {
+ $a1[$key] = MDB2_Schema::arrayMergeClobber($a1[$key], $val);
+ } else {
+ $a1[$key] = $val;
+ }
+ }
+ return $a1;
+ }
+
// }}}
// {{{ resetWarnings()
@@ -923,7 +948,7 @@
return $change;
}
if (!empty($change)) {
- $changes['tables']+= $change;
+ $changes['tables'] =
MDB2_Schema::arrayMergeClobber($changes['tables'], $change);
}
}
if (array_key_exists('tables', $previous_definition) &&
is_array($previous_definition['tables'])) {
@@ -951,7 +976,7 @@
return $change;
}
if (!empty($change)) {
- $changes['sequences']+= $change;
+ $changes['sequences'] =
MDB2_Schema::arrayMergeClobber($changes['sequences'], $change);
}
}
if (array_key_exists('sequences', $previous_definition) &&
is_array($previous_definition['sequences'])) {
@@ -1143,7 +1168,7 @@
if (array_key_exists($was_table_name, $previous_definition)) {
$changes['change'][$was_table_name] = array();
if ($was_table_name != $table_name) {
- $changes['change'][$was_table_name]+= array('name' =>
$table_name);
+ $changes['change'][$was_table_name] = array('name' =>
$table_name);
}
if (array_key_exists($was_table_name, $defined_tables)) {
return $this->raiseError(MDB2_SCHEMA_ERROR_INVALID, null, null,
@@ -1169,7 +1194,8 @@
return $change;
}
if (!empty($change)) {
- $changes['change'][$was_table_name]+= $change;
+ $changes['change'][$was_table_name]
+ =
MDB2_Schema::arrayMergeClobber($changes['change'][$was_table_name], $change);
}
}
if (array_key_exists('indexes', $current_definition) &&
is_array($current_definition['indexes'])) {
@@ -1191,7 +1217,8 @@
}
if (!empty($change)) {
if
(isset($changes['change'][$was_table_name]['indexes'])) {
- $changes['change'][$was_table_name]['indexes']+=
$change;
+ $changes['change'][$was_table_name]['indexes']
+ =
MDB2_Schema::arrayMergeClobber($changes['change'][$was_table_name]['indexes'],
$change);
} else {
$changes['change'][$was_table_name]['indexes'] =
$change;
}
@@ -1433,7 +1460,6 @@
if (empty($changes)) {
return $alterations;
}
-
if (array_key_exists('remove', $changes)) {
foreach ($changes['remove'] as $table_name => $table) {
$result = $this->db->manager->dropTable($table_name);
@@ -1583,15 +1609,16 @@
if (array_key_exists('tables', $changes) &&
array_key_exists('tables', $current_definition)) {
$current_tables = isset($current_definition['tables']) ?
$current_definition['tables'] : array();
$previous_tables = isset($previous_definition['tables']) ?
$previous_definition['tables'] : array();
- $result = $this->alterDatabaseTables($current_tables, $previous_tables, $changes);
+ $result = $this->alterDatabaseTables($current_tables, $previous_tables,
$changes['tables']);
if (is_numeric($result)) {
$alterations += $result;
}
}
+
if (!PEAR::isError($result) && array_key_exists('sequences', $changes)) {
$current_sequences = isset($current_definition['sequences']) ?
$current_definition['sequences'] : array();
$previous_sequences = isset($previous_definition['sequences']) ?
$previous_definition['sequences'] : array();
- $result = $this->alterDatabaseSequences($current_sequences, $previous_sequences,
$changes);
+ $result = $this->alterDatabaseSequences($current_sequences, $previous_sequences,
$changes['sequences']);
if (is_numeric($result)) {
$alterations += $result;
}
@@ -2022,7 +2049,8 @@
}
}
- if (is_string($previous_schema) && is_string($current_schema)
+ if (!$disable_query
+ && is_string($previous_schema) && is_string($current_schema)
&& !copy($current_schema, $previous_schema)
) {
return $this->raiseError(MDB2_SCHEMA_ERROR, null, null,