Try our conversational search powered by Generative AI!

Delete language version of a page.

Vote:
 

Hello!

I've tried the version gadget and while I'm pretty sure that's what the client asks for - they still want to be able to delete a language version that is not master from the tree view using "Move to Trash". 

So far the criteras I set up checks out, but it still deletes all the versions of the page. 
I understand that this is default behaviour in EPi, that when you use Move to Trash, you delete the page as a whole - all versions including master.

I've read some old topics that uses the DeleteLanguageBranch and that's what I've tried here.

Any suggestions on how to move forward or maybe even convincingly talk me out of this? 😅

public static void MovingContent(object sender, ContentEventArgs e)
		{
			var newsPage = e.Content as NewsPage;
			if (newsPage != null && newsPage.ArchiveLink == e.TargetLink)
				UnpublishNewsPageAndCreateRedirect(newsPage);


			if (e.TargetLink.CompareToIgnoreWorkID(ContentReference.WasteBasket) && e.Content is PageData)
			{
				var page = ServiceLocator.Current.GetInstance<IContentRepository>().Get<PageData>(e.ContentLink);
				var pageUrl = ServiceLocator.Current.GetInstance<UrlResolver>().GetVirtualPath(page.ContentLink);
				List<int> pageLanguages = page.ExistingLanguages.Select(x => x.LCID).ToList();

				var languages = ServiceLocator.Current.GetInstance<LanguageBranchRepository>().ListEnabled().Where(x => pageLanguages.Contains(x.Culture.LCID));

				bool msg = false;
				var languagesWithNoAccess = new List<string>();

				foreach (var lang in languages)
				{
					//check editing rights of current user
					if (lang.QueryEditAccessRights(PrincipalInfo.CurrentPrincipal))
					{
						//do not delete master branch
						if (page.MasterLanguage != lang.Culture)
						{
							//delete the branch corresponding to current lang from url. 
							if (pageUrl.VirtualPath.StartsWith(lang.Culture.Name))
							{
								ServiceLocator.Current.GetInstance<IContentRepository>().DeleteLanguageBranch(e.ContentLink, lang.Culture.Name, EPiServer.Security.AccessLevel.Delete);
							}
						}
					}
					else
					{
						languagesWithNoAccess.Add(lang.Name);
						msg = true;
					}

				}

				if (msg)
				{
					e.CancelReason = string.Format("You have no rights to delete version in {0}", string.Join(", ", languagesWithNoAccess));
					e.CancelAction = true;
					return;
				}

			}
		}
#265883
Edited, Oct 29, 2021 11:33
Vote:
 

I would avoid this if possible. If the editors ever attend a course, they will be frustrated by the fact that their edit mode do not work the way the course tells them.

Consider using the LanguageManager gadget instead?

#265895
Oct 29, 2021 18:25
Sebastian Romedahl - Nov 02, 2021 10:13
I've checked out the Language Manager, and in my opinion that is the tool for the job. However - Is it possible to restore deleted versions of a page? From what I can see they are just deleted and you'll have to recreate deleted pages again from scratch.
Tomas Hensrud Gulla - Nov 02, 2021 11:34
You are correct. Deleted language versions cannot be restored.
* 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.