--- modules/rules/rules/modules/taxonomy.rules.inc.old Wed Aug 05 19:20:41 2009 +++ modules/rules/rules/modules/taxonomy.rules.inc Sun Sep 19 20:19:45 2010 @@ -201,10 +201,39 @@ * Action: Remove a term from content. */ function rules_action_taxonomy_term_remove_from_content($node, $taxonomy_term, $settings) { - if (isset($node->taxonomy[$taxonomy_term->tid])) { - unset($node->taxonomy[$taxonomy_term->tid]); + $recursive_search = _rules_action_taxonomy_term_remove_from_content_helper($taxonomy_term->tid, $node->taxonomy); + if ($recursive_search != FALSE) { + switch (count($recursive_search)) { + case 2: + unset($node->taxonomy[$recursive_search[0]][$recursive_search[1]]); + break; + case 1: + unset($node->taxonomy[$recursive_search[0]]); + break; + default: + break; + } + unset($recursive_search); return array('node' => $node); } +} + +/** + * Helper: This is a helper function for recursive array search + */ + +function _rules_action_taxonomy_term_remove_from_content_helper($needle, $haystack, $path=array()) { + if(!is_array($haystack)) {return FALSE;} + foreach($haystack as $key => $val) { + if(is_array($val) && $subPath = _rules_action_taxonomy_term_remove_from_content_helper($needle, $val, $path)) { + $path = array_merge($path, array($key), $subPath); + return $path; + } elseif($val == $needle) { + $path[] = $key; + return $path; + } + } + return FALSE; } /**