This is an inofficial follow-up of #319346: blogapi_mt_set_post_categories() allows assigning arbitrary categories to posts regardless of taxonomy settings.

It wasn't possible in D6 and below, but we should now be able to use the taxonomy load_multiple functions instead of doing arbitrary queries in the validate function, atleast with a few tweaks to those functions :)

What this patch contains:
1. Re-introduce the tests that weren't commited in #319346: blogapi_mt_set_post_categories() allows assigning arbitrary categories to posts regardless of taxonomy settings
2. Add the same node type handling to taxonomy_term_load_multiple() that is already in taxonomy_vocabulary_load_multiple()
3. Use a inner join if a type is specified in taxonomy_vocabulary_load_multiple (I am not 100% sure, but using leftJoin doesn't make sense to me for that)
4. Add term_access tags to both load functions.. not sure, do we need a different tag for vocabulary?
5. use taxonomy_*_load_multiple() functions in blogapi_mt_validate_terms()

catch and I discussed if we should create a general taxonomy validation function for that stuff, but I'm not sure how to do the validation error handling. Any ideas?

Comments

catch’s picture

Subscribing. Not sure if vocabularies should have a different tag or not. Since we already do the node type join for vocabularies it doesn't seem too bad adding it for terms too - certainly a lot nicer than blogapi querying directly.

catch’s picture

Also, this code will have to change drastically if and when #412518: Convert taxonomy_node_* related code to use field API + upgrade path gets in. Long term that's going to be the way to remove special casing of nodes in taxonomy.module, but while we've got it, might as well have it centralised.

berdir’s picture

Issue tags: +DBTNG Conversion

Tagging with the dbtng conversion tag. it's not actually a dbtng conversion, but it is imho the proper way to get rid of another two db_rewrite_sql calls :)

The problem imho is that hook_node_validate() implementations do use form_set_error to set the errors, so these aren't catched when saving a node with blogapi. If there would be a generic way to do it, we could move the validation to taxonomy_node_validate and then just display the error in blogapi.module

catch’s picture

Status: Needs review » Reviewed & tested by the community

Took another look at this and I'm happy. Marking RTBC.

jrchamp’s picture

A delightful side note is that this appears to kill off the last use of the db_placeholders in core which "is deprecated in Drupal 7 and will be removed as soon as it is expunged from core".

catch’s picture

Status: Reviewed & tested by the community » Needs work

The last submitted patch failed testing.

berdir’s picture

Status: Needs work » Reviewed & tested by the community

Re-setting status.

berdir’s picture

Status: Reviewed & tested by the community » Needs work

Ups, that wasn't a testbot error, I have to re-roll.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new10.21 KB

Ok, updated, changes.

- used taxonomy api functions for updating a vocabulary in the tests
- used vocabulary_access in vocabulary_load_multiple. term_access will break things I think.

jrchamp’s picture

You calculate the array_unique($node->taxonomy) twice.

Would it be better to simply do:

      $term_list = array_unique($node->taxonomy);
      $terms = taxonomy_term_load_multiple($term_list, array('type' => $node->type));

and:

      if (count($term_list) != $found_count) {
berdir’s picture

StatusFileSize
new9.95 KB

Good catch, re-rolled.

Status: Needs review » Needs work

The last submitted patch failed testing.

jrchamp’s picture

Status: Needs work » Needs review
StatusFileSize
new9.5 KB

Re-rolled. It appears someone removed the drupalLogin($web_user) call, which the patch from #12 also removed.

berdir’s picture

Status: Needs review » Reviewed & tested by the community

This was RTBC already and there were only minor changes since then..

catch’s picture

Status: Reviewed & tested by the community » Needs work

Hate to do this but:

+    $this->assertFalse($result, t('Post categories fail validation (attempt to post two when one is allowed).'));
+    // Change to required.
+    $this->updateVocabulary($vid, 'simpletest_vocab1', FALSE, TRUE);
+    $result = xmlrpc($local, 'mt.setPostCategories', $nid, $web_user->name, $web_user->pass_raw, array());
+    $this->assertFalse($result, t("Post categories fail validation (none posted when it's required)."));
+    // Change to allowing multiple, not required.

Could use a line break before those inline comments to make the test code less dense.

jrchamp’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new9.51 KB

Rerolled with spacing change request from #16.

catch’s picture

lovely.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks!

Status: Fixed » Closed (fixed)
Issue tags: -DBTNG Conversion

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