You are here

webform_civicrm.install in Webform CiviCRM Integration 6

Webform CiviCRM module's install and uninstall code.

File

webform_civicrm.install
View source
<?php

/**
 * @file
 * Webform CiviCRM module's install and uninstall code.
 */

/**
 * Implementation of hook_schema().
 */
function webform_civicrm_schema() {
  $schema['webform_civicrm_forms'] = array(
    'description' => 'CiviCRM settings for individual Webform nodes.',
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Webform Node ID',
      ),
      'activity_type_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'FK to {civicrm_activity} activity_type_id',
      ),
      'activity_subject' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Subject of auto-created activities',
      ),
      'prefix_known' => array(
        'description' => 'Form prefix for known users.',
        'type' => 'text',
        'not null' => TRUE,
      ),
      'prefix_unknown' => array(
        'description' => 'Form prefix for unknown users.',
        'type' => 'text',
        'not null' => TRUE,
      ),
      'message' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Message to show to known users',
      ),
      'confirm_subscription' => array(
        'description' => 'Send confirmation for mailing list subscriptions.',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
      'block_unknown_users' => array(
        'description' => 'Only allow known contacts to use form.',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'nid',
    ),
  );
  $schema['webform_civicrm_submissions'] = array(
    'description' => 'Link between form submissions and CiviCRM contacts.',
    'fields' => array(
      'sid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Webform Submission ID',
      ),
      'contact_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'FK to {civicrm_contact} id',
      ),
      'activity_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'FK to {civicrm_activity} id',
      ),
    ),
    'primary key' => array(
      'sid',
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_install().
 */
function webform_civicrm_install() {
  drupal_install_schema('webform_civicrm');
}

/**
 * Implementation of hook_uninstall().
 */
function webform_civicrm_uninstall() {
  drupal_uninstall_schema('webform_civicrm');
}

/**
 * Add column for message to webform_civicrm_forms table.
 */
function webform_civicrm_update_6100() {
  $message = array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
    'description' => 'Message to show to known users',
  );
  $ret = array();
  db_add_field($ret, 'webform_civicrm_forms', 'message', $message);
  return $ret;
}

/**
 * Add missing activity targets.
 */
function webform_civicrm_update_6101() {
  civicrm_initialize();
  $db = db_query('SELECT * FROM {webform_civicrm_submissions} WHERE contact_id <> 0 AND activity_id <> 0');
  $sql = 'INSERT INTO civicrm_activity_target (activity_id, target_contact_id) VALUES (%1,%2)';
  $n = 1;
  $c = 0;
  $params = array();
  while ($row = db_fetch_array($db)) {
    $params[$n] = array(
      $row['activity_id'],
      'Integer',
    );
    $params[$n + 1] = array(
      $row['contact_id'],
      'Integer',
    );
    if ($n > 1) {
      $sql .= ',(%' . $n . ',%' . ($n + 1) . ')';
    }
    $n += 2;
    ++$c;
  }
  if ($n > 1) {
    CRM_Core_DAO::executeQuery($sql, $params);
  }
  $ret = array(
    array(
      'success' => TRUE,
      'query' => t('@num activity target contacts added.', array(
        '@num' => $c,
      )),
    ),
  );
  return $ret;
}

/**
 * Add column for confirm_subscription to webform_civicrm_forms table.
 */
function webform_civicrm_update_6102() {
  $confirm_subscription = array(
    'description' => 'Send confirmation for mailing list subscriptions.',
    'type' => 'int',
    'size' => 'tiny',
    'not null' => TRUE,
    'default' => 0,
  );
  $ret = array();
  db_add_field($ret, 'webform_civicrm_forms', 'confirm_subscription', $confirm_subscription);
  return $ret;
}

Functions

Namesort descending Description
webform_civicrm_install Implementation of hook_install().
webform_civicrm_schema Implementation of hook_schema().
webform_civicrm_uninstall Implementation of hook_uninstall().
webform_civicrm_update_6100 Add column for message to webform_civicrm_forms table.
webform_civicrm_update_6101 Add missing activity targets.
webform_civicrm_update_6102 Add column for confirm_subscription to webform_civicrm_forms table.