diff --git a/dotCMS/src/main/java/com/dotcms/content/elasticsearch/business/ESContentFactoryImpl.java b/dotCMS/src/main/java/com/dotcms/content/elasticsearch/business/ESContentFactoryImpl.java index 61a3c28d0c27..367156012244 100644 --- a/dotCMS/src/main/java/com/dotcms/content/elasticsearch/business/ESContentFactoryImpl.java +++ b/dotCMS/src/main/java/com/dotcms/content/elasticsearch/business/ESContentFactoryImpl.java @@ -791,13 +791,29 @@ protected List findAllUserVersions(Identifier identifier) throws Dot return cons; } + @Override + protected List findAllVersions(Identifier identifier) throws DotDataException, DotStateException, DotSecurityException { + return findAllVersions(identifier, true); + } + @Override - protected List findAllVersions(Identifier identifier) throws DotDataException, DotStateException, DotSecurityException { + protected List findAllVersions(Identifier identifier, boolean bringOldVersions) throws DotDataException, DotStateException, DotSecurityException { if(!InodeUtils.isSet(identifier.getInode())) return new ArrayList(); DotConnect dc = new DotConnect(); - dc.setSQL("SELECT inode FROM contentlet WHERE identifier=? order by mod_date desc"); + StringBuffer query = new StringBuffer(); + + if(bringOldVersions) { + query.append("SELECT inode FROM contentlet WHERE identifier=? order by mod_date desc"); + + } else { + query.append("SELECT inode FROM contentlet c INNER JOIN contentlet_version_info cvi " + + "ON (c.inode = cvi.working_inode OR c.inode = cvi.live_inode) " + + "WHERE c.identifier=? order by c.mod_date desc "); + } + + dc.setSQL(query.toString()); dc.addObject(identifier.getId()); List> list=dc.loadObjectResults(); ArrayList inodes=new ArrayList(list.size()); diff --git a/dotCMS/src/main/java/com/dotcms/content/elasticsearch/business/ESContentletAPIImpl.java b/dotCMS/src/main/java/com/dotcms/content/elasticsearch/business/ESContentletAPIImpl.java index 47013817ef22..82718d82893f 100644 --- a/dotCMS/src/main/java/com/dotcms/content/elasticsearch/business/ESContentletAPIImpl.java +++ b/dotCMS/src/main/java/com/dotcms/content/elasticsearch/business/ESContentletAPIImpl.java @@ -3777,8 +3777,14 @@ public List findAllUserVersions(Identifier identifier,User user, boo @CloseDBIfOpened @Override - public List findAllVersions(Identifier identifier, User user,boolean respectFrontendRoles) throws DotSecurityException,DotDataException, DotStateException { - List contentlets = contentFactory.findAllVersions(identifier); + public List findAllVersions(Identifier identifier, User user, boolean respectFrontendRoles) throws DotSecurityException,DotDataException, DotStateException { + return findAllVersions(identifier, true, user, respectFrontendRoles); + } + + @CloseDBIfOpened + @Override + public List findAllVersions(Identifier identifier, boolean bringOldVersions, User user, boolean respectFrontendRoles) throws DotSecurityException,DotDataException, DotStateException { + List contentlets = contentFactory.findAllVersions(identifier, bringOldVersions); if(contentlets.isEmpty()) return new ArrayList(); if(!permissionAPI.doesUserHavePermission(contentlets.get(0), PermissionAPI.PERMISSION_READ, user, respectFrontendRoles)){ @@ -5089,7 +5095,7 @@ private Contentlet copyContentlet(Contentlet contentletToCopy, Host host, Folder List versionsToMarkWorking = new ArrayList(); Map> contentletsToCopyRules = Maps.newHashMap(); - versionsToCopy.addAll(findAllVersions(APILocator.getIdentifierAPI().find(contentletToCopy.getIdentifier()), user, respectFrontendRoles)); + versionsToCopy.addAll(findAllVersions(APILocator.getIdentifierAPI().find(contentletToCopy.getIdentifier()), false, user, respectFrontendRoles)); // we need to save the versions from older-to-newer to make sure the last save // is the current version diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/ContentletAPI.java b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/ContentletAPI.java index 4bada75c910c..49a011f31fce 100644 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/ContentletAPI.java +++ b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/ContentletAPI.java @@ -1091,10 +1091,10 @@ public Contentlet checkin(Contentlet currentContentlet, ContentletRelationships * @throws DotSecurityException */ public void restoreVersion(Contentlet contentlet, User user, boolean respectFrontendRoles) throws DotSecurityException, DotContentletStateException, DotDataException; - + /** * Retrieves all versions for a contentlet identifier - * Note this method should not be used currently because it could pull too many versions. + * Note: This method could pull too many versions. * @param identifier * @param user * @param respectFrontendRoles @@ -1103,8 +1103,26 @@ public Contentlet checkin(Contentlet currentContentlet, ContentletRelationships * @throws DotDataException * @throws DotStateException if the identifier is for contentlet */ + public List findAllVersions(Identifier identifier, User user, boolean respectFrontendRoles) throws DotSecurityException, DotDataException, DotStateException; - + + /** + * Retrieves all versions for a contentlet identifier. + * Note: This method could pull too many versions. + * @param identifier - Identifier object that belongs to a contentlet + * @param bringOldVersions - boolean value which determines if old versions (non-live, non-working + * should be brought here). @see copyContentlet method, which requires passing in only live/working + * versions of contents to be copied + * @param user - User in context who has triggered this call. + * @param respectFrontendRoles - For permissions validations + * @return + * @throws DotSecurityException + * @throws DotDataException + * @throws DotStateException if the identifier is for contentlet + */ + + public List findAllVersions(Identifier identifier, boolean bringOldVersions, User user, boolean respectFrontendRoles) throws DotSecurityException, DotDataException, DotStateException; + /** * Retrieves all versions for a contentlet identifier checked in by a real user meaning not the system user * @param identifier @@ -1115,6 +1133,7 @@ public Contentlet checkin(Contentlet currentContentlet, ContentletRelationships * @throws DotDataException * @throws DotStateException if the identifier is for contentlet */ + public List findAllUserVersions(Identifier identifier, User user, boolean respectFrontendRoles) throws DotSecurityException, DotDataException, DotStateException; /** diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/ContentletAPIInterceptor.java b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/ContentletAPIInterceptor.java index e50b6907f0bf..099537539379 100644 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/ContentletAPIInterceptor.java +++ b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/ContentletAPIInterceptor.java @@ -653,7 +653,7 @@ public List findAllUserVersions(Identifier identifier,User user, boo } @Override - public List findAllVersions(Identifier identifier, User user,boolean respectFrontendRoles) throws DotSecurityException, DotDataException, DotStateException { + public List findAllVersions(Identifier identifier, User user, boolean respectFrontendRoles) throws DotSecurityException, DotDataException, DotStateException { for(ContentletAPIPreHook pre : preHooks){ boolean preResult = pre.findAllVersions(identifier, user, respectFrontendRoles); if(!preResult){ @@ -668,6 +668,22 @@ public List findAllVersions(Identifier identifier, User user,boolean return c; } + @Override + public List findAllVersions(Identifier identifier, boolean bringOldVersions, User user, boolean respectFrontendRoles) throws DotSecurityException, DotDataException, DotStateException { + for(ContentletAPIPreHook pre : preHooks){ + boolean preResult = pre.findAllVersions(identifier, bringOldVersions, user, respectFrontendRoles); + if(!preResult){ + Logger.error(this, "The following prehook failed " + pre.getClass().getName()); + throw new DotRuntimeException("The following prehook failed " + pre.getClass().getName()); + } + } + List c = conAPI.findAllVersions(identifier, bringOldVersions, user, respectFrontendRoles); + for(ContentletAPIPostHook post : postHooks){ + post.findAllVersions(identifier, bringOldVersions, user, respectFrontendRoles,c); + } + return c; + } + @Override public List findByStructure(Structure structure, User user, boolean respectFrontendRoles, int limit, int offset) throws DotDataException, DotSecurityException { for(ContentletAPIPreHook pre : preHooks){ diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/ContentletAPIPostHook.java b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/ContentletAPIPostHook.java index 8ab69ca14878..5509d9e8a6de 100644 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/ContentletAPIPostHook.java +++ b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/ContentletAPIPostHook.java @@ -804,6 +804,19 @@ public default void restoreVersion(Contentlet contentlet, User user, boolean res * @param returnValue - value returned by primary API Method */ public default void findAllVersions(Identifier identifier, User user, boolean respectFrontendRoles,List returnValue){} + + /** + * Retrieves all versions for a contentlet identifier + * Note this method should not be used currently because it could pull too many versions. + * @param identifier - Identifier object that belongs to a contentlet + * @param bringOldVersions - boolean value which determines if old versions (non-live, non-working + * should be brought here). @see copyContentlet method, which requires passing in only live/working + * versions of contents to be copied + * @param user - User in context who has triggered this call. + * @param respectFrontendRoles - For permissions validations + * @param returnValue - value returned by primary API Method + */ + public default void findAllVersions(Identifier identifier, boolean bringOldVersions, User user, boolean respectFrontendRoles,List returnValue){} /** * Retrieves all versions for a contentlet identifier checked in by a real user meaning not the system user diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/ContentletAPIPreHook.java b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/ContentletAPIPreHook.java index dce7cbfde33b..9f96c3f714f6 100644 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/ContentletAPIPreHook.java +++ b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/ContentletAPIPreHook.java @@ -942,6 +942,21 @@ public default boolean restoreVersion(Contentlet contentlet, User user, boolean public default boolean findAllVersions(Identifier identifier, User user, boolean respectFrontendRoles){ return true; } + + /** + * Retrieves all versions for a contentlet identifier. + * Note: This method could pull too many versions. + * @param identifier - Identifier object that belongs to a contentlet + * @param bringOldVersions - boolean value which determines if old versions (non-live, non-working + * should be brought here). @see copyContentlet method, which requires passing in only live/working + * versions of contents to be copied + * @param user - User in context who has triggered this call. + * @param respectFrontendRoles - For permissions validations + * @return + */ + public default boolean findAllVersions(Identifier identifier, boolean bringOldVersions, User user, boolean respectFrontendRoles){ + return true; + } /** * Retrieves all versions for a contentlet identifier checked in by a real user meaning not the system user diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/ContentletFactory.java b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/ContentletFactory.java index ed7c811dcbde..2a23ffbf3219 100644 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/ContentletFactory.java +++ b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/business/ContentletFactory.java @@ -227,14 +227,23 @@ public abstract class ContentletFactory { /** * Retrieves all versions for a contentlet identifier * @param identifier - * @param user - * @param respectFrontendRoles * @return * @throws DotDataException * @throws DotSecurityException */ protected abstract List findAllVersions(Identifier identifier) throws DotDataException, DotSecurityException; + /** + * Retrieves all versions for a contentlet identifier. + * @param identifier + * @param bringOldVersions Include old versions of contents, so it will return only live/working + * versions of contents, regardless of their languages + * @return + * @throws DotDataException + * @throws DotSecurityException + */ + protected abstract List findAllVersions(Identifier identifier, boolean bringOldVersions) throws DotDataException, DotSecurityException; + /** * Converts a "fat" (legacy) contentlet into a new contentlet. * @param Fat contentlet to be converted.