You are here

function themekey_abstract_rule_del in ThemeKey 7.3

4 calls to themekey_abstract_rule_del()
themekey_abstract_update_static_rule in ./themekey_build.inc
themekey_css_rule_del in themekey_css/themekey_css_build.inc
Deletes a ThemeKey rule from database.
themekey_redirect_rule_del in themekey_redirect/themekey_redirect_build.inc
Deletes a ThemeKey rule from database.
themekey_rule_del in ./themekey_build.inc
Deletes a ThemeKey rule from database.

File

./themekey_build.inc, line 432
The functions in this file are the back end of ThemeKey which should be used only if you configure something, but not when ThemeKey switches themes.

Code

function themekey_abstract_rule_del($table, $id) {

  // TRANSACTIONS - SEE http://drupal.org/node/355875
  // The transaction opens here.
  $txn = db_transaction();
  $result = db_select($table, 'tp');
  $result
    ->condition('parent', $id);
  $result
    ->addExpression('COUNT(*)', 'num_childs');
  $num_childs = $result
    ->execute()
    ->fetchField();
  if (FALSE !== $num_childs) {
    if ($num_childs > 0) {
      throw new ThemeKeyRuleDeletionException(t('ThemeKey rule could not be deleted because it has children in the chain'));
    }
    else {
      $result = db_delete($table)
        ->condition('id', $id)
        ->execute();
      if (!$result) {
        throw new ThemeKeyRuleDeletionException(t('Error while deleting ThemeKey rule'));
      }
      else {

        // $txn goes out of scope here, and the entire transaction commits.
        return TRUE;
      }
    }
  }
  else {
    throw new ThemeKeyRuleDeletionException(t('Error while deleting ThemeKey rule'));
  }
}