Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#12716 Update version_ts for all page versions. Refresh all page vers… #13076

Merged
merged 5 commits into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContentletVersionInfo> findContentletVersionInfos(String identifier) throws DotDataException, DotStateException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContentletVersionInfo> findContentletVersionInfos(final String identifier) throws DotDataException, DotStateException {
return versionableFactory.findAllContentletVersionInfos(identifier);
}




@WrapInTransaction
@Override
public void saveVersionInfo(final VersionInfo vInfo) throws DotDataException, DotStateException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,7 @@ public abstract class VersionableFactory {
*/
protected abstract VersionInfo findVersionInfoFromDb(Identifier identifier) throws DotDataException, DotStateException;

protected abstract List<ContentletVersionInfo> findAllContentletVersionInfos(String identifier)
throws DotDataException, DotStateException ;

}
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,17 @@ protected ContentletVersionInfo findContentletVersionInfoInDB(String identifier,
contv = (ContentletVersionInfo)dh.load();
return contv;
}
@Override
protected List<ContentletVersionInfo> findAllContentletVersionInfos(final String identifier)throws DotDataException, DotStateException {

HibernateUtil dh = new HibernateUtil(ContentletVersionInfo.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure but shouldn't include cache here? if not apply nvm my comment

dh.setQuery("from "+ContentletVersionInfo.class.getName()+" where identifier=? ");
dh.setParam(identifier);

Logger.debug(this.getClass(), "getContentletVersionInfo query: "+dh.getQuery());
return (List<ContentletVersionInfo>)dh.list();

}
@Override
protected void saveContentletVersionInfo(ContentletVersionInfo cvInfo, boolean updateVersionTS) throws DotDataException, DotStateException {
Identifier ident = this.iapi.find(cvInfo.getIdentifier());
Expand Down
129 changes: 49 additions & 80 deletions dotCMS/src/main/java/com/dotmarketing/factories/MultiTreeFactory.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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());

}
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand All @@ -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<ContentletVersionInfo> 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<String> inodes = new HashSet<String>();
List<ContentletVersionInfo> 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<Contentlet> contentlets = APILocator.getContentletAPIImpl().findContentlets(Lists.newArrayList(inodes));
for (Contentlet pageContent : contentlets) {
IHTMLPage htmlPage = APILocator.getHTMLPageAssetAPI().fromContentlet(pageContent);
PageServices.invalidateAll(htmlPage);
}
}

}