diff options
author | Oleg Pudeyev <oleg@bsdpower.com> | 2012-12-06 21:49:24 -0500 |
---|---|---|
committer | Oleg Pudeyev <oleg@bsdpower.com> | 2012-12-06 21:49:24 -0500 |
commit | 26fd70d9cdffe0107635db5f3846dbe5ea6e3fae (patch) | |
tree | 641a33e35665c3b8198fd2d641a687560342ba56 /tests/test_framework/phpbb_database_test_connection_manager.php | |
parent | 74093d0fd383619ec8b58914ebe2edd68145e070 (diff) | |
parent | 2364d4b2172c9f54520f04001b29c517d7138b69 (diff) | |
download | forums-26fd70d9cdffe0107635db5f3846dbe5ea6e3fae.tar forums-26fd70d9cdffe0107635db5f3846dbe5ea6e3fae.tar.gz forums-26fd70d9cdffe0107635db5f3846dbe5ea6e3fae.tar.bz2 forums-26fd70d9cdffe0107635db5f3846dbe5ea6e3fae.tar.xz forums-26fd70d9cdffe0107635db5f3846dbe5ea6e3fae.zip |
Merge remote-tracking branch 'upstream/develop' into ticket/11015
* upstream/develop: (196 commits)
[ticket/11219] Coding guidelines and naming consistency changes
[ticket/10841] Revert more whitespace changes.
[ticket/10841] Revert whitespace changes.
[ticket/10841] adding space after if
[ticket/10841] removing unnecessary spacing
[ticket/10841] changing affectedrows check to COUNT in sql
[ticket/10841] Modifying style and language selectors in UCP
[ticket/11247] Fix wrong property reference in flock class.
[ticket/10602] Avoid a race condition.
[ticket/10602] Use last_queue_run for its intended purpose.
[ticket/10716] Collect standard error from executed php process.
[ticket/10716] Skip test if php is not in PATH.
[ticket/10716] Exclude our dependencies from linting.
[ticket/10103] New and improved wording.
[ticket/10716] Only lint on php 5.3+.
[ticket/10103] Assert with messages.
[ticket/10103] assertLessThan/assertGreaterThan.
[ticket/10103] Inline assignment is bad?
[ticket/10103] $rv had too few characters.
[ticket/10103] Correct flock class documentation.
...
Conflicts:
phpBB/includes/functions.php
tests/cache/cache_test.php
Diffstat (limited to 'tests/test_framework/phpbb_database_test_connection_manager.php')
-rw-r--r-- | tests/test_framework/phpbb_database_test_connection_manager.php | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 479e3aaca5..3fe3ab8d90 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -426,4 +426,111 @@ class phpbb_database_test_connection_manager $this->pdo->exec($query); } } + + /** + * Performs synchronisations on the database after a fixture has been loaded + * + * @param PHPUnit_Extensions_Database_DataSet_XmlDataSet $xml_data_set Information about the tables contained within the loaded fixture + * + * @return null + */ + public function post_setup_synchronisation($xml_data_set) + { + $this->ensure_connected(__METHOD__); + $queries = array(); + + // Get escaped versions of the table names used in the fixture + $table_names = array_map(array($this->pdo, 'PDO::quote'), $xml_data_set->getTableNames()); + + switch ($this->config['dbms']) + { + case 'oracle': + // Get all of the information about the sequences + $sql = "SELECT t.table_name, tc.column_name, d.referenced_name as sequence_name, s.increment_by, s.min_value + FROM USER_TRIGGERS t + JOIN USER_DEPENDENCIES d ON (d.name = t.trigger_name) + JOIN USER_TRIGGER_COLS tc ON (tc.trigger_name = t.trigger_name) + JOIN USER_SEQUENCES s ON (s.sequence_name = d.referenced_name) + WHERE d.referenced_type = 'SEQUENCE' + AND d.type = 'TRIGGER' + AND t.table_name IN (" . implode(', ', array_map('strtoupper', $table_names)) . ')'; + + $result = $this->pdo->query($sql); + + while ($row = $result->fetch(PDO::FETCH_ASSOC)) + { + // Get the current max value of the table + $sql = "SELECT MAX({$row['COLUMN_NAME']}) AS max FROM {$row['TABLE_NAME']}"; + $max_result = $this->pdo->query($sql); + $max_row = $max_result->fetch(PDO::FETCH_ASSOC); + + if (!$max_row) + { + continue; + } + + $max_val = (int) $max_row['MAX']; + $max_val++; + + /** + * This is not the "proper" way, but the proper way does not allow you to completely reset + * tables with no rows since you have to select the next value to make the change go into effect. + * You would have to go past the minimum value to set it correctly, but that's illegal. + * Since we have no objects attached to our sequencers (triggers aren't attached), this works fine. + */ + $queries[] = 'DROP SEQUENCE ' . $row['SEQUENCE_NAME']; + $queries[] = "CREATE SEQUENCE {$row['SEQUENCE_NAME']} + MINVALUE {$row['MIN_VALUE']} + INCREMENT BY {$row['INCREMENT_BY']} + START WITH $max_val"; + } + break; + + case 'postgres': + // Get the sequences attached to the tables + $sql = 'SELECT column_name, table_name FROM information_schema.columns + WHERE table_name IN (' . implode(', ', $table_names) . ") + AND strpos(column_default, '_seq''::regclass') > 0"; + $result = $this->pdo->query($sql); + + $setval_queries = array(); + while ($row = $result->fetch(PDO::FETCH_ASSOC)) + { + // Get the columns used in the fixture for this table + $column_names = $xml_data_set->getTableMetaData($row['table_name'])->getColumns(); + + // Skip sequences that weren't specified in the fixture + if (!in_array($row['column_name'], $column_names)) + { + continue; + } + + // Get the old value if it exists, or use 1 if it doesn't + $sql = "SELECT COALESCE((SELECT MAX({$row['column_name']}) + 1 FROM {$row['table_name']}), 1) AS val"; + $result_max = $this->pdo->query($sql); + $row_max = $result_max->fetch(PDO::FETCH_ASSOC); + + if ($row_max) + { + $seq_name = $this->pdo->quote($row['table_name'] . '_seq'); + $max_val = (int) $row_max['val']; + + // The last parameter is false so that the system doesn't increment it again + $setval_queries[] = "SETVAL($seq_name, $max_val, false)"; + } + } + + // Combine all of the SETVALs into one query + if (sizeof($setval_queries)) + { + $queries[] = 'SELECT ' . implode(', ', $setval_queries); + } + break; + } + + foreach ($queries as $query) + { + $this->pdo->exec($query); + } + } } |