[opencms-dev] Massive Publishing.....
Patricio Echague
patricioe at gmail.com
Tue Nov 28 01:20:05 CET 2006
Hi all, we are having problems at the time we are publishing a plenty of
file in a transaction, with the CMS API. Our app is running in Cluster with
Two fronts server (online)and another one behing (only offline). We are
using OCEE module and cache in some files. We make a zip package with all
content and then do an import of that zip. After that, we do a massive
publish with the following class.
As a result, some files after publishing, dissapear. But, if we make an
touch over this files, these ones appears again. It is a hard task ! :S
Anyone have an answer ?
Below, our class.
public class AutoTouch {
public static StringBuffer autoTouch(CmsObject cms, String
pakageFilename) throws Exception{
StringBuffer report = new StringBuffer();
//read the manifiest.xml from the zip file
List resourcePathList = ExportUtils.readFileListFromZip(cms,
pakageFilename);
//touch files
touch(cms, resourcePathList, report);
//add needed resurces (sush as
List resourceList = buildResourceList(cms, resourcePathList,
report);
//unlock resources
unlockResources(cms, resourceList, report);
//publish files
publish(cms, resourceList, report);
return report;
}
private static void touch(CmsObject cms, List resourcePathList,
StringBuffer report) throws CmsException{
long now = (new Date()).getTime();
CmsResource cmsResource;
report.append("<strong>Touching Resources</strong><br>\n");
for(Iterator ite = resourcePathList.iterator(); ite.hasNext();){
String resourcePath = "/" + (String)ite.next();
if (!cms.existsResource(resourcePath)){
report.append(resourcePath + ": <strong>not
found</strong><br>\n");
ite.remove();
}else{
cmsResource = cms.readResource(resourcePath);
if (cmsResource.isFile()){
cms.lockResource(resourcePath);
cms.setDateLastModified(resourcePath, now, false);
report.append(resourcePath + ": touched<br>\n");
}
}
}
report.append("<strong>Resources Touched</strong><br>");
report.append("<br>\n<br>\n");
}
private static List buildResourceList(CmsObject cms, List
resourcePathList, StringBuffer report) throws CmsException{
List resourceList = new LinkedList();
Iterator ite = resourcePathList.iterator();
while(ite.hasNext()){
CmsResource cmsResource = cms.readResource((String) ite.next());
while(true){
String parentPath = CmsResource.getParentFolder(
cmsResource.getRootPath());
if(parentPath==null) break;
parentPath = cms.getRequestContext
().removeSiteRoot(parentPath);
CmsResource parentResource = cms.readResource(parentPath);
if(parentResource.getState() != CmsResource.STATE_NEW)
break;
cmsResource = parentResource;
}
resourceList.add(cmsResource);
}
return resourceList;
}
private static void unlockResources(CmsObject cms, List resourceList,
StringBuffer report) throws CmsException {
for(Iterator ite = resourceList.iterator(); ite.hasNext();){
CmsResource cmsResource = (CmsResource) ite.next();
OpenCmsUtil.unlockResource(cms,cmsResource.getRootPath());
}
}
private static void publish(CmsObject cms, List resourceList,
StringBuffer report) throws CmsException {
CmsPublishList publishList = cms.getPublishList(resourceList, false,
false, false);
CmsStringBufferReport publishReport = new CmsStringBufferReport(new
Locale("en"));
cms.publishProject(publishReport, publishList);
report.append("<strong>File Publish Report</strong><br>\n");
report.append(publishReport.toString().replaceAll("\n","<br>\n"));
}
}
--
Patricio.-
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20061128/36d4fc3b/attachment.htm>
More information about the opencms-dev
mailing list