I'm sure you guys are sick of me by now, but... ;)

http://planet-soc.com/

Observe that all of the most recent feed items have created dates like 23:02 (cron job goes off hourly)... this means that new feeds submitted swamp the front page with multiple posts from the same person as it goes back to retrieve old posts.

CommentFileSizeAuthor
#6 item_1.patch1.53 KBwebchick
#5 item_0.patch1.15 KBwebchick

Comments

m3avrck’s picture

Here is relevant code:

    if ($item->get_date()) {
      // "created" is a node property, however we have to use "date" to set this with drupal_execute since it is the form element name
      // we pass in 'Y-m-d H:i:s O' to $item->get_date() since PHP4 can't strtotime() the default SimplePie date
      $values['date'] = format_date(strtotime($item->get_date('Y-m-d H:i:s O')), 'custom', 'Y-m-d H:i:s O');  
    }

Obviously in that case $item->get_date() is empty so it defaults to the current time. Looks to be an issue with SimplePie...

webchick’s picture

I did confirm that the following works when executed alone:

    $node = array('type' => 'feed_item');
    $values['title'] = 'Some title';
    $values['date'] = '2007-04-23 23:09:35 -0500';
    $values['name'] = 'webchick'; // some user
    $values['format'] = 1;
    $values['body'] = 'Some description';
    $values['expires'] = 0;
    $values['url'] = 'http://example.com/';     
    $values['fid'] = 538; // some feed id
    drupal_execute('feed_item_node_form', $values, $node);

So now it's a question of whether the $item->get_date is failing or whether the format_date function is being used incorrectly. It appears to be neither... this is generated from a couple var_dumps right before:

    // create a new feed-item node, adding in all of the other node defaults
    drupal_execute('feed_item_node_form', $values, $node);
DATE:string(22) "24 April 2007, 1:36 am"

VALUES:array(9) {
  ["title"]=>
  string(4) "test"
  ["date"]=>
  string(25) "2007-04-23 23:36:06 +0000"
  ["name"]=>
  string(16) "Drupal SoC Group"
  ["format"]=>
  string(1) "1"
  ["body"]=>
  string(106) "

ignore me

SoC 2007
"
  ["expires"]=>
  string(1) "0"
  ["url"]=>
  string(34) "http://groups.drupal.org/node/3794"
  ["fid"]=>
  string(2) "83"
  ["taxonomy"]=>
  array(1) {
    ["tags"]=>
    array(1) {
      [2]=>
      string(6) "Drupal"
    }
  }
}

so as you can see, Simplepie seems to be parsing the date properly, and Drupal's sticking it in the $values['date'] field as you'd expect.

Now, it's worth pointing out that above was generated during a manual feed refresh, and not a cron run... and seems to work properly (?!). For some reason, hitting cron.php isn't picking up new feeds even though I know they're there...

I give up on this for tonight. :(

m3avrck’s picture

Try this, replace line 391 with:

$values['date'] = date('Y-m-d H:i:s O', strtotime($item->get_date('Y-m-d H:i:s O')));     

It seems Drupal's format_date() is causing trouble when cron runs...

m3avrck’s picture

Actually, try this

$values['date'] = date('Y-m-d H:i:s O', strtotime($item->get_date('Y-m-d H:i:s O')) + variable_get('date_default_timezone', 0));

This adjusts for the site timezone since no user is logged in when cron runs.

webchick’s picture

Status: Active » Needs review
StatusFileSize
new1.15 KB

Wow, this patch gets the official 'biggest, most obscure pain in the ass' award. ;)

The short version is that there is code in node_submit() that only changes the $node->created time if you're a node admin. Which means when your cron job is running as an anonymous user, it bypasses this code, and the $node->created stays NULL (which means it'll be the current date/time).

So, to compensate, you need to set the created time sometime after node_submit() does its thing. You have two opportunities: one is simplefeed_item_submit() (which I tried, but it killed feed creation for some reason), and the other is hook_nodeapi op submit, which this patch implements.

Many thanks to Ted for working through the problem w/ me on IRC. :)

webchick’s picture

StatusFileSize
new1.53 KB

And actually, you need to fix the uid here as well for the same reason.

m3avrck’s picture

Status: Needs review » Fixed

whoooooooohoooooo!

commited, thanks Angie!

Anonymous’s picture

Status: Fixed » Closed (fixed)