Index: uuid_features.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/uuid_features/uuid_features.module,v retrieving revision 1.1 diff -u -p -r1.1 uuid_features.module --- uuid_features.module 26 Jul 2010 22:16:15 -0000 1.1 +++ uuid_features.module 8 Nov 2010 13:12:57 -0000 @@ -19,6 +19,12 @@ function uuid_features_features_api() { 'default_file' => FEATURES_DEFAULTS_INCLUDED, 'file' => drupal_get_path('module', 'uuid_features') .'/includes/uuid_vocabulary.features.inc', ), + 'uuid_vocabulary_terms' => array( + 'name' => t('Vocabulary with terms'), + 'default_hook' => 'uuid_features_default_vocabularies_terms', + 'default_file' => FEATURES_DEFAULTS_INCLUDED, + 'file' => drupal_get_path('module', 'uuid_features') .'/includes/uuid_vocabulary_terms.features.inc', + ), 'uuid_term' => array( 'name' => t('Taxonomy Term'), 'default_hook' => 'uuid_features_default_terms', Index: includes/uuid_term.features.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/uuid_features/includes/uuid_term.features.inc,v retrieving revision 1.1.2.1 diff -u -p -r1.1.2.1 uuid_term.features.inc --- includes/uuid_term.features.inc 27 Jul 2010 14:42:19 -0000 1.1.2.1 +++ includes/uuid_term.features.inc 8 Nov 2010 13:12:57 -0000 @@ -120,6 +120,13 @@ function uuid_term_features_revert($modu */ function uuid_term_features_rebuild($module) { $terms = module_invoke($module, 'uuid_features_default_terms'); + return uuid_term_features_rebuild($terms); +} + +/** + * Rebuild terms based on UUID from code defaults. + */ +function uuid_term_features_rebuild_terms($terms) { if (!empty($terms)) { foreach ($terms as $data) { $existing = uuid_get_serial_id('term_data', 'tid', $data['uuid']); Index: includes/uuid_vocabulary.features.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/uuid_features/includes/uuid_vocabulary.features.inc,v retrieving revision 1.1 diff -u -p -r1.1 uuid_vocabulary.features.inc --- includes/uuid_vocabulary.features.inc 26 Jul 2010 22:16:15 -0000 1.1 +++ includes/uuid_vocabulary.features.inc 8 Nov 2010 13:12:57 -0000 @@ -90,6 +90,13 @@ function uuid_vocabulary_features_revert */ function uuid_vocabulary_features_rebuild($module) { $vocabs = module_invoke($module, 'uuid_features_default_vocabularies'); + uuid_vocabulary_features_rebuild_vocabs($vocabs); +} + +/** + * Rebuilds terms based on UUID from code defaults. + */ +function uuid_vocabulary_features_rebuild_vocabs($vocabs) { if (!empty($vocabs)) { foreach ($vocabs as $data) { $existing = db_result(db_query('SELECT vid FROM {uuid_vocabulary} WHERE uuid = "%s"', $data['uuid'])); Index: includes/uuid_vocabulary_terms.features.inc =================================================================== RCS file: includes/uuid_vocabulary_terms.features.inc diff -N includes/uuid_vocabulary_terms.features.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ includes/uuid_vocabulary_terms.features.inc 8 Nov 2010 13:12:57 -0000 @@ -0,0 +1,116 @@ + $vocabularies, "terms" => $terms);'; + + $code = implode("\n", $code); + + return array('uuid_features_default_vocabularies_terms' => $code); +} + +/** + * Implementation of hook_features_revert(). + * Deletes new terms before rebuilding all default terms. + */ +function uuid_vocabulary_terms_features_revert($module) { + $feature = features_get_features($module); + $overrides = features_detect_overrides($feature); + if(!empty($overrides['uuid_vocabulary_terms'])) { + $normal = features_get_normal('uuid_vocabulary_terms', $module); + $default = features_get_default('uuid_vocabulary_terms', $module); + + // get new terms not present in default feature + $new_terms = array_udiff($normal['terms'], $default['terms'], '_uuid_vocabulary_terms_compare_func'); + foreach($new_terms as $new_term) { + $tid = uuid_get_serial_id('term_data', 'tid', $new_term['uuid']); + taxonomy_del_term($tid); + } + } + + // resave all terms in default feature + uuid_vocabulary_terms_features_rebuild($module); +} + +/** + * Implementation of hook_features_rebuild(). + * Rebuilds vocab and terms based on UUID from code defaults. + */ +function uuid_vocabulary_terms_features_rebuild($module) { + $vocabularies_and_terms = module_invoke($module, 'uuid_features_default_vocabularies_terms'); + uuid_vocabulary_features_rebuild_vocabs($vocabularies_and_terms['vocabularies']); + uuid_term_features_rebuild_terms($vocabularies_and_terms['terms']); +} + +/** + * Comparison function for udiff. + */ +function _uuid_vocabulary_terms_compare_func($term1, $term2) +{ + if($term1['uuid'] == $term2['uuid']) { + return 0; + } + elseif($term1['uuid'] < $term2['uuid']) { + return 1; + } + else { + return -1; + } +}