You are here

function crm_core_contact_update_7003 in CRM Core 7

Add missing uid to contact base table. See http://drupal.org/node/1914326.

File

modules/crm_core_contact/crm_core_contact.install, line 301
Install, update and uninstall functions for the CRM Core Contact module.

Code

function crm_core_contact_update_7003() {
  $table = 'crm_core_contact';
  db_add_field($table, 'uid', array(
    'description' => 'The {users}.uid that owns this contact; initially, this is the user that created it.',
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));

  // Restore missing data from the revisions table.
  db_query("UPDATE {crm_core_contact}\n    INNER JOIN (\n      SELECT MAX({crm_core_contact_revision}.vid), uid, contact_id\n      FROM {crm_core_contact_revision}\n      WHERE {crm_core_contact_revision}.uid > 0\n      GROUP BY {crm_core_contact_revision}.contact_id\n    ) contact_revisions ON ({crm_core_contact}.contact_id = contact_revisions.contact_id)\n    SET {crm_core_contact}.uid = contact_revisions.uid");
}