You are here

uc_webform_pane.install in Ubercart Webform Checkout Pane 7.3

Install hooks for uc_webform_pane.

File

uc_webform_pane.install
View source
<?php

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

/**
 * Implements 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;
}

/**
 * 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('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.
  db_query("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");
}

/**
 * Assign all Webform pane submissions to order users (updates anonymous checkouts with user creation).
 */
function uc_webform_pane_update_6309() {
  db_query("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)");
}

/**
 * Remove the unused cid_order_id field.
 */
function uc_webform_pane_update_6310() {

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

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

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

Functions

Namesort descending Description
uc_webform_pane_schema Implements hook_schema().
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.