Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContentItemContentFolderID is NULL for Content Items migrated with a custom mapping class #321

Open
twozero6 opened this issue Dec 17, 2024 · 9 comments

Comments

@twozero6
Copy link

After migrating a K13 database to XbyK 29.7.0, I tried to upgrade the DB to 30.0.0 and the SQL upgrade failed due to:

The ALTER TABLE statement conflicted with the CHECK constraint "CHECK_CMS_ContentItem_ContentItemIsReusable_ContentItemContentFolderID". The conflict occurred in database "redacted-xbyk-project", table "dbo.CMS_ContentItem".

When running the following query, all content items that were migrated through a custom mapping class are returned:

SELECT * FROM CMS_ContentItem WHERE ContentItemIsReusable = 1 and ContentItemContentFolderID IS NULL

In addition to setting the FolderID value during a migration, please give us an option to Set\Create a folder for each item as a part of the ClassMapping class.

@liparova
Copy link
Collaborator

liparova commented Jan 6, 2025

Thank you for highlighting this request. We will review it internally and keep you informed of any developments.

@akfakmot
Copy link
Collaborator

Hello,
today we will be releasing a new version of Migration Tool, which will address this issue. If you want to upgrade the database, we'll ask you to run a one-shot SQL that will be provided. Alternatively rerunning the migration with the coming MT version should also fix this issue.

I will keep you informed.

@bluemodus-mwills
Copy link

Thank you, @akfakmot !

@akfakmot
Copy link
Collaborator

@bluemodus-mwills @twozero6
Hello. Newest release 2.1.0 contains a new flexibility feature - a content item director - which will enable you fine-control over individual content items, including what content item goes to which folder. Since the documents are yet being forged, let me give you guidance here.

  • In Migration.Tool.Extensions create a class inheriting from ContentItemDirectorBase and register it in UseCustomizations as services.AddTransient<ContentItemDirectorBase, YOUR_DIRECTOR_CLASS>()
  • Override its method Direct
  • Then during the migration run, the Direct method will be called for each content item, allowing you to either do nothing (then the migration behavior is unchanged), or take action, in this case call action.OverrideContentFolder(contentFolderGuid)
  • You can use information from ContentItemSource parameter of the direct method to filter on the content items. Useful infos are e.g. SourceNode.NodeAliasPath, ClassName

example:

Image

@akfakmot
Copy link
Collaborator

@twozero6 Regarding the existing rows with ContentItemContentFolderID=NULL, please set them to a non-NULL value by the following query or alike.

-- set everything to root folder
UPDATE CMS_ContentItem SET ContentItemContentFolderID=(SELECT ContentFolderID FROM CMS_ContentFolder WHERE ContentFolderTreePath = '/')

Newest Migration Tool version doesn't produce new instances of this problem. Even with custom classmappings, the folder ID is set to root if not specified.

@bluemodus-mwills
Copy link

@akfakmot -- I like that simple ContentItemDirector solution. Thank you!!

@twozero6
Copy link
Author

@akfakmot this is perfect, thank you!

@twozero6
Copy link
Author

twozero6 commented Feb 7, 2025

@akfakmot just confirming I will test this next week but the solution seems great.

@twozero6
Copy link
Author

@akfakmot @Sapphirress I confirmed this is no longer an issue. The director approach will also work for sorting the items on a re-run. However, I was wondering about creating folders during the initial migration -- right now, everything except for media goes into the root folder. Is it an option to have each type go into its own folder by default? Would that be considered a separate Enhancement request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants