You are here

function themekey_rule_del in ThemeKey 7.2

Same name and namespace in other branches
  1. 6.4 themekey_build.inc \themekey_rule_del()
  2. 6.2 themekey_build.inc \themekey_rule_del()
  3. 6.3 themekey_build.inc \themekey_rule_del()
  4. 7.3 themekey_build.inc \themekey_rule_del()
  5. 7 themekey_build.inc \themekey_rule_del()

Deletes a ThemeKey rule from database.

Parameters

$id: id of the rule to be deleted from database

Throws

ThemeKeyRuleDeletionException

4 calls to themekey_rule_del()
themekey_admin_delete_rule_confirm_submit in ./themekey_admin.inc
Execute ThemeKey rule deletion
themekey_features_graceful_rule_deletion in ./themekey_features.module
Deletes all rules related to this feature, except that the administrator added childs
themekey_ui_del_path_theme in ./themekey_ui_helper.inc
Deletes a ThemeKey rule.
themekey_update_static_rule in ./themekey_build.inc
Adds or modifies a so-called static rule in the database. Static rules can be moved around in the chain and enabled or disabled by the site administrator, but the values are immutable. There's one static rule per static property.

File

./themekey_build.inc, line 406
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_rule_del($id) {

  // TRANSACTIONS - SEE http://drupal.org/node/355875
  // The transaction opens here.
  $txn = db_transaction();
  $result = db_select('themekey_properties', '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('themekey_properties')
        ->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'));
  }
}