如何在Drupal 7中以编程方式批量创建/更新别名

Iro*_*ood 6 drupal pathauto drupal-7 drupal-path-aliases

如何通过仅使用drupal 7核心(使用它的优秀批处理API)以编程方式批量别名节点URL?)?

我的问题实际上是如何使用drupal并识别存储在url_alias表中的别名

背景:

我工作的项目有超过200,000个节点(Drupal 7),并且对所有这些节点的系统默认URL进行别名将花费数年时间来使用pathauto模块(每20分钟有10个别名).我尝试了一切来改善那些性能但失败了(尝试了不同的服务器,不同的mysql优化,不同的模式).

我已经准备好了批处理功能,它们在20分钟内对200,000个节点进行了别名,它们创建了存储在表"url_alias"中的干净别名.我花了很多时间查看pathauto代码,但无法找到或理解模块如何为drupal提供识别批量更新路径的命令.

感谢您的提示,答案或想法..非常感谢!

Eug*_*lin 8

这是将更新指定类型的所有节点的别名的函数

<?php
  module_load_include('inc', 'pathauto');
  module_load_include('inc', 'pathauto.pathauto');

  // Get all nodes that need to be updated
  $query = db_select('node', 'n');
  $query->addField('n', 'nid');
  $query->condition('n.type', array('TYPE1', 'TYPE2'), 'IN');

  $nids = $query->execute()->fetchCol();

  // Save current action for new aliases and change it to delete old one.
  $alias_action = variable_get('pathauto_update_action', 0);
  variable_set('pathauto_update_action', PATHAUTO_UPDATE_ACTION_DELETE);

  pathauto_node_update_alias_multiple($nids, 'bulkupdate');

  // Restore original action for new aliases.
  variable_set('pathauto_update_action', $alias_action);

?>
Run Code Online (Sandbox Code Playgroud)

  • 不要使用`variable_set()`来*暂时*在请求期间修改一个值 - 竞争条件很容易咬你.而是设置和恢复`$ conf ['pathauto_update_action']`,它不会影响其他请求. (3认同)