You are here

function domain_prefix_update_sequences in Domain Access 5

Correct the {sequences} table if doing an update.

Parameters

$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

1 call to domain_prefix_update_sequences()
domain_prefix_form_submit in domain_prefix/domain_prefix.module
FormsAPI for domain_prefix_form.

File

domain_prefix/domain_prefix.module, line 608
Interface for selective table prefixing for use with Domain Access. For this module to work correctly, you will need to follow the INSTALL.txt instructions for editing your settings.php file.

Code

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);
        }
      }
    }
  }
}