Drupal 8:删除所有相同类型的节点 [英] Drupal 8: delete all nodes of the same type
问题描述
我需要删除 Drupal 8 中所有相同类型的节点(节点超过7k)。
I have a need to remove all nodes of the same type in Drupal 8 (there are over 7k of nodes).
它对于Drupal 7来说不是问题(数据库查询+ node_delete或node_delete_multiple将解决我的问题)。但是,D8稍有不同:)
It wouldn't be a problem for Drupal 7 (DB query + node_delete or node_delete_multiple would have solved my issue). However, D8 is slightly different :)
请咨询,我该怎么做。
Please, advice, how can I do it. Thanks in advance!
推荐答案
一个人应该使用实体查询而不是直接对数据库进行操作:
One should use entity queries instead of acting directly on the database:
$result = \Drupal::entityQuery('node')
->condition('type', 'my_content_type_name')
->execute();
entity_delete_multiple('node', $result);
像其他答案中那样设置范围应该不太困难。
Setting up ranges like in the other answer shouldn't be too difficult.
有关详细信息,请参见 EntityFieldQuery已被重写。
See EntityFieldQuery has been rewritten for more information.
这篇关于Drupal 8:删除所有相同类型的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!