2016-10-09 9 views
1

私は研究目的で使用されているデータベースを持っています。残念なことに、この研究では、あるアルゴリズムの最初のインスタンスの元のTIDを再利用するのではなく、誤って重複したタクソノミの用語を作成してしまったアルゴリズムが長時間進行してしまいました。Drupal:大規模な複製と分類用語のマージ

これを修正するために、 "term_merge"と "taxonomy_manager"モジュールを使用しようとしました。 "term_merge"は、重複を除去するためのインタフェースを提供し、データベースサーバのメモリ制限を使い果たすのを防ぐために、時間としてロードする用語の数を制限することができます。しかし、私のユースケースでは、/ admin/structure/taxonomy/[My-Vocabulary]/mergeにある設定画面を読み込むことができず、/ admin/structure/taxonomy/[My -Vocabulary]/merge/duplicatesを指定します。これらの両方が1024Mに設定されているにもかかわらずメモリ制限を使い果たします。

これを回避するために、term_mergeモジュールにあるterm_merge関数を呼び出すカスタムモジュールを作成しました。このプロジェクトには問題のタクソノミー語彙を使用するノードバンドルが1つしかないので、term_mergeモジュールによって提供される機能を使用することなく、重複する用語をマージするための自分のロジックを安全に書くことができます。理論的にはより安全なプロセスを可能にするために、この目的のために設計されているようにそれを利用してください。

私のモジュールは、ページのコールバックと、重複したタクソノミー用語を参照するTIDのリストを調達するロジックを提供します。

//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); 

これは、任意のマージされた用語にはなりません。または、ウォッチドッグやウェブサーバのログにエラーや通知を提供しない:ここでterm_merge関数の呼び出しが含まれているコードがあります。

TIDの配列全体を使用するのではなく、各個別の重複TIDをマージするためにterm_mergeを呼び出してみました。

term_merge関数をプログラム的に使用するにはどのようにしたらよいか、あるいはいくつかの用語には何千もの重複がある大きなデータベースから多くの重複項を削除することができます。ここでは参考のため

は、term_mergeで撮影したパラメータに関する情報を提供するコメントが貢献し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 
*/ 

答えて

0

機能term_merge以降に開発されたように思わフォームのサブミットを処理するために関数内で使用されるインテントで、私のカスタムモジュールは、batch_processが呼び出されない方法でそれを使います。

は、明示的にこの次解きを呼び出す:

batch_process() 

ませ引数が関数に渡さする必要はありません。

+0

ソリューションであると思われる場合は、自分の回答を受け入れることができます。 – pal4life

関連する問題