You are here

party.install in Party 7

Same filename and directory in other branches
  1. 8.2 party.install

Contains install hooks for the CRM party module.

File

party.install
View source
<?php

/**
 * @file
 * Contains install hooks for the CRM party module.
 */

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

  // Set up our initial primary fields.
  variable_set('party_primary_fields', array(
    'label' => array(
      'party:pid' => array(
        'data_set' => 'party',
        'property' => 'pid',
        // Make this likely to be the last label plugin.
        'weight' => 50,
        'callback' => 'party_label_default',
      ),
    ),
  ));
}

/**
 * Implements hook_uninstall().
 */
function party_uninstall() {
  variable_del('party_primary_fields');
}

/**
 * Implements hook_schema().
 */
function party_schema() {
  $schema['party'] = array(
    'description' => 'Stores Id, name and email for party contacts',
    'fields' => array(
      'pid' => array(
        'description' => 'Primary key for the party.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'label' => array(
        'description' => 'A label for the party. This is generated by one of a number of plugins.',
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'default' => 'No Label Yet',
      ),
      'archived' => array(
        'description' => 'Boolean flag for whether this party should be archived.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'hidden' => array(
        'description' => 'Boolean flag for whether this party should be hidden.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'merged_party' => array(
        'description' => 'The pid of the party this has been merged into',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'email' => array(
        'description' => 'The primary email address for this party. This is generated based off of the primary field settings.',
        'type' => 'varchar',
        'length' => 255,
      ),
    ),
    'indexes' => array(
      'archived' => array(
        'archived',
      ),
      'hidden' => array(
        'hidden',
      ),
    ),
    'primary key' => array(
      'pid',
    ),
  );

  // Connect parties to attached entities.
  $schema['party_attached_entity'] = array(
    'description' => "This links parties to attached entities.",
    'fields' => array(
      'delta' => array(
        'description' => 'The delta of this attached entity, so that every record in the table is unique',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'pid' => array(
        'description' => 'The id of the party entity.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'eid' => array(
        'description' => 'The id of the attached entity.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'data_set' => array(
        'description' => 'The data set this entity falls under.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'entity_type' => array(
        'description' => 'The type of the attached entity.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'entity_bundle' => array(
        'description' => 'The bundle of the attached entity.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'hat_main' => array(
        'description' => 'Is this the main set for this hat.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'hat' => array(
        'description' => 'The hat this is associated with.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => 'all',
      ),
    ),
    'indexes' => array(
      'party' => array(
        'pid',
      ),
      'entity' => array(
        'eid',
      ),
    ),
    'primary key' => array(
      'pid',
      'data_set',
      'delta',
    ),
  );
  return $schema;
}

/**
 * Add a default value to party labels.
 */
function party_update_7021() {
  db_change_field('party', 'label', 'label', array(
    'description' => 'A label for the party. This is generated by one of a number of plugins.',
    'type' => 'varchar',
    'length' => '255',
    'not null' => TRUE,
    'default' => 'No Label Yet',
  ));
}

/**
 * Drop Party Bundles.
 */
function party_update_7022() {
  db_drop_field('party', 'type');
}

/**
 * Add the primary email field.
 */
function party_update_7023() {
  db_add_field('party', 'email', array(
    'description' => 'The primary email address for this party. This is generated based off of the primary field settings.',
    'type' => 'varchar',
    'length' => 255,
  ));
}

/**
 * Drop the party pieces table.
 */
function party_update_7024() {
  if (db_table_exists('party_party_pieces')) {
    db_delete('party_party_pieces');
  }
}

/**
 * Remove the module and status field.
 */
function party_update_7025() {
  db_drop_field('party', 'module');
  db_drop_field('party', 'status');

  // Rebuild the schema cache.
  drupal_flush_all_caches();
}

/**
 * Rename merged to hidden and add archived.
 */
function party_update_7026() {

  // Update the name of the merged field.
  $spec = array(
    'description' => 'Boolean flag for whether this party should be hidden.',
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  );
  db_change_field('party', 'merged', 'hidden', $spec);
  $spec = array(
    'description' => 'Boolean flag for whether this party should be archived.',
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  );
  db_add_field('party', 'archived', $spec);

  // Add our indexes.
  db_add_index('party', 'archived', array(
    'archived',
  ));
  db_add_index('party', 'hidden', array(
    'hidden',
  ));

  // Rebuild the schema cache.
  drupal_flush_all_caches();
}

/**
 * Convert the label and primary fields data.
 */
function party_update_7027() {
  $primary_fields = array(
    'label' => array(),
    'email' => array(),
  );

  // Convert legacy label plugins.
  $plugins = array(
    'username' => 0,
    'pid' => 0,
    'attached_entity_field' => 0,
  );
  $plugins = variable_get('party_label_plugins', $plugins);
  asort($plugins);
  foreach ($plugins as $name => $weight) {
    $primary_fields['label'][$name] = array(
      'data_set' => NULL,
      'property' => NULL,
      'weight' => $weight,
    );
  }

  // Convert settings for any plugins provided by party. Other modules will need
  // to do the same.
  if (isset($primary_fields['label']['username'])) {
    $primary_fields['label']['username']['data_set'] = 'user';
    $primary_fields['label']['username']['property'] = 'uid';
    $primary_fields['label']['username']['callback'] = 'uid_to_username';
  }
  if (isset($primary_fields['label']['pid'])) {
    $primary_fields['label']['pid']['data_set'] = 'party';
    $primary_fields['label']['pid']['property'] = 'pid';
    $primary_fields['label']['pid']['callback'] = 'party_label_default';
  }
  if (isset($primary_fields['label']['attached_entity_field'])) {
    $primary_fields['label']['attached_entity_field']['data_set'] = variable_get('party_name_label_data_set', 'party');
    $primary_fields['label']['attached_entity_field']['property'] = variable_get('party_name_label_field', NULL);

    // If this is a name field then add a callback.
    $property = $primary_fields['label']['attached_entity_field']['property'];
    if ($info = field_info_field($property) && $info['type'] == 'name') {
      $primary_fields['label']['attached_entity_field']['callback'] = 'party_name_field_label';
    }
    variable_del('party_name_label_data_set');
    variable_del('party_name_label_field');
  }

  // Convert legacy primary fields.
  $legacy_primary_fields = variable_get('party_primary_fields', array());
  if (!empty($legacy_primary_fields['email'])) {
    $key = $legacy_primary_fields['email'];
    list($data_set, $property, $value) = explode(':', $legacy_primary_fields['email']);
    $primary_fields['email'][$key] = array(
      'data_set' => $data_set,
      'property' => $value,
      'value' => NULL,
      'weight' => 0,
    );
    if ($property) {
      $primary_fields['email'][$key]['property'] = $property;
      $primary_fields['email'][$key]['value'] = $value;
    }
  }
  if (!empty($legacy_primary_fields['email2'])) {
    $key = $legacy_primary_fields['email2'];
    list($data_set, $property, $value) = explode(':', $legacy_primary_fields['email2']);
    $primary_fields['email'][$key] = array(
      'data_set' => $data_set,
      'property' => $value,
      'value' => NULL,
      'weight' => 1,
    );
    if ($property) {
      $primary_fields['email'][$key]['property'] = $property;
      $primary_fields['email'][$key]['value'] = $value;
    }
  }

  // Store the new settings back.
  variable_set('party_primary_fields', $primary_fields);
}

/**
 * Mark all parties for re-indexing now we've fixed the track item change bug.
 */
function party_update_7028() {
  $conditions = array(
    'enabled' => 1,
    'item_type' => $type,
    'read_only' => 0,
  );
  $indexes = search_api_index_load_multiple(FALSE, $conditions);
  if (!$indexes) {
    return;
  }
  foreach ($indexes as $index) {
    _search_api_index_reindex($index);
  }
}

Functions

Namesort descending Description
party_install Implements hook_install().
party_schema Implements hook_schema().
party_uninstall Implements hook_uninstall().
party_update_7021 Add a default value to party labels.
party_update_7022 Drop Party Bundles.
party_update_7023 Add the primary email field.
party_update_7024 Drop the party pieces table.
party_update_7025 Remove the module and status field.
party_update_7026 Rename merged to hidden and add archived.
party_update_7027 Convert the label and primary fields data.
party_update_7028 Mark all parties for re-indexing now we've fixed the track item change bug.