How can I prevent endless recursion with Drupal's node_load()? -


i'm using ubercart product , product_kit modules. great @ linking relevant product kit products included, want link individual product kits may part of.

i figured database search on sku/model number (got part done easily), , use node_load($nid) related kit.

i have far:

function amh_shop_nodeapi(&$node, $op, $a3 = null, $a4 = null) {     if ($node->type == 'product') {         if ($op == 'load') {             error_log("product::load");              $bundles = array();             $results = db_query('select distinct n.nid {node} n right join {uc_products} on up.nid = n.nid up.model "%s /%" or up.model "%/ %s /%" or up.model "%/ %s"', $node->model, $node->model, $node->model);              while ($bundle = db_fetch_object($results)) {                 error_log("bundle::load");                 $bundles[] = node_load($bundle->nid);             }         }     } } 

but, because product kits loading products, end in recursive loop.

i guess question comes in 2 parts:

  1. the question title of post: how prevent recursion?

  2. slightly different question answers first 1 anyway: should doing when node being loaded, or later in process (for example, @ view or alter)?

hey there module called http://drupal.org/project/contemplate. had similar problem of recursion within module, figured out workaround setting recursion_limit.

i not sure if solves problem, worth going through module , search code contemplate_max_recursion_depth. might give pointers.

hope helps..


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -