1. Create a new content type.
3. Go to the Activity Settings and remove the messages for the previously created content type for user role "All".
4. Create some content with the new type - insert, update, delete.
5. Logon to the server as anonymous user and go to the Activity page.

Observed behavior:

In the Activity page there is an empty table, not showing any content. There is a pager appearing on the bottom and you have to click on it until you find content, which is allowed to be shown.

Expected behavior:

The Activity page should show the first available content, which can be presented to the active user role.

--------

I have inspected the code and it looks like the devil is in the activity_token_replace method. This method knows how to handle properly the activities. However the other method activity_get_activity, which pulls the data doesn't care about the Activity settings and simply returns all the records up to the limit. We have to somehow combine these two methods.

CommentFileSizeAuthor
#6 activity_query.patch1.55 KBnekobul

Comments

sirkitree’s picture

Thank you for your detailed report. This has been a thorn in our side for quite some time and no one has come up with a solution as of yet.

nekobul’s picture

Jerad,

I was able to setup an updated activity_get_activity method, which uses a new SQL statement to do the proper selection. It combines the information found in variable and activity table. Check the updated method for 5.x branch below. I don't have too much knowledge about the 6.x branch, but I don't think it is going to be too much of an hassle to include it there, too.

function activity_get_activity($uids = ACTIVITY_ALL, $filters = NULL, $limit = NULL, $tablesort_headers = NULL) {
  $wheres = array();

  // Build the WHERE clause for user id.
  if (!is_array($uids)) {
    $wheres[] = "activity_targets.target_uid = %d";
    $params[] = $uids;
  }
  else {
    foreach ($uids as $uid) {
      $nums[] = "%d";
      $params[] = $uid;
    }
    $wheres[] = 'activity_targets.target_uid IN ('. implode(',', $nums). ')';
  }

  // Build sql limiting query to on filtered fields
  if (!empty($filters) && is_array($filters)) {
    foreach ($filters as $column => $filter) {
      // Of the possible columns, role is in the at table and all others in the
      // a table. Prefix the column name with the appropriate table.
      if ($column == 'target_role') {
        $column = 'activity_targets.target_role';
      }
      else {
        $column = "activity.{$column}";
      }

      // attempt to rewrite old filters to the new format
      if (!is_array($filter) || (!array_key_exists('include', $filter) && !array_key_exists('exclude', $filter))) {
        $filter = array('include' => $filter);
      }

      foreach ($filter as $criteria => $values) {
        if (is_array($values)) {
          foreach ($values as $value) {
            $strings[] = "'%s'";
            $params[] = $value;
          }
          $wheres[] = $column . ($criteria == 'exclude' ? ' NOT IN ' : ' IN ') .'('. implode(',', $strings). ')';
        }
        else {
          $wheres[] = $column . ($criteria == 'exclude' ? ' != ' : ' = ') ."'%s'";
          // $values is a string with the single value.
          $params[] = $values;
        }
      }
    }
  }
  if (count($wheres) > 0) {
    $where = implode(' AND ', $wheres);
    $where = "WHERE $where";
  }

  // We always include tablesort_sql in the query so that this API is friendly
  // to sortable tables. If no headers were passed in, use the default headers.
  if (empty($tablesort_headers)) {
    $tablesort_headers = activity_get_tablesort_headers();
    $tablesort_headers['activity.created']['sort'] = 'desc';
  }

  // Build the sql and do the query. Wrapping it in db_rewrite_sql allows other
  // modules to impose access restrictions on activity listings.
  $sql = "SELECT activity.*, activity_targets.target_uid, activity_targets.target_role
    FROM {activity} INNER JOIN
    (
      SELECT SUBSTRING_INDEX(name, '_', -1) target_role,
      SUBSTRING_INDEX(SUBSTRING_INDEX(name, '_', 2), '_', -1) `type`,
      SUBSTRING_INDEX(SUBSTRING_INDEX(name, '_', -2), '_', 1) operation

      FROM {variable} WHERE name LIKE '%activity_%_%_%' AND `value` <> 's:0:\"\";'
    ) v
    ON activity.`type` = v.`type` AND activity.`operation` = v.`operation`
    INNER JOIN {activity_targets}
    ON activity.aid = activity_targets.aid AND activity_targets.target_role = v.target_role
    $where ";
  $tablesort_sql = tablesort_sql($tablesort_headers);

  $sql = db_rewrite_sql("$sql $tablesort_sql", 'activity_targets', 'aid', array('uids' => $uids));

  if (is_numeric($limit)) {
    $result = pager_query($sql, $limit, 0, NULL, $params);
  }
  else {
    $result = db_query($sql, $params);
  }
  $activity = array();
  while ($row = db_fetch_array($result)) {
    $row['data'] = unserialize($row['data']);
    $row['data']['created'] = $row['created'];
    $row['data']['activity_id'] = $row['aid'];
    $row['data']['module'] = $row['module'];
    $row['data']['type'] = $row['type'];
    $row['data']['operation'] = ($row['data']['operation'] ? $row['data']['operation'] : $row['operation']);


    // Invoke activityapi
    activity_invoke_activityapi($row, 'load');

    $activity[] = $row;
  }

  return $activity;
}
nekobul’s picture

Jerad,

I haven't heard back from you what do you think about the solution I have proposed. Is there something you are concerned about?

sirkitree’s picture

Sorry for the delay nekobul, I've been heavily involved in Activity2 for the 6.x branch lately and haven't paid a whole lot of attention to 5.x at all. Jaydub has been taking care of 5.x but I also know that he just started a new job recently and has had his hands full as well. I'm afraid 5.x is slowing going the way of the dinosaur.

That being said, if you could help us out by providing an actual patch file against 5.x-4.x-dev and maybe even (bonus points here) 6.x-1.x it's more likely to get a serious review. Also, to help catch our eyes a bit better, mark the issue as 'needs review' once you upload a patch file. Thanks!

jaydub’s picture

Regarding the 5.4 release, I do want to port all the work (that can be ported) from the 6.1 branch. I'm tied up for the next week with an international film festival at night and work during daytime but after that I hope to move quickly :)

nekobul’s picture

StatusFileSize
new1.55 KB

Jeff,

Find attached patch file against activity-5.x-4.x-dev branch. The patch will be similar for 6.x branch if the created records in {variable} table haven't changed and {activity} and {activity_targets} table are the same.

nekobul’s picture

Status: Active » Needs review
nekobul’s picture

Version: 5.x-3.0-beta2 » 5.x-4.x-dev
sirkitree’s picture

Status: Needs review » Closed (won't fix)

5.x unsupported please see 6.x-2

jrabeemer’s picture

#6 patch seems to be working for me.