<div dir="ltr"><div><div>Hello,<br><br>We are building an application in opencms 7.5.4 to let change and publish several resources together.</div>
<div><br>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.<br>
<br>We saw that the second time no resources are inside the publish list.<br></div><div>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?<br>
<br></div>Any idea what's going on?<br><div><br>here a jsp to execute twice to replicate the problem:<br><br>------------<br><br></div><div><%@ page import="<br>    org.opencms.jsp.*,<br>    org.opencms.main.*,<br>
    org.opencms.relations.*,<br>    org.opencms.db.*,<br>    org.opencms.file.*,<br>    org.opencms.lock.*,<br>    org.opencms.xml.content.*,<br>    java.util.*,<br>    org.opencms.loader.*,<br>    org.opencms.report.*,<br>
    org.opencms.workplace.explorer.*,<br>    org.opencms.util.*<br>"  <br>%><br><%<br><br>    CmsJspActionElement cmsAction = new CmsJspActionElement(pageContext, request, response);<br>    CmsObject cms = cmsAction.getCmsObject();<br>
<br><br>    List<CmsResource> resources = new ArrayList<CmsResource>();<br><br>    Boolean publish = true;<br>    <br><br>    int resourcesCount = 2;<br>    <br>    String[] paths = {"/contenidos/2011/12/20/noticia_0007.html","/contenidos/2011/12/20/noticia_0017.html"};<br>
    <br>    for (int idx=0;idx<resourcesCount;idx++) {<br>        Random rand = new Random();<br>        int randomNum = rand.nextInt(1000) + 1;<br>        <br>        String path = paths[idx];<br>        String title = "new title " + randomNum;<br>
        String copete = "new upertitle " + randomNum;<br>        String body = "new body " + randomNum;<br>        <br>        CmsFile file = cms.readFile(path);<br>        <br>        CmsLock cachedlock = OpenCms.getMemoryMonitor().getCachedLock(cms.getRequestContext().addSiteRoot(path));<br>
        if (cachedlock == null)<br>                    cachedlock = CmsLock.getNullLock();<br>                    <br>        if (!cachedlock.getSystemLock().isUnlocked())<br>                    OpenCms.getMemoryMonitor().uncacheLock(cms.getRequestContext().addSiteRoot(path));<br>
                <br>    <br>    <br>        CmsLock lock = cms.getLock(path);<br>            <br>        //if(publish && lock.isNullLock() && lock.isOwnedBy(cms.getRequestContext().currentUser()) )<br>          //        cms.changeLock(path);<br>
<br>        if (lock.isUnlocked())<br>            cms.lockResource(path);<br>        else if (!lock.getUserId().equals(cms.getRequestContext().currentUser().getId()))<br>            cms.changeLock(path);<br>            <br>
        <br>    <br>        CmsXmlContent content = CmsXmlContentFactory.unmarshal(cms, file);<br>    <br>        content.setAutoCorrectionEnabled(true);<br>        content.correctXmlStructure(cms);<br>    <br>    <br>        content.getValue("titulo", Locale.ENGLISH).setStringValue(cms, title);<br>
        content.getValue("copete", Locale.ENGLISH).setStringValue(cms, copete);<br>        content.getValue("cuerpo", Locale.ENGLISH).setStringValue(cms, body);    <br>                                      <br>
           file.setContents(content.marshal());<br>           cms.writeFile(file);        <br>    <br>        cms.unlockResource(path);<br>        <br>           resources.add(file);<br>    <br>    }<br>       <br>       if(publish) {<br>
       <br>            CmsPublishList pList = OpenCms.getPublishManager().getPublishList(cms, resources, true);<br>            CmsPublishList pRelated = OpenCms.getPublishManager().getRelatedResourcesToPublish(cms,pList);<br>
            CmsPublishList pall = OpenCms.getPublishManager().mergePublishLists(<br>                                cms,<br>                                pList ,<br>                                pRelated );<br>            %>file to publish:<br><%<br>
            for (Object lockRes : pList.getAllResources() ) {<br>            %><%=cms.getSitePath((CmsResource)lockRes)%> - <%=cms.readPropertyObject((CmsResource)lockRes, "Title", false).getValue("")%><br/><%<br>
            }<br>            %>related files to publish:<br><%<br>            for (Object lockRes : pRelated.getAllResources() ) {<br>            %><%=cms.getSitePath((CmsResource)lockRes)%> - <%=cms.readPropertyObject((CmsResource)lockRes, "Title", false).getValue("")%><br/><%<br>
            }<br>                 CmsStringBufferReport report = new CmsStringBufferReport(Locale.ENGLISH);<br>                 OpenCms.getPublishManager().publishProject(cms, report, pall);<br>             %>end<br>:<br>
             <%=report.toString() %><%<br>       }<br>%><br></div><div><br>----------------<br><br></div>Thanks you,<br></div>Víctor Podberezski<br></div>