Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
There currently is not a way to delete product revisions. We should copy what the Node module provides.
/**
* Deletes a node revision.
*
* @param $revision_id
* The revision ID to delete.
*/
function node_revision_delete($revision_id) {
if ($revision = node_load(NULL, $revision_id)) {
// Prevent deleting the current revision.
$node = node_load($revision->nid);
if ($revision_id == $node->vid) {
return FALSE;
}
db_delete('node_revision')
->condition('nid', $revision->nid)
->condition('vid', $revision->vid)
->execute();
module_invoke_all('node_revision_delete', $revision);
field_attach_delete_revision('node', $revision);
return TRUE;
}
return FALSE;
}
Comment | File | Size | Author |
---|---|---|---|
#7 | 2660056-7.delete_product_revisions.patch | 3.36 KB | rszrama |
|
Comments
Comment #2
mglamanOr implement the methods required so we can re-use Entity API's helper functions: http://drupal.stackexchange.com/a/188724/13179
Comment #3
mglamanComment #4
candelas CreditAttribution: candelas as a volunteer commentedYes, my table with revisions is growing and we don't use those revisions for anything :)
Comment #5
DrupalWoody CreditAttribution: DrupalWoody commentedWhere do you put this code to get it to run?
I tried to use the Field SQL Norevisions module on a test copy of my database, and it cleared out 4 GB of revisions, but didn't touch any of my commerce product entities, so there's still 12 GB of revisions left.
Comment #6
potop CreditAttribution: potop commentedImplemented this functionality in a module: Commerce Product Revision Delete Using the code provided by Matt Glaman in the answer here.
Comment #7
rszrama CreditAttribution: rszrama at Centarro commentedFollowing the pattern of #2442049: Commerce order revision deletion callback, I implemented the
EntityAPIContollerRevisionableInterface
in the product controller, added acommerce_product_is_latest_revision()
function similar to the one for orders, and documented the revision delete hook incommerce_product.api.php
.Comment #8
rszrama CreditAttribution: rszrama at Centarro commentedWith this interface implemented, you delete a product revision by calling
entity_revision_delete('commerce_product', ##)
, and it will prevent you from deleting the current revision.Comment #9
rszrama CreditAttribution: rszrama at Centarro commentedCommitted.