You are here

function node_gallery_api_node_update in Node Gallery 7

Implements hook_node_update().

File

./node_gallery_api.module, line 737
Node Gallery module.

Code

function node_gallery_api_node_update($node) {
  if (in_array($node->type, (array) node_gallery_api_get_types('item'))) {
    $relationships = node_gallery_api_get_relationships(NULL, $node->nid);
    foreach ($relationships as $relationship) {
      $cover_nid = node_gallery_api_get_cover_nid($relationship->ngid);
      if (empty($cover_nid)) {
        node_gallery_api_set_gallery_cover_item($node->nid, $relationship->ngid);
      }
      node_gallery_api_clear_gallery_caches($relationship->ngid);
      node_gallery_api_update_image_counts($relationship->ngid);
    }
  }
  elseif (in_array($node->type, node_gallery_api_get_types('gallery'))) {
    $node->node_gallery['ngid'] = $node->nid;
    $old_node = node_load($node->nid);
    if ($node->status != $old_node->status) {

      // Publish status changed.
      _node_gallery_api_set_publish($node, $node->status);
    }
    $gallery_exists = db_query('SELECT ngid FROM {node_gallery_galleries} WHERE ngid = :ngid', array(
      ':ngid' => $node->nid,
    ))
      ->fetchField();
    if ($gallery_exists) {
      drupal_write_record('node_gallery_galleries', $node->node_gallery, 'ngid');
    }
    else {
      drupal_write_record('node_gallery_galleries', $node->node_gallery);
    }
    node_gallery_api_update_image_counts($node->nid);
    if (module_exists('pathauto')) {

      // Our tokens are all based off the gallery nid or title,
      // no need for processing if those stay the same.
      if ($node->title != $old_node->title) {
        $item_nids = node_gallery_api_get_item_nids($node->nid);
        if (count($item_nids) > 0) {
          if (function_exists('pathauto_node_update_alias_multiple')) {
            pathauto_node_update_alias_multiple($item_nids, 'bulkupdate');
          }
        }
      }
    }
  }
}