2

I'm planning to rename one of my custom content types, so that I can free up its name for a new Orchard module I am working on. I'm hoping to use Schema.ExecuteSql in a migration class as suggested by this SO answer, but I want to make sure I know all of the updates I will need to do.

So far, I understand that I need to update fields in the following tables:

  • Orchard_Framework_ContentTypeRecord
  • Settings_ContentTypeDefinitionRecord
  • Settings_ContentPartDefinitionRecord

Also, here is my general plan for the update SQL I will need to run:

DECLARE @From VARCHAR(50) = 'OriginalName'
DECLARE @To VARCHAR(50) = 'NewName'

BEGIN TRANSACTION

BEGIN TRY

    UPDATE [Current_Orchard_Framework_ContentTypeRecord]
    SET [Name] = @To
    WHERE [Name] = @From

    UPDATE [Current_Settings_ContentTypeDefinitionRecord]
    SET [Name] = @To, [DisplayName] = @To
    WHERE [Name] = @From

    UPDATE [dbo].[Current_Settings_ContentPartDefinitionRecord]
    SET [Name] = @To + 'Part'
    WHERE [Name] = @From + 'Part'

    --COMMIT TRANSACTION
    ROLLBACK TRANSACTION /*Rollback while testing*/
END TRY

BEGIN CATCH
    ROLLBACK TRANSACTION
END CATCH

Is there anything else I am missing that will need to be renamed to fully rename my content type?

4

1 回答 1

0

这可能不是您问题的确切答案,但是 - 尽管它具有轶事特征 - 它可能会帮助您找到解决方案。

我在一个 Orchard 网站上工作

  • 很多页面
  • 很多指向网站上其他页面的 html 链接
  • 导航中的许多自定义链接项(链接到目标页面内的某些锚点等)

在我们计划对网站进行删除之前不久,出于 SEO 原因,决定将最突出页面的 URL 从更改http://www.example.org/orchard/products/category-name/product-namehttp://www.example.org/orchard/shop/category-name/product-name-keyword-anotherkeyword(必须爱 SEO...)

手动执行此操作需要很长时间。更改内容项本身的 URL 很容易(但在大约 20 个项目上执行此操作仍需要一些时间),但更改所有<a href120 多个内容项中的所有这些 s,以及 5 个导航中的所有自定义链接(5语言)根本不可能。

所以唯一可行的方法似乎是数据库操作。

我曾经MS SQL Server Management Studio将 Orchard 数据库中的所有表导出到单独的 .sql 文件中。然后,我习惯于Notepad++搜索包含部分字符串的所有文件,/products/category/product-name并记下表名和字段名(通常是Textor Data

在这种情况下,结果如下表所示:

  • Common_BodyPartRecord.Table
  • Orchard_Framework_ContentItemRecord
  • Orchard_Framework_ContentItemVersionRecord

对于search-replaceSQl 中的部分字符串,您使用该replace函数,并且由于表字段的数据类型,果园将数据存储在您必须转换字符串。生成的 SQL 查询如下所示:

update [Orchard_Live].[dbo].[Common_BodyPartRecord] 
    set Text = cast(replace(cast(Text as nvarchar(max)),     N'/products/category/product-name', N'/shop/category-name/product-name-keyword-anotherkeyword') as ntext)
where cast(Text as nvarchar(max)) LIKE N'%/products/category/product-name%'

update [Orchard_Live].[dbo].[Orchard_Framework_ContentItemRecord] 
set Data = cast(replace(cast(Data as nvarchar(max)), N'/products/category/product-name', N'/shop/category-name/product-name-keyword-anotherkeyword') as ntext)
where cast(Data as nvarchar(max)) LIKE N'%/products/category/product-name%'

update [Orchard_Live].[dbo].[Orchard_Framework_ContentItemVersionRecord] 
set Data = cast(replace(cast(Data as nvarchar(max)), N'/products/category/product-name', N'/shop/category-name/product-name-keyword-anotherkeyword') as ntext)
where cast(Data as nvarchar(max)) LIKE N'%/products/category/product-name%'

我必须为每个必须更改的 URL 执行此操作。花了很长时间,但到目前为止仍然比手动更改所有内容要好。也许这个“工作流程”也可以帮助您解决问题。

于 2015-03-16T09:39:37.297 回答