Make Content Taxonomy Fields compatible with Merge feature
| Project: | Taxonomy Manager |
| Version: | 6.x-1.0-beta2 |
| Component: | Code |
| Category: | feature request |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
For freetagging vocabularies i use Content Taxonomy Autocomplete (6.x-1.0-beta6) field to save terms.
In my content type i have 3 such fields - Region, Street and Index
Users often input street address wrong (for example "13 Avenue" and "13th Avenue") - so i want to merge "13 Avenue" into "13th Avenue". But when i merge term "13 Avenue" with "13th Avenue" in Street vocabulary - all other terms (Region and Index) in nodes becames empty!
Explain in detail
First i have such nodes:
title: Teddy Shop
Region: West
Street: 13 Avenue
Index: 31000
After merging:
title: Teddy Shop
Region:
Street:
Index:
What is the reason for such problem? Maybe - the using of Content Taxonomy Field inspite of direct assigning vocabulary to node?

#1
I find out that terms from other vocabularies disappears when module delete term which is still linked to node.
So module must first assign new merged term to node and then delete old unnecessary term
So if i want merge "13 Avenue" into "13th Avenue" then module must do in such order
1. Update all nodes and set "13th Avenue" where term is "13 Avenue"
2. Delete unnecessary term "13 Avenue"
#2
I believe you're right – it's because of CCK Content Taxonomy Fields.
This would be a very useful feature, but implementation may not be straightforward...
(subscribing)
#3
yes, at the moment the Merge feature is not compatible with Content Taxonomy Fields!!
As far as I remember I pointed this out in the readme.txt
I'm planing to implement this, but can't tell you when I'm going to find time to implement this feature
#4
changing title...
#5
Any progress on this yet?
(subscribing)
#6
also interested in this.
#7
implementating a hook as mentioned in a TODO should solve this if correctly implmentated them by content_taxonomy
ie
//TODO: add hook, so that other modules can consider changes
<?phpforeach ($merging_terms as $merge_term) {
if ($merge_term != $main_term) {
//update node-relations
module_invoke_all('taxonomy_manager_term','merge',$main_term,$merge_term); // the hook
?>
and then content_taxonomy could implement something like
<?phpfunction content_taxonomy_taxonomy_manager_term($op,$arg0=null,$arg1=null) {
switch($op) {
case 'merge':
$new = $arg0;
$old = $arg1 ;
$types = content_types();
foreach(content_fields() as $fieldname => $fieldinfo) {
if ($fieldinfo['type']=='content_taxonomy') {
foreach($types as $type=>$info) {
if ($info['fields'][$fieldname]) {
if ($info['tables']['content_'.$fieldname]) $table = 'content_' . $fieldname;
else $table = _content_tablename($type['type'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE);
$dbfield = $fieldname . '_value';
if (!db_result(db_query("SELECT vid from {$table} where $dbfield=%d LIMIT 1",$old))) continue;
db_query("UPDATE {$table} SET $dbfield=%d where $dbfield=%d",array($new,$old));
//cleanup
$vids = array();
if ($fieldinfo['multiple'] > 0) {
$query = "SELECT vid from {$table} where $dbfield=%d GROUP by vid, $dbfield having count(delta) > 1";
$result =db_query($query,$new);
while ($row = db_fetch_object($result)) {
$result2 = db_query("SELECT delta from {$table} where $dbfield=%d AND vid=%d ",array($new,$row->vid));
while ($delta = db_fetch_object($result2)) {
if (!in_array($row->vid,$vids)) $vids[] = $row->vid;
else {
db_query("DELETE from {$table} where $dbfield=%d AND vid=%d AND delta=%d",array($new,$row->vid,$delta->delta));
}
}
}
}
}
}
}
}
break;
}
}
?>
(...with a much better 'cleanup' area, blerg).
Wouldn't that work?