You are here

support_substatus.install in Support Ticketing System 6

File

support_substatus/support_substatus.install
View source
<?php

/**
 * Helpdesk / support ticket substatus database schema.
 * Copyright (c) 2013 Tag1 Consulting, Inc <jeremy@tag1consulting.com>.
 */

/**
 * Support substatus database schema definition.
 */
function support_substatus_schema() {
  $schema['support_substatus'] = array(
    'description' => 'Assign substatus fields to support clients.',
    'fields' => array(
      'ssid' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'substatus' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'default' => '',
      ),
      'disabled' => array(
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => FALSE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'ssid',
    ),
    'keys' => array(
      'substatus' => array(
        'substatus',
        'disabled',
        'weight',
      ),
    ),
  );
  $schema['support_substatus_client'] = array(
    'fields' => array(
      'ssid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ),
      'clid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'ssid',
      'clid',
    ),
  );
  $schema['support_substatus_state'] = array(
    'fields' => array(
      'ssid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ),
      'stid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'ssid',
      'stid',
    ),
  );
  $schema['support_substatus_ticket'] = array(
    'description' => 'Stores which substatus fields are assigned to tickets.',
    'fields' => array(
      'trid' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'type' => array(
        'type' => 'varchar',
        'length' => 16,
        'not null' => TRUE,
        'default' => '',
      ),
      'id' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ),
      'subid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ),
      'nid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ),
      'current' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'trid',
    ),
    'keys' => array(
      'nid' => array(
        'nid',
        'subid',
        'current',
      ),
    ),
    'unique keys' => array(
      'rate' => array(
        'type',
        'id',
        'subid',
      ),
    ),
  );
  return $schema;
}

/**
 * Install support database schema.
 */
function support_substatus_install() {
  drupal_install_schema('support_substatus');
}

/**
 * Cleanup.
 * @todo: variable and other cleanup
 */
function support_substatus_uninstall() {
  drupal_uninstall_schema('support_substatus');
}

/**
 * Track Current status (for filtering and sorting).
 */
function support_substatus_update_6101() {
  $ret = array();
  db_add_field($ret, 'support_substatus_ticket', 'current', array(
    'type' => 'int',
    'not null' => TRUE,
    'unsigned' => TRUE,
    'default' => 0,
  ), array(
    'indexes' => array(
      'current' => array(
        'current',
      ),
    ),
  ));
  $result = db_query('SELECT DISTINCT(nid) FROM {support_substatus_ticket}');
  while ($nid = db_result($result)) {
    $trid = db_result(db_query_range('SELECT trid FROM {support_substatus_ticket} WHERE nid = %d ORDER BY trid DESC', $nid, 0, 1));
    db_query('UPDATE {support_substatus_ticket} SET current = 1 WHERE trid = %d', $trid);
  }
  return $ret;
}

Functions

Namesort descending Description
support_substatus_install Install support database schema.
support_substatus_schema Support substatus database schema definition.
support_substatus_uninstall Cleanup. @todo: variable and other cleanup
support_substatus_update_6101 Track Current status (for filtering and sorting).