Skip to content
Snippets Groups Projects
Commit 37361158 authored by Alex Barth's avatar Alex Barth
Browse files

#889196 David Goode: Support for non-numeric vocabulary IDs for feature-based vocabularies.

parent 2c274aeb
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
Feeds 6.x 1.0 XXXXXXXXXXXXXXXXXX Feeds 6.x 1.0 XXXXXXXXXXXXXXXXXX
-------------------------------- --------------------------------
- #889196 David Goode: Support for non-numeric vocabulary IDs for feature-based
vocabularies.
- #632920 nickbits, dixon_, David Goode, alex_b et al: Inherit OG, taxonomy, - #632920 nickbits, dixon_, David Goode, alex_b et al: Inherit OG, taxonomy,
language, user properties from parent feed node. Note: Signatures of language, user properties from parent feed node. Note: Signatures of
FeedsProcessor::map(), existingItemId(), FeedsParser::getSourceElement() FeedsProcessor::map(), existingItemId(), FeedsParser::getSourceElement()
......
...@@ -60,8 +60,7 @@ class FeedsTermProcessor extends FeedsProcessor { ...@@ -60,8 +60,7 @@ class FeedsTermProcessor extends FeedsProcessor {
} }
// Set messages. // Set messages.
$vocabularies = taxonomy_get_vocabularies(); $vocabulary = $this->vocabulary();
$vocabulary = $vocabularies[$this->config['vocabulary']];
if ($no_name) { if ($no_name) {
drupal_set_message( drupal_set_message(
format_plural( format_plural(
...@@ -89,8 +88,8 @@ class FeedsTermProcessor extends FeedsProcessor { ...@@ -89,8 +88,8 @@ class FeedsTermProcessor extends FeedsProcessor {
*/ */
public function clear(FeedsBatch $batch, FeedsSource $source) { public function clear(FeedsBatch $batch, FeedsSource $source) {
$deleted = 0; $deleted = 0;
$vocabulary = $this->vocabulary();
$result = db_query("SELECT tid FROM {term_data} WHERE vid = %d", $this->config["vocabulary"]); $result = db_query("SELECT tid FROM {term_data} WHERE vid = %d", $vocabulary->vid);
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {
if (taxonomy_del_term($term->tid) == SAVED_DELETED) { if (taxonomy_del_term($term->tid) == SAVED_DELETED) {
$deleted++; $deleted++;
...@@ -98,8 +97,6 @@ class FeedsTermProcessor extends FeedsProcessor { ...@@ -98,8 +97,6 @@ class FeedsTermProcessor extends FeedsProcessor {
} }
// Set messages. // Set messages.
$vocabularies = taxonomy_get_vocabularies();
$vocabulary = $vocabularies[$this->config['vocabulary']];
if ($deleted) { if ($deleted) {
drupal_set_message(format_plural($deleted, 'Deleted @number term from !vocabulary.', 'Deleted @number terms from !vocabulary.', array('@number' => $deleted, '!vocabulary' => $vocabulary->name))); drupal_set_message(format_plural($deleted, 'Deleted @number term from !vocabulary.', 'Deleted @number terms from !vocabulary.', array('@number' => $deleted, '!vocabulary' => $vocabulary->name)));
} }
...@@ -116,7 +113,8 @@ class FeedsTermProcessor extends FeedsProcessor { ...@@ -116,7 +113,8 @@ class FeedsTermProcessor extends FeedsProcessor {
if (!$target_term) { if (!$target_term) {
$target_term = array(); $target_term = array();
} }
$target_term['vid'] = $this->config['vocabulary']; $vocabulary = $this->vocabulary();
$target_term['vid'] = $vocabulary->vid;
$target_term = parent::map($batch, $target_term); $target_term = parent::map($batch, $target_term);
// Taxonomy module expects synonyms to be supplied as a single string. // Taxonomy module expects synonyms to be supplied as a single string.
if (isset($target_term['synonyms']) && is_array(isset($target_term['synonyms']))) { if (isset($target_term['synonyms']) && is_array(isset($target_term['synonyms']))) {
...@@ -142,7 +140,12 @@ class FeedsTermProcessor extends FeedsProcessor { ...@@ -142,7 +140,12 @@ class FeedsTermProcessor extends FeedsProcessor {
public function configForm(&$form_state) { public function configForm(&$form_state) {
$options = array(0 => t('Select a vocabulary')); $options = array(0 => t('Select a vocabulary'));
foreach (taxonomy_get_vocabularies() as $vid => $vocab) { foreach (taxonomy_get_vocabularies() as $vid => $vocab) {
$options[$vid] = $vocab->name; if (strpos($vocab->module, 'features_') === 0) {
$options[$vocab->module] = $vocab->name;
}
else {
$options[$vid] = $vocab->name;
}
} }
$form = array(); $form = array();
$form['vocabulary'] = array( $form['vocabulary'] = array(
...@@ -186,7 +189,8 @@ class FeedsTermProcessor extends FeedsProcessor { ...@@ -186,7 +189,8 @@ class FeedsTermProcessor extends FeedsProcessor {
), ),
); );
// Let implementers of hook_feeds_term_processor_targets() add their targets. // Let implementers of hook_feeds_term_processor_targets() add their targets.
drupal_alter('feeds_term_processor_targets', $targets, $this->config['vocabulary']); $vocabulary = $this->vocabulary();
drupal_alter('feeds_term_processor_targets', $targets, $vocabulary->vid);
return $targets; return $targets;
} }
...@@ -198,11 +202,33 @@ class FeedsTermProcessor extends FeedsProcessor { ...@@ -198,11 +202,33 @@ class FeedsTermProcessor extends FeedsProcessor {
// The only possible unique target is name. // The only possible unique target is name.
foreach ($this->uniqueTargets($batch) as $target => $value) { foreach ($this->uniqueTargets($batch) as $target => $value) {
if ($target == 'name') { if ($target == 'name') {
if ($tid = db_result(db_query("SELECT tid FROM {term_data} WHERE name = '%s' AND vid = %d", $value, $this->config["vocabulary"]))) { $vocabulary = $this->vocabulary();
if ($tid = db_result(db_query("SELECT tid FROM {term_data} WHERE name = '%s' AND vid = %d", $value, $vocabulary->vid))) {
return $tid; return $tid;
} }
} }
} }
return 0; return 0;
} }
/**
* Return vocabulary to map to.
*
* Feeds supports looking up vocabularies by their module name as part of an
* effort to use the vocabulary.module field as machine name to make
* vocabularies exportable.
*/
protected function vocabulary() {
$vocabularies = taxonomy_get_vocabularies();
if (is_numeric($this->config['vocabulary'])) {
return $vocabularies[$this->config['vocabulary']];
}
else {
foreach ($vocabularies as $vocabulary) {
if ($vocabulary->module == $this->config['vocabulary']) {
return $vocabulary;
}
}
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment