Пример #1
0
 /// <summary>
 ///  When the Umbraco Forms package is installed this will update the contact template and the forms picker property type
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void PackagingService_ImportedPackage(IPackagingService sender, Core.Events.ImportPackageEventArgs <Core.Packaging.Models.InstallationSummary> e)
 {
     if (e != null && e.PackageMetaData != null && e.PackageMetaData.Name == "Umbraco Forms")
     {
         var formsInstallHelper = new FormsInstallationHelper(ApplicationContext.Current.Services);
         formsInstallHelper.UpdateUmbracoDataForFormsInstallation();
     }
 }
        /// <summary>
        /// This will check if Forms is installed and if not it will update the markup in the contact template to render a message to install forms
        /// and update the contactForm property type to become a label
        /// </summary>
        public void UpdateUmbracoDataForNonFormsInstallation()
        {
            var macroService    = _services.MacroService;
            var doctypeService  = _services.ContentTypeService;
            var dataTypeService = _services.DataTypeService;
            var fileService     = _services.FileService;

            // check if forms is installed
            var formMacro = macroService.GetByAlias(FormsMacroAlias);

            if (formMacro == null)
            {
                // find the doctype and change the form chooser property type

                var contactFormType = doctypeService.Get(DocTypeAlias);
                if (contactFormType != null)
                {
                    var formPicker = contactFormType.PropertyTypes.FirstOrDefault(x => x.Alias == PropertyAlias);

                    var labelDataType = dataTypeService.GetDataType(Constants.DataTypes.LabelString);
                    if (labelDataType != null && formPicker != null)
                    {
                        formPicker.DataTypeId = labelDataType.Id;
                        doctypeService.Save(contactFormType);
                    }
                }

                // update the template
                var contactView = fileService.GetTemplate(TemplateAlias);
                if (contactView != null)
                {
                    var templateContent = contactView.Content;
                    if (string.IsNullOrWhiteSpace(templateContent) == false)
                    {
                        // do the replacement
                        templateContent =
                            PreInstallContactFormHtmlPattern.Replace(templateContent, PostInstallContactFormHtml);

                        contactView.Content = templateContent;
                        fileService.SaveTemplate(contactView);
                    }
                }
            }
            else
            {
                // forms is installed
                var formsInstallHelper = new FormsInstallationHelper(Current.Services);
                formsInstallHelper.UpdateUmbracoDataForFormsInstallation();
            }
        }
        public bool Execute(string packageName, XElement xmlData)
        {
            var contentService   = Current.Services.ContentService;
            var mediaTypeService = Current.Services.MediaTypeService;
            var mediaService     = Current.Services.MediaService;
            var dataTypeService  = Current.Services.DataTypeService;
            var fileService      = Current.Services.FileService;
            var contentSection   = Current.Configs.Settings().Content;

            var formsInstallHelper = new FormsInstallationHelper(Current.Services);

            formsInstallHelper.UpdateUmbracoDataForNonFormsInstallation();
            formsInstallHelper.UpdateUmbracoDataForFormsInstallation();

            // update master view for all templates (packager doesn't support this)
            var master = fileService.GetTemplate("master");

            if (master != null)
            {
                var templatesToFind = new[] { "Blog", "Blogpost", "contact", "contentPage", "home", "people", "Person", "Product", "Products" };
                foreach (var template in fileService.GetTemplates().Where(x => templatesToFind.InvariantContains(x.Alias)))
                {
                    // we'll update the master template for all templates that doesn't have one already
                    if (template.Alias != master.Alias && (
                            template.IsMasterTemplate == false && string.IsNullOrWhiteSpace(template.MasterTemplateAlias)))
                    {
                        template.SetMasterTemplate(master);
                        fileService.SaveTemplate(template);
                    }
                }
            }

            // create media folders

            this.CreateMediaItem(mediaService, mediaTypeService, -1, "folder", new Guid("b6f11172-373f-4473-af0f-0b0e5aefd21c"), "Design", string.Empty, true);
            this.CreateMediaItem(mediaService, mediaTypeService, -1, "folder", new Guid("1fd2ecaf-f371-4c00-9306-867fa4585e7a"), "People", string.Empty, true);
            this.CreateMediaItem(mediaService, mediaTypeService, -1, "folder", new Guid("6d5bf746-cb82-45c5-bd15-dd3798209b87"), "Products", string.Empty, true);

            // create media
            IMedia mediaRoot = mediaService.GetById(-1);
            IEnumerable <IMedia> rootMedia = mediaService.GetRootMedia().ToArray();

            try
            {
                foreach (XElement selectNode in xmlData.Elements("mediaItem"))
                {
                    IMedia media1 = mediaRoot;
                    foreach (IMedia media2 in rootMedia)
                    {
                        if (media2.Name.InvariantEquals((string)selectNode.Attribute("folder")))
                        {
                            media1 = media2;
                        }
                    }

                    // add UDI support
                    var key = selectNode.Attribute("key") != null &&
                              string.IsNullOrWhiteSpace((string)selectNode.Attribute("key")) == false
                        ? Guid.Parse((string)selectNode.Attribute("key"))
                        : Guid.Empty;

                    int mediaItem = CreateMediaItem(mediaService, mediaTypeService, media1.Id, "image", key, (string)selectNode.Attribute("name"), (string)selectNode.Attribute("path"), false);
                }
            }
            catch (Exception ex)
            {
                Current.Logger.Error <InstallPackageAction>(ex, "Error during post processing of Starter Kit");
            }

            GridMediaFixup(contentService, mediaService, contentSection, Current.Logger);

            var contentHome = contentService.GetRootContent().FirstOrDefault(x => x.ContentType.Alias == "home");

            if (contentHome != null)
            {
                // publish everything (moved here due to Deploy dependency checking)
                contentService.SaveAndPublishBranch(contentHome, true);
            }
            else
            {
                Current.Logger.Warn <InstallPackageAction>("The installed Home page was not found");
            }

            return(true);
        }
Пример #4
0
        public bool Execute(string packageName, XmlNode xmlData)
        {
            var contentService     = ApplicationContext.Current.Services.ContentService;
            var contentTypeService = ApplicationContext.Current.Services.ContentTypeService;
            var mediaService       = ApplicationContext.Current.Services.MediaService;
            var dataTypeService    = ApplicationContext.Current.Services.DataTypeService;
            var fileService        = ApplicationContext.Current.Services.FileService;

            var formsInstallHelper = new FormsInstallationHelper(ApplicationContext.Current.Services);

            formsInstallHelper.UpdateUmbracoDataForNonFormsInstallation();

            // update master view for all templates (packager doesn't support this)
            var master = fileService.GetTemplate("master");

            if (master != null)
            {
                foreach (var template in fileService.GetTemplates())
                {
                    // we'll update the master template for all templates that doesn't have one already
                    if (template.Alias != master.Alias && (
                            template.IsMasterTemplate == false && string.IsNullOrWhiteSpace(template.MasterTemplateAlias)))
                    {
                        template.SetMasterTemplate(master);
                        fileService.SaveTemplate(template);
                    }
                }
            }

            var contentHome = contentService.GetRootContent().FirstOrDefault(x => x.ContentType.Alias == "home");

            if (contentHome != null)
            {
                // update default design
                contentHome.SetValue("colorTheme", GetPreValueId(dataTypeService, "Home - Color Theme - Radio button list", "earth"));
                contentHome.SetValue("font", GetPreValueId(dataTypeService, "Home - Font - Radio button list", "serif"));
                contentService.Save(contentHome);
            }

            // update default currency pre value
            IContent productContent = contentService.GetById(new Guid("485343b1-d99c-4789-a676-e9b4c98a38d4"));

            if (productContent != null)
            {
                productContent.SetValue("defaultCurrency", GetPreValueId(dataTypeService, "Products - Default Currency - Dropdown list", "€"));
                contentService.Save(productContent);
            }

            // create media folders

            this.CreateMediaItem(mediaService, contentTypeService, -1, "folder", new Guid("b6f11172-373f-4473-af0f-0b0e5aefd21c"), "Design", string.Empty, true);
            this.CreateMediaItem(mediaService, contentTypeService, -1, "folder", new Guid("1fd2ecaf-f371-4c00-9306-867fa4585e7a"), "People", string.Empty, true);
            this.CreateMediaItem(mediaService, contentTypeService, -1, "folder", new Guid("6d5bf746-cb82-45c5-bd15-dd3798209b87"), "Products", string.Empty, true);

            // create media
            IMedia mediaRoot = mediaService.GetById(-1);
            IEnumerable <IMedia> rootMedia = mediaService.GetRootMedia().ToArray();

            try
            {
                if (xmlData.HasChildNodes)
                {
                    foreach (XmlNode selectNode in xmlData.SelectNodes("./mediaItem"))
                    {
                        IMedia media1 = mediaRoot;
                        foreach (IMedia media2 in rootMedia)
                        {
                            if (media2.Name.InvariantEquals(selectNode.Attributes["folder"].Value))
                            {
                                media1 = media2;
                            }
                        }

                        // add UDI support
                        var key = selectNode.Attributes["key"] != null &&
                                  string.IsNullOrWhiteSpace(selectNode.Attributes["key"].Value) == false
                            ? Guid.Parse(selectNode.Attributes["key"].Value)
                            : Guid.Empty;

                        int mediaItem = CreateMediaItem(mediaService, contentTypeService, media1.Id, "image", key, selectNode.Attributes["name"].Value, selectNode.Attributes["path"].Value, false);
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error <InstallPackageAction>("Error during post processing of Starter Kit", ex);
            }

            // we need to update the references for the photo used in the grid in a blog post and about us page
            ReplaceMediaGridValues(new Guid("a4174f42-86fb-47ee-a376-c3366597c5fc"), new Guid("208abda1-63b5-4ba1-bc2a-3d40fe156bb6"), "BlogPost", contentService, mediaService);
            ReplaceMediaGridValues(new Guid("d62f0f1d-e4a9-4093-94ae-4efce18872ee"), new Guid("981014a4-f0b9-46db-aa91-87cf2027f6e0"), "AboutUs", contentService, mediaService);

            if (contentHome != null)
            {
                // publish everything (moved here due to Deploy dependency checking)
                contentService.PublishWithChildrenWithStatus(contentHome, 0, true);
            }

            return(true);
        }