It should be possible to do:
$term = taxonomy_term_load($tid);
taxonomy_term_save($term);

Same as you can with any other entity in core. However our crappy hierarchy handling breaks on this.

For one, unless you explicitly load term->parent it'll get wiped. Additionally we delete then insert on both inserts and updates when it's only needed for inserts.

i'd prefer it we could load $parents in taxonomy_term_load() but that's much more of an API change. The only one here is that if you wanted to kill parents in a programmatic update you'd have to explicitly set parent to 0.

Comments

catch’s picture

Priority: Normal » Critical

Since this is data loss, and updating terms is a perfectly reasonable thing to want to do, and the patch is straightforward, bumping to critical.

catch’s picture

StatusFileSize
new2.44 KB

Slightly slimmer version

catch’s picture

StatusFileSize
new2.43 KB
catch’s picture

StatusFileSize
new1.02 KB

Added to existing test. This should have one fail.

catch’s picture

StatusFileSize
new3.45 KB

Test + patch combined.

dries’s picture

The code would be slightly more intuitive if the delete and the insert were closer to each other in the code. That said, this looks like a valid fix.

catch’s picture

We could switch the update/insert if/else, that'd get them a bit closer I guess.

catch’s picture

StatusFileSize
new3.88 KB

Untested patch switching the order, also removed the $term->name check since that seems just odd here.

dries’s picture

Status: Needs review » Reviewed & tested by the community

This looks better to me, and the tests seem to work. Marking this RTBC.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Reviewed it once more, and decided to commit this patch to CVS HEAD. Thanks!

Status: Fixed » Closed (fixed)

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