You are here

casetracker.install in Case Tracker 7

Same filename and directory in other branches
  1. 5 casetracker.install
  2. 6 casetracker.install
  3. 7.2 casetracker.install

Install, update and uninstall functions for the casetracker module.

File

casetracker.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the casetracker module.
 *
 */

/**
 * Implements hook_schema().
 */
function casetracker_schema() {
  $schema['casetracker_case'] = array(
    'fields' => array(
      'nid' => array(
        'description' => 'The {node} the case relates to.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'vid' => array(
        'description' => 'The {node_revision} for the case.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'pid' => array(
        'description' => 'The project {node} the case is related to.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'case_number' => array(
        'description' => 'the case number of this node (namespaced per projects). Deprecated.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'assign_to' => array(
        'description' => 'The {user} that the case is assigned to.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'case_priority_id' => array(
        'description' => 'The {casetracker_case_states} that describes the case priority.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'case_type_id' => array(
        'description' => 'The {casetracker_case_states} that describes the case type.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'case_status_id' => array(
        'description' => 'Store the {casetracker_case_states} that describes the case status.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'nid' => array(
        'nid',
      ),
      'p_id' => array(
        'pid',
      ),
    ),
    'primary key' => array(
      'vid',
    ),
  );
  $schema['casetracker_case_states'] = array(
    'fields' => array(
      'csid' => array(
        'description' => 'unique ID of this case state.',
        'type' => 'serial',
        'size' => 'tiny',
        'not null' => TRUE,
      ),
      'case_state_name' => array(
        'description' => 'name of this case state.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'case_state_realm' => array(
        'description' => 'the realm ("priority", etc.) of this state.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'weight' => array(
        'description' => 'The weight of an case state.',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'weight' => array(
        'weight',
      ),
    ),
    'primary key' => array(
      'csid',
    ),
  );
  $schema['casetracker_comment_status'] = array(
    'fields' => array(
      'cid' => array(
        'description' => 'Store the {comment} that the record relates to.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'pid' => array(
        'description' => 'Store the {project} that the record relates to.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'title' => array(
        'description' => 'Title of the case.',
        'type' => 'varchar',
        'length' => 250,
        'not null' => FALSE,
      ),
      'assign_to' => array(
        'description' => 'The {user} too whom the case is assigned.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'case_priority_id' => array(
        'description' => 'The {casetracker_case_states} that describes the case priority.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'case_type_id' => array(
        'description' => 'The {casetracker_case_states} that describes the case type.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'case_status_id' => array(
        'description' => 'Store the {casetracker_case_states} that describes the case status.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'state' => array(
        'description' => 'Record whether the row is for the "before" the comment (0) or "after" (1).',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'cid' => array(
        'cid',
      ),
    ),
  );
  return $schema;
}

/**
 * Implements hook_install().
 */
function casetracker_install() {

  // Create default case states.
  $values = array(
    array(
      'case_state_name' => 'High',
      'case_state_realm' => 'priority',
      'weight' => -1,
    ),
    array(
      'case_state_name' => 'Normal',
      'case_state_realm' => 'priority',
      'weight' => 0,
    ),
    array(
      'case_state_name' => 'Low',
      'case_state_realm' => 'priority',
      'weight' => 1,
    ),
    array(
      'case_state_name' => 'Open',
      'case_state_realm' => 'status',
      'weight' => 0,
    ),
    array(
      'case_state_name' => 'Resolved',
      'case_state_realm' => 'status',
      'weight' => 1,
    ),
    array(
      'case_state_name' => 'Deferred',
      'case_state_realm' => 'status',
      'weight' => 2,
    ),
    array(
      'case_state_name' => 'Duplicate',
      'case_state_realm' => 'status',
      'weight' => 3,
    ),
    array(
      'case_state_name' => 'Closed',
      'case_state_realm' => 'status',
      'weight' => 4,
    ),
    array(
      'case_state_name' => 'Bug',
      'case_state_realm' => 'type',
      'weight' => 0,
    ),
    array(
      'case_state_name' => 'Feature Request',
      'case_state_realm' => 'type',
      'weight' => 1,
    ),
    array(
      'case_state_name' => 'General Task',
      'case_state_realm' => 'type',
      'weight' => 2,
    ),
  );
  $query = db_insert('casetracker_case_states')
    ->fields(array(
    'case_state_name',
    'case_state_realm',
    'weight',
  ));
  foreach ($values as $record) {
    $query
      ->values($record);
  }
  $query
    ->execute();
}

/**
 * Implements hook_uninstall().
 */
function casetracker_uninstall() {

  // Delete variables
  variable_del('casetracker_default_assign_to');
  variable_del('casetracker_default_case_priority');
  variable_del('casetracker_default_case_status');
  variable_del('casetracker_default_case_type');
  variable_del('casetracker_project_node_types');
  variable_del('casetracker_case_node_types');
}

Functions