? .git ? .gitignore ? 907064-1_track_imported.patch ? 907064-2_track_imported.patch ? libraries/simplepie.inc Index: feeds.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/feeds/feeds.install,v retrieving revision 1.10 diff -u -p -r1.10 feeds.install --- feeds.install 28 Jul 2010 14:22:50 -0000 1.10 +++ feeds.install 9 Sep 2010 23:02:08 -0000 @@ -187,6 +187,36 @@ function feeds_schema() { 'guid' => array(array('guid', 255)), ), ); + $schema['feeds_term_item'] = array( + 'description' => 'Tracks imported terms.', + 'fields' => array( + 'tid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => 'Imported term id.', + ), + 'id' => array( + 'type' => 'varchar', + 'length' => 128, + 'not null' => TRUE, + 'default' => '', + 'description' => 'The id of the fields object that is the creator of this item.', + ), + 'feed_nid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => t("Node id of the owner feed, if available."), + ), + ), + 'primary key' => array('tid'), + 'indexes' => array( + 'id_feed_nid' => array('id', 'feed_nid'), + 'feed_nid' => array('feed_nid'), + ), + ); $schema['feeds_push_subscriptions'] = array( 'description' => 'PubSubHubbub subscriptions.', 'fields' => array( @@ -513,3 +543,42 @@ function feeds_update_6010() { } return array(); } + +/** + * Add imported flag for terms. + */ +function feeds_update_6011() { + $ret = array(); + $schema = array( + 'description' => 'Tracks imported terms.', + 'fields' => array( + 'tid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => 'Imported term id.', + ), + 'id' => array( + 'type' => 'varchar', + 'length' => 128, + 'not null' => TRUE, + 'default' => '', + 'description' => 'The id of the fields object that is the creator of this item.', + ), + 'feed_nid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => t("Node id of the owner feed, if available."), + ), + ), + 'primary key' => array('tid'), + 'indexes' => array( + 'id_feed_nid' => array('id', 'feed_nid'), + 'feed_nid' => array('feed_nid'), + ), + ); + db_create_table($ret, 'feeds_term_item', $schema); + return $ret; +} Index: feeds.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/feeds/feeds.module,v retrieving revision 1.52 diff -u -p -r1.52 feeds.module --- feeds.module 31 Aug 2010 00:45:54 -0000 1.52 +++ feeds.module 9 Sep 2010 23:02:08 -0000 @@ -350,6 +350,29 @@ function _feeds_nodeapi_node_processor($ } /** + * Implementation of hook_taxonomy(). + */ +function feeds_taxonomy($op = NULL, $type = NULL, $term = NULL) { + if ($type =='term' && $term['tid']) { + switch ($op) { + case 'delete': + db_query("DELETE FROM {feeds_term_item} WHERE tid = %d", $term['tid']); + break; + case 'update': + if (isset($term['importer_id'])) { + db_query("DELETE FROM {feeds_term_item} WHERE tid = %d", $term['tid']); + } + case 'insert': + if (isset($term['importer_id'])) { + $term['id'] = $term['importer_id']; + drupal_write_record('feeds_term_item', $term); + } + break; + } + } +} + +/** * Implementation of hook_form_alter(). */ function feeds_form_alter(&$form, $form_state, $form_id) { Index: plugins/FeedsTermProcessor.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/feeds/plugins/FeedsTermProcessor.inc,v retrieving revision 1.16 diff -u -p -r1.16 FeedsTermProcessor.inc --- plugins/FeedsTermProcessor.inc 8 Sep 2010 21:03:50 -0000 1.16 +++ plugins/FeedsTermProcessor.inc 9 Sep 2010 23:02:08 -0000 @@ -47,6 +47,8 @@ class FeedsTermProcessor extends FeedsPr } // Save the term. + $term['importer_id'] = $this->id; + $term['feed_nid'] = $this->feed_nid; taxonomy_save_term($term); if ($tid) { @@ -89,7 +91,13 @@ class FeedsTermProcessor extends FeedsPr public function clear(FeedsBatch $batch, FeedsSource $source) { $deleted = 0; $vocabulary = $this->vocabulary(); - $result = db_query("SELECT tid FROM {term_data} WHERE vid = %d", $vocabulary->vid); + $result = db_query("SELECT td.tid + FROM {term_data} td + JOIN {feeds_term_item} ft ON td.tid = ft.tid + WHERE td.vid = %d + AND ft.id = '%s' + AND ft.feed_nid = %d", + $vocabulary->vid, $this->id, $source->feed_nid); while ($term = db_fetch_object($result)) { if (taxonomy_del_term($term->tid) == SAVED_DELETED) { $deleted++; Index: tests/feeds_processor_term.test =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/feeds/tests/feeds_processor_term.test,v retrieving revision 1.1 diff -u -p -r1.1 feeds_processor_term.test --- tests/feeds_processor_term.test 9 Sep 2010 22:56:55 -0000 1.1 +++ tests/feeds_processor_term.test 9 Sep 2010 23:02:08 -0000 @@ -89,5 +89,18 @@ class FeedsCSVtoTermsTest extends FeedsW // Import again. $this->importFile('term_import', $this->absolutePath() .'/tests/feeds/users.csv'); $this->assertText('There are no new terms.'); + + // Add a term manually, delete all terms, this term should still stand. + $edit = array( + 'name' => 'Cousin Itt', + ); + $this->drupalPost('admin/content/taxonomy/1/add/term', $edit, t('Save')); + $this->drupalPost('import/term_import/delete-items', array(), t('Delete')); + $this->drupalGet('admin/content/taxonomy/1'); + $this->assertText('Cousin Itt'); + $this->assertNoText('Morticia'); + $this->assertNoText('Fester'); + $this->assertNoText('Gomez'); + $this->assertNoText('Pugsley'); } }