private ContentItem LocateStartPage(ContentItem startPageConfigured) { ContentItem startPage = startPageConfigured; lock (_syncLock) { if (host.CurrentSite.StartPageID != host.CurrentSite.RootItemID) // only when start <> root { if (startPage != null) { if (!(startPage is IStartPage)) { logger.WarnFormat("Configured start page is no IStartPage #{0} -> {1}", host.CurrentSite.StartPageID, startPage.GetType().FullName); startPage = null; } if (startPage != null && !startPage.IsPublished()) { logger.ErrorFormat("Configured start page is not published #{0} -> {1}", startPage.ID, startPage.GetType().FullName); startPage = null; } } if (startPage == null) { // try to locate start page below root var root = persister.Repository.Get(host.CurrentSite.RootItemID); if (root == null) { // no content? return(null); } ItemList children = root.GetChildren(new TypeFilter(typeof(IStartPage)), new PublishedFilter()); if (children.Count == 1) { startPage = children[0]; logger.InfoFormat("Auto updated start page to #{0} -> {1}", startPage.ID, startPage.GetType().FullName); var newSite = new Site(root.ID, startPage.ID); host.ReplaceSites(newSite, new List <Site>()); } } if (startPage == null) { return(startPageConfigured); // keep configured } } } return(startPage); }
public virtual void Import(IImportRecord record, ContentItem destination, ImportOption options) { var security = N2.Context.Current.Resolve <ISecurityManager>(); using (security.Disable()) // TODO restrict to Admin User { ResetIDs(record.ReadItems); if ((options & ImportOption.AllItems) == ImportOption.AllItems) { record.RootItem.AddTo(destination); if (_persister != null) { _persister.SaveRecursive(record.RootItem); } } else if ((options & ImportOption.Children) == ImportOption.Children) { RemoveReferences(record.ReadItems, record.RootItem); while (record.RootItem.Children.Count > 0) { ContentItem child = record.RootItem.Children[0]; child.AddTo(destination); if (_persister != null) { _persister.SaveRecursive(child); } } } else { logger.ErrorFormat("Option {0} isn't supported", options); throw new NotImplementedException("This option isn't implemented, sorry."); } if ((options & ImportOption.Attachments) == ImportOption.Attachments) { foreach (Attachment a in record.Attachments) { try { a.Import(_fs); } catch (Exception ex) { logger.Warn(ex); record.FailedAttachments.Add(a); } } } } }
public virtual void Import(IImportRecord record, ContentItem destination, ImportOption options) { ResetIDs(record.ReadItems); if ((options & ImportOption.AllItems) == ImportOption.AllItems) { record.RootItem.AddTo(destination); persister.SaveRecursive(record.RootItem); } else if ((options & ImportOption.Children) == ImportOption.Children) { RemoveReferences(record.ReadItems, record.RootItem); while (record.RootItem.Children.Count > 0) { ContentItem child = record.RootItem.Children[0]; child.AddTo(destination); persister.SaveRecursive(child); } } else { logger.ErrorFormat("Option {0} isn't supported", options); throw new NotImplementedException("This option isn't implemented, sorry."); } if ((options & ImportOption.Attachments) == ImportOption.Attachments) { foreach (Attachment a in record.Attachments) { try { a.Import(fs); } catch (Exception ex) { logger.Warn(ex); record.FailedAttachments.Add(a); } } } }
public virtual void Import(IImportRecord record, ContentItem destination, ImportOption options) { ResetIDs(record.ReadItems); if ((options & ImportOption.AllItems) == ImportOption.AllItems) { record.RootItem.AddTo(destination); try { persister.SaveRecursive(record.RootItem); } catch (Exception ex) { logger.Warn(ex); if (record.RootItem != null) { record.FailedContentItems.Add(new Tuple <ContentItem, Exception>(record.RootItem, ex)); } } } else if ((options & ImportOption.Children) == ImportOption.Children) { RemoveReferences(record.ReadItems, record.RootItem); while (record.RootItem.Children.Count > 0) { ContentItem child = null; bool added = false; try { child = record.RootItem.Children[0]; child.AddTo(destination); added = true; persister.SaveRecursive(child); } catch (Exception ex) { logger.Warn(ex); if (child != null) { record.FailedContentItems.Add(new Tuple <ContentItem, Exception>(child, ex)); } // ROLL BACK: Undo child.AddTo if SaveRecursive failed. That way the import can still continue successfully. if (added && destination != null && child != null) { destination.Children.Remove(child); } } } } else { logger.ErrorFormat("Option {0} isn't supported", options); throw new NotImplementedException("This option isn't implemented, sorry."); } if ((options & ImportOption.Attachments) == ImportOption.Attachments) { foreach (Attachment a in record.Attachments) { try { a.Import(fs); } catch (Exception ex) { logger.Warn(ex); record.FailedAttachments.Add(a); } } } }