Prevent page from being changed when I save and publish it programmatically

Marija Jemuovic
Member since: 2010
 

Hi, guys,

How can I prevent page from being changed when I save and publish it programmatically?

Basically, I would like to prevent that ChangedBy and Changed are changed when I add items to a specific content area programmatically.

Thx a lot!

Marija

#114544
Dec 15, 2014 11:51
Per Magne Skuseth
Member since: 2009
 

Does the ForceCurrentVersion flag update those values?

#114545
Dec 15, 2014 12:17
Marija Jemuovic
Member since: 2010
 

Not sure, let me give it a try

#114547
Dec 15, 2014 12:19
Marija Jemuovic
Member since: 2010
 

I have to use ForceCurrentVersion  with Publish, otherwise the page doesn't get published at all. This does change the username, but I'll give it some more debugging to make sure I've tried out everything.

#114567
Dec 15, 2014 16:12
Per Magne Skuseth
Member since: 2009
 

If the page is not already published, and you need to do that, perhaps you could try manually setting the properties for Status, perhaps check IsPendingPublished and also StartPublish.  ForceCurrentVersion will not clear the cache, so you'll probably need to do that as well.

#114593
Dec 16, 2014 10:08
Marija Jemuovic
Member since: 2010
 

Hey, Per, thx a lot for your help, this combination worked: SaveAction.CheckIn | SaveAction.ForceCurrentVersion:

contentRepo.Save(clone, SaveAction.CheckIn | SaveAction.ForceCurrentVersion, AccessLevel.NoAccess);

DataFactoryCache.RemovePage(currentPage.ContentLink);

#114825
Dec 23, 2014 13:55
 
#114852
Dec 24, 2014 12:38
Marija Jemuovic
Member since: 2010
 

I've added the following blog post on the subject: http://www.mogul.com/en/about-mogul/blog/saveactionsave-saveactionforcecurrentversion-doesnt-change-changed-but-does-touch-changedby

#117889
Feb 23, 2015 16:48
Per Magne Skuseth
Member since: 2009
 

Hi,

thanks for sharing that! There might be a way around the "ChangedBy" though. Have you tried something like this?

            var clone = somePage.CreateWritableClone();
            // create a temporary principal with the same name as the current "changedBy" value
            PrincipalInfo.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(somePage.ChangedBy),null);

            // modfiy stuff 
            clone.PageName = "My new name";
              
            // .. and save
            contentRepository.Save(clone, SaveAction.Publish, AccessLevel.NoAccess);
#117892
Feb 23, 2015 17:54
Marija Jemuovic
Member since: 2010
 

I have thought about it, but it looked dirty. Then I would need to reset back the current principal. Then in future, if someone else gets hold of the code and wraps the actual principal in an if statement, here go the website autorization, everybody gets manager's access rights :D Paranoid or realistic?

#117893
Feb 23, 2015 18:14
Per Magne Skuseth
Member since: 2009
 

Maybe a little bit of both? :-)

I guess it's not the safest bit of code, but if done right it I wouldn't be too worried. Well.. Until someone else gets hold of the code as you say. 
This blogpost shows a rather clean way of temporary using another principal. Use at own risk I suppose

#117907
Feb 24, 2015 8:38
Marija Jemuovic
Member since: 2010
 

I've seen the blogpost, didn't cross my mind that I could use it for my thing ;)

Thx for a nice discussion!

#117919
Feb 24, 2015 10:26
 
#117926
Feb 24, 2015 11:30
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.