Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not all recipe steps are being execute when executing a recipe from migration #14881

Closed
MikeAlhayek opened this issue Dec 11, 2023 · 4 comments
Closed
Labels

Comments

@MikeAlhayek
Copy link
Member

MikeAlhayek commented Dec 11, 2023

I have a recipe that is executed from a migration step. The recipe does multiple step. In summary here is what the recipe does

  1. Enables features (important to note OrchardCore.Deployment and OrchardCore.Search.Elasticsearch)
  2. Does other steps like adding layers, contents....
  3. ElasticIndexSettings this step supposed to create an elasticsearch index. This features required both OrchardCore.Deployment and OrchardCore.Search.Elasticsearch to work.
    services.AddTransient<IDeploymentSource, ElasticIndexDeploymentSource>();

But, for some reason the ElasticIndexSettings step never get called. If I make the recipe as a startup or parcial recipe, then everything works. @jtkech any idea why this recipe is failing when invoked from a migration?

Here is the full recipe

{
  "tags": [
    "hidden"
  ],
  "variables": {
    "now": "[js: new Date().toISOString()]"
  },
  "steps": [

    // add features
    {
      "name": "Feature",
      "enable": [
        "OrchardCore.Liquid",
        "OrchardCore.Settings",
        "OrchardCore.Contents",
        "OrchardCore.Title",
        "OrchardCore.Widgets",
        "OrchardCore.ContentFields",
        "OrchardCore.Layers",
        "OrchardCore.Flows",
        "OrchardCore.Taxonomies",
        "OrchardCore.Taxonomies.ContentsAdminList",
        "OrchardCore.Media",
        "OrchardCore.Media.Indexing",
        "OrchardCore.Alias",
        "OrchardCore.Autoroute",
        "OrchardCore.Html",
        "OrchardCore.Search",
        "OrchardCore.Deployment",
        "OrchardCore.Search.Elasticsearch",
        "OrchardCore.ArchiveLater",
        "OrchardCore.PublishLater"
      ]
    },

    // add layers
    {
      "name": "Layers",
      "Layers": [

        // knowledge-base layer
        {
          "Name": "knowledge-base",
          "Rule": null,
          "Description": null,
          "LayerRule": {
            "Conditions": [
              {
                "$type": "OrchardCore.Rules.Models.AnyConditionGroup, OrchardCore.Rules",
                "DisplayText": null,
                "Conditions": [
                  {
                    "$type": "OrchardCore.Rules.Models.UrlCondition, OrchardCore.Rules",
                    "Value": "/knowledge-base/category/",
                    "Operation": {
                      "$type": "OrchardCore.Rules.Models.StringStartsWithOperator, OrchardCore.Rules",
                      "CaseSensitive": false
                    },
                    "Name": "UrlCondition",
                    "ConditionId": "4q7ayd91z69gzv8qzta07rtpm0"
                  },
                  {
                    "$type": "OrchardCore.Rules.Models.ContentTypeCondition, OrchardCore.Rules",
                    "Value": "KnowledgeBaseArticle",
                    "Operation": {
                      "$type": "OrchardCore.Rules.Models.StringEqualsOperator, OrchardCore.Rules",
                      "CaseSensitive": false
                    },
                    "Name": "ContentTypeCondition",
                    "ConditionId": "4bee24643tz0nsgwn948venadz"
                  },
                  {
                    "$type": "OrchardCore.Rules.Models.RoleCondition, OrchardCore.Rules",
                    "Value": "/search",
                    "Operation": {
                      "$type": "OrchardCore.Rules.Models.StringStartsWithOperator, OrchardCore.Rules",
                      "CaseSensitive": false
                    },
                    "Name": "RoleCondition",
                    "ConditionId": "4017ez2rhw7za5fxmcn0kgbw5k"
                  }
                ],
                "Name": "AnyConditionGroup",
                "ConditionId": "49kzd1py7h3vnx29608cmmta5a"
              }
            ],
            "Name": null,
            "ConditionId": "4jm7m68aj30g0rczdne1c4b1cp"
          }
        },

        // knowledge-base-documents layer
        {
          "Name": "knowledge-base-documents",
          "Rule": null,
          "Description": null,
          "LayerRule": {
            "Conditions": [
              {
                "$type": "OrchardCore.Rules.Models.AnyConditionGroup, OrchardCore.Rules",
                "DisplayText": null,
                "Conditions": [
                  {
                    "$type": "OrchardCore.Rules.Models.UrlCondition, OrchardCore.Rules",
                    "Value": "/knowledge-base/category/",
                    "Operation": {
                      "$type": "OrchardCore.Rules.Models.StringStartsWithOperator, OrchardCore.Rules",
                      "CaseSensitive": false
                    },
                    "Name": "UrlCondition",
                    "ConditionId": "4rgsspd31y3m67jk68q0ny57ng"
                  },
                  {
                    "$type": "OrchardCore.Rules.Models.ContentTypeCondition, OrchardCore.Rules",
                    "Value": "KnowledgeBaseArticle",
                    "Operation": {
                      "$type": "OrchardCore.Rules.Models.StringEqualsOperator, OrchardCore.Rules",
                      "CaseSensitive": false
                    },
                    "Name": "ContentTypeCondition",
                    "ConditionId": "4s8zc1yn4qg64xscsdth3c6jcf"
                  }
                ],
                "Name": "AnyConditionGroup",
                "ConditionId": "4jd36bg0n6p2htsvrw5vgf6cdt"
              }
            ],
            "Name": null,
            "ConditionId": "4ywdwwjm06x2t2t0yr332en2wd"
          }
        },

        // Home Page Layer
        {
          "Name": "home-page",
          "Description": "A layer to make content visible on home page.",
          "LayerRule": {
            "Conditions": [
              {
                "$type": "OrchardCore.Rules.Models.HomepageCondition, OrchardCore.Rules",
                "Value": true,
                "Name": "HomepageCondition",
                "ConditionId": "[js: uuid()]"
              }
            ],
            "ConditionId": "[js: uuid()]"
          }
        },

        // Secure Home Page Layer
        {
          "Name": "secure-home-page",
          "Description": "A layer to make content visible on home page when the user is authenticated.",
          "LayerRule": {
            "ConditionId": "[js: uuid()]",
            "Conditions": [
              {
                "$type": "OrchardCore.Rules.Models.IsAuthenticatedCondition, OrchardCore.Rules",
                "Name": "IsAuthenticatedCondition",
                "ConditionId": "[js: uuid()]"
              },
              {
                "$type": "OrchardCore.Rules.Models.HomepageCondition, OrchardCore.Rules",
                "Value": true,
                "Name": "HomepageCondition",
                "ConditionId": "[js: uuid()]"
              }
            ]
          }
        },

        //Anonymous Home Page Layer
        {
          "Name": "anonymous-home-page",
          "Description": "A widget layer for unauthenticated users.",
          "LayerRule": {
            "Conditions": [
              {
                "$type": "OrchardCore.Rules.Models.HomepageCondition, OrchardCore.Rules",
                "Value": true,
                "Name": "HomepageCondition",
                "ConditionId": "[js: uuid()]"
              },
              {
                "$type": "OrchardCore.Rules.Models.IsAnonymousCondition, OrchardCore.Rules",
                "Name": "IsAnonymousCondition",
                "ConditionId": "[js: uuid()]"
              }
            ],
            "ConditionId": "[js: uuid()]"
          }
        }
      ]
    },


    // add admin menu
    {
      "name": "AdminMenu",
      "data": [
        {
          "Id": "ebb5bfcdab424e83b6dff20144a66dc4",
          "Name": "Admin Menu",
          "Enabled": true,
          "MenuItems": [
            {
              "$type": "OrchardCore.Contents.AdminNodes.ContentTypesAdminNode, OrchardCore.Contents",
              "ShowAll": false,
              "IconClass": null,
              "ContentTypes": [
                {
                  "ContentTypeId": "KnowledgeBaseArticle",
                  "IconClass": "fas fa-newspaper"
                },
                {
                  "ContentTypeId": "KnowledgeBaseTutorial",
                  "IconClass": "fab fa-youtube"
                },
                {
                  "ContentTypeId": "SitePage",
                  "IconClass": "fab fa-internet-explorer"
                }
              ],
              "UniqueId": "9e07bfcfb0b947ba9b8f262045b24ad1",
              "Enabled": true,
              "Text": null,
              "Id": null,
              "Href": null,
              "Url": null,
              "Position": null,
              "Priority": 0,
              "LinkToFirstChild": true,
              "LocalNav": false,
              "Culture": null,
              "Items": [],
              "Classes": []
            }
          ]
        },
        {
          "Id": "3c37a893ad0a47d5bdb202c7f6801ee0",
          "Name": "Knowledge Base Menu",
          "Enabled": true,
          "MenuItems": [
            {
              "$type": "OrchardCore.Contents.AdminNodes.ContentTypesAdminNode, OrchardCore.Contents",
              "ShowAll": false,
              "IconClass": null,
              "ContentTypes": [
                {
                  "ContentTypeId": "KnowledgeBaseArticle",
                  "IconClass": null
                }
              ],
              "UniqueId": "3fa5de65cd34478888f57dabedb5f5a8",
              "Enabled": true,
              "Text": null,
              "Id": null,
              "Href": null,
              "Url": null,
              "Position": null,
              "Priority": 0,
              "LinkToFirstChild": true,
              "LocalNav": false,
              "Culture": null,
              "Items": [],
              "Classes": []
            }
          ]
        }
      ]
    },

    // add content definitions
    {
      "name": "ContentDefinition",
      "ContentTypes": [

        // add KnowledgeBaseCategoryTerm
        {
          "Name": "KnowledgeBaseCategoryTerm",
          "DisplayName": "Knowledge Base Category Term",
          "Settings": {
            "ContentTypeSettings": {},
            "FullTextAspectSettings": {}
          },
          "ContentTypePartDefinitionRecords": [
            {
              "PartName": "TitlePart",
              "Name": "TitlePart",
              "Settings": {
                "TitlePartSettings": {
                  "Options": 3
                },
                "ContentTypePartSettings": {
                  "Position": "0"
                }
              }
            },
            {
              "PartName": "ThumbnailPart",
              "Name": "ThumbnailPart",
              "Settings": {
                "ContentTypePartSettings": {
                  "Position": "1"
                }
              }
            },
            {
              "PartName": "FeaturedPart",
              "Name": "FeaturedPart",
              "Settings": {
                "ContentTypePartSettings": {
                  "Position": "2"
                }
              }
            }
          ]
        },

        // add KnowledgeBaseArticle
        {
          "Name": "KnowledgeBaseArticle",
          "DisplayName": "Knowledge Base Article",
          "Settings": {
            "ContentTypeSettings": {
              "Creatable": true,
              "Listable": true,
              "Draftable": true,
              "Stereotype": "KnowledgeBaseDocument",
              "Securable": true
            },
            "FullTextAspectSettings": {}
          },
          "ContentTypePartDefinitionRecords": [
            {
              "PartName": "TitlePart",
              "Name": "TitlePart",
              "Settings": {
                "TitlePartSettings": {
                  "Options": 3
                },
                "ContentTypePartSettings": {
                  "Position": "1"
                }
              }
            },
            {
              "PartName": "AttachmentPart",
              "Name": "AttachmentPart",
              "Settings": {
                "ContentTypePartSettings": {
                  "Position": "2"
                },
                "ElasticContentIndexSettings": {
                  "Included": true
                }
              }
            },
            {
              "PartName": "KnowledgeBaseTutorialPart",
              "Name": "KnowledgeBaseTutorialPart",
              "Settings": {
                "ContentTypePartSettings": {
                  "Position": "3"
                }
              }
            },
            {
              "PartName": "HtmlBodyPart",
              "Name": "HtmlBodyPart",
              "Settings": {
                "ContentTypePartSettings": {
                  "DisplayName": "Details",
                  "Position": "4",
                  "Editor": "Trumbowyg"
                },
                "HtmlBodyPartSettings": {},
                "HtmlBodyPartTrumbowygEditorSettings": {
                  "Options": "{\r\n    autogrow: true,\r\n    btns: [\r\n        [\"viewHTML\"],\r\n        [\"undo\", \"redo\"],\r\n        [\"formatting\"],\r\n        [\"strong\", \"em\", \"del\"],\r\n        [\"foreColor\", \"backColor\"],\r\n        [\"superscript\", \"subscript\"],\r\n        [\"link\"],\r\n        [\"insertShortcode\"],\r\n        [\"image\"],\r\n        [\"align\"],\r\n        [\"fontsize\"],\r\n      \t[\"fontfamily\"],\r\n        [\"unorderedList\", \"orderedList\"],\r\n        [\"horizontalRule\"],\r\n        [\"removeformat\"],\r\n        ['table'],\r\n        [\"fullscreen\"]\r\n    ],\r\n    btnsDef: {\r\n        align: {\r\n            dropdown: [\"justifyLeft\", \"justifyCenter\", \"justifyRight\", \"justifyFull\"],\r\n            ico: \"justifyLeft\"\r\n        },\r\n        image: {\r\n            dropdown: [\"insertImage\", \"base64\", \"noembed\"],\r\n            ico: \"insertImage\"\r\n        }\r\n    }\r\n}"
                },
                "ElasticContentIndexSettings": {}
              }
            },
            {
              "PartName": "KnowledgeBaseArticlePart",
              "Name": "KnowledgeBaseArticlePart",
              "Settings": {
                "ContentTypePartSettings": {
                  "Position": "5"
                }
              }
            },
            {
              "PartName": "RelatedContentPart",
              "Name": "RelatedContentPart",
              "Settings": {
                "ContentTypePartSettings": {},
                "RelatedContentPartSettings": {
                  "IndexName": "knowledge_base",
                  "ProviderName": "Elasticsearch",
                  "TotalVisible": 10,
                  "MaxQueryTerms": 25,
                  "MinTermFrequency": 2,
                  "MaxDocumentFrequency": 2147483647,
                  "MinDocumentFrequency": 5
                },
                "ElasticContentIndexSettings": {}
              }
            },
            {
              "PartName": "PublishLaterPart",
              "Name": "PublishLaterPart",
              "Settings": {
                "ContentTypePartSettings": {
                  "Position": "10"
                }
              }
            },
            {
              "PartName": "ArchiveLaterPart",
              "Name": "ArchiveLaterPart",
              "Settings": {
                "ContentTypePartSettings": {
                  "Position": "11"
                }
              }
            }
          ]
        },

        // add HtmlDashboardWidget
        {
          "Name": "HtmlDashboardWidget",
          "DisplayName": "Html Dashboard Widget",
          "Settings": {
            "ContentTypeSettings": {
              "Draftable": true,
              "Versionable": true,
              "Stereotype": "DashboardWidget",
              "Securable": true
            },
            "FullTextAspectSettings": {}
          },
          "ContentTypePartDefinitionRecords": [
            {
              "PartName": "HtmlDashboardWidget",
              "Name": "HtmlDashboardWidget",
              "Settings": {
                "ContentTypePartSettings": {
                  "Position": "3"
                }
              }
            },
            {
              "PartName": "DashboardPart",
              "Name": "DashboardPart",
              "Settings": {
                "ContentTypePartSettings": {
                  "Position": "2"
                }
              }
            },
            {
              "PartName": "HtmlBodyPart",
              "Name": "HtmlBodyPart",
              "Settings": {
                "ContentTypePartSettings": {
                  "Position": "1",
                  "Editor": "Trumbowyg"
                },
                "HtmlBodyPartTrumbowygEditorSettings": {
                  "Options": "{\r\n    autogrow: true,\r\n    btns: [\r\n        [\"viewHTML\"],\r\n        [\"undo\", \"redo\"],\r\n        [\"formatting\"],\r\n        [\"strong\", \"em\", \"del\"],\r\n        [\"foreColor\", \"backColor\"],\r\n        [\"superscript\", \"subscript\"],\r\n        [\"link\"],\r\n        [\"insertShortcode\"],\r\n        [\"image\"],\r\n        [\"align\"],\r\n        [\"fontsize\"],\r\n      \t[\"fontfamily\"],\r\n        [\"unorderedList\", \"orderedList\"],\r\n        [\"horizontalRule\"],\r\n        [\"removeformat\"],\r\n        ['table'],\r\n        [\"fullscreen\"]\r\n    ],\r\n    btnsDef: {\r\n        align: {\r\n            dropdown: [\"justifyLeft\", \"justifyCenter\", \"justifyRight\", \"justifyFull\"],\r\n            ico: \"justifyLeft\"\r\n        },\r\n        image: {\r\n            dropdown: [\"insertImage\", \"base64\", \"noembed\"],\r\n            ico: \"insertImage\"\r\n        }\r\n    }\r\n}"
                },
                "GraphQLContentTypePartSettings": {},
                "HtmlBodyPartSettings": {}
              }
            },
            {
              "PartName": "TitlePart",
              "Name": "TitlePart",
              "Settings": {
                "ContentTypePartSettings": {
                  "Position": "0"
                }
              }
            }
          ]
        },

        // add HtmlWidget
        {
          "Name": "HtmlWidget",
          "DisplayName": "Html Widget",
          "Settings": {
            "ContentTypeSettings": {
              "Stereotype": "Widget"
            },
            "FullTextAspectSettings": {}
          },
          "ContentTypePartDefinitionRecords": [
            {
              "PartName": "HtmlWidget",
              "Name": "HtmlWidget",
              "Settings": {
                "ContentTypePartSettings": {
                  "Position": "0"
                }
              }
            },
            {
              "PartName": "HtmlBodyPart",
              "Name": "HtmlBodyPart",
              "Settings": {
                "ContentTypePartSettings": {
                  "Position": "1"
                },
                "HtmlBodyPartSettings": {
                  "SanitizeHtml": false
                },
                "ElasticContentIndexSettings": {}
              }
            }
          ]
        },

        // add WysiwygWidget
        {
          "Name": "WysiwygWidget",
          "DisplayName": "Wysiwyg Widget",
          "Settings": {
            "ContentTypeSettings": {
              "Stereotype": "Widget"
            },
            "FullTextAspectSettings": {}
          },
          "ContentTypePartDefinitionRecords": [
            {
              "PartName": "WysiwygWidget",
              "Name": "WysiwygWidget",
              "Settings": {
                "ContentTypePartSettings": {
                  "Position": "0"
                }
              }
            },
            {
              "PartName": "HtmlBodyPart",
              "Name": "HtmlBodyPart",
              "Settings": {
                "ContentTypePartSettings": {
                  "Position": "1",
                  "Editor": "Trumbowyg"
                },
                "HtmlBodyPartTrumbowygEditorSettings": {
                  "Options": "{\r\n    autogrow: true,\r\n    btns: [\r\n        [\"viewHTML\"],\r\n        [\"undo\", \"redo\"],\r\n        [\"formatting\"],\r\n        [\"strong\", \"em\", \"del\"],\r\n        [\"foreColor\", \"backColor\"],\r\n        [\"superscript\", \"subscript\"],\r\n        [\"link\"],\r\n        [\"insertShortcode\"],\r\n        [\"image\"],\r\n        [\"align\"],\r\n        [\"fontsize\"],\r\n      \t[\"fontfamily\"],\r\n        [\"unorderedList\", \"orderedList\"],\r\n        [\"horizontalRule\"],\r\n        [\"removeformat\"],\r\n        ['table'],\r\n        [\"fullscreen\"]\r\n    ],\r\n    btnsDef: {\r\n        align: {\r\n            dropdown: [\"justifyLeft\", \"justifyCenter\", \"justifyRight\", \"justifyFull\"],\r\n            ico: \"justifyLeft\"\r\n        },\r\n        image: {\r\n            dropdown: [\"insertImage\", \"base64\", \"noembed\"],\r\n            ico: \"insertImage\"\r\n        }\r\n    }\r\n}"
                },
                "HtmlBodyPartSettings": {},
                "ElasticContentIndexSettings": {}
              }
            }
          ]
        }
      ],
      "ContentParts": [

        // Add 'AttachmentPart'.
        {
          "Name": "AttachmentPart",
          "Settings": {
            "ContentPartSettings": {
              "Attachable": true,
              "DisplayName": "Attachment Part",
              "Description": "Provides a way to optionally add attachments and index them."
            }
          },
          "ContentPartFieldDefinitionRecords": [
            {
              "FieldName": "MediaField",
              "Name": "Files",
              "Settings": {
                "ContentPartFieldSettings": {
                  "DisplayName": "Files",
                  "Position": "0"
                },
                "MediaFieldSettings": {},
                "ElasticContentIndexSettings": {
                  "Included": true
                }
              }
            }
          ]
        },

        // Add 'RelatedContentPart'.
        {
          "Name": "RelatedContentPart",
          "Settings": {
            "ContentPartSettings": {
              "Attachable": true,
              "DisplayName": "Related Content Part",
              "Description": "Provides content items that are related to the current content item. This requires an active search provided"
            }
          },
          "ContentPartFieldDefinitionRecords": []
        },

        // Add 'ThumbnailPart'.
        {
          "Name": "ThumbnailPart",
          "Settings": {
            "ContentPartSettings": {
              "Attachable": true
            }
          },
          "ContentPartFieldDefinitionRecords": [
            {
              "FieldName": "MediaField",
              "Name": "Image",
              "Settings": {
                "ContentPartFieldSettings": {
                  "DisplayName": "Image"
                },
                "MediaFieldSettings": {
                  "Multiple": false,
                  "AllowAnchors": true
                }
              }
            }
          ]
        },

        // Add 'FeaturedPart'.
        {
          "Name": "FeaturedPart",
          "Settings": {
            "ContentPartSettings": {
              "Attachable": true
            }
          },
          "ContentPartFieldDefinitionRecords": [
            {
              "FieldName": "BooleanField",
              "Name": "Featured",
              "Settings": {
                "ContentPartFieldSettings": {
                  "DisplayName": "Featured?"
                }
              }
            }
          ]
        },

        // Add 'KnowledgeBaseArticlePart'.
        {
          "Name": "KnowledgeBaseArticlePart",
          "Settings": {
            "ContentPartSettings": {
              "Attachable": true,
              "DisplayName": "Knowledge Base Article Part"
            }
          },
          "ContentPartFieldDefinitionRecords": [
            {
              "FieldName": "TaxonomyField",
              "Name": "Taxonomy",
              "Settings": {
                "ContentPartFieldSettings": {
                  "DisplayName": "Categories"
                },
                "TaxonomyFieldSettings": {
                  "Required": true,
                  "TaxonomyContentItemId": "4y02gnr8b3evn1fp2j0b2zxw42"
                },
                "LuceneContentIndexSettings": {}
              }
            }
          ]
        },

        // add KnowledgeBaseTutorialPart
        {
          "Name": "KnowledgeBaseTutorialPart",
          "Settings": {
            "ContentPartSettings": {
              "Attachable": true,
              "DisplayName": "Knowledge Base Tutorial Part"
            }
          },
          "ContentPartFieldDefinitionRecords": []
        }
      ]
    },

    // add content
    {
      "name": "content",
      "data": [

        // Knowledge Base Article Categories
        {
          "ContentItemId": "4y02gnr8b3evn1fp2j0b2zxw42",
          "ContentItemVersionId": "4eafft7q6qmdv7595gkza7ynmh",
          "ContentType": "Taxonomy",
          "DisplayText": "Knowledge Base Article Categories",
          "Latest": true,
          "Published": true,
          "ModifiedUtc": "[js: variables('now')]",
          "PublishedUtc": "[js: variables('now')]",
          "CreatedUtc": "[js: variables('now')]",
          "Owner": "[js: parameters('AdminUserId')]",
          "Author": "[js: parameters('AdminUsername')]",
          "TitlePart": {
            "Title": "Knowledge Base Article Categories"
          },
          "TaxonomyPart": {
            "TermContentType": "KnowledgeBaseCategoryTerm",
            "Terms": [
              {
                "ContentItemId": "4s2xx512c7vdb0306c7f8w7awa",
                "ContentItemVersionId": null,
                "ContentType": "KnowledgeBaseCategoryTerm",
                "DisplayText": "General",
                "Latest": false,
                "Published": false,
                "ModifiedUtc": "[js: variables('now')]",
                "PublishedUtc": "[js: variables('now')]",
                "CreatedUtc": "[js: variables('now')]",
                "Owner": "[js: parameters('AdminUserId')]",
                "Author": "[js: parameters('AdminUsername')]",
                "TitlePart": {
                  "Title": "General"
                },
                "ThumbnailPart": {
                  "Image": {
                    "Paths": [],
                    "MediaTexts": [],
                    "Anchors": []
                  }
                },
                "FeaturedPart": {
                  "Featured": {
                    "Value": false
                  }
                },
                "TermPart": {
                  "TaxonomyContentItemId": "4y02gnr8b3evn1fp2j0b2zxw42"
                },
                "@WeldedPartSettings": {
                  "TermPart": {}
                }
              }
            ]
          },
          "AutoroutePart": {
            "Path": "knowledge-base/category",
            "SetHomepage": false,
            "Disabled": false,
            "RouteContainedItems": true,
            "Absolute": false
          },
          "AliasPart": {
            "Alias": "knowledge-base-categories"
          }
        },

        // Knowledge Base Category List
        {
          "ContentItemId": "4xaqarjye7t6xz78xbzaw8dg43",
          "ContentItemVersionId": "43j4x2cp4g1n223r53qft2wwdd",
          "ContentType": "ListTaxonomyTerms",
          "DisplayText": "Knowledge Base Category List",
          "Latest": true,
          "Published": true,
          "ModifiedUtc": "[js: variables('now')]",
          "PublishedUtc": "[js: variables('now')]",
          "CreatedUtc": "[js: variables('now')]",
          "Owner": "[js: parameters('AdminUserId')]",
          "Author": "[js: parameters('AdminUsername')]",
          "TaxonomyTermList": {
            "TaxonomyContentItemId": "4y02gnr8b3evn1fp2j0b2zxw42"
          },
          "LayerMetadata": {
            "RenderTitle": false,
            "Position": 1.0,
            "Zone": "Start",
            "Layer": "knowledge-base"
          }
        },

        // Search form for Knowledge Form
        {
          "ContentItemId": "4zev0brp6b8ej4g5c5xcs0cwxa",
          "ContentItemVersionId": "44sjq2hzhsdxp7837wqgvdycng",
          "ContentType": "SearchForm",
          "DisplayText": "Search form for Knowledge Form",
          "Latest": true,
          "Published": true,
          "ModifiedUtc": "[js: variables('now')]",
          "PublishedUtc": "[js: variables('now')]",
          "CreatedUtc": "[js: variables('now')]",
          "Owner": "[js: parameters('AdminUserId')]",
          "Author": "[js: parameters('AdminUsername')]",
          "SearchFormPart": {
            "IndexName": "knowledge_base",
            "Placeholder": "Search the Help library"
          },
          "LayerMetadata": {
            "RenderTitle": false,
            "Position": 1.0,
            "Zone": "Middle",
            "Layer": "knowledge-base-documents"
          }
        },

        // Knowledge Base Article Categories
        {
          "ContentItemId": "4y02gnr8b3evn1fp2j0b2zxw42",
          "ContentItemVersionId": "4eafft7q6qmdv7595gkza7ynmh",
          "ContentType": "Taxonomy",
          "DisplayText": "Knowledge Base Article Categories",
          "Latest": false,
          "Published": true,
          "ModifiedUtc": "[js: variables('now')]",
          "PublishedUtc": "[js: variables('now')]",
          "CreatedUtc": "[js: variables('now')]",
          "Owner": "[js: parameters('AdminUserId')]",
          "Author": "[js: parameters('AdminUsername')]",
          "TitlePart": {
            "Title": "Knowledge Base Article Categories"
          },
          "TaxonomyPart": {
            "TermContentType": "KnowledgeBaseCategoryTerm",
            "Terms": [
              {
                "ContentItemId": "4s2xx512c7vdb0306c7f8w7awa",
                "ContentItemVersionId": null,
                "ContentType": "KnowledgeBaseCategoryTerm",
                "DisplayText": "General",
                "Latest": false,
                "Published": false,
                "ModifiedUtc": "[js: variables('now')]",
                "PublishedUtc": "[js: variables('now')]",
                "CreatedUtc": "[js: variables('now')]",
                "Owner": "[js: parameters('AdminUserId')]",
                "Author": "[js: parameters('AdminUsername')]",
                "TitlePart": {
                  "Title": "General"
                },
                "ThumbnailPart": {
                  "Image": {
                    "Paths": [],
                    "MediaTexts": [],
                    "Anchors": []
                  }
                },
                "FeaturedPart": {
                  "Featured": {
                    "Value": false
                  }
                },
                "TermPart": {
                  "TaxonomyContentItemId": "4y02gnr8b3evn1fp2j0b2zxw42"
                },
                "@WeldedPartSettings": {
                  "TermPart": {}
                }
              }
            ]
          },
          "AutoroutePart": {
            "Path": "knowledge-base/category",
            "SetHomepage": false,
            "Disabled": false,
            "RouteContainedItems": true,
            "Absolute": false
          },
          "AliasPart": {
            "Alias": "knowledge-base-categories"
          }
        },

        // TopViewedContentsDashboardWidget
        {
          "ContentItemId": "4qb3qcx7k7zhyyj5kpvvywqpxw",
          "ContentItemVersionId": "4avk1r5rrs2615xx106889tb5n",
          "ContentType": "TopViewedContentsDashboardWidget",
          "DisplayText": null,
          "Latest": true,
          "Published": true,
          "ModifiedUtc": "[js: variables('now')]",
          "PublishedUtc": "[js: variables('now')]",
          "CreatedUtc": "[js: variables('now')]",
          "Owner": "[js: parameters('AdminUserId')]",
          "Author": "[js: parameters('AdminUsername')]",
          "DashboardPart": {
            "Position": 0.0,
            "Width": 2.0,
            "Height": 2.0
          },
          "TopViewedContentsPart": {
            "TotalVisible": 10,
            "TotalMinitesToCache": 30
          }
        },

        // TopSearchedContentItemsDashboardWidget
        {
          "ContentItemId": "4n5qqz17mg2c77m3n6nkc0bfmm",
          "ContentItemVersionId": "4be00y8w5r68q1mr67qyj2zjds",
          "ContentType": "TopSearchedContentItemsDashboardWidget",
          "DisplayText": null,
          "Latest": true,
          "Published": true,
          "ModifiedUtc": "[js: variables('now')]",
          "PublishedUtc": "[js: variables('now')]",
          "CreatedUtc": "[js: variables('now')]",
          "Owner": "[js: parameters('AdminUserId')]",
          "Author": "[js: parameters('AdminUsername')]",
          "DashboardPart": {
            "Position": 1.0,
            "Width": 2.0,
            "Height": 2.0
          },
          "TopSearchedContentPart": {
            "IndexName": "knowledge_base",
            "ProviderName": "Elasticsearch",
            "TotalVisible": 10,
            "TotalMinitesToCache": 30
          }
        },

        // TopSearchedKeywordsDashboardWidget
        {
          "ContentItemId": "47xw8bj7hvwvmt658mh0ywdcnv",
          "ContentItemVersionId": "4gdye5erggtyv567mx0yknrjdp",
          "ContentType": "TopSearchedKeywordsDashboardWidget",
          "DisplayText": null,
          "Latest": true,
          "Published": true,
          "ModifiedUtc": "[js: variables('now')]",
          "PublishedUtc": "[js: variables('now')]",
          "CreatedUtc": "[js: variables('now')]",
          "Owner": "[js: parameters('AdminUserId')]",
          "Author": "[js: parameters('AdminUsername')]",
          "DashboardPart": {
            "Position": 2.0,
            "Width": 2.0,
            "Height": 2.0
          },
          "TopSearchedKeywordsPart": {
            "IndexName": "knowledge_base",
            "ProviderName": "Elasticsearch",
            "TotalVisible": 10,
            "TotalMinitesToCache": 30
          }
        },

        // StatsSummaryContentDashboardWidget
        {
          "ContentItemId": "4az6bp4yk1w261g5fqzsj5crd7",
          "ContentItemVersionId": "4v2mfwf4k284z5mgg3ftvtq2dj",
          "ContentType": "StatsSummaryContentDashboardWidget",
          "DisplayText": null,
          "Latest": true,
          "Published": true,
          "ModifiedUtc": "[js: variables('now')]",
          "PublishedUtc": "[js: variables('now')]",
          "CreatedUtc": "[js: variables('now')]",
          "Owner": "[js: parameters('AdminUserId')]",
          "Author": "[js: parameters('AdminUsername')]",
          "DashboardPart": {
            "Position": 4.0,
            "Width": 3.0,
            "Height": 1.0
          },
          "StatsSummaryContentPart": {
            "IndexName": "knowledge_base",
            "ProviderName": "Elasticsearch",
            "TotalMinitesToCache": 30
          }
        }
      ]
    },

    // add elasticsearch settings
    {
      "name": "ElasticIndexSettings",
      "Indices": [
        {
          "knowledge_base": {
            "AnalyzerName": "knowledgebase_analyzer",
            "IndexLatest": false,
            "IndexedContentTypes": [
              "KnowledgeBaseArticle"
            ],
            "Culture": "any",
            "StoreSourceData": false
          }
        }
      ]
    },

    // add site settings
    {
      "name": "Settings",
      "TaxonomyContentsAdminListSettings": {
        "TaxonomyContentItemIds": [
          "4y02gnr8b3evn1fp2j0b2zxw42"
        ]
      },
      "ContentViewingOptions": {
        "ContentTypes": [
          "KnowledgeBaseArticle"
        ]
      },
      "ElasticSettings": {
        "SearchIndex": "knowledge_base",
        "DefaultSearchFields": [
          "Content.ContentItem.FullText",
          "AttachmentPart.Files.FileText"
        ],
        "SearchType": "custom",
        "DefaultQuery": "{\r\n  \"query\": {\r\n    \"multi_match\": {\r\n      \"fields\": [\r\n        \"Content.ContentItem.FullText\",\r\n        \"AttachmentPart.Files.FileText\"\r\n      ],\r\n      \"query\": \"{{ term }}\",\r\n      \"fuzziness\": \"AUTO\",\r\n      \"analyzer\": \"knowledgebase_analyzer\"\r\n    }\r\n  }\r\n}"
      }
    }
  ]
}

That recipe existis in a file called knowlegde-base.recipe.json and is located inside the Migrations folder. Here it my migration step the invokes it.

public class KnowledgeBaseMigrations : DataMigration
{
    public int Create()
    {
        ShellScope.AddDeferredTask(async scope =>
        {
            var recipeMigrator = scope.ServiceProvider.GetService<IRecipeMigrator>();

            // Enable featurs in a seperate step before the knowledge-base recipe to ensure we can create Elasticsearch indces.
            // await recipeMigrator.ExecuteAsync("knowlegde-base-features.recipe.json", this);

            await recipeMigrator.ExecuteAsync("knowlegde-base.recipe.json", this);
        });

        return 1;
    }
}
@jtkech
Copy link
Member

jtkech commented Dec 11, 2023

  • Originally migrations were used for database migrations, they run while activating a shell and for some reasons the whole runs in the same child shell scope, not a shell scope per migration.

  • Then, I don't remember why, we introduced migration recipes, in that case, to follow the above constraint, all recipe steps run in the same child shell scope, not a shell scope per recipe step.

var shellScope = recipeStep.RecipeDescriptor.RequireNewScope
? await _shellHost.GetScopeAsync(_shellSettings)
: ShellScope.Current;

  • So not all recipe steps can be used through a migration recipe. For example when a Feature step is run through a regular recipe it enables features in its own shell scope, then when a next step runs in a new shell scope, the shell is re-activated to execute the migrations of the newly enabled features.

    But if run from a migration recipe all recipe steps run in the same child shell scope and we can't expect that the shell can be activated while it is activating by the parent shell scope.

    That's why we specify activateShell: false for the child shell scope used to activate the shell, so that it will not try to activate the shell while it is activating by the parent shell scope.

await new ShellScope(ShellContext).UsingAsync(async scope =>
{
var tenantEvents = scope.ServiceProvider.GetServices<IModularTenantEvents>();
foreach (var tenantEvent in tenantEvents)
{
await tenantEvent.ActivatingAsync();
}
foreach (var tenantEvent in tenantEvents.Reverse())
{
await tenantEvent.ActivatedAsync();
}
}, activateShell: false);

@MikeAlhayek
Copy link
Member Author

@jtkech thank you!

I also tried this and it did not work (note how I run the features first (which should be it's own scope). The the second recipe would have used the newly enabled features.

public class KnowledgeBaseMigrations : DataMigration
{
    public int Create()
    {
        ShellScope.AddDeferredTask(async scope =>
        {
            var recipeMigrator = scope.ServiceProvider.GetService<IRecipeMigrator>();

            await recipeMigrator.ExecuteAsync("knowlegde-base-features.recipe.json", this);

            await recipeMigrator.ExecuteAsync("knowlegde-base.recipe.json", this);
        });

        return 1;
    }
}

@jtkech
Copy link
Member

jtkech commented Dec 12, 2023

Yes, but as long as you are using the recipe migrator, because of the following all recipes and their steps will run in the same shell scope.

@MikeAlhayek
Copy link
Member Author

Thank you @jtkech

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants