Copied to clipboard

Flag this post as spam?

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


  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 01, 2013 @ 21:15
    Jan Skovgaard
    1

    Change datatype without "losing" data

    Hi guys

    In short I need to replace the lusini picker datatype with an instance of the MNTP instead since we just upgraded a clients site from Umbraco 4.0.2 to 4.11.8 and hence need to change the picker since lusini picker is no longer supported.

    I'm thinking it should be fairly easy to switch picker since the MNTP has the option to store chosen values in a CSV format just like the lusini picker does.

    However if I create a MNTP and change the datatype on my document type it seems like the chosen items disappear. If i change the datatype back to the lusini picker the data i still there...

    So what should I do in order to change the picker without losing the data chosen by the other picker?

    Any suggestions will be highly appreciated.

    Cheers,
    Jan

  • Charles Afford 1163 posts 1709 karma points
    May 06, 2013 @ 18:07
    Charles Afford
    0

    Hi Jan, if you have any luck with this, could you give me some advice on how you did it?  Thanks.  Charlie :)

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 09, 2013 @ 11:00
    Jan Skovgaard
    0

    Hi Charlie

    I'll let you know if I figure something out. Still hoping to get some input from some of the other bright minds in here.

    I've not been testing it yet but hopefully we have a client agreeing to do a upgrade project where we will need to do this so hoping to figure out the solution in advance :)

    But I'll keep my findings and ideas posted in here for the grabs.

    Cheers,
    Jan 

  • Charles Afford 1163 posts 1709 karma points
    May 09, 2013 @ 21:08
    Charles Afford
    0

    Thanks, Jan

  • Charles Afford 1163 posts 1709 karma points
    May 09, 2013 @ 21:09
    Charles Afford
    0

    Thanks, Jan

  • Niels Lynggaard 190 posts 548 karma points
    Jul 05, 2013 @ 00:38
    Niels Lynggaard
    1

    Hi Jan

    This is old, but I don't know if you figured it out? I recently had the same issue, changing from "media picker with preview" to the umbraco built in mediapicker (Since I was also upgrading an old 4 site.)

    I found this post and modified his code a bit.

    http://betafirm.com/upgrading-from-media-picker-with-preview-to-the-built-in-media-picker/

    Basically I wrote a tiny commandline program that just selected all the rows in the table 'cmsPropertyData' built on this datatype and then copied the value from the dataNText collumn into the dataInt collumn.

    After that, I was able to just edit the datatype and make the switch to the normal mediapicker.

    Hope you solved it, though ;)

    See you in about 1 1/2 months at the office ;)

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jul 05, 2013 @ 00:46
    Jan Skovgaard
    0

    Hi Niels

    Thank you very much for sharing this. I never got to do anything further about it since it was a part of a test-scenario and the client still has not got back to us on the upgrade offer made for them.

    So we have not spent further ressources investigating how to do it. But now it seems we can skip the research part once the client gives us a green light to move on with the project :)

    Yup, see you soon mate!

    /Jan

  • Niels Lynggaard 190 posts 548 karma points
    Jul 05, 2013 @ 00:55
    Niels Lynggaard
    0

    Glad to help.

    Looking forward :)

    /Niels

  • Niels Lynggaard 190 posts 548 karma points
    Jul 07, 2013 @ 04:41
    Niels Lynggaard
    2

    So, now I actually confirm that its possible, since I just did it on one website. 

    The Multi Node Picker stored the values commaseperated, but I wanted to go for the xml option, so basically I just looked up the PropertyTypeId's that was using the old datatype, and wrote a little console application that first selected all these rows from the cmsPropertyData table, converted the comma-separeted text into xml and pushed that back into the DB.

    After that, I could just switch the type of my property and the data is still there :)

    Now I just have to rewrite a some xslt, but...

    If you want to try it yourself, here's a bit of code for that:

     Console.WriteLine("Are you ready to Rumbleeeee?" + Environment.NewLine);
    Console.ReadKey();
    // Console.WriteLine("Insert ProrpertyID:");
    string prop = Console.ReadLine();
    using (
    //.\\SQLExpress
    SqlConnection cn =
    new SqlConnection(
    "server=(local);database=database;user id=user;password=pass"))
    {
    cn.Open();
    //If you have more than one propertytype that uses your datatype, just do a "where propertytypeid IN(xx,xx,xx,xx)..
    SqlCommand cmd =
    new SqlCommand(
    "SELECT id, contentNodeId, dataNtext FROM cmsPropertyData WHERE (propertytypeid=58) AND (dataNtext IS NOT NULL) and cast([dataNText] as nvarchar(max))<>'' ORDER BY contentNodeId",
    cn);
    SqlDataReader dr = cmd.ExecuteReader();

    Dictionary<int, string> pars = new Dictionary<int, string>();
    while (dr.Read())
    {
    //PUT THE DATA IN A NICE LITTLE LIST
    //SO WE CAN WORK ON IT BEFORE THE UPDATE COMMAND
    int nodeId;
    string data;
    nodeId = Int32.Parse(dr["id"].ToString());
    data = dr["dataNText"].ToString();
    Console.WriteLine("Found some good data:" + data+Environment.NewLine);
    string converted = "<MultiNodePicker type=\"content\"> ";
    foreach (var s in data.Split(','))
    {
    converted += "<nodeId>" + s + "</nodeId>";
    }
    converted += "</MultiNodePicker>";
    Console.WriteLine("Converted it would look like this: "+converted);
    pars.Add(nodeId,converted);
    }
    dr.Close();
    Console.WriteLine("Well thats all of them. Now I will update the DB so the datatype can be switched with ease.. Hang on to your hats!"+Environment.NewLine);
    //Pause program and wait for user:
    foreach (var par in pars)
    {
    using (SqlConnection cn2 = new SqlConnection("server=(local);database=database;user id=user;password=pass"))
    {
    var nodeId = par.Key;
    var dataText = par.Value;
    Console.WriteLine("Node: " + nodeId + " Text: " + dataText + Environment.NewLine);
    cn2.Open();
    SqlCommand UpdateCmd = new SqlCommand("UPDATE cmsPropertyData SET dataNtext = '" + dataText + "' WHERE id = '" + nodeId + "'", cn2);
    int i = UpdateCmd.ExecuteNonQuery();
    cn2.Close();
    }

    }
    Console.ReadKey();
    }
Please Sign in or register to post replies

Write your reply to:

Draft