24

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.

2
  • Do you need to keep the old fr-FR content? Commented Oct 7, 2016 at 16:35
  • For the time being, yes. Commented Oct 7, 2016 at 16:39

6 Answers 6

16

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.

5
  • Would you have to do this on all CD servers as well? Meaning that they will have to have PSE installed? Commented Oct 7, 2016 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
    Commented Oct 7, 2016 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) Commented Oct 7, 2016 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
    Commented Oct 7, 2016 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:. Commented Oct 9, 2016 at 19:05
10

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

4
  • 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). Commented Oct 7, 2016 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. Commented Oct 7, 2016 at 14:59
  • On 2nd look, "Never Publish" is a shared field, so this won't work. Commented Oct 7, 2016 at 15:09
  • Derek you could use __Hide version or __Valid to fields which are not shared.
    – ASura
    Commented Oct 7, 2016 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)

6
  • 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
    Commented Oct 7, 2016 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 Commented Oct 7, 2016 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 Commented Oct 7, 2016 at 8:19
  • The link is not working for me, connection error.
    – jammykam
    Commented Oct 7, 2016 at 9:23
  • @jammykam Are you still having issues with the link? It's working for me. Commented Oct 10, 2016 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.

2
  • 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. Commented Oct 7, 2016 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. Commented Oct 7, 2016 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 and acknowledge you have read our privacy policy.

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