Copied to clipboard

Flag this post as spam?

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


  • Robert J. Bullock 386 posts 405 karma points
    Apr 20, 2015 @ 16:59
    Robert J. Bullock
    0

    Umbraco 6 to 7: Multi Node Tree Picker Conversion

    Ok, I upgraded my site from 6 to 7. It's going fairly well now after fixing a lot of show stoppers! However, I just found out that MNTP didn't convert properly. In the old site, we stored the data as XML. In U7, it's stored as JSON (or looks like CSV to me, whatever)...

    The problem is how do I take the existing XML data and convert it to the new format? The data is not available via Umbraco even because U6 stored the XML in the dataNText field and U7 stores it in the dataNVarchar field in the cmsPropertyData table.

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Apr 20, 2015 @ 17:11
    Jeroen Breuer
    1

    Hello,

    I had the same problem. It was faster for me to manually change all the content than writing a converter. You could have a look PhoenixConverters.

    Jeroen

  • Robert J. Bullock 386 posts 405 karma points
    Apr 20, 2015 @ 17:33
    Robert J. Bullock
    0

    Yeah, it just might be... Only talking about 25-30 nodes. I guess I can just do it in the database manually.

  • Robert J. Bullock 386 posts 405 karma points
    Apr 20, 2015 @ 19:02
    Robert J. Bullock
    0

    Actually, it's 205 nodes... So I wrote a pure t-sql means of doing it... Not sure how to share this properly. First thing is create this function in your Umbraco database: 

    CREATE FUNCTION [dbo].[mntpConvert] (@mntpXml ntext)
        RETURNS nvarchar(MAX)
    AS BEGIN
        -- Declare the return variable here
        DECLARE @Result nvarchar(MAX)
        DECLARE @list nvarchar(MAX)
        DECLARE @xml XML
        DECLARE @mntpData nvarchar(MAX)
    
        SELECT @mntpData = CONVERT(nvarchar(500),@mntpXml)
        SELECT @xml = CONVERT(xml, @mntpData)
        SELECT @list = ISNULL( @list + ',', '' ) + x.y.value('.', 'VARCHAR(500)' )
        FROM @xml.nodes('MultiNodePicker/nodeId') x(y)
    
        -- Add the T-SQL statements to compute the return value here
        SELECT @Result = CONVERT(nvarchar(MAX),@list)
    
        -- Return the result of the function
        RETURN @Result
    
    END
    

    Then you have to figure out how to query the cmsPropertyData and update the right records. I did it by finding my property's id and creating the appropriate update statement.

  • Robert J. Bullock 386 posts 405 karma points
    Apr 20, 2015 @ 19:04
    Robert J. Bullock
    0

    Here's my t-sql statement to do the above but OBVIOUSLY you'd want to change the propertyTypeId:

    UPDATE cmsPropertyData
    SET dataNvarchar = dbo.mntpConvert(dataNtext)
    WHERE (propertytypeid = 138) 
    AND (DATALENGTH(dataNtext) <> 0) 
    AND (dataNtext IS NOT NULL)
    
  • Robert J. Bullock 386 posts 405 karma points
    Apr 20, 2015 @ 19:06
    Robert J. Bullock
    0

    And for good measure, set the dataNtext column to null:

    UPDATE cmsPropertyData
    SET dataNText = NULL
    WHERE (propertytypeid = 138)
    AND (DATALENGTH(dataNtext) <> 0) 
    AND (dataNtext IS NOT NULL)
    
  • Robert J. Bullock 386 posts 405 karma points
    Apr 20, 2015 @ 22:48
    Robert J. Bullock
    1

    Here's the code formatted better...

    CREATE FUNCTION [dbo].[mntpConvert] 
    (
        -- Add the parameters for the function here
        @mntpXml ntext
    )
    RETURNS nvarchar(MAX)
    AS
    BEGIN
        -- Declare the return variable here
        DECLARE @Result nvarchar(MAX)
        DECLARE @list nvarchar(MAX)
        DECLARE @xml XML
        DECLARE @mntpData nvarchar(MAX)
    
        SELECT @mntpData = CONVERT(nvarchar(500),@mntpXml)
        SELECT @xml = CONVERT(xml, @mntpData)
    
        SELECT @list = ISNULL( @list + ',', '' ) + x.y.value('.', 'VARCHAR(500)' )  
    FROM @xml.nodes('MultiNodePicker/nodeId') x(y) 
    
        -- Add the T-SQL statements to compute the return value here
        SELECT @Result = CONVERT(nvarchar(MAX),@list)
    
        -- Return the result of the function
        RETURN @Result
    
    END
    
    GO
    
Please Sign in or register to post replies

Write your reply to:

Draft