You are here

function hosting_task_update_6006 in Hostmaster (Aegir) 6

Add nid field to hosting_task_log and remove orphaned log entries.

File

modules/hosting/task/hosting_task.install, line 255

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;
}