You are here

function hosting_task_update_6006 in Hosting 7.4

Same name and namespace in other branches
  1. 6.2 task/hosting_task.install \hosting_task_update_6006()
  2. 7.3 task/hosting_task.install \hosting_task_update_6006()

Implements hook_update_N().

Add nid field to hosting_task_log and remove orphaned log entries.

File

task/hosting_task.install, line 277
Define the database schema and update functions for the hosting_task module.

Code

function hosting_task_update_6006() {
  $ret = array();

  // Add nid field.
  $field = array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  );

  // Add some useful indexes.
  $indexes = array(
    'indexes' => array(
      'vid_lid' => array(
        'vid',
        'lid',
      ),
      'nid' => array(
        'nid',
      ),
    ),
  );
  db_add_field($ret, 'hosting_task_log', 'nid', $field, $indexes);

  // Populate nid field.
  $query = "SELECT nid, vid FROM {hosting_task}";
  $result = db_query($query);
  while ($task = db_fetch_object($result)) {
    $query = "UPDATE {hosting_task_log} SET nid = %d WHERE vid = %d";
    db_query($query, $task->nid, $task->vid);
  }

  // Remove orphaned logs, which will have nid == 0 now.
  $query = "DELETE FROM {hosting_task_log} WHERE nid = %d";
  db_query($query, 0);
  return $ret;
}