Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • TomDS 8 posts 99 karma points
    Feb 25, 2019 @ 08:42
    TomDS
    0

    Migrate existing PropertyData to new PropertyType

    We have an existing PropertyType called IsPublic which uses a Umbraco.TrueFalse property editor.

    Requirements have changed and this value now needs to be represented by multiple checkboxes that are driven from an Enum with the Values Public, Group1, Group2.

    This all works as expected but with 10's of Thousands of documents we want to save our content editors from manually populating them all.

    Saving a document in Umbraco, I can see that it creates an entry in the table cmsPropertyData with the value [ "Public", "Group1", "Group2" ] in the dataNvarchar column.

    I've written a script to insert a row into this table based on the value of the original IsPublic flag.

    However following running this, when opening a document in Umbraco the changes aren't displayed.

    The script used to update is

    DECLARE @HasPublicFlag NVARCHAR(50) = '[    "Public",    "Group1",    "Group2"  ]'
    DECLARE @NoPublicFlag NVARCHAR(50) = '[    "Group1",    "Group2"  ]'
    
    DECLARE @feature INT = (SELECT nodeId FROM cmsContentType WHERE Alias = 'Feature')
    
    --Existing IsPublic flag
    DECLARE @featureIsPublic INT = (SELECT id FROM cmsPropertyType WHERE Alias = 'IsPublic' AND contentTypeId = @feature)
    
    --New PropertyType
    DECLARE @featureRoleRestriction INT = (SELECT id FROM cmsPropertyType WHERE Alias = 'documentRoleRestriction' AND contentTypeId = @page)
    
    --Get feature document versions that are either newest version or published
    ;WITH FeatureDocumentsToUpdate AS
    (
        SELECT d.*, pd.dataInt
        FROM cmsDocument d 
        JOIN cmsPropertyData pd ON pd.versionId = d.versionId
        LEFT JOIN cmsPropertyData pd2 ON pd2.versionId = d.versionId AND pd2.propertytypeid = @featureRoleRestriction
        WHERE (d.newest = 1 OR d.Published = 1) AND pd.propertytypeid = @featureIsPublic AND pd2.id IS NULL
    )
    
    --INSERT INTO cmsPropertyData based on value of existing flag
    INSERT INTO cmsPropertyData(contentNodeId, versionId, propertytypeid, dataNvarchar)
    SELECT s.nodeId, versionId, @featureRoleRestriction, 
        CASE WHEN s.dataInt = 0 THEN @NoPublicFlag ELSE @HasPublicFlag END AS NewValue
    FROM FeatureDocumentsToUpdate s
    

    Is there another table(s) that will need updating or is there a better way to do this?

  • Nik 1597 posts 7176 karma points MVP 6x c-trib
    Feb 25, 2019 @ 09:47
    Nik
    0

    Hi Tom,

    Have you considered using a script that updates the documents via the ContentService rather than hitting the database directly. It might be the case that you are missing some updates that tell Umbraco that things have changed, such as updating version numbers etc.

    Thanks

    Nik

  • TomDS 8 posts 99 karma points
    Feb 25, 2019 @ 10:02
    TomDS
    0

    Thanks Nik, for deployment reasons I was hoping to be able to perform this in a SQL script but I will investigate using the API as a backup.

  • TomDS 8 posts 99 karma points
    Feb 25, 2019 @ 16:36
    TomDS
    100

    It seems that what I was doing is working.

    The content does become visible after performing some of the following steps:

    • Re-publish entire site
    • Recycle the app pool
    • Delete umbraco.config to force a rebuild

    However I don't seem to be able to reliably reproduce it.

Please Sign in or register to post replies

Write your reply to:

Draft