You are here

function comment_deploy in Deploy - Content Staging 6

Implementation of hook_deploy(),

Parameters

$nid: Unique identifier for the node we're deploying.

Return value

The results of our xmlrpc call.

1 string reference to 'comment_deploy'
comment_deploy_comment_admin_overview_submit in modules/comment_deploy/comment_deploy.module
Submit handler for comment_admin_overview_form().

File

modules/comment_deploy/comment_deploy.module, line 107
Deployment API which enables modules to deploy items between servers.

Code

function comment_deploy($cid) {

  // Bail if this node comment exist.
  $comment = _comment_load($cid);
  if (empty($comment)) {
    return xmlrpc_error($xmlrpcusererr + 1, t('Comment not found'));
  }

  // comments do not have a load hook, so we have to add the uuid into the
  // object by hand
  $comment->uuid = deploy_uuid_get_comment_uuid($cid);

  // Comment author, don't bother if user is anon or admin
  if ($comment->uid > 1) {
    $remote_key = deploy_get_remote_key(deploy_uuid_get_user_uuid($comment->uid), 'users');
    $comment->uid = $remote_key['uid'];
  }

  // Comment node. Did you know that if no nid is specified in a comment, the
  // comment will still save without error? Isn't that convenient?
  $remote_key = deploy_get_remote_key(deploy_uuid_get_node_uuid($comment->nid), 'node');
  if (!$remote_key) {
    return xmlrpc_error($xmlrpcusererr + 1, t('Comment node not found.'));
  }
  $comment->nid = $remote_key['nid'];

  // Parent comment, if there is one
  if ($comment->pid) {
    $remote_key = deploy_get_remote_key(deploy_uuid_get_comment_uuid($comment->pid), 'comments');
    $comment->pid = $remote_key['cid'];
  }

  // Normally, like with users and nodes, the uuid is added to the object in the 'load'
  // op of their hook. Comments have no load op, so we have to get it by hand.
  $remote_key = deploy_get_remote_key($comment->uuid, 'comments');
  $comment->cid = isset($remote_key['cid']) ? $remote_key['cid'] : NULL;

  // And we're off.
  $cid = deploy_send(array(
    'comment.save',
  ), array(
    $comment,
  ));
  return $cid;
}