Copied to clipboard

Flag this post as spam?

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

  • Jeroen Breuer 4861 posts 12132 karma points MVP 3x admin c-trib
    Jul 11, 2016 @ 09:45
    Jeroen Breuer

    Manually execute uSync import


    I'm using the Umbraco migrations ( and I would like to make sure that uSync has run before the migration.

    Currently both uSync and the migrations are executed in the ApplicationStarted event. So it's not clear which code will run first.

    In a migration it's possible to also execute code. So in there I could run the uSync import code. Can I just run uSyncBackOffice.ImportAll()?


  • Kevin Jump 1768 posts 11344 karma points MVP 4x c-trib
    Jul 11, 2016 @ 10:18
    Kevin Jump


    yes, you can just call the back office.

    var uSyncBackOffice = uSyncBackOfficeContext.Instance;
    var actions = uSyncBackOffice.ImportAll()

    Then actions will be IEnumberable of uSyncAction if you want to check it all worked or not...

    ImportAll also takes a couple of optional params, so you can even run it from another folder, or force a full import (one where everything is imported even if it hasn't changed) if you want

  • vapenation 21 posts 139 karma points
    Dec 08, 2016 @ 07:51

    I tried this and it seems to have worked but for some reason, Usync didn't create a new log-entry. Does it not do this when you call the API manually?

  • Jeroen Breuer 4861 posts 12132 karma points MVP 3x admin c-trib
    Jul 11, 2016 @ 12:24
    Jeroen Breuer

    Thanks Kevin.

    Do you keep versions when running an import?

    If first would like to run a uSync import, than do my own code migration and than do another import.

    Maybe it's easier to explain what I'm trying to do ;-).

    I have some properties on a child doctype and I need to move it to a parent doctype and keep existing content. So this is my idea:

    1. Rename child doctype properties to temp name (uSync will register)
    2. Create same properties on parent doctype (uSync will register)
    3. Move content from temp child doctype properties to parent properties (migration code).
    4. Delete the temp properties from the child (uSync will register)

    For our CI I need to execute step 1 to 4 in that order. Any suggestions?


  • Kevin Jump 1768 posts 11344 karma points MVP 4x c-trib
    Jul 11, 2016 @ 12:40
    Kevin Jump


    the basic usync code isn't saving versions, but if you have a set of files for each stage, you can just pass the relevant folders into the ImportAll() call, so you might have folders called /step1 /step2 etc...

    you can just call ImportAll("~/mystuff/step1") then Importall("~mystuff/step2") so it would do two or how ever many imports... you wanted to do.

    uSync.Snapshots, will let you make snapshot folders, so you could use that to make a snapshots folder for each stage (they will only contain the changes between each snapshot)

    you could then import these as part of a migration either by calling ImportAll for the right folders or if you use usync. snapshots then you could call something similar to this to apply only one snapshot

    var root = IOHelper.MapPath("~/uSync/Snapshots");
    SnapshotManager snapshotManager = new SnapshotManager(root);
    return snapshotManager.Apply(snapshotName);

    Having said all of that, uSync and uSync Content Edition may do what you want in one go.

    If you move your properties to the parent, then umbraco will delete the content when that happens, but if you also import the content files with contentEdition it 'should' put all the content back*

    so a usync import with the doctype changes in it and the content files (produced by content edition) would do both?

    *you might have to do a forced import, because content changes are tracked by save date

  • Jeroen Breuer 4861 posts 12132 karma points MVP 3x admin c-trib
    Jul 11, 2016 @ 12:58
    Jeroen Breuer

    Thanks for your suggestions.

    It's a pretty large project with a lot of content so I prefer to do things manually instead of using uSync Content Edition. I'll try the different folder approach.

    How can I change the folder name? I assume I need to change the folder name. Than do step 1 and 2. Than change the folder name again for step 4?

    Might be easier to manually write the uSync file for deletion since I can't delete it yet.


  • Kevin Jump 1768 posts 11344 karma points MVP 4x c-trib
    Jul 11, 2016 @ 13:02
    Kevin Jump

    yeah from what you're saying i would be inclined to do bits of it by hand.

    Just take the relevant files from the doctype folder and cut/ paste the properties elements. then on sync the properties will be deleted / moved.

    if you used snapshots on the source site, you could just create a new snapshot between each step and then you would have different folders for each change (in the usync/snapshots folder).

Please Sign in or register to post replies

Write your reply to: