Problem/Motivation

In #2892807: Use the minimum_age_to_delete and when_to_delete variables to delete revisions the _node_revision_delete_candidates() function was updated allowing to know if a node is candidate to delete his revisions, but the _node_revision_delete_do_delete() function was not updated, so at this time if you set the Minimum age of revisions to delete this parameter is not use it and this will not be accomplish:

Revisions older of this age will be deleted, but just only after the "Minimum number of revisions to keep" will be reached. If you don't want to take in count the age of the revisions, set to "None".

So, you can loose some revisions because this parameter is not handled at this time.

Proposed resolution

Use the minimum_age_to_delete variable in the _node_revision_delete_do_delete() function.

Remaining tasks

Update the function and all the function calls to use the minimum_age_to_delete variable.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

adriancid created an issue. See original summary.

shiraz dindar’s picture

Category: Bug report » Task

The project page says:

7.x-3.0-beta1 released 10 August 2017
Now you can delete revisions based on age and inactivity. But more test are needed before the final release.

But this functionality isn't working yet, as noted in this task! It appears to be only half built -- it's in the UI but it's not actually in the _node_revision_delete_do_delete() function as noted in this task. This threw me off and I imagine it will others. Maybe update the 3.0-beta1 release note so it doesn't mislead?

adriancid’s picture

Thanks, I see what happens, I released the version and after a user saw the problem but I forgot to update the documentation. I will update now the doc.

kari.kaariainen’s picture

Has this been fixed or not? Can I rely on Minimum age of revisions to delete? Or was this a documentation issue?

adriancid’s picture

Is not possible at this time. Was a documentation issue

slydevil’s picture

Patch attached to accomplish this functionality. I did test as thoroughly as I could and will continue to do so, but it needs to put through it's paces.

slydevil’s picture

Status: Active » Needs review
adriancid’s picture

Thanks @slydevil I will try to port the remaining code for the node_revision_generate module to have a way to create revisions and then I will test your code.

adriancid’s picture

@slydevil of you want to help here are the issues we need to port from the 8.x branch https://www.drupal.org/project/issues/node_revision_delete?status=15&version=8.x

slydevil’s picture

I'll take a look

adriancid’s picture

Now is possible to create revisions (thanks to @slydevil) with this submodule #3021310: Create submodule to generate revisions.

If somebody wants to test the patch on this issue this will be great.

adriancid’s picture

Status: Needs review » Needs work
-  $query->condition('r.timestamp', strtotime($minimum_age_to_delete . ' ' . $minimum_age_to_delete_time . ' ago'), '<');
-  $query->condition('n.changed', strtotime($when_to_delete . ' ' . $when_to_delete_time . ' ago'), '<');

We need these lines because the function _node_revision_delete_candidates should return the candidates nodes with revisions that can be deleted and not the number of revisions that can be deleted.

slydevil’s picture

@adriancid, I did include those lines. The $when_to_delete variable is still there, but I took the strtotime call out and put it into a function called _node_revision_delete_determine_time(). The $minimum_age_to_delete is included in the second query:

  // Limit the candidates by the minimum age variable. This cannot be combined
  // with the above query because it will remove results that should be 
  // included.
 if (count($candidates)) {
   $query = db_select('node_revision', 'r');
   $query->fields('r', array('nid'));
   $query->condition('r.nid', $candidates);
   $query->condition('r.timestamp', $minimum_age_time, '<');
   $query->orderBy('r.nid');
   $candidates = $query->execute()->fetchCol();
 }
adriancid’s picture

Even if they are included the configuration page show the number of revision to delete and not the nodes with revitions that can be deleted.

You ca create 3 nodes and then create 10 revisions to each node and then go to the configuration page and you will see the diference.

slydevil’s picture

Missing a groupBy probably...I'll take a look.

slydevil’s picture

Yup, adding the group by worked. New patch attached.

slydevil’s picture

Status: Needs work » Needs review
volkswagenchick’s picture

Issue tags: +drupalnorth2019

Tagging for DrupalNorth 2019

juampynr’s picture

On a 20Gb database with 600.000 revisions the patch at #16 made the page admin/config/content/node_revision_delete unable to load and the Drush command unresponsive. I joined both queries into one and now the query just takes between 2 to 4 seconds. @slydevil said that joining them together may mean that the script could delete incorrect revisions but after looking at the code I did not get that impression. Can you clarify @slydevil?

adriancid’s picture

Status: Needs review » Fixed

thanks for the patch, that's what we have in the D8 version only one query, and is working fine.

  • adriancid committed 410c3e6 on 7.x-3.x authored by juampynr
    Issue #2915230 by slydevil, juampynr, adriancid: Use the...
adriancid’s picture

Category: Task » Feature request

Status: Fixed » Closed (fixed)

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