3

フィード モジュールを使用して、一連の出版物を Drupal コンテンツ タイプに取り込みます。これらは、cron を使用して定期的に実行するように設定されています。次のように動作する 2 つの個別のフィードがあります。

  • フィード 1 (pure_feed) - フィールドの大部分を取り込みます
  • フィード 2 (harvard_format) - 別の URL ソースにアクセスし、コンテンツ タイプの 1 つのフィールドを更新します。

私が抱えている問題は、フィード 2 が (フィード 1 を使用して作成された) 既存のノードを更新するのではなく、常に新しいノードのセットを作成することです。/import でデバッグ オプションを使用すると、フィード 2 の GUID がフィード 1 の GUID と一致することがわかりますが、1 セットのノードを更新するのではなく、2 セットのノードが作成されます。

これは、feeds_items データベース テーブルからの抜粋です。

フィード 1

フィード 2

ご覧のとおり、どちらも同じ GUID を持っていますが、別々のノードにマップされています。2 番目のフィードを最初のフィードと同じノードにマップする方法はありますか?

4

1 に答える 1

2

2番目のフィードが最初のフィードからノードを更新できるようにする何かを一緒にノックしました。これが正しいやり方かどうかはわかりませんが、機能します。これが将来誰かを助ける場合に備えて私がしたことです:

  • FeedsNodeProcessorを拡張するカスタムプロセッサを作成しました
  • FeedsNodeProcessorのすべての関数を新しいクラスにコピーしました。
  • 既存のEntityId関数を次のようにオーバーライドしました(harvard_formatは私のセカンダリフィードであり、pure_feedは私のプライマリフィードです):

保護された関数existingEntityId(FeedsSource $ source、FeedsParserResult $ result){

if($source->id == 'harvard_format') {

  $query = db_select('feeds_item')
    ->fields('feeds_item', array('entity_id'))
    ->condition('feed_nid', $source->feed_nid)
    ->condition('entity_type', $this->entityType())
    ->condition('id', 'pure_feed');

  // Iterate through all unique targets and test whether they do already
  // exist in the database.
  foreach ($this->uniqueTargets($source, $result) as $target => $value) {
    switch ($target) {
      case 'url':
        $entity_id = $query->condition('url', $value)->execute()->fetchField();
        break;
      case 'guid':
        $entity_id = $query->condition('guid', $value)->execute()->fetchField();
        break;
    }
    if (isset($entity_id)) {
      // Return with the content id found.
      return $entity_id;
    }
  }
  return 0;
}
elseif ($nid = parent::existingEntityId($source, $result)) {
  return $nid;
} else {

  // Iterate through all unique targets and test whether they do already
  // exist in the database.
  foreach ($this->uniqueTargets($source, $result) as $target => $value) {
    switch ($target) {
      case 'nid':
        $nid = db_query("SELECT nid FROM {node} WHERE nid = :nid", array(':nid' => $value))->fetchField();
        break;
      case 'title':
        $nid = db_query("SELECT nid FROM {node} WHERE title = :title AND type = :type", array(':title' => $value, ':type' => $this->config['content_type']))->fetchField();
        break;
      case 'feeds_source':
        if ($id = feeds_get_importer_id($this->config['content_type'])) {
          $nid = db_query("SELECT fs.feed_nid FROM {node} n JOIN {feeds_source} fs ON n.nid = fs.feed_nid WHERE fs.id = :id AND fs.source = :source", array(':id' => $id, ':source' => $value))->fetchField();
        }
        break;
    }
    if ($nid) {
      // Return with the first nid found.
      return $nid;
    }
  }
  return 0;
}

}

  • FeedsProcessorからProcess関数とnewItemInfo関数にコピーされます。
  • newItemInfoを次のようにオーバーライドしました。

保護された関数newItemInfo($ entity、$ feed_nid、$ hash =''){

$entity->feeds_item = new stdClass();
$entity->feeds_item->entity_id = 0;
$entity->feeds_item->entity_type = $this->entityType();
// Specify the feed id, otherwise pure_feed's entries in the feeds_item table will be changed to harvard_format
$entity->feeds_item->id = ($this->id == "harvard_format") ? "pure_feed" : $this->id; 
$entity->feeds_item->feed_nid = $feed_nid;
$entity->feeds_item->imported = REQUEST_TIME;
$entity->feeds_item->hash = $hash;
$entity->feeds_item->url = '';
$entity->feeds_item->guid = '';

}

于 2012-12-11T16:55:40.173 に答える