コード例 #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();
     }
 }
コード例 #2
0
        /// <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();
            }
        }
コード例 #3
0
        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);
        }