【发布时间】:2016-10-09 11:58:17
【问题描述】:
我有一个用于研究目的的数据库。不幸的是,在这项研究中,算法被允许运行的时间过长,从而无意中创建了重复的分类术语,而不是为术语的第一个实例重复使用原始 TID。
为了更正此问题,尝试使用“term_merge”和“taxonomy_manager”模块。 “term_merge”提供了一个用于删除重复项的界面,并且它能够设置一次加载多少项的限制,以防止耗尽数据库服务器的内存限制。但是,对于我的用例,我什至无法加载位于 /admin/structure/taxonomy/[My-Vocabulary]/merge 的配置屏幕,更不用说在 /admin/structure/taxonomy/[My -Vocabulary]/merge/duplicates,因为尽管所述限制设置为 1024M,但它们都耗尽了内存限制。
为了解决这个问题,我编写了一个自定义模块,它调用 term_merge 模块中的 term_merge 函数。由于该项目中只有一个节点包使用了相关分类词汇,因此我可以安全地编写自己的逻辑来合并重复的术语,而无需使用 term_merge 模块提供的功能,但我想使用它,因为它是为此目的而设计的,并且理论上可以实现更安全的过程。
我的模块提供了一个页面回调以及获取引用重复分类术语的 TID 列表的逻辑。这是包含对 term_merge 函数的调用的代码:
//Use first element, with lowest TID value, as the 'trunk'
// which all other terms will be merged into
$trunk = $tids[0];
//Remove first element from branch array, to ensure the trunk
//is not being merged into itself
array_shift($tids);
//Set the merge settings array, similarly to the default values
//which are given in _term_merge_batch_process of term_merge.batch.inc
$merge_settings = array(
'term_branch_keep' => FALSE,
'merge_fields' => array(),
'keep_only_unique' => TRUE,
'redirect' => -1,
'synonyms' => array(),
);
term_merge($tids, $trunk, $merge_settings);
这不会导致任何合并条款,也不会在 Watchdog 或网络服务器日志中提供任何错误或通知。
我还尝试为要合并的每个单独的重复 TID 调用 term_merge,而不是使用整个 TID 数组。
我将不胜感激有关如何以编程方式最好地使用 term_merge 函数的任何意见,或者允许我从大型数据库中删除许多重复术语的替代方法,其中一些术语有数千个重复项。
作为参考,这里是提供有关 term_merge 中采用的参数的信息的 cmets,可在贡献的 term_merge 模块的 term_merge.module 中找到:
/**
* Merge terms one into another using batch API.
*
* @param array $term_branch
* A single term tid or an array of term tids to be merged, aka term branches
* @param int $term_trunk
* The tid of the term to merge term branches into, aka term trunk
* @param array $merge_settings
* Array of settings that control how merging should happen. Currently
* supported settings are:
* - term_branch_keep: (bool) Whether the term branches should not be
* deleted, also known as "merge only occurrences" option
* - merge_fields: (array) Array of field names whose values should be
* merged into the values of corresponding fields of term trunk (until
* each field's cardinality limit is reached)
* - keep_only_unique: (bool) Whether after merging within one field only
* unique taxonomy term references should be kept in other entities. If
* before merging your entity had 2 values in its taxonomy term reference
* field and one was pointing to term branch while another was pointing to
* term trunk, after merging you will end up having your entity
* referencing to the same term trunk twice. If you pass TRUE in this
* parameter, only a single reference will be stored in your entity after
* merging
* - redirect: (int) HTTP code for redirect from $term_branch to
* $term_trunk, 0 stands for the default redirect defined in Redirect
* module. Use constant TERM_MERGE_NO_REDIRECT to denote not creating any
* HTTP redirect. Note: this parameter requires Redirect module enabled,
* otherwise it will be disregarded
* - synonyms: (array) Array of field names of trunk term into which branch
* terms should be added as synonyms (until each field's cardinality limit
* is reached). Note: this parameter requires Synonyms module enabled,
* otherwise it will be disregarded
* - step: (int) How many term branches to merge per script run in batch. If
* you are hitting time or memory limits, decrease this parameter
*/
【问题讨论】:
标签: drupal drupal-7 drupal-taxonomy