You are here

resource_conflict.install in Resource Conflict 7.3

Install, upgrade and uninstall hooks for the resource conflict module.

File

resource_conflict.install
View source
<?php

/**
 * @file
 * Install, upgrade and uninstall hooks for the resource conflict module.
 */

/**
 * Implements hook_uninstall().
 */
function resource_conflict_uninstall() {
  _resource_conflict_variable_delete_like('rc_type_%');
  _resource_conflict_variable_delete_like('rc_date_field_%');
  _resource_conflict_variable_delete_like('rc_reference_fields_%');
  _resource_conflict_variable_delete_like('rc_conflict_buffer_%');
  variable_del('rc_types');
}

/**
 * Delete all variables matching a pattern using SQL 'LIKE' syntax.
 *
 * @param string $pattern
 *   The pattern of variables to delete.
 */
function _resource_conflict_variable_delete_like($pattern) {
  $sql = "SELECT name FROM {variable} WHERE name LIKE :pattern";
  $result = db_query($sql, array(
    ':pattern' => $pattern,
  ));
  foreach ($result as $row) {
    variable_del($row->name);
  }
}

/**
 * Remove any duplicates types due to this bug: https://drupal.org/node/1872030.
 *
 * We also can't trust that all the types in that array are accurate because of
 * that bug. To address, we verify that each one should actually be there by
 * checking the individual setting for that content type.
 */
function resource_conflict_update_7300() {
  $types = variable_get('rc_types', array());
  if (!empty($types)) {
    $deduped_types = array_unique($types);
  }
  foreach ($deduped_types as $index => $type) {
    if (variable_get('rc_type_' . $type, 0) !== 1) {

      // This content type should not be enabled.
      unset($deduped_types[$index]);
    }
  }
  variable_set('rc_types', $deduped_types);
}

Functions

Namesort descending Description
resource_conflict_uninstall Implements hook_uninstall().
resource_conflict_update_7300 Remove any duplicates types due to this bug: https://drupal.org/node/1872030.
_resource_conflict_variable_delete_like Delete all variables matching a pattern using SQL 'LIKE' syntax.