I recently upgraded term_fields from 1.6 to 2.x-dev and find that I am now unable to save term_field data while editing a term.

I am attempting to debug the problem, but this is what I have found so far:
* The update.php process ran without outputting an error
* There was no data lost (neither field values nor entire field definitions themselves)
* When editing a term in 2.x, any pre-existing field data is populated on the form. However, any changes to that data is not saved to the database.
* If I change any values in the database directly, those changes will show up on the term edit form.
* If I uninstall term_fields entirely and install 2.x from scratch, the module functions properly.
* A quick glance at the tables in MySQL indicates that the scheme is the same between my upgraded 1.x->2.x database and the database with a 2.x-from-scratch install.

Any thoughts? I'll report back if I find out anything else.

CommentFileSizeAuthor
#3 term_fields-1356140-3.patch1.15 KBkmonty

Comments

kmonty’s picture

Priority: Critical » Major

Downgrading the priority to major, as the possibility exists that this is something on my end.

kmonty’s picture

Priority: Major » Critical

Okay, I found the problem.

In the upgrade process, we call term_fields_update_6101(), which adds a vid field to {term_fields_terms} on line 185:

// Add the 'vid' column to . This allows to easily reset the values
// when a field is removed from a specific vocabulary.
db_add_field($ret, 'term_fields_term', 'vid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE), array('indexes' => array('vid' => array('vid'))));

The problem is we never assign a value for each row's vid, so every upgraded row is given a vid of 0.

In term_field.module's hook_taxonomy() implementation, on $op term insert or update, we select where to update a row based on BOTH the tid and vid (line 241):

db_query("UPDATE {term_fields_term} SET ". implode(', ', $nulls) ." WHERE tid = %d AND vid = %d", $args);

Of course, every upgraded row has a vid of 0, so this query returns no results.

The quick solution is to remove the AND vid = %d (it's not necessary anyway), but that's not a proper solution. I'll work on figuring out the best way to update each row during the upgrade process and post a patch when it's ready.

kmonty’s picture

Status: Active » Needs review
StatusFileSize
new1.15 KB

Here's a patch that runs a hook_update_N() function updating each row in {term_fields_term}

seworthi’s picture

Patch work great for me. Same update path.

b-prod’s picture

Status: Needs review » Fixed

You're totally right.
I put some comments in the code suffixed by "@todo" by in this case ("Add terms vid to the {term_fields_term} table;") I forgot the "@todo" string...
So I skipped this todo task (bad me!).

Fixed in the DEV version.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

clarifying some points