I am trying to use Content Profile within VBO, with an action to automatically create a new profile node if certain conditions are met. I noticed that content_profile_load returns a NULL profile even if a profile has already been created during the same page request, resulting in duplicate profile nodes. The reason is that a static cache is used, but there is no way to reset the cache. Would it be possible to add a $reset parameter to the function, defaulting to FALSE, to force it to try to load again:

<?php
function content_profile_load($type, $uid, $lang = '', $reset = FALSE) {
  static $cache = array();

  if (!isset($cache[$type][$uid][$lang]) || $reset) {
    $cache[$type][$uid][$lang] = FALSE;
    $params = array('type' => $type, 'uid' => $uid);
    if ($node = node_load($lang ? $params + array('language' => $lang) : $params)) {
      $cache[$type][$uid][$lang] = $node->nid;
    }
    return $node;
  }
  return !empty($cache[$type][$uid][$lang]) ? node_load($cache[$type][$uid][$lang]) : FALSE;
}
?>

Thanks for your consideration.

Comments

daniels____’s picture

+1

xurizaemon’s picture

Status: Active » Closed (duplicate)

This is a dupe of #592138: Add $reset parameter to content_profile_load() unless I'm missing some subtle difference.