spicywebau / craft-neo

A Matrix-like field type for Craft CMS that uses existing fields
Other
403 stars 63 forks source link

Error when uninstalling Neo #895

Closed gateszies closed 3 weeks ago

gateszies commented 3 weeks ago

Bug Description

I'm running into a few errors when trying to uninstall Neo that prevent it from successfully uninstalling.

On the first run of $ craft plugin/uninstall neo I get the below error:

failed to uninstall neo: An error occurred while executing the "benf\neo\migrations\Install migration: Invalid entry type ID: 3314

On the second run of the same command, I get this error:

failed to uninstall neo: An error occurred while executing the "benf\neo\migrations\Install migration: craft\elements\Entry::setTypeId():
Argument #1 ($typeld) must be of type int, null given, called in /app/vendor/yiisoft/yii2/base/Component.php on line

We want to convert our Neo fields to native Matrix fields and I'm curious where functionality currently stands. I know there was some discussion here about this topic.

Neo fields can already be converted to Matrix fields as they exist now (and this should happen automatically if you uninstall Neo). How does this work in Craft 5 with the introduction of Entry Types for Matrixes?

Steps to reproduce

  1. Run $ craft plugin/uninstall neo on site using Craft 5

Expected behaviour

Block types map to Entry Types cleanly to easily migrate from Neo to Matrixes.

Neo version

5.0.0-RC.1

Craft CMS version

5.1.7

What is the affected Neo field's propagation method?

No response

Does this issue involve templating, and if so, is eager-loading used?

This is not a templating issue

ttempleton commented 3 weeks ago

Thanks for reporting that - fixed now in 5.0.3.

When performing Neo-to-Matrix conversion on Craft 5, the conversion from Neo block types to entry types may append a number to the end of the entry type's name and handle, if an entry type with the same name or handle already exists. Any templates that reference the former Neo field's block type handles will need to be updated accordingly. Also, any nested Matrix fields will now be retained in the newly-converted Matrix field.

Neo-to-Matrix conversion should otherwise work the same as it has in the past - and it is important to note that this includes the loss of block hierarchy. We have no plans to update Neo-to-Matrix conversion beyond the existing implementation while we still support Neo - which we have no plans to stop doing.

gateszies commented 2 weeks ago

@ttempleton Thanks for the prompt reply! That is working well for me locally now.

Regarding the migration, can you expand on what you mean by the loss of block hierarchy? Right now when I uninstall, all Neo block types within a Neo field map to Entry Types within one Matrix field. I lose any child block content within a Neo block because child blocks are also converted to Entry Types, and you can't reference an Entry Type within an Entry Type.

Ideally, child blocks with Will this block type be allowed at the top level? toggled off would convert to separate Matrix fields to retain structure, allowing the user to place that Matrix field within the parent Matrix field.

ttempleton commented 2 weeks ago

Regarding the migration, can you expand on what you mean by the loss of block hierarchy?

When converting a Neo field to Matrix, all structural data is lost - all resulting Matrix entries will just exist at the same level, the same as how it worked on previous Craft versions, without creating nested Matrix fields for former Neo child blocks.

We're not planning to convert child blocks into nested Matrix entries at this stage, because we feel that the existing functionality is still sufficient for the try-before-you-buy reasoning that Neo-to-Matrix conversion was originally created for. Though I do get where you're coming from with the child block types that aren't allowed at the top level, and I'm not opposed to that idea.

That said, all of Neo's methods for converting block types to entry types are part of the plugin's public API, and the rest of the conversion class code could be used as a starting point for anyone who is interested in creating their own plugin or module to migrate Neo child blocks to nested Matrix entries.

Another potential solution (although I haven't tried this) is to add the Matrix field itself to the field layouts of the entry types it uses that need child entries, using a plugin like Smith to copy the entries where they need to go, and writing a module to listen to the event that Matrix fields trigger to allow filtering which entry types can be used, to set the nested entry types to what used to be the allowed Neo child block types.