0

I need to change the bundle/type of some nodes. I tried https://www.drupal.org/project/convert_bundles but there was no way to select just a few nodes and change the bundle/type so I tried the very simple way:

 $node = Node::load(123); $node->set('type', 'new_type_name'); $node->save(); 

This seems to work: the content type of the node changed. But when I look at the field's database tables there is still the old type/bundle name in the column "bundle" for each field of this node. This only changes when I actually change the field in the node edit form and save it.

My question: does somebody know if there are any sideeffects when there are fields connected to a node where in the field's table is the wrong bundle name stored?

3
  • i guess you need to run cron an the field_cron() will remove orphan db-entries? drupal.stackexchange.com/questions/38328/… Commented Feb 2, 2022 at 14:55
  • I think there is a misunderstanding: there are no orphan db-entries. The entries in the field tables are correctly connected to an existing entity. Only in the field's db entry the old bundle of this entity is still set. And I wonder if this difference (bundle in entity base table and bundle in field table) can make any problems. Commented Feb 2, 2022 at 15:59
  • I know followed the way described here noreiko.com/blog/changing-type-node with some adjustments. In this way the bundle value is updated in every field table but I leave the question open as I would be interested in the answer. Commented Feb 3, 2022 at 9:31

1 Answer 1

0

As commented by @johnSmith, purging is the problem here, but there are two different purging processes. The first one is triggered when the field storage is removed and the entire table is marked as deleted and purged in cron runs, this should still work. The second one is triggered when a field is removed only from a bundle. Then the affected field items are marked as deleted and purged. This doesn't work any longer. But even if this doesn't bother you and you don't notice other side effects, I still would recommend to update every field table and leave the entity tables in a consistent state as described in the latest comment.

2
  • This is not the problem: no fields are removed/deleted in any way. The fields of the source entity type and the new entity type are the same at this moment. Commented Feb 8, 2022 at 8:10
  • I've described two field operations, one still working and one not. I would restore to full operation, for the future, not for now. Commented Feb 8, 2022 at 8:59

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.