diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 453bc2494f688666f49e02802d559956c915211a..c7f75b74278e9eb28bf0939c77db48e881b734e4 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,6 +3,7 @@ Feeds 6.x 1.0 XXXXXXXXXXXXXXXXXX -------------------------------- +- #853156 alex_b: Support real updates of terms. - #858684 alex_b: Fix notices when file not found. Feeds 6.x 1.0 Beta 4, 2010-07-25 diff --git a/plugins/FeedsTermProcessor.inc b/plugins/FeedsTermProcessor.inc index 9ed5b42156f30c828617df75c1656ef556556f76..fa714d7eb4dc2657f416e76f99c63fce4835e46d 100644 --- a/plugins/FeedsTermProcessor.inc +++ b/plugins/FeedsTermProcessor.inc @@ -25,10 +25,15 @@ class FeedsTermProcessor extends FeedsProcessor { while ($item = $batch->shiftItem()) { - if (!($tid = $this->existingItemId($item, $source)) || $this->config['update_existing']) { + if (!($tid = $this->existingItemId($item, $source)) || $this->config['update_existing'] != FEEDS_SKIP_EXISTING) { // Map item to a term. - $term = $this->map($item); + $term = array(); + if ($tid && $this->config['update_existing'] == FEEDS_UPDATE_EXISTING) { + $term = (array) taxonomy_get_term($tid, TRUE); + $term = module_invoke_all('feeds_taxonomy_load', $term); + } + $term = $this->map($item, $term); // Check if term name is set, otherwise continue. if (empty($term['name'])) { @@ -109,13 +114,15 @@ class FeedsTermProcessor extends FeedsProcessor { /** * Execute mapping on an item. */ - protected function map($source_item) { - // Prepare term object. - $target_term = array(); + protected function map($source_item, $target_term = array()) { + // Prepare term object, have parent class do the iterating. $target_term['vid'] = $this->config['vocabulary']; - - // Have parent class do the iterating. - return parent::map($source_item, $target_term); + $target_term = parent::map($source_item, $target_term); + // Taxonomy module expects synonyms to be supplied as a single string. + if (isset($target_term['synonyms']) && is_array(isset($target_term['synonyms']))) { + $target_term['synonyms'] = implode("\n", $target_term['synonyms']); + } + return $target_term; } /** @@ -124,7 +131,7 @@ class FeedsTermProcessor extends FeedsProcessor { public function configDefaults() { return array( 'vocabulary' => 0, - 'update_existing' => 0, + 'update_existing' => FEEDS_SKIP_EXISTING, 'mappings' => array(), ); } @@ -145,11 +152,15 @@ class FeedsTermProcessor extends FeedsProcessor { '#options' => $options, '#default_value' => $this->config['vocabulary'], ); - // @todo Implement true updating. $form['update_existing'] = array( - '#type' => 'checkbox', - '#title' => t('Replace existing terms'), - '#description' => t('If an existing term is found for an imported term, replace it. Existing terms will be determined using mappings that are a "unique target".'), + '#type' => 'radios', + '#title' => t('Update existing terms'), + '#description' => t('Select how existing terms should be updated. Existing terms will be determined using mappings that are a "unique target".'), + '#options' => array( + FEEDS_SKIP_EXISTING => 'Do not update existing terms', + FEEDS_REPLACE_EXISTING => 'Replace existing terms', + FEEDS_UPDATE_EXISTING => 'Update existing terms (slower than replacing them)', + ), '#default_value' => $this->config['update_existing'], ); return $form; @@ -165,6 +176,14 @@ class FeedsTermProcessor extends FeedsProcessor { 'description' => t('Name of the taxonomy term.'), 'optional_unique' => TRUE, ), + 'description' => array( + 'name' => t('Term description'), + 'description' => t('Description of the taxonomy term.'), + ), + 'synonyms' => array( + 'name' => t('Term synonyms'), + 'description' => t('One synonym or an array of synonyms of the taxonomy term.'), + ), ); // Let implementers of hook_feeds_term_processor_targets() add their targets. drupal_alter('feeds_term_processor_targets', $targets, $this->config['vocabulary']);