Hello, I'm trying to use this action to re-save "old" nodes to update some of their data when cron is ran:

$old   = '1 month';        # Content is considered outdated if older than {$old}
$type  = 'model';      # Apply to nodes of type {$type}
$count = 20;           # Update {$count} nodes per cron
 
$old = strtotime("now - $old");
 
$nids = db_query_range('
  SELECT n.nid
  FROM {node} n 
  WHERE n.type = :type AND n.created < :old 
  ORDER BY n.created ASC',
  0, $count, array(':old' => $old, ":type"=>$type)
);
 
foreach ($nids as $nid){
   $node = node_load($nid);
   node_save($node);
}

However, when I've enabled the action and try to run cron, I receive this message:

  • Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /home/content/21/7456221/html/theme/includes/entity.inc).
  • Recoverable fatal error: Object of class stdClass could not be converted to string in DatabaseStatementBase->execute() (line 2135 of /home/content/21/7456221/html/theme/includes/database/database.inc)

Could anyone shed some light on what has gone wrong? Thank you.

Comments

millwardesque’s picture

node_load expects the $nid parameter to be the NID of the node rather than an object containing the NID (see http://api.drupal.org/api/drupal/modules--node--node.module/function/nod...)

Try using the following instead.

foreach ($nids as $nid) {
  $node = node_load($nid->nid);
  node_save($node);
}
andregriffin’s picture

Status: Active » Fixed

That worked brilliantly. Thank you so much!

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

obfuscate client name