[opencms-dev] a problem publishing several time the same resources in short time

Victor Podberezski vpodberezski at tfsla.com
Tue Aug 13 21:53:30 CEST 2013


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20130813/53b308cd/attachment.htm>


More information about the opencms-dev mailing list