You are here

function oa_messages_entity_update in Open Atrium Core 7.2

Implements hook_entity_update().

File

modules/oa_messages/oa_messages.module, line 313

Code

function oa_messages_entity_update($entity, $type) {

  // only create messages for node updates
  if ($type !== 'node') {
    return;
  }
  $update = TRUE;
  $update = isset($entity->title) && $entity->title !== $entity->original->title ? TRUE : FALSE;
  $node_published = FALSE;
  $node_unpublished = FALSE;
  if (isset($entity->status)) {
    $node_published = $entity->status == 1 && $entity->original->status == 0;
    $node_unpublished = $entity->status == 0 && $entity->original->status == 1;
  }
  if ($node_published && variable_get('oa_messages_publish_notifications', FALSE)) {
    $update = TRUE;
  }
  if ($node_unpublished && variable_get('oa_messages_unpublish_notifications', FALSE)) {
    $update = TRUE;
  }
  if (!$update && module_exists('diff')) {
    module_load_include('inc', 'diff', 'diff.diff');
    $context = array(
      'entity_type' => $type,
      'old_entity' => $entity->original,
      'new_entity' => $entity,
      'view_mode' => FALSE,
    );
    $fields = diff_entity_diff($entity->original, $entity, $context);
    foreach ($fields as $field => $data) {
      if ($data['#old'] !== $data['#new']) {
        $update = TRUE;
        break;
      }
    }
  }
  if ($update) {
    $types = oa_core_list_content_types(TRUE);
    if ($type == 'node' && array_key_exists($entity->type, $types)) {
      $message = oa_messages_create('oa_update', $entity, $type);
    }
  }
}