In Drupal 7 the table for taxonomy term data changed from term_data to taxonomy_term_data. Also function names for loading and deleting terms were modified. This patch contains the necessary changes.

Comments

paulgemini’s picture

Forgive me (I'm a novice), but is this the patch that makes the taxonomy bulk operations work? I added it and I still received the error described here:

http://drupal.org/node/1015164

aangel’s picture

It doesn't appear to be...looking at the code it doesn't make changes where the error is occurring. I applied it anyway to be sure and the error persists.
I think this part just hasn't been ported yet, per the discussion at http://drupal.org/node/1108578

sun’s picture

Status: Active » Needs work
+++ b/views_bulk_operations.module
@@ -983,8 +983,8 @@ function views_bulk_operations_views_bulk_operations_object_info() {
     'term' => array(
       'type' => 'term',
-      'base_table' => 'term_data',
-      'load' => 'taxonomy_get_term',
+      'base_table' => 'taxonomy_term_data',
+      'load' => 'taxonomy_term_load',
       'title' => 'name',
     ),

This is already going to be changed via #1123364: Implement hook_views_bulk_operations_object_info() for entities and can be removed from this patch.

Powered by Dreditor.

Taxoman’s picture

Subscribing

paulgemini’s picture

subscribing

bojanz’s picture

Status: Needs work » Fixed

Marking this as fixed.
The first chunk (fixing delete) just went into the reloaded branch, soon to be merged into 7.x-3.x
The second chunk was already there.

Modifying terms on nodes will be possible once #1057158: Provide an action for modifying entity values gets done.
The separate taxonomy.action.inc was removed because in D7 terms work through ordinary reference fields.

Status: Fixed » Closed (fixed)

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

kclarkson’s picture

So fields Actions needs to be done before we get bulk taxonomy update?

bojanz’s picture

Yes. But getting that to work generically (VBO supports all entity types) is a huge & hard effort that nobody's contributing to, so it will take a while.

If someone wants to port over / write just the taxonomy actions themselves, even as a stop gap measure, I wouldn't complain. It's just not my priority with the general field updating still unresolved.

erik2e’s picture

bojanz does not lie when he writes about a huge & hard effort :)

i came up with quick and basic taxonomy actions, and i'll share the code after a bit of cleaning. this is used in 2 d7 production sites for mass taxonomy operations, so i guess it should be usable for someone else.

you can add/update/delete the terms of selected nodes. i may add support for other entities if needed, but the code is really a quick answer to a client need for mass taxonomy operations on nodes.

@bojanz, should I just upload the .inc files here ?

bojanz’s picture

Yes, please do, and then reopen the issue.

erik2e’s picture

Assigned: Unassigned » erik2e
Category: bug » feature
Status: Closed (fixed) » Needs review

Please find attached the 2 actions mentionned above. 2 files in the zip/tgz :

  • terms_fields.action.inc contains the action "Modify node terms per fields". It takes all taxonomy terms found withing the selected nodes, and present you a form for each field where you can select terms and related action (add, replace, delete, or do do nothing).
  • terms_fields_bundles.action.inc contains the action "Modify node terms per fields & node types". It's basically the same action as the other one, except you have distinct form for each field/node type combination. This can be useful if you need to do different actions on the same field, depending on node type.

Just copy the files to the actions/ subdirectory of the VBO module directory.

As I said, this is quick and basic code. Comments/feedback are welcome. The action only works on nodes, and is provided without any warranty, use it at your own risks.

erik2e’s picture

StatusFileSize
new3.92 KB
new2.34 KB

Better with the files attached ...

erik2e’s picture

Component: Core » Actions

Forgot to mention that you need to setup and activate the Entity API module

bojanz’s picture

Entity API is a VBO dependency, it's always there.
Thanks, I'll take a look.

erik2e’s picture

Oops, I forgot that VBO requires Entity API :) The module_exists() checks might be removed.

Let me know if you find this useful, and if I can help with the generic Fields Actions.

erik2e’s picture

StatusFileSize
new3.91 KB

Re-oops. I screwed the actions, this cannot work (name changes on the callback, and name mismatch on one of the files).

Please find attached a working version.

philipz’s picture

The actions do not show up on the vbo field's action list. I cleared the cache just to be sure.

bojanz’s picture

Yes, you need to add the filename to views_bulk_operations_load_action_includes().

Thanks for the code, erik2e, I'm on DrupalCon London right now, but when that ends I will review this.

erik2e’s picture

Version: 7.x-3.x-dev » 7.x-3.0-beta2

The code does not work with -beta2. Even if you add the filenames to function views_bulk_operations_load_action_includes() it won't work.

I'll double check the changes done in beta2 and update the code.

The code works with beta1 if you want to try it before the fix is sent.

Things are moving fast on the VBO planet :-)

bojanz’s picture

There's shouldn't be anything else other than the line in views_bulk_operations_load_action_includes(), but do double check :)

erik2e’s picture

StatusFileSize
new427 bytes
new3.9 KB

I've double check :-)

It seems the context parameter of function views_bulk_operations_taxonomy_action_form have changed, the $nid of selected node was the key of the array, and it is now the value. The code is updated, but I'd like to find a way to make a patch that includes the addition of the 2 actions files in the actions/ directory.

In the meantime, please find attached a new zip with the 2 updated .inc files, to be copied in the actions/ subfolder of the VBO module directory. And also find a patch for the .module file to include the 2 new actions in the list.

Basically, at line 50 of the views_bulk_operations.module, you have to add the 2 new actions as follow :

'delete.action.inc',
'script.action.inc',
'user_roles.action.inc',
+ 'terms_fields.action.inc',
+ 'terms_fields_bundles.action.inc'
);

epoitras’s picture

Very much appreciated erik2e, thank you.

infojunkie’s picture

FYI, the latest 6.x dev release has a better mechanism for detecting actions, without sacrificing too much resources. Check function _views_bulk_operations_load_actions.

bojanz’s picture

I'm fine with the current approach to detecting. Discussed it with catch, we saw the benefit to doing what 6.x-1.x does, despite the variable_set ugliness, but simplicity won out in the end.

grossmann’s picture

I tested the patch and files of #22 and they seem to work so far.
Thanks for this cause it is a most needed feature for me. It would be a nice feature to see in the selection view which terms are already selected.
grossmann-mcs

sachbearbeiter’s picture

sub

erik2e’s picture

@grossmann-mcs, I thought about this feature, but you can either display terms common to all nodes, or terms that are used by some of the node, so I did not implemented anything :)

What I've done is have the terms reference fields displayed in the view that uses VBO, and added a filter so one can quickly select nodes depending on their terms. That made everyone happy in my context.

Adding this is not very hard, but this code is a quick hack to get things running for mass taxonomy operations in a particular context, so unless the module maintainers are planning on integrating it, I won't work further on it.

Support for other entities (supports only nodes for now), and an extra form page asking a few options (display fields only or each combination of fields/bundles, pre-selection of terms common to all node or all terms used, use of field native widget or generic select list) would indeed make a more usable vbo taxonomy solution.

@bojanz, did you had any time to review the code ? How would a dedicated vbo taxonomy action fit in the plans ?

grossmann’s picture

@erik2e, yes I see the problem with showing terms when I select multible nodes. I will be easier to filter them beforehand and then execute the action.
I would love to see the taxonomy handling added to the module because this makes life so much easier. Good work on that.
grossmann-mcs

bojanz’s picture

@grossmann-mcs, I thought about this feature, but you can either display terms common to all nodes, or terms that are used by some of the node, so I did not implemented anything :)

And both would be wrong. When bulk editing there's no point in showing any values.

I like these actions. The code has a bad way of getting bundles, but once I get a faster & generic way of doing that into VBO (as a part of #1057158: Provide an action for modifying entity values) that can easily be fixed here as well.
I'm just not sure how useful this action will be once #1057158: Provide an action for modifying entity values is done (I'm working on it this week). I already have there support for fields on all entities (per bundle), including taxonomy references.
I'll just let the users decide once both solutions are in the queue and awaiting review.

Once again, thank you for your work, erik2e.

erik2e’s picture

@bojanz, Glad to hear you're working on #1057158: Rewrite fields.action.inc :-)

We'll see if there's the need for specific taxonomy actions. In the meantime, let me know if you need any help on #1057158, even for testing (any Git place to be cloned ? :-)

mike27’s picture

@erik2e
Hello,
I applied the patch and enabled Entity. However when i try to modify taxonomy terms i have the following error:

Notice: Trying to get property of non-object in views_bulk_operations_terms_fields_action_form() (line 105 of ..\views_bulk_operations\actions\terms_fields.action.inc).

Can you tell me what am i doing wrong because i think that the patch and files should have worked.

Thank

erik2e’s picture

Hello mike27,

Latest patch (#22) is designed for 3.0-beta2. It is not compatible with previous version and the error you have is probably due to an older version.

Previous version of the actions files (#17) are working with pre 3.0-beta2 version.

You should either upgrade VBO to -beta2 and use #22, or use the files in #17.

If you upgrade to 3.0-beta2, don't forget to patch or manually add the actions in the .module file or they won't appear in the list.

mike27’s picture

Hello erik2e,

I did what is mentioned in this thread an d i have no errors.

The action is present but when i try to add a term, the action deletes any existing terms and leaves the field blank.

It is like it has no write permissions. However the processed post seems to be updated (the date is changing)

I also tried to perform the same action with rules but it is too complicated.

If you could provide any further help is much appreciated.
Thanks
Mike

webchick’s picture

mike27’s picture

Can anybody write step by step how modifing terms can be performed with vbo and rules? Component - Condition - Action.

Unfortunately patch and actions do not update terms correctly (or I miss something)

What i have managed to figure out is creating a component

Variables
1)Entity - Node
2) List of taxonomy terms

Condition
Entity has field --> Set Node and preffered term field

Action
Set data value
(replace "preffered term field" with variable "List of taxonomy terms" )

However this component works with term ids and not term names and only replace modification can be performed (not e.g. add extra terms)

Any help is much appreciated.

Thank you in advance,
Mike

bojanz’s picture

You have an exported rule available in http://drupal.org/node/1057158#comment-4792118 ready to be used with VBO (just change the field name).
As you'll see there, you add items instead of replacing through a different action (called something like "Add item to list").

mike27’s picture

Thank you bojanz,

It works indeed. I suppose there is no way to add new terms since it works with term ids.

I hope there is an improvement soon.

Thank you again,

Mike

erik2e’s picture

@mike27, sorry for the lack of feedback. I don't have the problem on sites where these actions are used, so we may need to enter a full debug cycle to track the problem down :-)

Can you let me know the modules and versions you're using ?

Glad to see that you have it working by using rules, however. VBO definitely rocks :)

Concerning the add new terms features, if what you want is to be able to add new terms in the vocabulary directly from the VBO UI, while adding these to the taxonomy fields, I may add it in the next few days. I'll add a basic text field where you can add comma separated new terms. These will be added in the vocabulary, and assigned to the taxonomy field. Quick hack but that will save time to the current users.

@bojanz, any help needed for #1057158: Rewrite fields.action.inc ? Can we test and help debug ?

gidgetk’s picture

I applied erik2e's fix/path in #22 and it works perfectly so far.

mike27’s picture

erik2e,

sorry for the delay, i use the following modules

Entity API 7.x-1.0-beta10

Views Bulk Operations 7.x-3.0-beta2

Views 7.x-3.0-beta2

Rules 7.x-2.0-rc1

Refineo’s picture

After applying the patch (#22), when a node selected has no taxonomy term reference fields at all, system displays a warning message:

"Warning: Invalid argument supplied for foreach() in views_bulk_operations_terms_fields_action_submit() (line 184 of /***/sites/all/modules/contrib/views_bulk_operations/actions/terms_fields.action.inc)."

Refineo’s picture

patch (#22) error: The node multiple taxonomy terms are not updated.
Test scenario:

  • 1.select a node that contains 2 term reference fields
  • 2.select modify node terms per fields
  • 3.click "execute"
  • 4.terms for field select a term from vocabulary (vocabulary_1)
  • 5.select Action to take for this field: Add the selected terms
  • 6.terms for field select a term from vocabulary (vocabulary_2)
  • 7.select Action to take for this field: Add the selected terms
  • 8.click "Next"
  • 9."You selected the following item: " . Click "Confirm"
  • 10. Performed Modify node terms per fields on 1 item.
  • 11. Edit the node to check if terms are updated.

ERROR: The node multiple taxonomy terms are not updated.

Drupal 7.8

prodigeek’s picture

StatusFileSize
new37.45 KB

When I try running the tag update, I get all the way to the confirmation screen when I get an ajax error (see attached screenshot).

I've tried it in both Firefox and Chrome.

itamair’s picture

prolems for me too ...
It was working somehow then I added a new term_reference_field to more than one content types, (shown in the same view) and the VBO is not able to update terms on some content types (actually works just on one of them).
When lunched the command these error messages appears:

Notice: Undefined index: node in views_bulk_operations_terms_fields_action_form() (line 117 of ...
Warning: Invalid argument supplied for foreach() in views_bulk_operations_terms_fields_action_form() (line 117 ...

anou’s picture

Hello,
I wanted to mention three things :

  1. The #22 code & patch work fine with -beta3
  2. Don't forget to modify the configuration (select the 2 new operations) in the VBO's view
  3. Optionally you can translate them also via /admin/config/regional/translate/translate

Thanks for the code. Very useful for me.

David

robloach’s picture

Version: 7.x-3.0-beta2 » 7.x-3.x-dev

May be running into this pretty soon.

erik2e’s picture

Sorry for the lack of feedback. After some quick checks, I was not able to reproduce the problems mentionned by mike27, refineo and itamair. I'll try to find time to fix the issues later on, but as I said, this really is some quick hack work, so you may be more lucky walking the VBO/Rules path, or help bojanz finish #1057158: Rewrite fields.action.inc.

I'll of course get back here if I fix something in the current patch.

@Rob Loach, what do you mean by "may be running into this" ? Are you planning to work on taxonomy actions ?

Nick Lewis’s picture

Status: Needs review » Needs work

If your view has exposed filters that are set, this patch will result in the following error.
PDOException: You cannot serialize or unserialize PDO instances in dmemcache_set() (line 41 of /sites/all/modules/memcache/dmemcache.inc).
Error is same regardless of cache backend.

Nick Lewis’s picture

Status: Needs work » Needs review

Nevermind. The problem is unique to views 3.x/7.x "search terms" exposed widget. I wrote a patch for views that resolves the problem:
#1372376: Search Terms Exposed Filter Breaks Views Bulk Operations

jeffschuler’s picture

StatusFileSize
new14.09 KB

#22 is working for me. I rerolled all changes in #22 as a single patch and removed improper whitespace and tabs.

jeffschuler’s picture

Status: Needs review » Needs work

Actually, this patch (#51, was #22,) is working in 7.x-3.0-beta3 for me, but not in 7.x-3.x-dev.

In 7.x-3.x-dev I get the following error when I attempt to execute one of the taxonomy-related VBO actions:

Notice: Undefined index: selection in views_bulk_operations_terms_fields_action_form() (line 101 of /sites/all/modules/views_bulk_operations/actions/terms_fields.action.inc).
Warning: Invalid argument supplied for foreach() in views_bulk_operations_terms_fields_action_form() (line 101 of /sites/all/modules/views_bulk_operations/actions/terms_fields.action.inc).

SammMoney’s picture

@ #22 Just wanted to pop in and say thanks for posting this, its really helping me out.

daniel wentsch’s picture

Thanks for your work in #22, erik2e.
Still don't get it to work. Applied the patch against VBO 3.0-beta3 and put the action files into their directory.
Now, I am able to configure term actions in my view and when I actually run them I get a success messages that tells me: "Performed Modify node terms per fields on 1 entry." But the given node still hasn't got a term applied.
Any idea?

goodeit’s picture

Thanks for the patch, erik2e and jeffschueler.

The patch in #51 applied fine to 7.x-3.0-beta3, and I can go through the form and select terms to add/delete/etc. However, when I submit on the confirmation page, the views_bulk_operations_terms_fields_action() function fails silently. I did some debugging and it stops on entity_save('node',$entity); at line 64.

I compared $entity from the beginning of the method to right before entity_save(), and they are identical except for the new term in my taxonomy field.

bojanz’s picture

There's now a final patch at #1057158: Provide an action for modifying entity values that I plan to commit in the next day or two (depending on user testing).
It allows you (among other things) to edit term reference fields, with both add or replace (append values, or replace values)

The only thing missing is the "Delete selected terms" option.
How important is this option? Is it something we need in VBO? If yes, do we want it in the "Modify entity fields" action, or do we want
to have a separate action that allows deleting terms?

I haven't reviewed the patch here because I'm hoping that the "Modify entity fields" action is enough.
If it's not, let's discuss it.

summit’s picture

+1 for deleting selected terms, because then all term manipulation can be done through VBO.
Greetings, Martijn

goodeit’s picture

@bojanz: I also think that deleting selected terms is an important option to have in VBO. As far as how it's implemented, it would probably be better off in the "modify entity fields" action to go with the add and replace functions.

(update to #55, I tracked the problem down to an Ubercart bug, fixed it, and now all actions work fine using the patch in #51.)

grossmann’s picture

+1 for bulk deleting terms. This is a must have. If you can bulk add then you have to be able to bulk remove or we end up on manually removing accidently wrong added terms on 10k nodes by hand ;-).
grossmann-mcs

erik2e’s picture

Thanks bojanz, I won't miss to test this in the next few days/hours :-)

Deleting terms is needed on the few sites I have running these taxonomy actions, and grossmann-mcs is right : people adding wrong terms on 10k nodes could be hurt :-)

If there's a single action for add/modify, then I think adding the delete feature to it would be a good idea. If they are distinct actions, then a distinct delete action is fine.

I guess someone, including me of course, could add this and save your time for something more important. I'll try to work on it while testing the new actions.

Thanks again for your work on VBO, and thanks jeffschueler for the patch cleanup !

commercebythegraceofgod’s picture

Version: 7.x-3.x-dev » 7.x-3.0-beta3
Category: feature » bug

First off, thanks for working on this patch/issue.

One small issue you might want to be aware of: It doesn't allow you to modify values on items sorted by a contextual filter, or at least those using search terms. It throws a reference to the cache...however, I cleared and disabled cache, then tried again. I received the same results.

If you know a better way to go about sorting these, please let me know. I have 750+ products that I must tag. If there isn't a solution, it's back to Commerce BPC to figure out how to replace only the taxonomy fields.

Error follows:

Notice: Undefined index: node in views_bulk_operations_terms_fields_action_form() (line 117 of /srv/www/.../public_html/drupal/sites/all/modules/views_bulk_operations/actions/terms_fields.action.inc).
Warning: Invalid argument supplied for foreach() in views_bulk_operations_terms_fields_action_form() (line 117 of /srv/www/.../public_html/drupal/sites/all/modules/views_bulk_operations/actions/terms_fields.action.inc).
<strong>PDOException: You cannot serialize or unserialize PDO instances in DrupalDatabaseCache->set() (line 418 of /srv/www/.../public_html/drupal/includes/cache.inc</strong>).
bojanz’s picture

Okay, you've convinced me.
I'll add the "delete" functionality to #1057158: Provide an action for modifying entity values.
Of course, not all multiple fields can support that, only the ones with property_info types: list<$entity_type> (this includes entityreference, taxonomy term, product reference fields...) and perhaps list / list, needs to be checked.

@erik2e
You could help me by reviewing the existing patch at #1057158: Provide an action for modifying entity values and commenting. Read your patch in this issue, very sound approach and code, so I would like to know if you find my current code understandable and maintainable.
While you do that, I'll try to do a reroll with delete functionality.

erik2e’s picture

@bojanz, I will review the patch asap and provide the requested feedback. Glad to finally help on the "official" solution :-)

For problems with the patch in #51, I'll try to test this further against -beta3 and find some answers.

OnkelTem’s picture

I confirm both #54 and #55.

On -dev, I'm getting this:

Notice: Undefined index: selection in views_bulk_operations_terms_fields_action_form() (line 101 of .../sites/all/modules/views_bulk_operations/actions/terms_fields.action.inc).
Warning: Invalid argument supplied for foreach() in views_bulk_operations_terms_fields_action_form() (line 101 of .../sites/all/modules/views_bulk_operations/actions/terms_fields.action.inc).

On -beta3 - no terms are applied.

bojanz’s picture

Status: Needs work » Closed (won't fix)

Just committed #1057158: Provide an action for modifying entity values.
This provides the "add" and "replace" taxonomy functionality.
Opened a followup issue for adding "delete": #1421656: Extend the "modify entity values" action to add a delete mode for multiple-value properties and fields.

Closing this issue, since the code found here won't be committed.
Big thanks to erik2e for keeping this alive and providing a temporary solution. I appreciate it.

erik2e’s picture

I'm glad to see this closed :)

This code was not made to be committed, and it's nice to see the official code available. I'm currently testing this, and will try to find time to work on #1421656.

Thanks for all the work on VBO bojanz.

slefevre1’s picture

Sorry for being dense, but is this working now, or just not going to be implemented? If it works, how do you implement it? I have a VBO field set up in my view, but I can't find any taxonomy operations for it.

pyrello’s picture

@slefevre1 - Instead of "Modify taxonomy terms" it is now "Modify entity values" since taxonomy is added via taxonomy references now.

Valeratal’s picture

Modify entity values - this help add term

But How mass-delete term? :)

philipz’s picture