You should be able to call GetPage first, update the properties you want to update, and then call Save.
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.
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);
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 ---
It works fine if I use:
epi.Save(languageBranch, SaveAction.ForceCurrentVersion, AccessLevel.NoAccess);
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.
And if you do this?
epi.Save(languageBranch, SaveAction.ForceCurrentVersion, AccessLevel.NoAccess);
epi.Save(languageBranch, SaveAction.Publish, AccessLevel.NoAccess);
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?
When you open the page in cms does it say it has pending changes to publish?
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...
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?
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.
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! :)
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