Hi,

My activity all block is set to show 10 items. Most of the time it does just that. Occasionally, the 'more' link stops showing up. And also, on occasion, the block displays less than 10 items. Or both...

I can't find anything in the code that would be causing this.

There are several hundred activity items in the system, so that's obviously not the problem. Is it time-based?

Comments

mstef’s picture

...........................?

Scott Reynolds’s picture

i would bet on node_access causing troubles here.

OfficeMedium’s picture

(edit out)

mstef’s picture

No, it's not. I'm using UID 1.

The problem seems to be activity_get_activity().

I have about 400 activity items. The block # is set to 10. activity_block() asks activity_get_activity() for 11 items, and it returns 8 items...

The function is a bit confusing so I'm having trouble finding out why it's doing that...

Also having trouble finding out why this only happens when it decides to happen..

mstef’s picture

Well, I just commented out the db_rewrite_sql() which, according to the documentation, says it allows other modules to impose access restrictions on activity listings.

But why, as uid 1, that would cause problems?

But ah, removing that causes a lot of problems...perhaps i need to just use a regular DB query..

?????

Query: SELECT activity.*, activity_targets.target_uid, activity_targets.target_role FROM {activity_targets} activity_targets INNER JOIN {activity} activity ON activity.aid = activity_targets.aid WHERE activity_targets.target_uid = %d ORDER BY activity.created DESC ORDER BY activity.created DESC;

mstef’s picture

It's not just the "All" block either...

so..

no one happened to notice this?

mstef’s picture

commenting out activity_invoke_activityapi($row, 'load'); restores the correct amount of items..

now I'm not sure what that function does exactly or why it would cause items to stop showing...i have to guess some other module is telling the rows not to show, but why?

Scott Reynolds’s picture

Echoing my first comment

/**	 
* Implementation of hook_activityapi().
*/
function nodeactivity_activityapi(&$activity, $op) {
  if ($op == 'load') {
    if ($activity['data']['module'] == 'nodeactivity' && !node_access('view', node_load($activity['data']['node-id']))) {
      $activity = array();
    }
  }
}
mstef’s picture

Echoing comment #4...

I'm logged in as UID 0 (aka, admin)

Node access restrictions don't exist.

Scott Reynolds’s picture

Uid 0 IS NOT admin. Its ANON. From your comment #4 Uid 1 is admin.

No, it's not. I'm using UID 0.

mstef’s picture

yea i meant 1...oops...

still though...

mstef’s picture

AND...say it was an access permission (which it can't be)...i have about 300 activity items..it should return enough to fill the 10 mark..

but as I'm realizing, this coding was done very foolishly because only 11 items are sent to activity_get_activity()...there's no fall back if items aren't allowed to be shown...

oops?

mstef’s picture

Two more reasons why you're wrong...

All of the hundreds of items show up on the page view (strange)

Right now, only 9 items are showing on the block...the 10th item is a logged in/logged out item...not even a node#

mstef’s picture

A problem this big, no one notices it or tries to find a solution?

sirkitree’s picture

Being insulting and seemingly ungrateful for free time spent on things is not the best way to get help with something mike

mstef’s picture

insulting, ungrateful?

mstef’s picture

just a bit shocked how such a big flaw (perhaps 2 flaws) could go unnoticed for almost a year now

Scott Reynolds’s picture

insulting, ungrateful?

Stop it Mike you know better. In a private mail to me you apologized for being a bit 'round in the issue thread'. Don't act surprised when someone calls you on it.

mstef’s picture

I was rude. I didn't insult any one. And I don't know where ungrateful came from...

Regardless, any one look into this issue?

mstef’s picture

Alright, I don't think the node permissions are causing the problems any more. The real problem, like I said, is that the block gives activity_get_activity() a certain amount of items it wants, for example 11. The function fetches 11 items, but if a few aren't able to be viewed because of access restrictions, less items are returned - and no 'more' link (which is very bad).

I added a few small lines to the function to fix this - the best solution I can think of now. There is an additional perimeter added ($block). I suggest when adjust activity_block() [case: 'all'] to add $block = TRUE. What it does it simple. It fetches 3x the amount of items requested, and iterates items until the $limit is reached (so the true remaining amount is returned).

function activity_get_activity($uids = ACTIVITY_ALL, $filters = NULL, $limit = NULL, $tablesort_headers = NULL, $block = FALSE) {
  $count = 0;

  $wheres = array();

  // Build the WHERE clause for user id.
  if (!is_array($uids)) {
    $wheres[] = "activity_targets.target_uid = %d";
    $params[] = $uids;
  }
  else {
    if (!empty($uids)) {
      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)) {
    $ops = array(
      'include' => " = '%s'",
      'exclude' => " != '%s'",
      'lt' => ' < %d',
      'gt' => ' > %d',
      'lte' => ' <= %d',
      'gte' => ' >= %d'
    );
    
    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) || count(array_intersect(array_keys($ops), array_keys($filter))) == 0)  {
        $filter = array('include' => $filter);
      }

      foreach ($filter as $criteria => $values) {
        if (is_array($values)) {
          $strings = array();
          foreach ($values as $value) {
            $strings[] = "'%s'";
            $params[] = $value;
          }
          $wheres[] = $column . ($criteria == 'exclude' ? ' NOT IN ' : ' IN ') .'('. implode(',', $strings). ')';
        }
        else {
          $wheres[] = $column . $ops[$criteria];
          // $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_targets} activity_targets INNER JOIN {activity} activity ON activity.aid = activity_targets.aid
    $where ";
  $tablesort_sql = tablesort_sql($tablesort_headers);

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

  //Multiply limit by 3 incase some items aren't allowed to show
  //Ensures that the limit amount gets returned
  if (is_numeric($limit)) {
	if($block) {
      $result = pager_query($sql, ($limit * 3), 0, NULL, $params);
    }
    else {
 	  $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']['aid'] 		= $row['aid'];
    $row['data']['uid'] 		= $row['uid'];
    $row['data']['module'] 		= $row['module'];
    $row['data']['type'] 		= $row['type'];
    $row['data']['operation'] 	= ($row['data']['operation'] ? $row['data']['operation'] : $row['operation']);
    $row['data']['created'] 	= $row['created'];

    // Load Activity comments if user can view comments
    // Use a permissions check here to save comment loading if user cannot view
    if (user_access('view activity comments')) {
      $row['comments'] = activity_comments_load($row['aid']);
    }

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

    if (!empty($row)) {
      $activity[] = $row;
      
      //Count item insertion
      $count += 1;
      
      //Break if limit reached and block
      if($block && ($count >= $limit)) {
		break;  
	  }
    }
  }

  return $activity;
}
sirkitree’s picture

Status: Active » Closed (won't fix)

closing. 1.x no longer supported.