Skip to content

Commit

Permalink
#12716 Update version_ts for all page versions. Refresh all page vers…
Browse files Browse the repository at this point in the history
…ions from cache.
  • Loading branch information
dsilvam committed Nov 16, 2017
1 parent 228b7e4 commit f4a569d
Showing 1 changed file with 45 additions and 80 deletions.
125 changes: 45 additions & 80 deletions dotCMS/src/main/java/com/dotmarketing/factories/MultiTreeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import com.dotmarketing.beans.Identifier;
import com.dotmarketing.beans.Inode;
Expand Down Expand Up @@ -53,8 +54,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());

}
Expand Down Expand Up @@ -127,7 +128,7 @@ public static void deleteMultiTreeByParent1(Contentlet contentlet, Long language
* @throws DotDataException
* @throws DotSecurityException
*
* @see MultiTreeFactory#updateVersionTs(String, Long)
* @see MultiTreeFactory#updateHTMLPageVersionTS(String)
* @see MultiTreeFactory#refreshPageInCache(String, Long)
*/
public static void deleteMultiTreeByParent1(Identifier parent, Long languageId)
Expand All @@ -138,7 +139,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;
}
Expand All @@ -160,9 +161,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);
Expand All @@ -174,35 +175,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);
Expand Down Expand Up @@ -398,8 +384,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());
Expand Down Expand Up @@ -657,7 +643,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
Expand All @@ -668,61 +654,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 {
Identifier identifier = APILocator.getIdentifierAPI().find(id);
List<Contentlet> allContentletVersions = APILocator.getContentletAPI()
.findAllVersions(identifier, APILocator.getUserAPI().getSystemUser(), false);

for (Contentlet contentlet : allContentletVersions) {
ContentletVersionInfo versionInfo = APILocator.getVersionableAPI()
.getContentletVersionInfo(id, contentlet.getLanguageId());
if(versionInfo!=null) {
versionInfo.setVersionTs(new Date());
APILocator.getVersionableAPI().saveContentletVersionInfo(versionInfo);
}
}

}

/**
* Refresh Cached objects of page given a HTMLPage Identifier.
*
* @param id 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());
}


/**
* Refresh Cached objects of page given a HTMLPage Identifier and a Language Id.
* Refresh cached objects for all versions of the HTMLPage with the given pageIdentifier.
*
* @param id The HTMLPage Identifier to pass in
* @param languageId A language Id that points to a specific version we'll clean up
* @param pageIdentifier The HTMLPage Identifier to pass in
* @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);
private static void refreshPageInCache(String pageIdentifier) throws DotDataException, DotSecurityException {
Identifier ident = APILocator.getIdentifierAPI().find(pageIdentifier);
List<Contentlet> allPageVersions = APILocator.getContentletAPI()
.findAllVersions(ident, APILocator.getUserAPI().getSystemUser(), false);

for (Contentlet pageContent : allPageVersions) {
IHTMLPage htmlPage = APILocator.getHTMLPageAssetAPI().fromContentlet(pageContent);
PageServices.invalidateAll(htmlPage);
}
}

}

0 comments on commit f4a569d

Please sign in to comment.