#Moving Properties between Compositions

1 messages · Page 1 of 1 (latest)

atomic plinth
#

Is there a way to move properties between compositions without using code solution such as ContentService API or a database solution?

austere snow
#

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 :)

atomic plinth
#

I should have added it's an Umbraco Cloud project. I assume this will make things complicated.

austere snow
#

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)

atomic plinth
fallen tendon
#

ah no, that just changes the doctype.. never mind 🙈

atomic plinth
#

I asked Co-Pilot for a programatic solution which I assume it got from someone who has done this

    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.
fallen tendon
#

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 😅

ruby onyx
#

(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"

slow monolith
#

@atomic plinth 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 composition.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)

GitHub

The simple, flexible and friendly ASP.NET CMS used by more than 730.000 websites - kasparboelkjeldsen/Umbraco-CMS

#

You shut down umbraco, fiddle with the SQL, delete all temp files and wake up umbraco and it should accept it's new reality 🙂

atomic plinth
atomic plinth
slow monolith