You are here

function taxonomy_term_deploy in Deploy - Content Staging 6

Implementation of hook_deploy().

Parameters

$tid: Unique identifier for the term we're deploying.

Return value

The results of our deployment.

For reference here is how the term needs to be formatted.

[name] => Test [description] => test [parent] => Array ( [247] => 247 ) [relations] => Array ( [247] => 247 [249] => 249 ) [synonyms] => test test [weight] => 5 [vid] => 3 [tid] => 335

File

modules/taxonomy_deploy/taxonomy_deploy.module, line 158
Deployment API which enables modules to deploy items between servers.

Code

function taxonomy_term_deploy($tid) {

  // If there is no term with this tid then bail
  $term = taxonomy_get_term($tid);
  if (!$term) {
    return FALSE;
  }

  // Fill out term object with all the data it needs that taxonomy_get_term() doesn't provide
  // because it sucks.
  //
  // Yes it really is "parent" even though a term can have multiple parents.
  $term->parent = array();
  foreach (taxonomy_get_parents($tid) as $key => $parent) {

    // if the deployment weighting has done its job, then any parent terms
    // should have been deployed prior to this one. If not, then we need to fail out
    $remote_key = deploy_get_remote_key(deploy_uuid_get_term_uuid($key), 'term_data');
    $term->parent[$remote_key['tid']] = $remote_key['tid'];
  }

  // Same thing for related terms.
  $term->relations = array();
  foreach (taxonomy_get_related($tid) as $key => $relation) {

    // If you have circular related terms (which is possible) then one of them has
    // to come up before the other one, which means the other one will not exist
    // remotely. Therefore we can't really fail out when we encounter that situation,
    // therefore when we enounter that situation we just ignore that term and move on.
    // It all works out because when the related term comes up, it will link them
    // both at save anyways.
    $remote_key = deploy_get_remote_key(deploy_uuid_get_term_uuid($key), 'term_data');
    $term->relations[$remote_key['tid']] = $remote_key['tid'];
  }

  // Synch up with the remote vocabulary, which in theory can't not exist at this point.
  $remote_key = deploy_get_remote_key(deploy_uuid_get_vocabulary_uuid($term->vid), 'vocabulary');
  $term->vid = $remote_key['vid'];

  // Synonyms are much easier thankfully.
  $term->synonyms = implode("\n", taxonomy_get_synonyms($tid));

  // Mormally, like with users and nodes, the uuid is added to the object in the 'load'
  // op of their hook. Taxonomy terms and vocabs have no load op, so we have to
  // get it by hand.
  $uuid = deploy_uuid_get_term_uuid($tid);
  $remote_key = deploy_get_remote_key($uuid, 'term_data');
  $term->tid = isset($remote_key['tid']) ? $remote_key['tid'] : NULL;
  $term->uuid = $uuid;
  return deploy_send(array(
    'taxonomy.saveTerm',
  ), array(
    $term,
  ));
}