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

delete formie/gc/delete-orphaned-fields is not removing all unused fields #1653

Closed
aloco opened this issue Dec 7, 2023 · 4 comments
Closed
Milestone

Comments

@aloco
Copy link

aloco commented Dec 7, 2023

Describe the bug

Hi,

we have an installment with a very big form inside, containing a lot of fields. I noticed that in the database, there are a lot of custom fields related to formie. I removed the big form but there are still custom fields inside, it looks like they got somehow orphaned during development, however, I can´t delete them with formie/gc/delete-orphaned-fields, seems like there is something messed up. Do you know how I can get rid of those fields? We notice performance issues which might be caused by something else, however, seems like around 1600 custom fields in the table are a reason for that: craftcms/cms#13992

Thank you in advance!

Steps to reproduce

We somehow got a lot of custom orphaned fields, not sure how to reproduce.

Form settings

  • Multi-page form: Yes
  • Submission Method: Ajax
  • Client-side Validation: Yes
  • Custom Form Templates: No

Craft CMS version

4.11.1

Plugin version

2.0.42

Multi-site?

Yes

Additional context

Blitz 4.9.0
captcha.eu 1.0.4
CP Field Inspect 1.4.4
Empty Coalesce 4.0.0
Field Manager 3.0.8
Formie 2.0.42
Hyper 1.1.16
ImageOptimize 4.0.5
Redactor 3.0.4
Retour 4.1.14
SEOmatic 4.0.35
Smith 2.0.0
Sprig 2.7.2
Super Table 3.0.12
Timber 1.0.2
Vite 4.0.6
Wishlist 2.0.7

@engram-design
Copy link
Member

The reason fields aren't removed when a form is deleted is to support soft-deletion of forms. This is because you can soft delete a form and restore it later. However, fields don't support being soft-deleted, and once they've been deleted, they're gone.

For this reason, we don't delete the fields when you delete a form. There's also no hard-delete event raised for us to delete the fields when Craft's garbage collection process has hard-deleted the form to cleanup those fields. So that's why we have a process that checks for any hard-deleted forms, and if their fields are still around to deleted them.

So - I would first check if there are any trashed forms. They should be hard-deleted. Then, running that console command should pick up on any fields used by those now non-existant forms.

@aloco
Copy link
Author

aloco commented Dec 8, 2023

Hi, thank you for the fast reply, I tried that but it didn´t resolve the issue for me.

I digged a little and found the following: In deleteOrphanedFields you are calling $this->getAllFields() where you receive all custom fields and filter them by the context value formie: - but in my database there are also formieFields:, they get not cleaned. Looks like FormieFieldTrait.php is setting this as context ..

@engram-design
Copy link
Member

So formieFields: context fields are fields that are children of other fields - namely Group and Repeater fields. When their parent Group/Repeater field is deleted, these should also be removed.

@engram-design engram-design added this to the 2.1.0 milestone Dec 17, 2023
@engram-design
Copy link
Member

Updated in 2.1.0

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

No branches or pull requests

2 participants