You are here

salesforce_api.install in Salesforce Suite 7

Installs any global tables needed for Salesforce integration.

File

salesforce_api/salesforce_api.install
View source
<?php

/**
 * @file
 * Installs any global tables needed for Salesforce integration.
 */

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

  // nothing yet.
}

/**
 * Implements hook_uninstall().
 */
function salesforce_api_uninstall() {
  drupal_uninstall_schema('salesforce_api');
  db_query("DELETE FROM {variable} WHERE name LIKE 'salesforce%%'");
  db_query("DELETE FROM {cache} WHERE cid = 'salesforce_api_sf_objects'");
}

/**
 * Implements hook_enable().
 */
function salesforce_api_enable() {
  drupal_set_message(t('Salesforce API: Before making any Salesforce connections, please <a href="!url">enter your Salesforce API credentials</a>', array(
    '!url' => url(SALESFORCE_PATH_ADMIN),
  )), 'warning');
  drupal_set_message(t('Salesforce API: The default Salesforce object have been enabled, to export/import any other objects see the <a href="!url">Object setup</a> page.', array(
    '!url' => url(SALESFORCE_PATH_OBJECT),
  )), 'warning');
}

/**
 * Implements hook_schema().
 */
function salesforce_api_schema() {
  $schema['salesforce_object_map'] = array(
    'description' => 'Drupal to Salesforce object mapping table',
    'fields' => array(
      'fieldmap' => array(
        'description' => 'Fieldmap id',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'oid' => array(
        'description' => 'Specific Drupal object identifier (e.g. node id or comment id)',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'sfid' => array(
        'description' => 'Salesforce object identifier (e.g. "node", "comment")',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'drupal_entity' => array(
        'description' => 'Drupal entity (e.g. "node", "user")',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'drupal_bundle' => array(
        'description' => 'Drupal bundle (e.g. "page", or vocabulary name)',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'indexes' => array(
      'sfid' => array(
        'sfid',
      ),
    ),
    'primary key' => array(
      'drupal_entity',
      'drupal_bundle',
      'oid',
    ),
  );
  $schema['salesforce_field_map'] = array(
    'description' => 'Drupal to Salesforce field mappings',
    'fields' => array(
      'fieldmap' => array(
        'description' => 'The primary identifier for a fieldmap.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'automatic' => array(
        'description' => 'Boolean indicating whether this action/map is automatic or triggered.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
      ),
      'salesforce' => array(
        'description' => 'The kind of Salesforce object this map is for.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'drupal_entity' => array(
        'description' => 'The Drupal entity for this object map (e.g. "node", "user").',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'drupal_bundle' => array(
        'description' => 'The Drupal bundle for this object map (e.g. "page" or vocabulary name)',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'description' => array(
        'description' => 'Name or brief description of this fieldmap',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'default' => '',
      ),
      'fields' => array(
        'description' => 'Serialized fieldmap',
        'type' => 'text',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'fieldmap',
    ),
  );
  return $schema;
}

/**
 * Implements hook_requirements().
 *
 * Check the Salesforce API configuration to see if we have valid credentials.
 */
function salesforce_api_requirements($phase) {
  $req = array();
  switch ($phase) {
    case 'install':
      break;
    case 'runtime':
      $username = variable_get('salesforce_api_username', FALSE);
      if (!$username) {
        $description = l(t('Enter your Salesforce credentials.'), SALESFORCE_PATH_ADMIN);
        $severity = REQUIREMENT_ERROR;
      }
      elseif (!salesforce_api_connect()) {
        $description = t('Unable to connect to Salesforce using <a href="!url">current credentials</a>.', array(
          '!url' => url(SALESFORCE_PATH_ADMIN),
        ));
        $severity = REQUIREMENT_ERROR;
      }
      else {
        $description = '';
        $severity = REQUIREMENT_OK;
      }
      $req[] = array(
        'title' => t('Salesforce Configuration'),
        'value' => l('Salesforce Admin', SALESFORCE_PATH_ADMIN),
        'description' => $description,
        'severity' => $severity,
      );
      break;
  }
  if (!empty($req)) {
    return $req;
  }
}