private void ImportStuff() { SiteData.CurrentSite = null; SiteData site = SiteData.CurrentSite; litMessage.Text = "<p>No Items Selected For Import</p>"; string sMsg = ""; if (chkSite.Checked || chkPages.Checked || chkPosts.Checked) { List <string> tags = site.GetTagList().Select(x => x.TagSlug.ToLowerInvariant()).ToList(); List <string> cats = site.GetCategoryList().Select(x => x.CategorySlug.ToLowerInvariant()).ToList(); wpSite.Tags.RemoveAll(x => tags.Contains(x.InfoKey.ToLowerInvariant())); wpSite.Categories.RemoveAll(x => cats.Contains(x.InfoKey.ToLowerInvariant())); sMsg += "<p>Imported Tags and Categories</p>"; List <ContentTag> lstTag = (from l in wpSite.Tags.Distinct() select new ContentTag { ContentTagID = Guid.NewGuid(), IsPublic = true, SiteID = site.SiteID, TagSlug = l.InfoKey, TagText = l.InfoLabel }).Distinct().ToList(); List <ContentCategory> lstCat = (from l in wpSite.Categories.Distinct() select new ContentCategory { ContentCategoryID = Guid.NewGuid(), IsPublic = true, SiteID = site.SiteID, CategorySlug = l.InfoKey, CategoryText = l.InfoLabel }).Distinct().ToList(); foreach (var v in lstTag) { v.Save(); } foreach (var v in lstCat) { v.Save(); } } SetMsg(sMsg); if (chkSite.Checked) { sMsg += "<p>Updated Site Name</p>"; site.SiteName = wpSite.SiteTitle; site.SiteTagline = wpSite.SiteDescription; site.Save(); } SetMsg(sMsg); if (!chkMapAuthor.Checked) { wpSite.Authors = new List <WordPressUser>(); } //itterate author collection and find if in the system foreach (WordPressUser wpu in wpSite.Authors) { wpu.ImportUserID = Guid.Empty; MembershipUser usr = null; //attempt to find the user in the userbase usr = SecurityData.GetUserListByEmail(wpu.Email).FirstOrDefault(); if (usr != null) { wpu.ImportUserID = new Guid(usr.ProviderUserKey.ToString()); } else { usr = SecurityData.GetUserListByName(wpu.Login).FirstOrDefault(); if (usr != null) { wpu.ImportUserID = new Guid(usr.ProviderUserKey.ToString()); } } if (chkAuthors.Checked) { if (wpu.ImportUserID == Guid.Empty) { usr = Membership.CreateUser(wpu.Login, ProfileManager.GenerateSimplePassword(), wpu.Email); Roles.AddUserToRole(wpu.Login, SecurityData.CMSGroup_Users); wpu.ImportUserID = new Guid(usr.ProviderUserKey.ToString()); } if (wpu.ImportUserID != Guid.Empty) { ExtendedUserData ud = new ExtendedUserData(wpu.ImportUserID); if (ud != null) { if (!String.IsNullOrEmpty(wpu.FirstName) || !String.IsNullOrEmpty(wpu.LastName)) { ud.FirstName = wpu.FirstName; ud.LastName = wpu.LastName; ud.Save(); } } else { throw new Exception(String.Format("Could not find new user: {0} ({1})", wpu.Login, wpu.Email)); } } } } wpSite.Comments.ForEach(r => r.ImportRootID = Guid.Empty); using (ISiteNavHelper navHelper = SiteNavFactory.GetSiteNavHelper()) { if (chkPages.Checked) { sMsg += "<p>Imported Pages</p>"; int iOrder = 0; SiteNav navHome = navHelper.FindHome(site.SiteID, false); if (navHome != null) { iOrder = 2; } foreach (var wpp in (from c in wpSite.Content where c.PostType == WordPressPost.WPPostType.Page orderby c.PostOrder, c.PostTitle select c).ToList()) { GrabAttachments(wpp); RepairBody(wpp); ContentPage cp = ContentImportExportUtils.CreateWPContentPage(wpSite, wpp, site); cp.SiteID = site.SiteID; cp.ContentType = ContentPageType.PageType.ContentEntry; cp.EditDate = SiteData.CurrentSite.Now; cp.NavOrder = iOrder; cp.TemplateFile = ddlTemplatePage.SelectedValue; WordPressPost parent = (from c in wpSite.Content where c.PostType == WordPressPost.WPPostType.Page && c.PostID == wpp.ParentPostID select c).FirstOrDefault(); SiteNav navParent = null; SiteNav navData = navHelper.GetLatestVersion(site.SiteID, false, cp.FileName.ToLowerInvariant()); if (parent != null) { navParent = navHelper.GetLatestVersion(site.SiteID, false, parent.ImportFileName.ToLowerInvariant()); } //if URL exists already, make this become a new version in the current series if (navData != null) { cp.Root_ContentID = navData.Root_ContentID; if (navData.NavOrder == 0) { cp.NavOrder = 0; } } if (navParent != null) { cp.Parent_ContentID = navParent.Root_ContentID; } else { if (parent != null) { cp.Parent_ContentID = parent.ImportRootID; } } //preserve homepage if (navHome != null && navHome.FileName.ToLowerInvariant() == cp.FileName.ToLowerInvariant()) { cp.NavOrder = 0; } cp.RetireDate = CMSConfigHelper.CalcNearestFiveMinTime(cp.CreateDate).AddYears(200); cp.GoLiveDate = CMSConfigHelper.CalcNearestFiveMinTime(cp.CreateDate).AddMinutes(-5); //if URL exists already, make this become a new version in the current series if (navData != null) { cp.Root_ContentID = navData.Root_ContentID; cp.RetireDate = navData.RetireDate; cp.GoLiveDate = navData.GoLiveDate; } cp.SavePageEdit(); wpSite.Comments.Where(x => x.PostID == wpp.PostID).ToList().ForEach(r => r.ImportRootID = cp.Root_ContentID); iOrder++; } } if (chkPosts.Checked) { sMsg += "<p>Imported Posts</p>"; foreach (var wpp in (from c in wpSite.Content where c.PostType == WordPressPost.WPPostType.BlogPost orderby c.PostOrder select c).ToList()) { GrabAttachments(wpp); RepairBody(wpp); ContentPage cp = ContentImportExportUtils.CreateWPContentPage(wpSite, wpp, site); cp.SiteID = site.SiteID; cp.Parent_ContentID = null; cp.ContentType = ContentPageType.PageType.BlogEntry; cp.EditDate = SiteData.CurrentSite.Now; cp.NavOrder = SiteData.BlogSortOrderNumber; cp.TemplateFile = ddlTemplatePost.SelectedValue; SiteNav navData = navHelper.GetLatestVersion(site.SiteID, false, cp.FileName.ToLowerInvariant()); cp.RetireDate = CMSConfigHelper.CalcNearestFiveMinTime(cp.CreateDate).AddYears(200); cp.GoLiveDate = CMSConfigHelper.CalcNearestFiveMinTime(cp.CreateDate).AddMinutes(-5); //if URL exists already, make this become a new version in the current series if (navData != null) { cp.Root_ContentID = navData.Root_ContentID; cp.RetireDate = navData.RetireDate; cp.GoLiveDate = navData.GoLiveDate; } cp.SavePageEdit(); wpSite.Comments.Where(x => x.PostID == wpp.PostID).ToList().ForEach(r => r.ImportRootID = cp.Root_ContentID); } using (ContentPageHelper cph = new ContentPageHelper()) { //cph.BulkBlogFileNameUpdateFromDate(site.SiteID); cph.ResolveDuplicateBlogURLs(site.SiteID); cph.FixBlogNavOrder(site.SiteID); } } } SetMsg(sMsg); wpSite.Comments.RemoveAll(r => r.ImportRootID == Guid.Empty); if (wpSite.Comments.Any()) { sMsg += "<p>Imported Comments</p>"; } foreach (WordPressComment wpc in wpSite.Comments) { int iCommentCount = -1; iCommentCount = PostComment.GetCommentCountByContent(site.SiteID, wpc.ImportRootID, wpc.CommentDateUTC, wpc.AuthorIP, wpc.CommentContent); if (iCommentCount < 1) { iCommentCount = PostComment.GetCommentCountByContent(site.SiteID, wpc.ImportRootID, wpc.CommentDateUTC, wpc.AuthorIP); } if (iCommentCount < 1) { PostComment pc = new PostComment(); pc.ContentCommentID = Guid.NewGuid(); pc.Root_ContentID = wpc.ImportRootID; pc.CreateDate = site.ConvertUTCToSiteTime(wpc.CommentDateUTC); pc.IsApproved = false; pc.IsSpam = false; pc.CommenterIP = wpc.AuthorIP; pc.CommenterName = wpc.Author; pc.CommenterEmail = wpc.AuthorEmail; pc.PostCommentText = wpc.CommentContent; pc.CommenterURL = wpc.AuthorURL; if (wpc.Approved == "1") { pc.IsApproved = true; } if (wpc.Approved.ToLowerInvariant() == "trash") { pc.IsSpam = true; } if (wpc.Type.ToLowerInvariant() == "trackback" || wpc.Type.ToLowerInvariant() == "pingback") { pc.CommenterEmail = wpc.Type; } pc.Save(); } } SetMsg(sMsg); BindData(); }
private void ImportStuff() { SiteData.CurrentSite = null; SiteData site = SiteData.CurrentSite; litMessage.Text = "<p>No Items Selected For Import</p>"; string sMsg = ""; if (chkSite.Checked || chkPages.Checked || chkPosts.Checked) { List <string> tags = site.GetTagList().Select(x => x.TagSlug.ToLower()).ToList(); List <string> cats = site.GetCategoryList().Select(x => x.CategorySlug.ToLower()).ToList(); exSite.TheTags.RemoveAll(x => tags.Contains(x.TagSlug.ToLower())); exSite.TheCategories.RemoveAll(x => cats.Contains(x.CategorySlug.ToLower())); sMsg += "<p>Imported Tags and Categories</p>"; List <ContentTag> lstTag = (from l in exSite.TheTags.Distinct() select new ContentTag { ContentTagID = Guid.NewGuid(), SiteID = site.SiteID, IsPublic = l.IsPublic, TagSlug = l.TagSlug, TagText = l.TagText }).ToList(); List <ContentCategory> lstCat = (from l in exSite.TheCategories.Distinct() select new ContentCategory { ContentCategoryID = Guid.NewGuid(), SiteID = site.SiteID, IsPublic = l.IsPublic, CategorySlug = l.CategorySlug, CategoryText = l.CategoryText }).ToList(); foreach (var v in lstTag) { v.Save(); } foreach (var v in lstCat) { v.Save(); } } SetMsg(sMsg); if (chkSnippet.Checked) { List <string> snippets = site.GetContentSnippetList().Select(x => x.ContentSnippetSlug.ToLower()).ToList(); exSite.TheSnippets.RemoveAll(x => snippets.Contains(x.ContentSnippetSlug.ToLower())); sMsg += "<p>Imported Content Snippets</p>"; List <ContentSnippet> lstSnip = (from l in exSite.TheSnippets.Distinct() select new ContentSnippet { SiteID = site.SiteID, Root_ContentSnippetID = Guid.NewGuid(), ContentSnippetID = Guid.NewGuid(), CreateUserId = SecurityData.CurrentUserGuid, CreateDate = site.Now, EditUserId = SecurityData.CurrentUserGuid, EditDate = site.Now, RetireDate = l.RetireDate, GoLiveDate = l.GoLiveDate, ContentSnippetActive = l.ContentSnippetActive, ContentBody = l.ContentBody, ContentSnippetSlug = l.ContentSnippetSlug, ContentSnippetName = l.ContentSnippetName }).ToList(); foreach (var v in lstSnip) { v.Save(); } } SetMsg(sMsg); if (chkSite.Checked) { sMsg += "<p>Updated Site Name</p>"; site.SiteName = exSite.TheSite.SiteName; site.SiteTagline = exSite.TheSite.SiteTagline; site.Save(); } SetMsg(sMsg); if (!chkMapAuthor.Checked) { exSite.TheUsers = new List <SiteExportUser>(); } //itterate author collection and find if in the system foreach (SiteExportUser seu in exSite.TheUsers) { seu.ImportUserID = Guid.Empty; MembershipUser usr = null; //attempt to find the user in the userbase usr = SecurityData.GetUserListByEmail(seu.Email).FirstOrDefault(); if (usr != null) { seu.ImportUserID = new Guid(usr.ProviderUserKey.ToString()); } else { usr = SecurityData.GetUserListByName(seu.Login).FirstOrDefault(); if (usr != null) { seu.ImportUserID = new Guid(usr.ProviderUserKey.ToString()); } } if (chkAuthors.Checked) { if (seu.ImportUserID == Guid.Empty) { usr = Membership.CreateUser(seu.Login, ProfileManager.GenerateSimplePassword(), seu.Email); Roles.AddUserToRole(seu.Login, SecurityData.CMSGroup_Users); seu.ImportUserID = new Guid(usr.ProviderUserKey.ToString()); } if (seu.ImportUserID != Guid.Empty) { ExtendedUserData ud = new ExtendedUserData(seu.ImportUserID); if (ud != null) { if (!String.IsNullOrEmpty(seu.FirstName) || !String.IsNullOrEmpty(seu.LastName)) { ud.FirstName = seu.FirstName; ud.LastName = seu.LastName; ud.Save(); } } else { throw new Exception(String.Format("Could not find new user: {0} ({1})", seu.Login, seu.Email)); } } } } if (chkPages.Checked) { sMsg += "<p>Imported Pages</p>"; sitePageList = site.GetFullSiteFileList(); int iOrder = 0; SiteNav navHome = GetHomePage(site); if (navHome != null) { iOrder = 2; } foreach (var impCP in (from c in exSite.ThePages where c.ThePage.ContentType == ContentPageType.PageType.ContentEntry orderby c.ThePage.NavOrder, c.ThePage.NavMenuText select c).ToList()) { ContentPage cp = impCP.ThePage; cp.Root_ContentID = impCP.NewRootContentID; cp.ContentID = Guid.NewGuid(); cp.SiteID = site.SiteID; cp.ContentType = ContentPageType.PageType.ContentEntry; cp.EditDate = SiteData.CurrentSite.Now; cp.EditUserId = exSite.FindImportUser(impCP.TheUser); cp.CreateUserId = exSite.FindImportUser(impCP.TheUser); if (impCP.CreditUser != null) { cp.CreditUserId = exSite.FindImportUser(impCP.CreditUser); } cp.NavOrder = iOrder; cp.TemplateFile = ddlTemplatePage.SelectedValue; ContentPageExport parent = (from c in exSite.ThePages where c.ThePage.ContentType == ContentPageType.PageType.ContentEntry && c.ThePage.FileName.ToLower() == impCP.ParentFileName.ToLower() select c).FirstOrDefault(); BasicContentData navParent = null; BasicContentData navData = GetFileInfoFromList(site, cp.FileName); if (parent != null) { cp.Parent_ContentID = parent.NewRootContentID; navParent = GetFileInfoFromList(site, parent.ThePage.FileName); } //if URL exists already, make this become a new version in the current series if (navData != null) { cp.Root_ContentID = navData.Root_ContentID; impCP.ThePage.RetireDate = navData.RetireDate; impCP.ThePage.GoLiveDate = navData.GoLiveDate; if (navData.NavOrder == 0) { cp.NavOrder = 0; } } //preserve homepage if (navHome != null && navHome.FileName.ToLower() == cp.FileName.ToLower()) { cp.NavOrder = 0; } //if the file url in the upload has an existing ID, use that, not the ID from the queue if (navParent != null) { cp.Parent_ContentID = navParent.Root_ContentID; } cp.RetireDate = impCP.ThePage.RetireDate; cp.GoLiveDate = impCP.ThePage.GoLiveDate; cp.SavePageEdit(); iOrder++; } } SetMsg(sMsg); if (chkPosts.Checked) { sMsg += "<p>Imported Posts</p>"; sitePageList = site.GetFullSiteFileList(); List <ContentTag> lstTags = site.GetTagList(); List <ContentCategory> lstCategories = site.GetCategoryList(); foreach (var impCP in (from c in exSite.ThePages where c.ThePage.ContentType == ContentPageType.PageType.BlogEntry orderby c.ThePage.CreateDate select c).ToList()) { ContentPage cp = impCP.ThePage; cp.Root_ContentID = impCP.NewRootContentID; cp.ContentID = Guid.NewGuid(); cp.SiteID = site.SiteID; cp.Parent_ContentID = null; cp.ContentType = ContentPageType.PageType.BlogEntry; cp.EditDate = SiteData.CurrentSite.Now; cp.EditUserId = exSite.FindImportUser(impCP.TheUser); cp.CreateUserId = exSite.FindImportUser(impCP.TheUser); if (impCP.CreditUser != null) { cp.CreditUserId = exSite.FindImportUser(impCP.CreditUser); } cp.NavOrder = SiteData.BlogSortOrderNumber; cp.TemplateFile = ddlTemplatePost.SelectedValue; cp.ContentCategories = (from l in lstCategories join o in impCP.ThePage.ContentCategories on l.CategorySlug.ToLower() equals o.CategorySlug.ToLower() select l).Distinct().ToList(); cp.ContentTags = (from l in lstTags join o in impCP.ThePage.ContentTags on l.TagSlug.ToLower() equals o.TagSlug.ToLower() select l).Distinct().ToList(); BasicContentData navData = GetFileInfoFromList(site, cp.FileName); //if URL exists already, make this become a new version in the current series if (navData != null) { cp.Root_ContentID = navData.Root_ContentID; impCP.ThePage.RetireDate = navData.RetireDate; impCP.ThePage.GoLiveDate = navData.GoLiveDate; } cp.RetireDate = impCP.ThePage.RetireDate; cp.GoLiveDate = impCP.ThePage.GoLiveDate; cp.SavePageEdit(); } using (ContentPageHelper cph = new ContentPageHelper()) { //cph.BulkBlogFileNameUpdateFromDate(site.SiteID); cph.ResolveDuplicateBlogURLs(site.SiteID); cph.FixBlogNavOrder(site.SiteID); } } SetMsg(sMsg); if (chkComments.Checked) { sMsg += "<p>Imported Comments</p>"; sitePageList = site.GetFullSiteFileList(); foreach (var impCP in (from c in exSite.TheComments orderby c.TheComment.CreateDate select c).ToList()) { int iCommentCount = -1; PostComment pc = impCP.TheComment; BasicContentData navData = GetFileInfoFromList(site, pc.FileName); if (navData != null) { pc.Root_ContentID = navData.Root_ContentID; pc.ContentCommentID = Guid.NewGuid(); iCommentCount = PostComment.GetCommentCountByContent(site.SiteID, pc.Root_ContentID, pc.CreateDate, pc.CommenterIP, pc.PostCommentText); if (iCommentCount < 1) { iCommentCount = PostComment.GetCommentCountByContent(site.SiteID, pc.Root_ContentID, pc.CreateDate, pc.CommenterIP); } if (iCommentCount < 1) { pc.Save(); } } } } SetMsg(sMsg); BindData(); }