public int Create()
        {
            foreach (var contentTypeName in _contentTypesToUpdate)
            {
                var typeDef = ContentDefinitionManager.GetTypeDefinition(contentTypeName);
                if (typeDef == null)
                {
                    continue;
                }

                var localizationPart = typeDef.Parts.Where(p => p.PartDefinition.Name == LocalizationPartTypeName).FirstOrDefault();
                if (localizationPart == null)
                {
                    ContentDefinitionManager.AlterTypeDefinition(contentTypeName, c => c.WithPart(LocalizationPartTypeName));
                    typeDef = ContentDefinitionManager.GetTypeDefinition(contentTypeName);
                }

                var autoroutePart = typeDef.Parts.Where(p => p.PartDefinition.Name == AutoroutePartTypeName).FirstOrDefault();
                if (autoroutePart == null)
                {
                    continue;
                }

                var autoroutePartSettings = LoadAutorouteSettings(autoroutePart.Settings);

                var routePattern = autoroutePartSettings.Patterns.Where(p => p.Name == LocalizedTitleName).FirstOrDefault();
                if (routePattern == null)
                {
                    var patterns  = autoroutePartSettings.Patterns.ToList();
                    var baseRoute = patterns.FirstOrDefault();
                    routePattern = new RoutePattern
                    {
                        Name    = LocalizedTitleName,
                        Pattern = baseRoute != null?string.Format("{{Content.Culture}}/{0}", baseRoute.Pattern) : "{Content.Culture}/{Content.Slug}",
                                      Description = baseRoute != null?string.Format("en-us/{0}", baseRoute.Description) : "en-us/my-content-item"
                    };
                    patterns.Add(routePattern);
                    autoroutePartSettings.Patterns = patterns;
                }
                var defaultIndex = autoroutePartSettings.Patterns.IndexOf(routePattern);
                autoroutePartSettings.DefaultPatternIndex = defaultIndex.ToString();

                SetAutorouteSettings(autoroutePartSettings, autoroutePart.Settings);

                ContentDefinitionManager.StoreTypeDefinition(typeDef);
            }
            return(4);
        }
Beispiel #2
0
        public int UpdateFrom1()
        {
            // if the default layout data was unchanged, fix it with the new default

            var formLayoutPart = ContentDefinitionManager
                                 .GetTypeDefinition("Form")
                                 .Parts
                                 .FirstOrDefault(x => x.PartDefinition.Name == "LayoutPart");

            if (formLayoutPart != null &&
                formLayoutPart.Settings["LayoutTypePartSettings.DefaultLayoutData"] != null)
            {
                var layout = formLayoutPart.Settings["LayoutTypePartSettings.DefaultLayoutData"];

                if (GetMD5(layout) == _oldLayoutHash)
                {
                    ContentDefinitionManager.AlterTypeDefinition("Form", type => type
                                                                 .WithPart("LayoutPart", p => p
                                                                           .WithSetting("LayoutTypePartSettings.DefaultLayoutData", DefaultFormLayoutData))
                                                                 );
                }
            }

            var formWidgetLayoutPart = ContentDefinitionManager
                                       .GetTypeDefinition("FormWidget")
                                       .Parts
                                       .FirstOrDefault(x => x.PartDefinition.Name == "LayoutPart");

            if (formWidgetLayoutPart != null &&
                formWidgetLayoutPart.Settings["LayoutTypePartSettings.DefaultLayoutData"] != null)
            {
                var layout = formWidgetLayoutPart.Settings["LayoutTypePartSettings.DefaultLayoutData"];

                if (GetMD5(layout) == _oldLayoutHash)
                {
                    ContentDefinitionManager.AlterTypeDefinition("FormWidget", type => type
                                                                 .WithPart("LayoutPart", p => p
                                                                           .WithSetting("LayoutTypePartSettings.DefaultLayoutData", DefaultFormLayoutData))
                                                                 );
                }
            }

            return(2);
        }
Beispiel #3
0
        public SyncNameProviderHelperTests()
        {
            SyncNameProviderCSharpScriptGlobals = A.Fake <ISyncNameProviderCSharpScriptGlobals>();

            ContentDefinitionManager = A.Fake <IContentDefinitionManager>();
            ContentTypeDefinition    = new ContentTypeDefinition("name", "displayName",
                                                                 new []
            {
                new ContentTypePartDefinition(nameof(GraphSyncPart), new ContentPartDefinition(nameof(GraphSyncPart)), null)
            },
                                                                 new JObject());
            A.CallTo(() => ContentDefinitionManager.GetTypeDefinition(_contentType)).Returns(ContentTypeDefinition);

            SuperpositionContentItemVersion = A.Fake <ISuperpositionContentItemVersion>();

            SyncNameProvider = new SyncNameProvider(
                SyncNameProviderCSharpScriptGlobals,
                ContentDefinitionManager,
                SuperpositionContentItemVersion);
        }