function oa_clone_batch_og_vocab in Open Atrium Clone 7.2
Clones a vocab and it's terms.
1 string reference to 'oa_clone_batch_og_vocab'
- _oa_clone_batch_space in ./
oa_clone.module - Recursively clone a Space while setting up a batch for cloning content.
File
- ./
oa_clone.module, line 667
Code
function oa_clone_batch_og_vocab($space, $vocab_vid, $original_space_nid) {
if (($vocab = taxonomy_vocabulary_load($vocab_vid)) && ($relations = og_vocab_relation_get($vocab_vid))) {
$first_relation = reset($relations);
if (variable_get('og_vocab_allow_shared_vocabularies', FALSE) && !empty($first_relation->settings['shared'])) {
// Just save relationship to this vocab.
og_vocab_relation_save($vocab->vid, 'node', $space->nid, $first_relation->settings);
}
else {
$new_vocab = clone $vocab;
unset($new_vocab->vid);
$new_vocab->machine_name = $new_vocab->machine_name . '_' . $space->nid;
taxonomy_vocabulary_save($new_vocab);
if (!empty($new_vocab->vid)) {
og_vocab_relation_save($new_vocab->vid, 'node', $space->nid, $first_relation->settings);
db_query('INSERT into {og_vocab} (vid, entity_type, bundle, settings, field_name) SELECT :vid, entity_type, bundle, settings, field_name FROM {og_vocab} WHERE vid = :old_vid', array(
':vid' => $new_vocab->vid,
':old_vid' => $vocab_vid,
));
// Copy the terms. Currently not further batched as term save is fast.
if ($tree = taxonomy_get_tree($vocab_vid)) {
$saved = array();
foreach ($tree as $term) {
$loaded_term = taxonomy_term_load($term->tid);
$new_term = clone $loaded_term;
unset($new_term->tid);
$new_term->vid = $new_vocab->vid;
if (!empty($term->parents)) {
foreach ($term->parents as $parent_id) {
if (!empty($saved[$parent_id])) {
$new_term->parent[] = $saved[$parent_id];
}
}
}
taxonomy_term_save($new_term);
if (!empty($new_term->tid)) {
$saved[$term->tid] = $new_term->tid;
}
}
}
}
}
}
}