You are here

function pmproject_update in Drupal PM (Project Management) 7

Implements hook_update().

File

pmproject/pmproject.module, line 457

Code

function pmproject_update($node) {
  _pmproject_beforesave($node);

  // This code needs to run whether or not revisions are being used
  $org_result = db_select('node', 'n')
    ->fields('n', array(
    'title',
  ))
    ->condition('n.type', 'pmorganization')
    ->condition('n.nid', $node->organization_nid)
    ->execute();
  $organization = $org_result
    ->fetchObject();

  // If the project has been moved to a different organization, all nodes that reference the project should be updated.
  if ($node->organization_nid != $node->organization_nid_old) {
    module_invoke_all('pmproject_change_hierarchy', $node->nid, $node->organization_nid, $organization->title);
  }

  // If this is a new node or we're adding a new revision,
  if ($node->revision) {
    pmproject_insert($node);
  }
  else {
    $per_result = db_select('node', 'n')
      ->fields('n', array(
      'title',
    ))
      ->condition('n.type', 'pmperson')
      ->condition('n.nid', $node->manager_nid)
      ->execute();
    $manager = $per_result
      ->fetchObject();
    if (!$manager) {
      $manger = new stdClass();
      $manager->title = '';
    }
    $assigned = node_load($node->assigned_nid);
    if (!$assigned) {
      $assigned = new stdClass();
      $assigned->title = '';
    }
    db_update('pmproject')
      ->fields(array(
      'nid' => $node->nid,
      'organization_nid' => $node->organization_nid,
      'organization_title' => $organization->title,
      'projectcategory' => $node->projectcategory,
      'projectstatus' => $node->projectstatus,
      'projectpriority' => $node->projectpriority,
      'pricemode' => $node->pricemode,
      'price' => $node->price,
      'currency' => $node->currency,
      'durationunit' => $node->durationunit,
      'duration' => $node->duration,
      'manager_nid' => $node->manager_nid,
      'manager_title' => $manager->title,
      'assigned_nid' => $node->assigned_nid,
      'assigned_title' => $assigned->title,
    ))
      ->condition('vid', $node->vid)
      ->execute();
    if ($node->title != $node->title_old) {
      module_invoke_all('pmproject_change', $node->nid, $node->title);
    }
  }
}