/// <summary>
        /// Creates the Site root using the branch template
        /// </summary>
        /// <param name="parentItem"></param>
        /// <param name="database"></param>
        /// <returns></returns>
        private Item CreateWebsiteRoot(Item parentItem, Database database)
        {
            Item       newWebRootItem     = null;
            BranchItem siteRootBranchItem = siteRootBranchTemplateID.Length > 0 ? database.Branches[siteRootBranchTemplateID] : database.Branches[TemplateIDs.Folder];

            //Check if branch template exists, else abort pipeline
            if (siteRootBranchItem != null)
            {
                Log.Audit((object)this, "Create Website Root: {0}", new string[1] {
                    AuditFormatter.FormatItem(parentItem)
                });

                using (new SecurityDisabler())
                {
                    //txtSiteName will replace the $name standard value defined under branch template when the site is created
                    newWebRootItem = siteRootBranchItem.AddTo(parentItem, txtSiteName.Value);
                }
            }
            else
            {
                Context.ClientPage.ClientResponse.Alert(Translate.Text("{0} branch was not found.", (object)siteRootBranchTemplateID));
            }

            return(newWebRootItem);
        }
        /// <summary>
        /// Create site definition
        /// </summary>
        /// <param name="parentItem"></param>
        /// <param name="database"></param>
        /// <param name="language"></param>
        /// <param name="websiteRootItem"></param>
        private void CreateSiteDefinition(Item parentItem, Database database, string language, Item websiteRootItem)
        {
            BranchItem siteDefinitionBranchItem = siteDefinitionBranchTemplateID.Length > 0 ? database.Branches[siteDefinitionBranchTemplateID] : database.Branches[TemplateIDs.Folder];

            if (siteDefinitionBranchItem != null)
            {
                Log.Audit((object)this, "Create Site Definition:{0}", new string[1] {
                    AuditFormatter.FormatItem(parentItem)
                });
                Item newSiteDefinition = siteDefinitionBranchItem.AddTo(parentItem, txtSiteName.Value);

                //Add values based on site root under site defintion
                using (new SecurityDisabler())
                {
                    /*BEGIN EDIT*/
                    newSiteDefinition.Editing.BeginEdit();
                    //setting the hostnames and language
                    newSiteDefinition.Fields["hostName"].Value = txtHostNames.Value;

                    //setting the primary language for the site from the list of languages under system/languages
                    var primaryLanguageItem = database.GetItem(LanguagesItemId).Axes.GetDescendants().FirstOrDefault(x => x.Name.ToLower().Equals(language.ToLower()));

                    if (primaryLanguageItem != null)
                    {
                        ID primaryLanguageId = primaryLanguageItem.ID;
                        newSiteDefinition.Fields["language"].Value = primaryLanguageId.ToString();
                    }

                    /*END EDIT*/
                    newSiteDefinition.Editing.EndEdit();

                    //updating the siteSettings reference
                    var siteSettingsItem = newSiteDefinition.Children.FirstOrDefault(x => x.Name.Equals("siteSettings"));
                    if (siteSettingsItem != null)
                    {
                        siteSettingsItem.Editing.BeginEdit();
                        var siteSettings = websiteRootItem.Children.FirstOrDefault(x => x.TemplateID.ToString().Equals(SiteSettingsTemplateId));

                        if (siteSettings != null)
                        {
                            siteSettingsItem.Fields["Value"].Value = siteSettings.ID.ToString();
                        }

                        siteSettingsItem.Editing.EndEdit();
                    }
                }
            }
            else
            {
                Context.ClientPage.ClientResponse.Alert(Translate.Text("{0} branch was not found.", (object)siteDefinitionBranchTemplateID));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Executes the command in the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public override void Execute(CommandContext context)
        {
            Assert.ArgumentNotNull(context, "context");
            Assert.IsNotNull(Context.ContentDatabase, ContentDatabaseMustNotBeNull);

            Item item            = Context.ContentDatabase.GetItem(context.Parameters[ItemKey]);
            Item branchInnerItem = Context.ContentDatabase.GetItem(context.Parameters[BranchKey]);

            Assert.IsNotNull(item, ItemCannotBeFound);
            Assert.IsNotNull(branchInnerItem, BranchCannotBeFound);

            BranchItem branchItem = new BranchItem(branchInnerItem);

            this.BranchLinkUpdater.UpdateItemLinks(branchItem.AddTo(item, context.Parameters[NameKey]), branchItem);
        }
    /// <summary>
    /// Executes the command in the specified context.
    /// </summary>
    /// <param name="context">The context.</param>
    public override void Execute(CommandContext context)
    {
      Assert.ArgumentNotNull(context, "context");
      Assert.IsNotNull(Context.ContentDatabase, ContentDatabaseMustNotBeNull);

      Item item = Context.ContentDatabase.GetItem(context.Parameters[ItemKey]);
      Item branchInnerItem = Context.ContentDatabase.GetItem(context.Parameters[BranchKey]);

      Assert.IsNotNull(item, ItemCannotBeFound);
      Assert.IsNotNull(branchInnerItem, BranchCannotBeFound);

      BranchItem branchItem = new BranchItem(branchInnerItem);

      this.BranchLinkUpdater.UpdateItemLinks(branchItem.AddTo(item, context.Parameters[NameKey]), branchItem);
    }