domain_prefix_update_sequences($op, $newtable, $sourcetable)
domain_prefix/domain_prefix.module, line 605
Correct the {sequences} table if doing an update.
$op The operation to perform, either 'update' or 'drop.'
$newtable The name of the table being updated.
$sourcetable The name of the table providing the tempalte for the update
function domain_prefix_update_sequences($op, $newtable, $sourcetable) {
$result = db_query("SELECT name, id FROM {sequences} WHERE name LIKE '{%s%}'", $sourcetable);
$dbprefix = domain_prefix_get_prefix();
$source = explode('_', $dbprefix . $sourcetable);
while ($variable = db_fetch_array($result)) {
// We have to match the variable source name, to prevent duplicates.
$var = explode('_', $variable['name']);
array_pop($var); // Toss out the last element.
$diff = array_diff($var, $source);
if (empty($diff)) {
$newvariable = $newtable . substr($variable['name'], strlen($dbprefix . $sourcetable));
$target = db_result(db_query("SELECT id FROM {sequences} WHERE name = '{%s}'", $newvariable));
if (!$target) {
if ($op == 'update') {
db_query("INSERT INTO {sequences} (name, id) VALUES ('{%s}', %d)", $newvariable, $variable['id']);
}
}
else {
if ($op == 'update') {
db_query("UPDATE {sequences} SET id = %d WHERE name = '{%s}'", $variable['id'], $newvariable);
}
else {
db_query("DELETE FROM {sequences} WHERE name = '{%s}'", $newvariable);
}
}
}
}
}