You are here

function uuid_term_features_rebuild in UUID Features Integration 7

Same name and namespace in other branches
  1. 6 includes/uuid_term.features.inc \uuid_term_features_rebuild()

Implements hook_features_rebuild().

Rebuilds terms based on UUID from code defaults.

3 calls to uuid_term_features_rebuild()
uuid_commerce_product_features_rebuild in includes/uuid_commerce_product.features.inc
Implements hook_features_rebuild().
uuid_node_features_rebuild in includes/uuid_node.features.inc
Implements hook_features_rebuild().
uuid_term_features_revert in includes/uuid_term.features.inc
Implements hook_features_revert().
2 string references to 'uuid_term_features_rebuild'
uuid_commerce_product_features_rebuild in includes/uuid_commerce_product.features.inc
Implements hook_features_rebuild().
uuid_node_features_rebuild in includes/uuid_node.features.inc
Implements hook_features_rebuild().

File

includes/uuid_term.features.inc, line 189
Features hooks for the uuid_term features component.

Code

function uuid_term_features_rebuild($module) {
  variable_set('menu_rebuild_needed', FALSE);
  lock_acquire('menu_rebuild');

  // Import the vocabularies first.
  taxonomy_features_rebuild($module);
  field_features_rebuild($module);
  $terms = features_get_default('uuid_term', $module);
  if (!empty($terms)) {

    // Verify that term objects is saved before any references are resolved.
    foreach ($terms as $data) {
      $existing = entity_get_id_by_uuid('taxonomy_term', array(
        $data['uuid'],
      ));
      if (!count($existing)) {
        $voc = taxonomy_vocabulary_machine_name_load($data['vocabulary_machine_name']);

        // Only save the term, if the corresponding vocabulary already exists.
        if ($voc) {
          $term = new stdClass();
          $term->uuid = $data['uuid'];
          $term->vid = $voc->vid;
          $term->name = $data['name'];
          taxonomy_term_save($term);
        }
      }
    }
    $entity_type = 'taxonomy_term';

    // Save all other data and resolve references.
    foreach ($terms as $data) {
      $term = (object) $data;
      $voc = taxonomy_vocabulary_machine_name_load($term->vocabulary_machine_name);
      if ($voc) {
        $term->vid = $voc->vid;
        drupal_alter('uuid_entity_features_rebuild', $entity_type, $term, $data, $module);
        uuid_features_file_field_import($term, 'taxonomy_term', $module);
        entity_uuid_save('taxonomy_term', $term);
      }
    }
    module_invoke_all('uuid_entity_features_rebuild_complete', $entity_type, $terms, $module);
  }
  lock_release('menu_rebuild');
  variable_set('menu_rebuild_needed', TRUE);
}