1

I want to delete all field collection revisions of a specific field. I found deleteRevision for this job, but I don't know how to use it. (I couldn't find any example of it.)

Anybody know how can I delete all field collection revisions of a specific field?

3

1 Answer 1

2

Since you want to purge revisions on a field in a field collection and not an entire content type, your best bet is going to be doing this directly in phpMyAdmin. I don't know of any modules that enable you to delete revisions for a particular field but not the whole content type.

I would locate the field in question and run DELETE from field_revision_field_yourfieldname.

Of course you should back up things before you run a delete query.

The data for nodes and node revisions are store in two different tables. The data for the node page is stored in field_data_yourfieldname. The data for the revision is stored in field_revision_field_yourfieldname.

To illustrate this concept for you, I set up a fresh install of drupal (7.28) on my local machine and connected it to a new empty database.

I set up a content type called field collection demo and I added two field collections. enter image description here

enter image description here

Since I'm not sure what your configuration entails, the fields I used may or may not be similar to your fields.

Then I created two sample nodes and edited both of them several times with revision tracking turned on. I mostly used lipsum text but for the last revision I typed meaningful text to help you see what's happening in the database.

Here you see that I have created the two nodes: enter image description here

Here you can see the lipsum text in the original post. enter image description here

Here you can see that I've created multiple revisions of the node. enter image description here

And here you can see the meaningful revised text that is the most recent revision. enter image description here

The next picture shows you how this data is stored in the database in the field_revision_field_yourfieldname table. enter image description here

You can manually delete one row from the table using the red "X" in phpMyAdmin. Look, for instance, at the last row in this table. enter image description here

After I click the red "X" for that row, it is deleted. enter image description here

You can see that now the revision that began with r2 is gone from the field_revision_field_my_fifth_field table.

This removes the revision from the node's revision page. Notice in this picture, the field labeled "My fifth field" is missing. enter image description here

But this does not affect the node's public view, because that data is stored in the field_data_my_fifth_field table not in the field_revision_field_my_fifth_field_table. enter image description here

Therefore, I can safely delete all the revisions from the field_revision_field_my_fifth_field_table with the delete query (as I've done on my demo site) and still view the node with no problems: enter image description here

All the revisions from the field "My fifth field" are gone on the revisions tab but the view tab remains unchanged.

If you wanted to delete all the revisions for all the fields that comprise a node collection, you would simply run the delete query for each of the field_revision_field_yourfieldname tables in the database.

4
  • Do you sure , if I delete all revision, the field collection show value or they will be empty ?
    – Yuseferi
    May 18, 2014 at 4:39
  • Well, it depends on what you mean by "will they be empty?" The data for nodes and node revisions are store in two different tables. The data for the node page is stored in field_data_yourfieldname. The data for the revision is stored in field_revision_field_yourfieldname. I'll revise my answer above with screenshots to illustrate. May 23, 2014 at 20:05
  • Did the revised answer above give you what you needed to delete the field collection revisions? May 27, 2014 at 0:47
  • I think doing this will remove data from fields in display as well as from edit form of node. This is what happens in my case. Dec 20, 2016 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.