During re-install of this module i got an error "function term_node_count_count_nodes() not found in term_node_count.install on line 36"

It could be fixed with one line of code drupal_load('module', 'term_node_count'); in beginning of function term_node_count_install().

Comments

fasdalf@fasdalf.ru’s picture

Like this

function term_node_count_install() {
  // Makes term_node_count_count_nodes() avaliable.
  drupal_load('module', 'term_node_count');

  drupal_install_schema('term_node_count');
	
	// we have to set the weight high so that our module's hooks run after node and taxonomy
	$sql = "UPDATE {system} SET weight = 10 WHERE name = 'term_node_count'";
	db_query($sql);
	
	// first we'll count all the number of published, current revisions for each term that has at least one
	$sql = 'INSERT INTO {term_node_count} (tid, node_count) (SELECT tid, COUNT(np.nid) FROM {term_node} tn LEFT JOIN {node} np ON tn.vid = np.vid AND np.status = 1 GROUP BY tid)';
	db_query($sql);
	
	// then we'll say that if there is a term id that isnt in term_count_count then it has 0 nodes
	$sql = 'INSERT INTO {term_node_count} (tid, node_count) (SELECT tid, 0 FROM {term_data} WHERE tid NOT IN (SELECT tid FROM {term_node_count}))';
	db_query($sql);
	
/////////////////////////////////////// patch	
	// the user might want parent terms to inherit node counts from their child terms
	if (variable_get('term_node_count_inherit', 0)) {
		// first we find all the terms that have child terms and update each separately
		$sql = 'SELECT parent FROM {term_hierarchy} WHERE parent != 0';
		$result = db_query($sql);
		$parents = array();
		while ($data = db_fetch_object($result)) {
			$parents[] = $data->parent;
		}
		
		// now that we have all parent terms, we'll go through and sum up the child term's node counts and update the parent term
		foreach ($parents as $pid) {
			$count = term_node_count_count_nodes($pid);
			$sql = 'UPDATE {term_node_count} SET node_count = %d WHERE tid = %d';
			db_query($sql, $count, $pid);
		}
	}
///////////////////////////////////////
		
}