23

There are currently five languages defined in a v7.2 site: en, en-GB, fr-FR, de-DE, en-AU, and zh-CN. Marketing has decided they no longer want to translate to fr-FR and would like to remove it from the site, however not lose all of the links.

The site will be upgraded to 8.x soon (most likely 8.2) and we'd like to utilize language fallback to have the fr-FR fallback to en-GB. Conceptually, we know how to set this up on the languages and templates, but how to we bulk "unpublish" all of the fr-FR versions of our items?

Update:

The intention isn't to completely remove the language versions, just unpublish them so they are no longer in the web database. Looking at the publishing restrictions fields, they are all shared.

  • Do you need to keep the old fr-FR content? – Sergeant Sitecore Oct 7 '16 at 16:35
  • For the time being, yes. – Derek Dysart Oct 7 '16 at 16:39
15

Because you want to keep the content in the Master database, but you do not want to publish it to the web database, this may be a good opportunity to use Workflow.

If you're using Workflow on these pages

Here's how to fix your issue:

  • Establish which Workflow your fr-FR pages are using.

  • In that Workflow, create a new Workflow state called "Archived" or "Disabled".

  • Make sure the Archived State's Final field is not checked off.

  • Use C#, Sitecore Rocks, or Powershell to set the Workflow State value of all fr-FR Item versions to the "Archived" state created above.

Example Routine:

public class Example
{
        public void Process()
        {
            var database = Sitecore.Configuration.Factory.GetDatabase("master");
            var language = Language.Parse("fr-FR");
            var items = database.SelectItems("/sitecore/content//*");

            foreach (var item in items)
            {
                var localized = item.Database.GetItem(item.ID, language);
                SetWorkflowState(localized);

                var olderVersions = localized.Versions.GetOlderVersions();

                foreach (var version in olderVersions)
                {
                    SetWorkflowState(version);
                }
            }
        }

        private void SetWorkflowState(Item item)
        {
            item.Editing.BeginEdit();
            item.Fields[FieldIDs.WorkflowState].Value = DisabledWorkflowStateId;
            item.Editing.EndEdit();
        }
}

I'm sure a powershell ace will add the equivalent in Powershell here.

If you're not using Workflow Yet

You must first set the Workflow for these Page Templates in their Standard Values, then you can proceed as above.

Don't Forget to Publish!

You'll probably want to run a full-site smart Publish to remove the fr-FR language content from the site - Keep in mind that you only need to publish the fr-FR language, which should keep your smart-publish burden down.

12

I think this is possible with SPE. Something like this should work:

Remove-ItemLanguage -Path master:\content\home -Language "fr-FR" -Recurse

Perform this on a CM server and publish the site to move the changes to the web database and the CD servers.

It's probably also a good idea to rebuild your indexes and link database after doing this.

It might also be a good idea to set your language fallback already before publishing and rebuilding indexes, this way you only need to do that once.

  • Would you have to do this on all CD servers as well? Meaning that they will have to have PSE installed? – Dmytro Shevchenko Oct 7 '16 at 8:03
  • 1
    You don't need to do this on the CD's..only on CM. The publish will site will take care of the web database and the CD servers. (I'll put this more clearly in the answer) – Gatogordo Oct 7 '16 at 8:07
  • I think this approach, done in the web database might be what we are looking for. Basically, we want to remove one language from the live site (but obvisoulsy if someone publishes that language it will be back) – Derek Dysart Oct 7 '16 at 15:12
  • Isn't that a scary thought? You might want to consider an extra script to disable the publishing of all fr-FR versions on your master db... – Gatogordo Oct 7 '16 at 15:20
  • 1
    If you wanted to only remove the web versions then change the query to use the web: database rather than the master:. – Michael West Oct 9 '16 at 19:05
9

You could loop through items in your tree and restrict publishing using Sitecore PowerShell.

$item = Get-Item master:/sitecore/content/home
$item.Editing.BeginEdit()
$item["__Never publish"] = "1"
$item.Editing.EndEdit()

Some useful links: https://community.sitecore.net/technical_blogs/b/sitecorejohn_blog/posts/fields-that-control-publishing-restrictions-in-the-sitecore-asp-net-cms

https://stackoverflow.com/questions/31950065/in-sitecore-powershell-can-you-make-an-item-unpublishable

https://sitecorepowershell.gitbooks.io/sitecore-powershell-extensions/content/appendix/commands/Get-ItemField.html

  • 1
    The OP is asking how to remove a certain language version of all items. Not how to make all of your content unpublishable (which is what your script does). – Dmytro Shevchenko Oct 7 '16 at 5:38
  • Actually, we don't want to get rid of the language, just unpublish all of the content from the web databases. This approach actually seems the most reasonable. – Derek Dysart Oct 7 '16 at 14:59
  • On 2nd look, "Never Publish" is a shared field, so this won't work. – Derek Dysart Oct 7 '16 at 15:09
  • Derek you could use __Hide version or __Valid to fields which are not shared. – ASura Oct 7 '16 at 16:27
5

An alternative using only the UI... What if...

  1. You delete de language. it will delete all the content in that language. It will take a while.
  2. Publish the languages folder with subitems. It will delete the french content from web database. Again, It will take a while, depending on your content.
  3. Create the language again, set up fallback and publish. If I understood the requisite you would then keep your links.

This post seems to confirm my point (thanks @dymitro)

  • Are you sure all content in that language is truly gone? Had some other experiences in the past where the data seemed gone but was still in the database (but that was in v6 so it might have changed).. – Gatogordo Oct 7 '16 at 8:12
  • I just did a quick test with 8.2 and the rows in the database have gone, But I can't be 100% sure that it will cover every single scenario. But given how simple it is, It's worth a try – Vicent Galiana Oct 7 '16 at 8:16
  • 2
    Following the link provided by dmytro, it is even configurable if you want to delete the data or not, so everything look like it works. newguid.net/sitecore/2013/beware-of-deleting-language-items – Vicent Galiana Oct 7 '16 at 8:19
  • The link is not working for me, connection error. – jammykam Oct 7 '16 at 9:23
  • @jammykam Are you still having issues with the link? It's working for me. – Vicent Galiana Oct 10 '16 at 7:45
4

In addition to other answers, you can do this manually by removing language versions directly from Sitecore databases, followed by rebuilding all caches and indexes.

1) Execute the following queries on your Master and Web databases:

DELETE
FROM [VersionedFields]
WHERE [Language] = 'fr-FR'

DELETE
FROM [UnversionedFields]
WHERE [Language] = 'fr-FR'

2) Clear item caches on all instances using the page /sitecore/admin/cache.aspx

3) Rebuild the link database on all Sitecore instances. You can do that from the control panel.

4) Rebuild search indexes on all Sitecore instances. You can do that from the control panel.

Be sure to test this thoroughly in a test setup, since modifying Sitecore databases directly may sometimes break your site.

  • 1
    Editing content directly in the database could look like the most straightforward, but it's something I always discourage unless it is confirmed with Sitecore that there is no other option and that it's a valid solution. Even sometimes after all these precautions I have seen side effects more difficult to solve that the original one. For me, a valid solution must be via UI or API. – Vicent Galiana Oct 7 '16 at 7:46
  • @VicentGaliana I agree, given that there's a "built-in" approach (newguid.net/sitecore/2013/beware-of-deleting-language-items), it's better to use that. I will keep my answer just in case. – Dmytro Shevchenko Oct 7 '16 at 8:12
0

One option would be to execute a script on web database. Following link explains what code to be executed

public void RemoveLanguageVersion(string rootItemPath, string languageName)
        {
            Language languageRemove = Sitecore.Globalization.Language.Parse(languageName);
            Item rootItem = Sitecore.Context.Database.GetItem(rootItemPath, languageRemove);

            if (rootItem != null)
            {
                using (new Sitecore.SecurityModel.SecurityDisabler())
                {
                    //Remove language version from root item               
                    rootItem.Versions.RemoveVersion();

                    //Remove language version recursively from child items of root item
                    foreach (Item child in rootItem.Axes.GetDescendants().Where(l => l.Language == languageRemove))
                    {
                        child.Versions.RemoveVersion();
                    }
                }
            }
        }

http://www.bugdebugzone.com/2014/06/remove-specific-language-version-from.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.