You are here

function pmtask_update in Drupal PM (Project Management) 7

Implements hook_update().

File

pmtask/pmtask.module, line 499

Code

function pmtask_update($node) {
  $org_query = db_select('node', 'n');
  $org_query
    ->join('pmorganization', 'sor', 'n.vid = sor.vid');
  $org_result = $org_query
    ->fields('n', array(
    'title',
  ))
    ->condition('n.type', 'pmorganization')
    ->condition('n.nid', $node->organization_nid)
    ->execute();
  $o = $org_result
    ->fetchObject();
  $node->organization_title = $o->title;
  $pro_query = db_select('node', 'n');
  $pro_query
    ->join('pmproject', 'spr', 'n.vid = spr.vid');
  $pro_result = $pro_query
    ->fields('n', array(
    'title',
  ))
    ->condition('n.type', 'pmproject')
    ->condition('n.nid', $node->project_nid)
    ->execute();
  $p = $pro_result
    ->fetchObject();
  $node->project_title = $p->title;
  if ($node->project_nid != $node->project_nid_old) {
    module_invoke_all('pmtask_change_hierarchy', $node->nid, $node->organization_nid, $node->organization_title, $node->project_nid, $node->project_title);
  }

  // if this is a new node or we're adding a new revision,
  if ($node->revision) {
    pmtask_insert($node);
  }
  else {
    _pmtask_beforesave($node);
    db_update('pmtask')
      ->fields(array(
      'stepno' => $node->stepno,
      'taskcategory' => $node->taskcategory,
      'taskstatus' => $node->taskstatus,
      'taskpriority' => $node->taskpriority,
      'organization_nid' => $node->organization_nid,
      'organization_title' => $node->organization_title,
      'project_nid' => $node->project_nid,
      'project_title' => $node->project_title,
      'parent_nid' => $node->parent_nid,
      'weight' => $node->weight,
      'durationunit' => $node->durationunit,
      'duration' => $node->duration,
      'pricemode' => $node->pricemode,
      'price' => $node->price,
      'currency' => $node->currency,
      'assigned_nid' => $node->assigned_nid,
      'assigned_title' => $node->assigned_title,
    ))
      ->condition('vid', $node->vid)
      ->execute();
    if ($node->title != $node->title_old || $node->stepno != $node->stepno_old) {
      module_invoke_all('pmtask_change', $node->nid, $node->title, $node->stepno);
    }
  }
}