private void purgeHistory(Node fileNode, Session session, PentahoJcrConstants pentahoJcrConstants)
      throws RepositoryException {
    // Delete all previous versions of this node
    VersionManager versionManager = session.getWorkspace().getVersionManager();
    if (JcrRepositoryFileUtils.isPentahoFolder(pentahoJcrConstants, fileNode)) {
      // go down to children
      NodeIterator nodes = fileNode.getNodes();
      while (nodes.hasNext()) {
        Node next = (Node) nodes.next();
        purgeHistory(next, session, pentahoJcrConstants);
      }
    } else if (JcrRepositoryFileUtils.isPentahoFile(pentahoJcrConstants, fileNode)
        && fileNode.isNodeType(pentahoJcrConstants.getPHO_MIX_VERSIONABLE())) {
      VersionHistory versionHistory = versionManager.getVersionHistory(fileNode.getPath());

      VersionIterator allVersions = versionHistory.getAllVersions();
      while (allVersions.hasNext()) {
        Version next = (Version) allVersions.next();
        String name = next.getName();
        // Root version cannot be deleted, the remove below will take care of that.
        if (!JCR_ROOT_VERSION.equals(name)) {
          versionHistory.removeVersion(name);
        }
      }
    }
  }