Bloom.Book.BookData.MigrateData C# (CSharp) Method

MigrateData() private method

private MigrateData ( DataSet data ) : void
data DataSet
return void
        private void MigrateData(DataSet data)
        {
            //Until late in Bloom 3, we collected the topic in the National language, which is messy because then we would have to know how to
            //translate from all those languages to all other languages. Now, we just save English, and translate from English to whatever.
            //By far the largest number of books posted to bloomlibrary with this problem were Tok Pisin books, which actually just had
            //an English word as their value for "topic", so there we just switch it over to English.
            NamedMutliLingualValue topic;
            if (!data.TextVariables.TryGetValue("topic", out topic))
                return;
            var topicStrings = topic.TextAlternatives;
            if (string.IsNullOrEmpty(topicStrings["en"] ) && topicStrings["tpi"] != null)
            {
                topicStrings["en"] = topicStrings["tpi"];

                topicStrings.RemoveLanguageForm(topicStrings.Find("tpi"));
            }

            // BL-2746 For awhile during the v3.3 beta period, after the addition of ckeditor
            // our topic string was getting wrapped in html paragraph markers. There were a good
            // number of beta testers, so we need to clean up that mess.
            topicStrings.Forms
                .ForEach(
                    languageForm =>
                        topicStrings[languageForm.WritingSystemId] = languageForm.Form.Replace("<p>", "").Replace("</p>", ""));

            if (!string.IsNullOrEmpty(topicStrings["en"]))
            {
                //starting with 3.5, we only store the English key in the datadiv.
                topicStrings.Forms
                    .Where(lf => lf.WritingSystemId != "en")
                    .ForEach(lf => topicStrings.RemoveLanguageForm(lf));

                _dom.SafeSelectNodes("//div[@id='bloomDataDiv']/div[@data-book='topic' and not(@lang='en')]")
                    .Cast<XmlElement>()
                    .ForEach(e => e.ParentNode.RemoveChild(e));
            }
        }