[opencms-dev] a problem publishing several time the same resources in short time
Christian Steinert
christian at christian-steinert.de
Fri Aug 16 16:47:35 CEST 2013
Dear Victor
when a resource is published then opencms locks it with a special type of lock until the publishing is completed. It would be dangerous to change this kind of mechanism because it is necessary to make sure that the opencms file system continues to be consistent. So if you cannot make a change to the file then you need to implement some kind of queue system that accepts as many changes as you need and writes them into the file system asynchronously whenever it is possible to get a hold of the file again. Of course this means that all your changes to this file must be made through this queue and that the changes must be written and published in the same order like they were meant to be made.
However, I am a bit concerned that you are trying to change the same files so quickly again and again.
All the best
Christian Steinert
> Hello,
>
> We are building an application in opencms 7.5.4 to let change and publish several resources together.
>
> The first time an user changes and publishes a group of resources seems to work fine. But if the same resources are change and publish moments later, the changes takes place, but the resources don't publish.
>
> We saw that the second time no resources are inside the publish list.
> Further analysis shows a problem with permissions. Something related to lock for publishing. Is any way that we could change or "cheat" this opencms behaviour?
>
> Any idea what's going on?
>
> here a jsp to execute twice to replicate the problem:
>
> ------------
>
> <%@ page import="
> org.opencms.jsp.*,
> org.opencms.main.*,
> org.opencms.relations.*,
> org.opencms.db.*,
> org.opencms.file.*,
> org.opencms.lock.*,
> org.opencms.xml.content.*,
> java.util.*,
> org.opencms.loader.*,
> org.opencms.report.*,
> org.opencms.workplace.explorer.*,
> org.opencms.util.*
> "
> %>
> <%
>
> CmsJspActionElement cmsAction = new CmsJspActionElement(pageContext, request, response);
> CmsObject cms = cmsAction.getCmsObject();
>
>
> List<CmsResource> resources = new ArrayList<CmsResource>();
>
> Boolean publish = true;
>
>
> int resourcesCount = 2;
>
> String[] paths = {"/contenidos/2011/12/20/noticia_0007.html","/contenidos/2011/12/20/noticia_0017.html"};
>
> for (int idx=0;idx<resourcesCount;idx++) {
> Random rand = new Random();
> int randomNum = rand.nextInt(1000) + 1;
>
> String path = paths[idx];
> String title = "new title " + randomNum;
> String copete = "new upertitle " + randomNum;
> String body = "new body " + randomNum;
>
> CmsFile file = cms.readFile(path);
>
> CmsLock cachedlock = OpenCms.getMemoryMonitor().getCachedLock(cms.getRequestContext().addSiteRoot(path));
> if (cachedlock == null)
> cachedlock = CmsLock.getNullLock();
>
> if (!cachedlock.getSystemLock().isUnlocked())
> OpenCms.getMemoryMonitor().uncacheLock(cms.getRequestContext().addSiteRoot(path));
>
>
>
> CmsLock lock = cms.getLock(path);
>
> //if(publish && lock.isNullLock() && lock.isOwnedBy(cms.getRequestContext().currentUser()) )
> // cms.changeLock(path);
>
> if (lock.isUnlocked())
> cms.lockResource(path);
> else if (!lock.getUserId().equals(cms.getRequestContext().currentUser().getId()))
> cms.changeLock(path);
>
>
>
> CmsXmlContent content = CmsXmlContentFactory.unmarshal(cms, file);
>
> content.setAutoCorrectionEnabled(true);
> content.correctXmlStructure(cms);
>
>
> content.getValue("titulo", Locale.ENGLISH).setStringValue(cms, title);
> content.getValue("copete", Locale.ENGLISH).setStringValue(cms, copete);
> content.getValue("cuerpo", Locale.ENGLISH).setStringValue(cms, body);
>
> file.setContents(content.marshal());
> cms.writeFile(file);
>
> cms.unlockResource(path);
>
> resources.add(file);
>
> }
>
> if(publish) {
>
> CmsPublishList pList = OpenCms.getPublishManager().getPublishList(cms, resources, true);
> CmsPublishList pRelated = OpenCms.getPublishManager().getRelatedResourcesToPublish(cms,pList);
> CmsPublishList pall = OpenCms.getPublishManager().mergePublishLists(
> cms,
> pList ,
> pRelated );
> %>file to publish:<br><%
> for (Object lockRes : pList.getAllResources() ) {
> %><%=cms.getSitePath((CmsResource)lockRes)%> - <%=cms.readPropertyObject((CmsResource)lockRes, "Title", false).getValue("")%><br/><%
> }
> %>related files to publish:<br><%
> for (Object lockRes : pRelated.getAllResources() ) {
> %><%=cms.getSitePath((CmsResource)lockRes)%> - <%=cms.readPropertyObject((CmsResource)lockRes, "Title", false).getValue("")%><br/><%
> }
> CmsStringBufferReport report = new CmsStringBufferReport(Locale.ENGLISH);
> OpenCms.getPublishManager().publishProject(cms, report, pall);
> %>end<br>:
> <%=report.toString() %><%
> }
> %>
>
> ----------------
>
> Thanks you,
> VĂctor Podberezski
>
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20130816/de9a2bd1/attachment.htm>
More information about the opencms-dev
mailing list