You are here

uc_webform_pane.install in Ubercart Webform Checkout Pane 6.3

Install hooks for uc_webform_pane.

File

uc_webform_pane.install
View source
<?php

/**
 * @file
 * Install hooks for uc_webform_pane.
 */

/**
 * Implementation of hook_install().
 */
function uc_webform_pane_install() {

  // Create tables.
  drupal_install_schema('uc_webform_pane');
}

/**
 * Implementation of hook_schema().
 */
function uc_webform_pane_schema() {
  $schema['uc_webform_pane'] = array(
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'nid',
    ),
  );
  $schema['uc_webform_pane_submissions'] = array(
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'sid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'order_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'nid' => array(
        'nid',
      ),
    ),
    'primary key' => array(
      'nid',
      'order_id',
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_uninstall().
 */
function uc_webform_pane_uninstall() {

  // Remove tables.
  drupal_uninstall_schema('uc_webform_pane');
}

/**
 * Add a new table to store webform submissions with related order ids.
 */
function uc_webform_pane_update_6204() {
  $ret = array();

  // Create the new table for storing submissions.
  if (!db_table_exists('uc_webform_pane_submissions')) {
    db_create_table($ret, 'uc_webform_pane_submissions', array(
      'description' => 'Stores webform submissions with related order ids.',
      'fields' => array(
        'nid' => array(
          'description' => 'The node identifier of a webform.',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
        ),
        'sid' => array(
          'description' => 'The submission identifier.',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
        ),
        'order_id' => array(
          'description' => 'The order identifier.',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
        ),
      ),
      'indexes' => array(
        'nid' => array(
          'nid',
        ),
      ),
      'primary key' => array(
        'nid',
        'order_id',
      ),
    ));
  }

  // Migrate old submissions to the new table.
  $ret[] = update_sql("INSERT IGNORE INTO {uc_webform_pane_submissions} (nid, sid, order_id) SELECT w.nid, w.sid, w.data FROM {uc_webform_pane} p, {webform_submitted_data} w WHERE p.nid = w.nid AND p.cid_order_id = w.cid");
  return $ret;
}

/**
 * Assign all Webform pane submissions to order users (updates anonymous checkouts with user creation).
 */
function uc_webform_pane_update_6309() {
  $ret = array();
  $ret[] = update_sql("UPDATE {webform_submissions} ws NATURAL JOIN {uc_webform_pane_submissions} ucwp LEFT JOIN {uc_orders} o ON ucwp.order_id = o.order_id SET ws.uid = o.uid WHERE EXISTS (SELECT uid FROM {users} u WHERE u.uid = o.uid)");
  return $ret;
}

/**
 * Remove the unused cid_order_id field.
 */
function uc_webform_pane_update_6310() {
  $ret = array();

  // Update the primary key
  db_drop_primary_key($ret, 'uc_webform_pane');
  db_add_primary_key($ret, 'uc_webform_pane', array(
    'nid',
  ));

  // Drop the unused field
  db_drop_field($ret, 'uc_webform_pane', 'cid_order_id');

  // Drop the additional index
  db_drop_index($ret, 'uc_webform_pane', 'nid');
  return $ret;
}

Functions

Namesort descending Description
uc_webform_pane_install Implementation of hook_install().
uc_webform_pane_schema Implementation of hook_schema().
uc_webform_pane_uninstall Implementation of hook_uninstall().
uc_webform_pane_update_6204 Add a new table to store webform submissions with related order ids.
uc_webform_pane_update_6309 Assign all Webform pane submissions to order users (updates anonymous checkouts with user creation).
uc_webform_pane_update_6310 Remove the unused cid_order_id field.