Moving Properties between Compositions
# help-with-umbraco
d
Is there a way to move properties between compositions without using code solution such as ContentService API or a database solution?
k
you can do it with uSync files (if you have all the content synced to disk, you can cut/paste the property values between content types) * don't try this without a safeynet / backup / on a live site :)
d
I should have added it's an Umbraco Cloud project. I assume this will make things complicated.
k
you might be able to do it with deploy files 😬
the problem you have is moving a property between content types is actually a delete and re-create in the background, and the delete will cause a refresh of all the content (so it will delete the content values!). then the create will put the new value in, but the content values will be gone. 😦 doing it with uSync (and the content files) means the delete does happen but when you import uSync puts the content back in because it has it outside the DB. i don't think there are non-hacky ways to do this, because via the api will trigger the internal notifications that do all the cleanup.
(it is possible to suppress notifications, which might stop the delete from popergaing but i am not 100% sure that will work in this case (not all notifications are supressible)
d
Thanks @Kevin Jump - perhaps the ability for 'merging' properties of the same datatype could be a request for the new back office. I think I'll have to investigate the code route.
s
Be very careful... might work but I have absolutely no idea 🤷 https://marketplace.umbraco.com/package/flip.umbraco
ah no, that just changes the doctype.. never mind 🙈
d
Hehe yes I had a look at that too 🙂
I asked Co-Pilot for a programatic solution which I assume it got from someone who has done this
Copy code
csharp
    var contentService = Services.ContentService;
    var allContent = contentService.GetRootContent().DescendantsOrSelf();
    
    foreach (var content in allContent)
    {
        if (content.HasProperty("oldPropertyAlias") && content.HasProperty("newPropertyAlias"))
        {
            var oldValue = content.GetValue("oldPropertyAlias");
            content.SetValue("newPropertyAlias", oldValue);
            contentService.SaveAndPublish(content);
        }
    }
At least it is only copying so I can test it's all there.
s
Yikes no, don't do this unless you only have a few nodes!
You can fiddle with the database instead and that should probably work, but it WILL confuse Umbraco Deploy, so you will need to resave the affected doctypes and then it might work. But I would then also fiddle with the Cloud database to do the same to prevent anything from messing up.
But definitely make copious backups before you do anything 😅
n
There was/is a blog post from Marc Goodson http://tooorangey.co.uk/posts/moving-just-keep-moving/ this was written for v7/v8 I think but conceptually should still be do-able with latter dbs
(I've used it heavily in the past)
Although.. watch out because the last part of that does say "just don't try that on cloud.. because it will break your deployments"
k
@Dean Leigh did a talk at one of our meet ups about the "unfriendlyness" of Umbraco deleting your data when you remove a composition, and even did a proof of concept for a change in Umbraco so you could swap comps instead - which is wildly outdated and should not be used for anything. That being said - it did stem from a client demand, so I did make this mad SQL script to swap compositions https://github.com/kasparboelkjeldsen/Umbraco-CMS/blob/feature/composition-swap/switch%20composition.sql It assumes your new composition is identical to the old one (ie. you should make a copy and then edit your copy afterwards, or your new one should match completly)
You shut down umbraco, fiddle with the SQL, delete all temp files and wake up umbraco and it should accept it's new reality 🙂
d
Thanks @Nik - it's the cloud part that seems to be the sticking point. I managed to do it in V7 somehow mucking around with the DBs and as @Kevin Jump explains there are options using Usync. In fact we have imported whole sites from our old Classic ASP CMS using Usync files.
This looks both very clever and really scary! For now I am composing them into the same named tabs and groups so at least from the editors perspective common properties are grouped nicely. However, for the devs and site managers not so nice.
k
It -was- super scary. Started with the smallest "can we enable this new block only on newspages?" and spiraled into "we are never ever ever ever putting a blocklist or a blockgrid on a composition again"
d
Hehe yes I think for many reasons that makes sense. One of the things I have been enjoying about Block List and Grid is the ability to 'nest' in ways you cannot do with compositions.
17 Views