Copied to clipboard

Flag this post as spam?

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


  • Hitesh Sharma 21 posts 121 karma points
    Nov 20, 2018 @ 07:50
    Hitesh Sharma
    0

    Wrapper around uSync

    I want a one click migration feature where back office users will be presented with a page. When click on a button on that page, the content from one installation will be copied to another installation.

    I read that uSync can do that but that requires user to go to developer section of both the installation.

    So I am thinking to write a wrapper around uSync which do this job for me. But I am not well aware of uSync and Umbraco and not sure how to start. Any help will be appreciated.

  • Kevin Jump 1423 posts 9136 karma points MVP 3x c-trib
    Nov 20, 2018 @ 09:50
    Kevin Jump
    100

    Hi

    Yeah it's all possible - but isn't everything possible for developers :)

    Below is the detail of what you might need to do, but for a "simple" answer it might be worth you looking at uSync.Snapshots code, and working out if you could just use that to create the snapshot, fire it over (see below) and run the snapshot on the other side

    Firstly to communicate between the sites you are going to need to have some WebApi endpoint (ApiController) on the target site , and a way of making it secure (so shared key / auth).

    Once that is done ! You will either need to pass the uSync configs over to the target server via the api, or know that they are getting copied somehow between the source and server folders. so you might for example export the items via usync - zip them up? and send them over the wire to the target server.

    Once you have the file(s) on the server you can call the uSync api endpoints to do the importing.

    There are "simple" enpoints for performing imports and exports of the whole lot - these are:

    uSyncBackOfficeContext.Instance.Import(group, folder, force) ; 
    uSyncBackOfficeContext.Instance.Export(group, folder) ; 
    

    but these do everything they find in the folder (so all doctypes, datatypes, content). You might for example only want to import a single doctype then you need to get the uSync Handler for doctypes and ask it to import the single file.

    You might be best looking at how the uSync chauffeur deliverable does that https://github.com/KevinJump/uSync/blob/v4_master/Jumoo.uSync.Chauffeur/uSyncDeliverable.cs#L175

    But! things don't have to go to disk at all - you can extract the config you want to push into memory pass it over and then import it from memory using the uSync.Core library (in reality this does all the hard work; all the usync.backoffice library does is mange umbraco events, and things going to and from the disk)

    With the core you can - for example - export a content item:

    var attempt = uSyncCoreContext.Instance.ContentSerializer.Serialize(item);
    

    this will give you the XElement object in attempt.Item

    you then pass this over and at the other end :

    var attempt = uSyncCoreContext.Instance.ContentSerializer.Deserialize(node, parentId, force);
    

    (in this instance for content you need to know or find the parentId on the target site, so you know where the content goes.

    Content is a two pass sync (because links and things might not be valid the first time the import is processed) - so you also need to call :

    uSyncCoreContext.Instance.ContentSerializer.DesearlizeSecondPass(attempt.Item, node);
    

    With all of this you will also need to consider syncornization, so depending on your setup and the nature of deployment you might be ok just sending a single bit of content or config over to the target server, but if it is missing the doctype/datatypes/templates that make up that config then you are not going to get a successful sync.

    So what courier does (i believe) is work out what dependencies there are for any particular item (so for content, you need to find the doctypes, for those doctypes the datatypes, templates and any parent/compositions) bundle them all up and send them over as part of the sync.

  • Hitesh Sharma 21 posts 121 karma points
    Nov 20, 2018 @ 10:21
    Hitesh Sharma
    0

    Thank you for such detailed answer, Kevin! This really gave me insights of the tool. I will take a look at Snapshot feature. A questions is - WIll this uSyncCoreContext and uSyncBackOfficeContext always be available in ApplicationContext? How will I access this? Injecting through something?

  • Kevin Jump 1423 posts 9136 karma points MVP 3x c-trib
    Nov 20, 2018 @ 10:53
    Kevin Jump
    0

    Hi

    The contexts are singletons, so should always available within an umbraco app.

    They are not resolvers or anything fancy (yet) so don't need to be injected into the controllers, (this does make unit testing with the current usync difficult)

  • Hitesh Sharma 21 posts 121 karma points
    Nov 20, 2018 @ 12:58
    Hitesh Sharma
    0

    Thanks Kevin!

    I just got more detail on my requirement. I have to actually move the content from one Content area (Parent) to another content area(Parent) on the same Umbraco Instance.

    I believe the Content edition will not work for me as it updates contents and matches the IDs, so if I export and import back on the same instance, it will update the original content area and not in the second content area.

  • Kevin Jump 1423 posts 9136 karma points MVP 3x c-trib
    Nov 20, 2018 @ 13:21
    Kevin Jump
    0

    Hi

    yeah content edtion won't work for that - because as you say it's internal content id matching .

    but

    Translation Manager might: ) (stop me here if you want, I after all am always going to think things i wrote will solve problems)

    primarily as the name suggests i has been written for translations but translation manager will copy content around a single umbraco instance, updating links and content as it goes,

    There is a Passthrough Provider that does nothing more than push the content from one place to another (its for when one instance has two sites for similar languages (e.g en-US and en-GB sites) - but this means you can 'send to translate' a section of a site and if it's configured this will just push the content from one place to another.

  • Hitesh Sharma 21 posts 121 karma points
    Nov 20, 2018 @ 13:25
    Hitesh Sharma
    0

    So I got more things to research on but it will definitely help me gain more understanding of Umbraco system.

    Many thanks for all this help, Kevin. And I will let you know how it goes. :)

Please Sign in or register to post replies

Write your reply to:

Draft