Activity Stream assigns the date and time of import to new feed items. When feed items are timestamped, AS should set the create date of new items to the original create date, or at least retain the original item's create date in a custom field.

Comments

akalsey’s picture

Status: Active » Closed (won't fix)

Activity Stream already works this way. If an item is timestamped, the timestamp of the feed (or API result) is used. If no timestamp is present, the time of import is used. _activitystream_save() does this...

<?php
    $node->title = $activity['title'];
    $node->body = $activity['body'];
    $node->created = $activity['timestamp'];
    $node->uid = $user->uid;
    $node->type = 'activitystream';

      node_object_prepare($node);
      node_save($node);
?>
samc’s picture

Category: feature » bug
Status: Closed (won't fix) » Active

Actually I can verify that this is not in fact working and is a bug in both Beta 1 and dev.

The source of the bug is the call to node_object_prepare() which overwrites the timestamp of the activity with the time the node is saved. The setting of the node options and uid are redundant as well.

Commenting out this line in Beta 1 fixes the timestamp problem and doesn't appear to have any ill effects.

Perhaps the module should simply invoke 'prepare' on the node?

function node_object_prepare(&$node) {
  // Set up default values, if required.
  $node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
  // If this is a new node, fill in the default values.
  if (!isset($node->nid)) {
    foreach (array('status', 'promote', 'sticky') as $key) {
      $node->$key = in_array($key, $node_options);
    }
    global $user;
    $node->uid = $user->uid;
    $node->created = time();
  }
  else {
    $node->date = format_date($node->created, 'custom', 'Y-m-d H:i:s O');
  }
  // Always use the default revision setting.
  $node->revision = in_array('revision', $node_options);

  node_invoke($node, 'prepare');
  node_invoke_nodeapi($node, 'prepare');
}
eojthebrave’s picture

Status: Active » Needs review
StatusFileSize
new943 bytes

I can confirm that this is an issue. The attached patch fixes it by assigning the $node->created date to the $activity['timestamp'] after the call to node_object_prepare() rather than before.

swe3tdave’s picture

You have to do something similar for the user->uid as well.. Or your going to get Anonymous (or the name of a logged user) instead of the feed's user...

eojthebrave’s picture

Here's a patch that fixes the UID issue as well. Thanks for pointing that out.

akalsey’s picture

Status: Needs review » Fixed

The only reason that node_object_prepare was being called was to set the default publishing options for the content type and to run the prepare hook in case other modules are using it.

I'd already moved a number of the publishing options into the module specifically. The only remaining one was revisions. So I've moved that into the module too. And I've added the prepare hook calls directly in the save routine. This means that we don't need to call node_object_prepare anymore.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

akalsey’s picture

Status: Closed (fixed) » Fixed

I wonder if there's a way to prevent the bot from closing issues. I mark them as fixed after checking in the code, then move them to closed when they make it into a release.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.