Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Query all of the nids of the research content type.
- $nids = db_select('node', 'n')
- ->fields('n', array('nid'))
- ->condition('type', 'research', '=')
- ->execute()
- ->fetchCol();
- foreach ($nids as $nid) {
- // The task now is to delete all revisions except the most recent 20 belonging to each of the nodes in the $nodes array.
- // We probably need a loop here that can loops through the $nodes array and then run the following on each node in the array
- // As written, the code below would delete all revisions belonging to each node, we need to limit that to those after the most recent 20.
- // Possible way to limit the array of revisons to delete: $revstodelete = array_slice($vid, < 19); to return revisions after the first 20.
- $node = node_load($nid, TRUE);
- $vids = \Drupal::entityManager()->getStorage('node')->revisionIds($node);
- $vids = array_slice($vids, 0, -20);
- foreach($vids as $vid){
- if ($node->vid !== $vid) {
- \Drupal::entityTypeManager()->getStorage('node')->deleteRevision($vid);
- }
- }
- }
Add Comment
Please, Sign In to add comment