Score:0

Change a node's type/bundle keep the old type/bundle in field tables

cn flag

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?

john Smith avatar
gr flag
i guess you need to run cron an the field_cron() will remove orphan db-entries? https://drupal.stackexchange.com/questions/38328/clean-deleted-field-from-database
Tobias Krause avatar
cn flag
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.
Tobias Krause avatar
cn flag
I know followed the way described here http://www.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.
Score:0
cn flag

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.

Tobias Krause avatar
cn flag
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.
4uk4 avatar
cn flag
I've described two field operations, one still working and one not. I would restore to full operation, for the future, not for now.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.