You are here

function activity_save_activity in Activity 7

Write all required db records for a new activity.

Parameters

ActivityActionHandler $handler: The handler for this action.

int $eid: The entity id for this action.

mixed $a1: The first argument passed to the action handler.

mixed $a2: The second argument passed to the action handler.

2 calls to activity_save_activity()
activity_batch_regenerate_step in ./activity.batch.inc
Batch regeneration step.
activity_record in ./activity.module
Action Callback.

File

./activity.module, line 223
Records Activity across the site and surfaces that to Views.

Code

function activity_save_activity(ActivityActionHandler $handler, $eid, $a1, $a2) {
  $objects = $handler
    ->loadObjects($eid);
  drupal_alter('activity_objects', $objects, $handler->type);
  $uid = $handler
    ->determineActor($objects);
  $timestamp = $handler
    ->determineTimestamp($objects);
  if ($handler
    ->valid($eid, $uid, $timestamp, $objects, $a1, $a2)) {
    $messages = $handler
      ->tokenize($objects);
    $nid = $handler
      ->determineNid($objects);
    $argument1 = NULL;
    $argument2 = NULL;
    if (isset($a1)) {
      $argument1 = serialize($a1);
    }
    if (isset($a2)) {
      $argument2 = serialize($a2);
    }

    // Recording one Activity is a number of different database inserts and
    // this makes all the database inserts into one transaction.
    $txn = db_transaction();

    // Write to {activity} table.
    $record = array(
      'uid' => $uid,
      'type' => $handler->type,
      'nid' => $nid,
      'eid' => $eid,
      'created' => $timestamp,
      'actions_id' => $handler->actions_id,
      'argument1' => $argument1,
      'argument2' => $argument2,
      'status' => $handler
        ->isPublished($objects, $uid) ? ACTIVITY_PUBLISHED : ACTIVITY_NOT_PUBLISHED,
    );
    $record = (object) $record;
    drupal_alter('activity_record', $record, $handler);
    drupal_write_record('activity', $record);
    drupal_alter('activity_messages', $messages, $handler->name, $objects);

    // Write messages to {activity_messages} table.
    activity_write_messages($messages, $record->aid);
    foreach (activity_get_grants($record) as $realm => $values) {
      foreach ($values as $value) {
        $row = array(
          'aid' => $record->aid,
          'realm' => $realm,
          'value' => $value,
        );
        drupal_write_record('activity_access', $row);
      }
    }
  }
}