KevinJump / uSync

Database syncing tool for Umbraco CMS
https://jumoo.co.uk/usync/
Mozilla Public License 2.0
111 stars 63 forks source link

Umbraco 8: Level changes for document-types inheriting compositions is not updating as expected #340

Open Scherling opened 2 years ago

Scherling commented 2 years ago

Bug Description On Umbraco 8 installation (8.16) using uSync 8.10.4 As an administrator when configuring document types, when a document type is created under a composition document type, thus inheriting its properties, the Levelproperty for the usync config ContentTypeelement for that document type will correctly be 1 higher than its parent element.

However, when manually editing this value afterwards in the usync file, for example needed if you decide to change inheritence structure later by adding an additional layer of inheritance, the levelfield of the umbracoNode is not updated as expected.

While the umbraco backoffice is still usable, it does cause some issues when selecting nodes in the tree. Instead of highligting the affected document type node when selecting it, the tree collapses back to a lower level, since the level value is wrong.

To Reproduce Steps to reproduce the behavior:

  1. Go to Settings page in Umbraco
  2. Create a new composition document type, for reference, let's call it BasePage
  3. Under BasePage create a new document type inheriting from it called ItemPage
  4. Confirm the Level in config files is +1 higher for itemPagethan BasePage
  5. Now change the structure by doing the following in usync config files:
    1. Create a new document type called BaseItemPage
    2. Set its level to the same as ItemPage
    3. Set its parent and composition to BasePage
    4. Set the parent and composition of ItemPage to the newly created BaseItemPage (Thus adding another layer of inheritance in between the existing document types)
    5. Update the Level property in the config file for ItemPage to be 1 higher, as it is now 1 step lower in the tree structure
    6. Run usync import
  6. Check the umbracoNode table for ItemPage, the value is unchanged, even though it has changed in the config file

Expected behavior The level value in the umbracoNode table in the database, should reflect the Level value in the usync config file after running the import

KevinJump commented 2 years ago

Hi,

I think this works but if you are editing the files you have to be careful of a number of things.

  1. If you create a new doctype by file, it much have a unique key (GUID) if you just copy something that is already there and don't alter this, then you will get clashes.

  2. When setting the parent / compostion make sure you update the key and alias values to match those of your baseItemPage This is how the parent is defined (and where things show in the tree). I suspect this is where it is going wrong for you

  3. Ensure the levels of the files make sense (e.g baseItemPage has level 2, itemPage has level 3). the Level in the uSync file isn't actually part of the information synced into Umbraco it determains the order of the sync, so for example all level 1 items get synced before level 2 and then level 3.

for my test i have

basePage (created inside Umbraco)

<?xml version="1.0" encoding="utf-8"?>
<ContentType Key="66efd9d0-b997-45c5-9c66-037aa96fe53c" Alias="basePage" Level="1">
  <Info>
    <Name>BasePage</Name>
    <Icon>icon-item-arrangement</Icon>
    <Thumbnail>folder.png</Thumbnail>
    <Description></Description>
    <AllowAtRoot>False</AllowAtRoot>
    <IsListView>False</IsListView>
    <Variations>Nothing</Variations>
    <IsElement>false</IsElement>
    <Compositions />
    <DefaultTemplate></DefaultTemplate>
    <AllowedTemplates />
  </Info>
  <Structure />
  <GenericProperties />
  <Tabs />
</ContentType>

baseItemPage (created by hand - its a copy of the orginnal itemPage with the key changed (note i just change 39 to 40 at the end of the key))

<?xml version="1.0" encoding="utf-8"?>
<ContentType Key="3f3556e5-3ac2-4fda-b8f9-4b42934a4b40" Alias="baseItemPage" Level="2">
  <Info>
    <Name>BaseItemPage</Name>
    <Icon>icon-item-arrangement</Icon>
    <Thumbnail>folder.png</Thumbnail>
    <Description></Description>
    <AllowAtRoot>False</AllowAtRoot>
    <IsListView>False</IsListView>
    <Variations>Nothing</Variations>
    <IsElement>false</IsElement>
    <Parent Key="66efd9d0-b997-45c5-9c66-037aa96fe53c">basePage</Parent>
    <Compositions>
      <Composition Key="66efd9d0-b997-45c5-9c66-037aa96fe53c">basePage</Composition>
    </Compositions>
    <DefaultTemplate></DefaultTemplate>
    <AllowedTemplates />
  </Info>
  <Structure />
  <GenericProperties />
  <Tabs />
</ContentType>

itemPage (create in Umbraco but then the Parent, Key and alias, and composition key and alias have changed to be those of the baseItemPage)

<?xml version="1.0" encoding="utf-8"?>
<ContentType Key="3f3556e5-3ac2-4fda-b8f9-4b42934a4b39" Alias="itemPage" Level="3">
  <Info>
    <Name>ItemPage</Name>
    <Icon>icon-item-arrangement</Icon>
    <Thumbnail>folder.png</Thumbnail>
    <Description></Description>
    <AllowAtRoot>False</AllowAtRoot>
    <IsListView>False</IsListView>
    <Variations>Nothing</Variations>
    <IsElement>false</IsElement>
    <Parent Key="3f3556e5-3ac2-4fda-b8f9-4b42934a4b40">baseItemPage</Parent>
    <Compositions>
      <Composition Key="3f3556e5-3ac2-4fda-b8f9-4b42934a4b40">baseItemPage</Composition>
    </Compositions>
    <DefaultTemplate></DefaultTemplate>
    <AllowedTemplates />
  </Info>
  <Structure />
  <GenericProperties />
  <Tabs />
</ContentType>

after a sync it looks like this.

image

jso-dwarf commented 2 years ago

I did some additional testing, and I wrongly assumed this to be an issue with the document type you update. It's not, but rather, it's an issue with the document types even lower in the hierachy. I think I confused myself a bit when I tried making a more generic example for the bug report.

Continuing my above example, if the tree structure contain an additional level, let's call it SubItemPagebelow ItemPage so that the final structure after the import looks like this:

image

Then pages below the changed page, is not updated accordingly. For SubItemPage I've increased the Level value in the config: image

The usync report before the import looks like this image "xml is different - but properties may not have changed"

And level and path is not bumped up in the DB image

Scherling commented 2 years ago

And just to clarify, the above post is still me, I just accidentally used my work account to post :)

KevinJump commented 2 years ago

OK, i will need to check this, it might be an Umbraco thing (but will see if i can confirm) - uSync sets the parent item via the Umbraco API, we don't actually set path or level - because these should be (and are usually) calculated when you set the parent.

so i wonder if something is going wrong when that happens, will take a deeper dive and see if we can sort the issue.

KevinJump commented 2 years ago

Hi I still can't reproduce this locally 😞

My testing below:

I have a number of files created by Umbraco and from uSync files.

image

at this point everything appears to be in the right place.

if i alter the BaseChildFile config. to move its level:

in the first instance moving it under baseGrandChild.

  1. Change its level (to 4) image

  2. change its parent and compositon values image

run the import:

  1. UI is ok image

  2. DB looks ok image

Now Move this to under BaseFromFile

  1. as above up level (5) change parent / compositon

image

  1. after update DB still looks ok

image

I am not sure what might be happening for you, but if the parent Key and Alias are set correctly, then Umbraco should be doing all the work to update the path and level values - as i said above the Level value for us isn't something we set in Umbraco its only really used to ensure things are imported in level order (e.g level 1 before level 5).

K

Scherling commented 2 years ago

Hi, thanks for investigating.

I will have to figure out if it's something else causing this issue, then. I'll let you know if I figure it out.

mbogunovic commented 2 years ago

@Scherling Same issue here, version 9.2.0 of uSync, umbraco.Cms 9.3.1

The solution that currently works in my case is using import option few times until my pages move to the correct structure. Keys are fine, whole configuration is fine.

But it is annoying to use import few times until everything sorts out. Not sure what could be the issue for this.

Sven883 commented 2 years ago

@mbogunovic +1 we're having the same issue! Also using the import option a few times until the pages move to the correct structure.