You are here

function activity_recreate_messages in Activity 7

Creates new messages for a set of activity records.

Parameters

array $records: An array of {activity} rows.

4 calls to activity_recreate_messages()
activity_batch_recreate_messages_step in ./activity.batch.inc
Batch operation callback to generate new messages.
activity_comment_update in ./activity.module
Implements hook_comment_update().
activity_node_update in ./activity.module
Implements hook_node_update().
activity_user_update in ./activity.module
Implements hook_user_update().

File

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

Code

function activity_recreate_messages(array $records) {
  foreach ($records as $record) {

    // Load the handler and check it its batchable.
    $handler = activity_handler_load($record->actions_id);
    if ($handler->batch) {
      $amids = db_query("SELECT amid FROM {activity_targets} WHERE aid = :aid", array(
        ":aid" => $record->aid,
      ))
        ->fetchCol();
      if (!empty($amids)) {
        db_delete('activity_targets')
          ->condition('amid', $amids, 'IN')
          ->execute();
        db_delete('activity_messages')
          ->condition('amid', $amids, 'IN')
          ->execute();
      }
      $objects = $handler
        ->loadObjects($record->eid);
      drupal_alter('activity_objects', $objects, $handler->type);
      $a1 = NULL;
      $a2 = NULL;
      if (isset($record->argument1)) {
        $a1 = unserialize($record->argument1);
      }
      if (isset($record->argument2)) {
        $a2 = unserialize($record->argument2);
      }

      // If the handler is valid, create the new messages, otherwise delete the
      // record of the activity.
      if ($handler
        ->valid($record->eid, $record->uid, $record->created, $objects, $a1, $a2)) {
        activity_write_messages($handler
          ->tokenize($objects), $record->aid);
      }
      else {

        // Delete the activity.
        db_delete('activity')
          ->condition('aid', $record->aid)
          ->execute();
      }
    }
  }
}