You are here

function salesforce_api_schema in Salesforce Suite 7.2

Same name and namespace in other branches
  1. 6.2 salesforce_api/salesforce_api.install \salesforce_api_schema()
  2. 7 salesforce_api/salesforce_api.install \salesforce_api_schema()

Implements hook_schema().

File

salesforce_api/salesforce_api.install, line 38
Installs any global tables needed for Salesforce integration.

Code

function salesforce_api_schema() {
  require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'salesforce_api') . '/salesforce_api.module';

  // Object mapping table.
  $schema['salesforce_object_map'] = array(
    'description' => 'Drupal to Salesforce object mapping table',
    'fields' => array(
      'name' => array(
        'description' => 'Foreign key for salesforce_field_map - the fieldmap that corresponds to this record.',
        'type' => 'varchar',
        'length' => 64,
      ),
      '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. 000000000000000000)',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'drupal_entity' => array(
        'description' => 'Drupal entity name (e.g. "node", "user")',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'drupal_bundle' => array(
        'description' => 'Drupal bundle name (e.g. "page", or vocabulary name)',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'created' => array(
        'description' => 'The Unix timestamp when the mapping was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'last_import' => array(
        'description' => 'The Unix timestamp when the record was last imported from Salesforce to Drupal.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'last_export' => array(
        'description' => 'The Unix timestamp when the record was last exported from Drupal to Salesforce.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'sfid' => array(
        'sfid',
      ),
      'name' => array(
        'name',
      ),
      'oid' => array(
        'oid',
      ),
      'entity_bundle_oid' => array(
        'drupal_entity',
        'drupal_bundle',
        'oid',
      ),
    ),
    // Primary key has been changed to the fieldmap:
    // one fieldmapping for each Drupal object - cf. [#1018690-8]
    // @todo: Write the 7.x upgrade routine to reflect this.
    'primary key' => array(
      'name',
      'oid',
    ),
  );

  // Field mapping table.
  $schema['salesforce_fieldmap'] = array(
    'description' => 'Drupal to Salesforce field mappings',
    'export' => array(
      'key' => 'name',
      'identifier' => 'salesforce_fieldmap',
      'default hook' => 'default_salesforce_fieldmaps',
      'export callback' => 'salesforce_api_salesforce_fieldmap_export',
    ),
    'fields' => array(
      'fieldmap' => array(
        'description' => 'Numeric ID of the fieldmap. Exists for backwards compatibility only.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'no export' => TRUE,
      ),
      'name' => array(
        'description' => 'Unique ID for this object. Used to identify it programmatically, and make it exportable via CTools.',
        'type' => 'varchar',
        'length' => 64,
      ),
      'automatic' => array(
        'description' => 'Indicates whether this fieldmap automatically exports to Salesforce.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => SALESFORCE_AUTO_SYNC_OFF,
        'size' => 'small',
      ),
      'salesforce' => array(
        'description' => 'The Salesforce object type for this fieldmap.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'drupal_entity' => array(
        'description' => 'The Drupal entity for this fieldmap (e.g. "node", "user").',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'drupal_bundle' => array(
        'description' => 'The Drupal bundle for this fieldmap (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,
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array(
      'fieldmap',
    ),
    'unique keys' => array(
      'name' => array(
        'name',
      ),
    ),
  );
  return $schema;
}