Modify / Publish error, failedcontents

Enonic version: 6.15.5
OS: Windows 10

Hello there,

Since a while, I have been facing an issue when I’m trying to publish some modified content in my Enonic App.

First I have my created and modified content successfully
image
image

Then, due to some business reasons that content has been updated again including a new status after a validation done by a job executed by Cronjob application from the Enonic store. The problem is after the modification is completed, the publish method failed, leaving the content with a Modified or Expired/Outdated status.

Having a look on the server logs, the publish method returns a node called failedcontents, showing that content couldn’t be published correctly.
image

Here you have the fragment of the modify/publish code that I’m running. I have already tried switching between branches draft/master without results.

        var modifyState = contentLib.modify({
            key: _id,
            editor: function (e) {
                e.data['s'] = updateOrderInput.s;
                e.data['TS'] = updateOrderInput.TS;
                e.data['date'] = updateOrderInput.date;
                e.data['lastTd'] = updateOrderInput.Td;
                return e;
            },
            branch: "draft"
        });


        if (modifyState != null) {                
            var modifyStatePush = contentLib.publish({
                keys: [_id],
                sourceBranch: 'draft',
                targetBranch: 'master',
                includeChildren: true,
                includeDependencies: false
            });
            return true;
        } //some variables are modificated.

Hope you kindly give me some advice or hint in order to solve or investigate how to solve this and get my content published correctly.

Thank you in advance.

When you manually publish the exact same item with exact same settings (children included, dependencies excluded) in the Content Studio (via Publish dialog), does it publish without errors?

2 Likes

Yeah, It does without errors. Manual publish works well.

Thanks for reply :blush:

Any other idea :stuck_out_tongue:

1 Like

i have the same problem… help :disappointed_relieved:

I assume you published it when it was in Modified status, right?

What if you the run the code snippet that publishes only that item?

1 Like
contentLib.publish({
                keys: ['119f0af2...'],
                sourceBranch: 'draft',
                targetBranch: 'master',
                includeChildren: true,
                includeDependencies: false
            });
1 Like

It was online, then run the code
image

and then this was the result.

thank you so much for giving some help :smiley:

So, what context are you running in? Could it be that the user does not have publish permissions?
Apparently, you are able to modify the item at least?

Hello tsi. :slight_smile:

How can I validate the context that you are asking for? However in my test environment I have the anonymous and everyone user permission enabled,I don’t know if you are refering to it.

The thing is that before the publish that I’m asking for, exist another modify/publish method that after executed, it leaves the content in online status. The problem comes after that, the the job runs and do the modify/publish process and that is the one that is ‘failing’ because it leaves the content in modified status but it does update the content.

So the problem at the end is that despite of data update done by the modify process, the publish method does not leave the content with online status.

Short version is that the code is running in a context, the context includes a user among other things. When requesting a page for instance, the context is the logged in user, or the user visiting a webpage. Running as a background job and accessing the storage, context should be specified to run as a user with proper permissions i.e. “system:su” or a user you have created.

You may do this by using the context library: https://repo.enonic.com/public/com/enonic/xp/docs/6.15.5/docs-6.15.5-libdoc.zip!/module-context.html#.run

FYI: In 7.0 branch and repo may no longer be specified in the content-lib directly, but requires use of context.

Hi there,
Here I have an update.
I have applied the change that you have sugested and it throws a new message.

2019-05-08 17:22:06,239 INFO com.siigo.aurora - (/lib/utilities.js) [AURORA SAYS] “[HOUSTON UPDATE JOB STATUS ERROR]: com.enonic.xp.repository.BranchNotFoundException: Branch with id [draft] not found”

This is the code that im using now.

Modify code (it is working well).

                var modifyState = contentLib.modify({
                    key: _id,
                    editor: function (e) {
                        e.data['s'] = updateInput.S;
                        e.data['oTS'] = updateInput.ts;
                        e.data['date'] = updateInput.Date;
                        e.data['ld'] = update.Id;
                        return e;
                    },
                    branch: "draft"
                });

Publish code

var modifyStatePush = contextLib.run({
                repository: 'system-repo',
                user: {
                    login: 'superuser', // or login: sum same result.
                    userStore: 'system'
                },
                principals: ["role:system.admin"]
            }, function(){
                UTIL.log("funcion anonyma: " + _id);
                var modifyStatePush = contentLib.publish({
                    keys: [_id],
                    sourceBranch: 'draft',
                    targetBranch: 'master'
                });
                UTIL.log(modifyStatePush);
            });

Thankyou

            repository: 'system-repo',

This is wrong. You should either omit this parameter at all (then it will use current repo) or explicitly specify correct repository which for 6.15.x is cms-repo.

user: {
                login: 'superuser', // or login: sum same result.
                userStore: 'system'
},

This is wrong as well. login should be su (not superuser or sum)

Hi ase! It worked!

var modifyStatePush = contextLib.run({
                repository: 'cms-repo',
                user: {
                    login: 'su',
                    userStore: 'system'
                },
                principals: ["role:system.admin"]
            }, function(){
                var modifyStatePush = contentLib.publish({
                    keys: [_id],
                    sourceBranch: 'draft',
                    targetBranch: 'master'
                });
                UTIL.log(modifyStatePush);
            });

image

Thank you so much! :slight_smile:

It also worked without the repository node.

Thnx :smiley:

Awesome, glad that it worked :slight_smile:

1 Like