-
Notifications
You must be signed in to change notification settings - Fork 683
Description
What happened?
Description
When running ./craft gc --delete-all-trashed, the garbage collector crashes during the "purging unsaved drafts" phase with the following error:
TypeError: craft\elements\Entry::craft\elements{closure}():
Argument #1 ($entryType) must be of type craft\models\EntryType,
craft\fields\ContentBlock given, called in
vendor/yiisoft/yii2/helpers/BaseArrayHelper.php on line 199
in vendor/craftcms/cms/src/elements/Entry.php:1739
The call chain is:
Gc::run()
→ Drafts::purgeUnsavedDrafts()
→ Elements::deleteElement()
→ Entry::beforeDelete()
→ Element::fieldLayoutFields()
→ Entry::getFieldLayout()
→ Entry::getType() ← fails here
It looks like Entry::getType() iterates over a collection that is expected to contain only EntryType instances, but a craft\fields\ContentBlock object is present in the list instead. Could this be an issue with how ContentBlock fields are filtered when resolving entry types for a section?
Steps to reproduce
- Have a project with Matrix/Content Builder fields using content blocks
- Run ./craft gc --delete-all-trashed
Expected behavior
Entry::getAvailableEntryTypes() should handle the case where the entry's parent field is a ContentBlock field, whose getFieldLayoutProviders() returns ContentBlock instances instead of EntryType instances. The garbage collector should be able to purge stale unsaved drafts without throwing a TypeError.
Actual behavior
Since the GC crashes before completing, soft-deleted elements and stale drafts are never purged. This can have side effects on plugins that rely on eventual hard-deletion (e.g. Neo blocks leaving orphaned rows in their tables because the CASCADE foreign key only triggers on hard-delete).
Craft CMS version
5.9.16
PHP version
8.2
Operating system and version
No response
Database type and version
No response
Image driver and version
No response