I noticed in the presave hook that node data and all the revisions were being loaded even if the node type wasn't using this module. I thought it might be beneficial to have the check in place before the query is ran and the node revisions loaded.

The new function would look like this:

/**
 * Implements of hook_presave().
 */
function node_revision_restrict_node_presave($node) {
  $node_type = $node->type;
  $count_to_restrict_set_value = variable_get('restrict_node_revision_number_for_' . $node_type);
  if (isset($count_to_restrict_set_value)) {
    $nid = $node->nid;
    $node_data = db_query('SELECT * FROM {node} WHERE nid = :nid', array(':nid' => $nid));
    foreach ($node_data as $node) {
      $revision_data = node_revision_list($node);
      foreach ($revision_data as $revision) {
        $revision_ids[] = $revision->vid;
      }
    
      $node_to_restrict = array_slice($revision_ids, $count_to_restrict_set_value, count($revision_ids));
      foreach ($node_to_restrict as $revision_id) {
        node_revision_delete($revision_id);
      }
    }  
  }
}

Comments

gbrands’s picture

vineet.osscube’s picture

HI Gerrit

We have resolved the issue you have raised in this module. In this regard, we have applied the code on hook_node_presave().

Additionally, we have also released a new version 7.x-1.2 . Moreover, your sugggestions acted like an enhancement and is beneficial for module.

Keep coming with your suggestions as it helps us to make our module even better for users.

Thanks and Regards,
Vineet

vineet.osscube’s picture

Status: Active » Closed (fixed)

closing the issue as fixed.