You are here

function oa_core_node_update in Open Atrium Core 7.2

Implements hook_node_update().

if saving a section or space node, update access locks on related content

File

includes/oa_core.access.inc, line 227
Code for Access Control functions for OpenAtrium spaces

Code

function oa_core_node_update($node) {
  if ($node->type == OA_SPACE_TYPE || $node->type == OA_GROUP_TYPE) {

    // check if group access changed and update space content grants
    $rebuild = module_invoke_all('oa_core_og_content_needs_rebuild', $node);
    if (in_array(TRUE, $rebuild, TRUE)) {

      // Get all subgroups for this node.
      $subgroup_nids = oa_core_get_groups_by_parent($node->nid, $node->type, NULL, FALSE, NULL, TRUE, FALSE);
      $batch = batch_get();

      // Don't do nested batch
      if (empty($batch)) {

        // Prepare the batch.
        _oa_core_update_access_records_batch_prepare($subgroup_nids);

        // Trigger the batch.
        batch_process();
      }
      else {
        oa_core_update_access_records($subgroup_nids);
      }
    }
    oa_core_clear_group_cache($node);
  }
  elseif ($node->type == OA_SECTION_TYPE) {

    // if section node changed from public to private, update content grants
    $was_public = oa_core_section_is_public($node->original);
    $is_public = oa_core_section_is_public($node);
    if ($was_public != $is_public) {

      // rebuild section content nodes
      $nids = db_select('field_data_' . OA_SECTION_FIELD, 'n')
        ->fields('n', array(
        'entity_id',
      ))
        ->condition('n.entity_type', 'node')
        ->condition('n.oa_section_ref_target_id', $node->nid)
        ->execute()
        ->fetchCol(0);

      // clear the static node cache for the space node so correct access
      // values are tested in hook_node_access_records
      entity_get_controller('node')
        ->resetCache(array(
        $node->nid,
      ));
      oa_core_update_access_records($nids);
    }
  }
}