From 108405241be414abf36d06ed6433083508cd3706 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Fri, 17 Nov 2017 14:49:57 -0600 Subject: [PATCH] =?UTF-8?q?#12716=20Update=20version=5Fts=20for=20all=20pa?= =?UTF-8?q?ge=20versions.=20Refresh=20all=20page=20vers=E2=80=A6=20(#13076?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * #12716 Update version_ts for all page versions. Refresh all page versions from cache. * #12716 something like this * #12716 something like this - unteseted * #12716 something like this - unteseted * #12716 rename variable. --- .../dotmarketing/business/VersionableAPI.java | 9 ++ .../business/VersionableAPIImpl.java | 9 ++ .../business/VersionableFactory.java | 3 + .../business/VersionableFactoryImpl.java | 10 ++ .../factories/MultiTreeFactory.java | 129 +++++++----------- 5 files changed, 80 insertions(+), 80 deletions(-) diff --git a/dotCMS/src/main/java/com/dotmarketing/business/VersionableAPI.java b/dotCMS/src/main/java/com/dotmarketing/business/VersionableAPI.java index fd9cbb1f7fac..9f153c298176 100644 --- a/dotCMS/src/main/java/com/dotmarketing/business/VersionableAPI.java +++ b/dotCMS/src/main/java/com/dotmarketing/business/VersionableAPI.java @@ -376,4 +376,13 @@ public interface VersionableAPI { */ public void removeVersionInfoFromCache(String identifier); + /** + * Will return a list of all ContentletVersionInfo for a given piece of content (if there are multiple languages) + * @param identifier + * @return + * @throws DotDataException + * @throws DotStateException + */ + public List findContentletVersionInfos(String identifier) throws DotDataException, DotStateException; + } diff --git a/dotCMS/src/main/java/com/dotmarketing/business/VersionableAPIImpl.java b/dotCMS/src/main/java/com/dotmarketing/business/VersionableAPIImpl.java index d8b62919571a..68c80de62eeb 100644 --- a/dotCMS/src/main/java/com/dotmarketing/business/VersionableAPIImpl.java +++ b/dotCMS/src/main/java/com/dotmarketing/business/VersionableAPIImpl.java @@ -588,7 +588,16 @@ public ContentletVersionInfo getContentletVersionInfo(final String identifier, final long lang) throws DotDataException, DotStateException { return versionableFactory.getContentletVersionInfo(identifier, lang); } + + @Override + @CloseDBIfOpened + public List findContentletVersionInfos(final String identifier) throws DotDataException, DotStateException { + return versionableFactory.findAllContentletVersionInfos(identifier); + } + + + @WrapInTransaction @Override public void saveVersionInfo(final VersionInfo vInfo) throws DotDataException, DotStateException { diff --git a/dotCMS/src/main/java/com/dotmarketing/business/VersionableFactory.java b/dotCMS/src/main/java/com/dotmarketing/business/VersionableFactory.java index 526e47a1c083..246c54dfc6e2 100644 --- a/dotCMS/src/main/java/com/dotmarketing/business/VersionableFactory.java +++ b/dotCMS/src/main/java/com/dotmarketing/business/VersionableFactory.java @@ -169,4 +169,7 @@ public abstract class VersionableFactory { */ protected abstract VersionInfo findVersionInfoFromDb(Identifier identifier) throws DotDataException, DotStateException; + protected abstract List findAllContentletVersionInfos(String identifier) + throws DotDataException, DotStateException ; + } diff --git a/dotCMS/src/main/java/com/dotmarketing/business/VersionableFactoryImpl.java b/dotCMS/src/main/java/com/dotmarketing/business/VersionableFactoryImpl.java index b939eb65c585..b833b690606c 100644 --- a/dotCMS/src/main/java/com/dotmarketing/business/VersionableFactoryImpl.java +++ b/dotCMS/src/main/java/com/dotmarketing/business/VersionableFactoryImpl.java @@ -295,7 +295,17 @@ protected ContentletVersionInfo findContentletVersionInfoInDB(String identifier, contv = (ContentletVersionInfo)dh.load(); return contv; } + @Override + protected List findAllContentletVersionInfos(final String identifier)throws DotDataException, DotStateException { + + HibernateUtil dh = new HibernateUtil(ContentletVersionInfo.class); + dh.setQuery("from "+ContentletVersionInfo.class.getName()+" where identifier=? "); + dh.setParam(identifier); + Logger.debug(this.getClass(), "getContentletVersionInfo query: "+dh.getQuery()); + return (List)dh.list(); + + } @Override protected void saveContentletVersionInfo(ContentletVersionInfo cvInfo, boolean updateVersionTS) throws DotDataException, DotStateException { Identifier ident = this.iapi.find(cvInfo.getIdentifier()); diff --git a/dotCMS/src/main/java/com/dotmarketing/factories/MultiTreeFactory.java b/dotCMS/src/main/java/com/dotmarketing/factories/MultiTreeFactory.java index 63dab7927c3c..36a307d46a7b 100644 --- a/dotCMS/src/main/java/com/dotmarketing/factories/MultiTreeFactory.java +++ b/dotCMS/src/main/java/com/dotmarketing/factories/MultiTreeFactory.java @@ -1,7 +1,11 @@ package com.dotmarketing.factories; import java.sql.SQLException; +import java.util.ArrayList; import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import com.dotmarketing.beans.Identifier; import com.dotmarketing.beans.Inode; @@ -22,6 +26,7 @@ import com.dotmarketing.services.PageServices; import com.dotmarketing.util.InodeUtils; import com.dotmarketing.util.Logger; +import com.google.common.collect.Lists; /** * This class provides utility routines to interact with the Multi-Tree @@ -53,8 +58,8 @@ public static void deleteMultiTree(Object o1, Object o2, Object o3) { db.addParam(inode2.getInode()); db.addParam(inode3.getInode()); db.getResult(); - - updateVersionTs(inode1.getInode()); + + updateHTMLPageVersionTS(inode1.getInode()); refreshPageInCache(inode1.getInode()); } @@ -127,8 +132,8 @@ public static void deleteMultiTreeByParent1(Contentlet contentlet, Long language * @throws DotDataException * @throws DotSecurityException * - * @see MultiTreeFactory#updateVersionTs(String, Long) - * @see MultiTreeFactory#refreshPageInCache(String, Long) + * @see MultiTreeFactory#updateHTMLPageVersionTS(String) + * @see MultiTreeFactory#refreshPageInCache(String) */ public static void deleteMultiTreeByParent1(Identifier parent, Long languageId) throws DotDataException, DotSecurityException { @@ -138,7 +143,7 @@ public static void deleteMultiTreeByParent1(Identifier parent, Long languageId) if (languageId == null) { db.executeStatement("DELETE FROM multi_tree WHERE parent1 = '" + parent.getId() + "';"); - updateVersionTs(parent.getId()); + updateHTMLPageVersionTS(parent.getId()); refreshPageInCache(parent.getId()); return; } @@ -160,9 +165,9 @@ public static void deleteMultiTreeByParent1(Identifier parent, Long languageId) .append("AND c.lang = ").append(languageId).append(");"); db.executeStatement(query.toString()); - - updateVersionTs(parent.getId(), languageId); - refreshPageInCache(parent.getId(), languageId); + + updateHTMLPageVersionTS(parent.getId()); + refreshPageInCache(parent.getId()); } catch (SQLException e) { throw new DotDataException(DELETE_MULTITREE_ERROR_MSG, e); @@ -174,35 +179,20 @@ public static void deleteMultiTreeByParent1(Identifier parent, Long languageId) } /** - * Deletes multi-tree relationships given a MultiTree object. - * + * Deletes multi-tree relationship given a MultiTree object. + * It also updates the version_ts of all versions of the htmlpage passed in (multiTree.parent1) + * * @param multiTree - * @throws DotDataException - * @throws DotSecurityException - * - */ - public static void deleteMultiTree (MultiTree o) throws DotDataException, DotSecurityException { - deleteMultiTree(o, APILocator.getLanguageAPI().getDefaultLanguage() - .getId()); - } - - /** - * Deletes multi-tree relationships given a MultiTree object and a Language Id. - * A language id is passed in so cleanup of cached resources of parent Page content - * Needs to be cleaned, along with update its version_ts value - * - * @param multiTree - * @param languageId - * @throws DotDataException + * @throws DotDataException * @throws DotSecurityException * */ - public static void deleteMultiTree(MultiTree o, Long languageId) throws DotDataException, DotSecurityException { + public static void deleteMultiTree(MultiTree multiTree) throws DotDataException, DotSecurityException { try { - String id = o.getParent1(); - HibernateUtil.delete(o); - updateVersionTs(id, languageId); - refreshPageInCache(id,languageId); + String id = multiTree.getParent1(); + HibernateUtil.delete(multiTree); + updateHTMLPageVersionTS(id); + refreshPageInCache(id); return; } catch (DotHibernateException e) { Logger.error(MultiTreeFactory.class, DELETE_MULTITREE_ERROR_MSG + e, e); @@ -398,8 +388,8 @@ public static void saveMultiTree(MultiTree o, long languageId) throws DotSecurit try { String id = o.getParent1(); HibernateUtil.saveOrUpdate(o); - updateVersionTs(id, languageId); - refreshPageInCache(id,languageId); + updateHTMLPageVersionTS(id); + refreshPageInCache(id); } catch (DotHibernateException e) { Logger.error(MultiTreeFactory.class, SAVE_MULTITREE_ERROR_MSG + e, e); throw new DotRuntimeException(e.getMessage()); @@ -657,7 +647,7 @@ public static java.util.List getParentsOfClass(Inode p, Class c) { } /** - * Update a HTML Page Version Info Timestamp given a HTMLPage Identifier. + * Update the version_ts of all versions of the HTML Page with the given id. * If a MultiTree Object has been added or deleted from this page, * its version_ts value needs to be updated so it can be included * in future Push Publishing tasks @@ -668,61 +658,40 @@ public static java.util.List getParentsOfClass(Inode p, Class c) { * @throws DotSecurityException * */ - private static void updateVersionTs(String id) throws DotDataException { - updateVersionTs(id, APILocator.getLanguageAPI().getDefaultLanguage().getId()); - } - - /** - * Update a HTML Page Version Info Timestamp given a HTMLPage Identifier and a Language Id. - * If a MultiTree Object has been added or deleted from this page, - * its version_ts value needs to be updated so it can be included - * in future Push Publishing tasks - * - * @param id The HTMLPage Identifier to pass in - * @throws DotContentletStateException - * @throws DotDataException - * @throws DotSecurityException - * - */ - private static void updateVersionTs(String id, Long languageId) throws DotDataException { - Identifier ident = APILocator.getIdentifierAPI().find(id); - ContentletVersionInfo versionInfo = APILocator.getVersionableAPI() - .getContentletVersionInfo(ident.getId(), languageId); - versionInfo.setVersionTs(new Date()); - APILocator.getVersionableAPI().saveContentletVersionInfo( - versionInfo); + private static void updateHTMLPageVersionTS(String id) throws DotDataException, DotSecurityException { + List infos = APILocator.getVersionableAPI().findContentletVersionInfos(id); + for (ContentletVersionInfo versionInfo : infos) { + if(versionInfo!=null) { + versionInfo.setVersionTs(new Date()); + APILocator.getVersionableAPI().saveContentletVersionInfo(versionInfo); + } + } } /** - * Refresh Cached objects of page given a HTMLPage Identifier. + * Refresh cached objects for all versions of the HTMLPage with the given pageIdentifier. * - * @param id The HTMLPage Identifier to pass in + * @param pageIdentifier The HTMLPage Identifier to pass in * @throws DotContentletStateException * @throws DotDataException * @throws DotSecurityException * */ - private static void refreshPageInCache(String id) throws DotDataException, DotSecurityException { - refreshPageInCache(id, APILocator.getLanguageAPI().getDefaultLanguage().getId()); - } - + private static void refreshPageInCache(String pageIdentifier) throws DotDataException, DotSecurityException { + Set inodes = new HashSet(); + List infos = APILocator.getVersionableAPI().findContentletVersionInfos(pageIdentifier); + for (ContentletVersionInfo versionInfo : infos) { + inodes.add(versionInfo.getWorkingInode()); + if(versionInfo.getLiveInode() != null){ + inodes.add(versionInfo.getLiveInode()); + } + } - /** - * Refresh Cached objects of page given a HTMLPage Identifier and a Language Id. - * - * @param id The HTMLPage Identifier to pass in - * @param languageId A language Id that points to a specific version we'll clean up - * @throws DotContentletStateException - * @throws DotDataException - * @throws DotSecurityException - * - */ - private static void refreshPageInCache(String id, Long languageId) throws DotDataException, DotSecurityException { - Identifier ident = APILocator.getIdentifierAPI().find(id); - Contentlet content = APILocator.getContentletAPI() - .findContentletByIdentifier(ident.getId(), false, languageId, APILocator.systemUser(), false); - IHTMLPage htmlPage = APILocator.getHTMLPageAssetAPI().fromContentlet(content); - PageServices.invalidateAll(htmlPage); + List contentlets = APILocator.getContentletAPIImpl().findContentlets(Lists.newArrayList(inodes)); + for (Contentlet pageContent : contentlets) { + IHTMLPage htmlPage = APILocator.getHTMLPageAssetAPI().fromContentlet(pageContent); + PageServices.invalidateAll(htmlPage); + } } }