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;
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mglaman created an issue. See original summary.

mglaman’s picture

Or implement the methods required so we can re-use Entity API's helper functions: http://drupal.stackexchange.com/a/188724/13179

mglaman’s picture

Version: 8.x-2.x-dev » 7.x-1.x-dev
candelas’s picture

Yes, my table with revisions is growing and we don't use those revisions for anything :)

DrupalWoody’s picture

Where 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.

potop’s picture

Implemented this functionality in a module: Commerce Product Revision Delete Using the code provided by Matt Glaman in the answer here.

rszrama’s picture

Status: Active » Needs review
FileSize
3.36 KB

Following the pattern of #2442049: Commerce order revision deletion callback, I implemented the EntityAPIContollerRevisionableInterface in the product controller, added a commerce_product_is_latest_revision() function similar to the one for orders, and documented the revision delete hook in commerce_product.api.php.

rszrama’s picture

With 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.

rszrama’s picture

Status: Needs review » Fixed

Committed.

  • rszrama committed a121dc8 on 7.x-1.x
    Issue #2660056 by rszrama: add a revision deletion function to the...

Status: Fixed » Closed (fixed)

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