Guest User

Untitled

a guest
Jun 24th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. <?php
  2.  
  3. // Query all of the nids of the research content type.
  4. $nids = db_select('node', 'n')
  5. ->fields('n', array('nid'))
  6. ->condition('type', 'research', '=')
  7. ->execute()
  8. ->fetchCol();
  9.  
  10. foreach ($nids as $nid) {
  11. // The task now is to delete all revisions except the most recent 20 belonging to each of the nodes in the $nodes array.
  12.  
  13. // We probably need a loop here that can loops through the $nodes array and then run the following on each node in the array
  14.  
  15. // 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.
  16. // Possible way to limit the array of revisons to delete: $revstodelete = array_slice($vid, < 19); to return revisions after the first 20.
  17. $node = node_load($nid, TRUE);
  18. $vids = \Drupal::entityManager()->getStorage('node')->revisionIds($node);
  19. $vids = array_slice($vids, 0, -20);
  20. foreach($vids as $vid){
  21. if ($node->vid !== $vid) {
  22. \Drupal::entityTypeManager()->getStorage('node')->deleteRevision($vid);
  23. }
  24. }
  25. }
Add Comment
Please, Sign In to add comment