如果您在 hook_node_update 或 Rule 或其他内容中执行此操作,则新的 $node 将无法用于其他模块,如 token、pathauto 等,因此您不会得到预期的结果。一个解决方案是重置缓存$node
:
<?php
// Reset the cached $node.
entity_get_controller('node')->resetCache(array($node->nid));
// Get all nids that reference this node. This is just an example.
$nids = db_query("SELECT entity_id FROM field_data_field_reference WHERE field_reference_target_id = {$node->nid}")->fetchCol();
// Include necessary Pathauto files.
module_load_include('inc', 'pathauto');
module_load_include('inc', 'pathauto.pathauto');
// 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);
// Clear path cache.
cache_clear_all('*', 'cache_path', TRUE);
?>