Try our conversational search powered by Generative AI!

CreateWritableClone in PageStoreService webservice

Vote:
 

Hi all!

I am updating product-pages from inriver PIM and I want to publish a new version of a page through PageStoreService webservice but I am not sure how to do that. The method GetDefaultPageData creates a new page and that’s not what I want to do and I can't find anything close to CreateWritableClone. Does anyone know how I can do that? 

Thank you in advance.

Br,

Isabel

#152141
Edited, Aug 17, 2016 17:57
Vote:
 

You should be able to call GetPage first, update the properties you want to update, and then call Save.

#152162
Aug 18, 2016 14:51
Vote:
 

Yes I know. But the changes are not published directly to the site. The changes are there if I look at the page via the CMS but on the site it isn't updated. I have to publish the page manually. 

#152163
Aug 18, 2016 14:57
Vote:
 

To do that you need to supply the optional parameter to the save method:
_contentRepository.Save(content, SaveAction.Publish);

If that doesn't work, mostly if you run this from a stand alone job, try with the last parameter too:

_contentRepository.Save(content, SaveAction.Publish, AccessLevel.NoAccess);

#152171
Aug 18, 2016 16:21
Vote:
 

That is exactly what I am trying to do:

epi.Save(languageBranch, SaveAction.Publish, AccessLevel.NoAccess); 

But I get an error message:

15:35:51 - Information  Something went wrong with saving page: PimSysId = 595578. Message: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'PK_tblContentLanguage'. Cannot insert duplicate key in object 'dbo.tblContentLanguage'. The duplicate key value is (31359, 1).

   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)

   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)

   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)

   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)

   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite)

   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)

   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)

   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()

   at EPiServer.DataAccess.ContentSaveDB.CreateContentVersion(IContent content, Boolean isNew, String currentUser)

   at EPiServer.DataAccess.ContentSaveDB.CreateAndSave(IContent content, Boolean delayPublish, Boolean forceCurrentVersion, Boolean forceNewVersion, String currentUser)

   at EPiServer.DataAccess.ContentSaveDB.<>c__DisplayClass16.<SaveInternal>b__15()

   at EPiServer.Data.Providers.SqlDatabaseHandler.<>c__DisplayClass4.<ExecuteTransaction>b__3()

   at EPiServer.Data.Providers.SqlDatabaseHandler.<>c__DisplayClass7`1.<ExecuteTransaction>b__6()

   at EPiServer.Data.Providers.SqlTransientErrorsRetryPolicy.Execute[TResult](Func`1 method)

   at EPiServer.DataAccess.ContentSaveDB.SaveInternal(IContent content, SaveAction action, Nullable`1 delayPublishUntil, String currentUser)

   at EPiServer.DataAccess.ContentSaveDB.Save(IContent content, SaveAction action, String currentUser)

   at EPiServer.DataAbstraction.ContentStore.Save(IContent content, SaveAction action, String currentUser)

   at EPiServer.DefaultContentProvider.Save(IContent content, SaveAction action)

   at EPiServer.Core.DefaultContentRepository.Save(IContent content, SaveAction action, AccessLevel access)

   at EPiServer.WebServices.PageStoreService.Save(RawPage page, SaveAction action, AccessLevel access)

   --- End of inner exception stack trace ---

#152172
Aug 18, 2016 16:47
Vote:
 

It works fine if I use: 

epi.Save(languageBranch, SaveAction.ForceCurrentVersion, AccessLevel.NoAccess); 

#152173
Aug 18, 2016 16:48
Vote:
 

That is why I think I need to create a clone of the page so that I can publish the page and see if the page on the site is updated without having to manually publishing it. But I am not sure how to do that in the PageStoreService.

#152174
Aug 18, 2016 16:53
Vote:
 

And if you do this?

epi.Save(languageBranch, SaveAction.ForceCurrentVersion, AccessLevel.NoAccess); 

epi.Save(languageBranch, SaveAction.Publish, AccessLevel.NoAccess); 

#152176
Aug 18, 2016 17:22
Vote:
 

I will try it and get back to you. 

#152214
Aug 19, 2016 12:26
Vote:
 

That didn't help at all. I still have to publish the page manually in the cms for the changes to be shown on the site.

Does it have anything to do with caching perhaps?

#152215
Aug 19, 2016 13:12
Vote:
 

When you open the page in cms does it say it has pending changes to publish?

#152216
Aug 19, 2016 13:34
Vote:
 

No, if I view the page in edit mode it has all the changes that I added in Inriver PIM but when I view it on the site it doesn't. It doesn't say that it needs to be published or anything...

#152217
Aug 19, 2016 13:36
Vote:
 

Then a caching problem is very possible. If the cms publish kills the cache as it should but your PageStoreService does not.

I am afraid you will have to check the remote event configuration, is the cms site and your job listening/posting to the same events?

#152218
Aug 19, 2016 13:46
Vote:
 
#152220
Aug 19, 2016 14:02
Vote:
 

I will try and get back to you.

#152221
Aug 19, 2016 14:14
Vote:
 

I can't find that class and method through the PageStoreService

#152222
Aug 19, 2016 14:56
Vote:
 

Sorry, did not realize you were using the PageStoreService

#152223
Aug 19, 2016 14:58
Vote:
 

I will add the a class that inherits the interface IInitializabaleModule and then add functionality for what happens when a page that is of a specific type is published. I will call the RemovePage-method you wrote about above. 

#152224
Aug 19, 2016 15:03
Vote:
 

I solved this one. Support could'nt tell me if there was a method in the PageStoreService similiar to CreateWritableClone.

So, I left this line in my connector:

epi.Save(languageBranch, SaveAction.ForceCurrentVersion, AccessLevel.NoAccess);

And in my epi-project I added a class that inherits the IInitializableModule. I then added the ContentEvent for SavedContent and implemented the method as below:

        private void contentEvents_SavedContent(object sender, EPiServer.ContentEventArgs e)

        {

            if (e != null && e.ContentLink != null)

            {

                var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();

                try

                {

                    var page = contentRepository.Get<PageData>(e.ContentLink);

                    if (!PageEditing.PageIsInEditMode && (page is RangePageType

                        || page is CollectionsPageType

                        || page is ProductFloorPageType))

                    {

                        DataFactoryCache.RemovePage(e.ContentLink);

                    }

                }

                catch (Exception ex)

                {

                    //what to do, what to do...

                }

            }

        }

This works just fine so far! Let me know if you come up with a better solution.

Thank you everyone who answered my post! :)

#152681
Aug 29, 2016 10:21
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.