You are here

function comment_deploy_check in Deploy - Content Staging 6

Implementation of hook_deploy_check().

Used to manage deployment dependencies. In a perfect world, I would module_invoke_all('comment_deploy_check') here, allowing anyone extending comment to hook in. However to keep complexity down, and acknowledging that its pretty rare that anyone extends comment, I'm just going to manage it by hand right here.

Parameters

$cid: Cid of the comment we're trying to deploy

File

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

Code

function comment_deploy_check($cid) {
  $pid = variable_get('deploy_pid', 0);
  $comment = _comment_load($cid);

  // Does our node exist? If not add it and run its dependency checks
  $nid = $comment->nid;
  if (!deploy_item_is_in_plan($pid, 'node', $nid)) {

    // Does this node exist on the remote server?
    $remote_key = deploy_get_remote_key(deploy_uuid_get_node_uuid($nid), 'node');

    // If not we're going to add it to the deployment plan, with a weight
    // of min(weight) - 1.
    if (!$remote_key) {
      $plan_node = node_load($nid);
      deploy_add_to_plan($pid, 'node', $plan_node->type . ': ' . $plan_node->title, $plan_node->nid, deploy_get_min_weight($pid) - 1, DEPLOY_NODE_GROUP_WEIGHT);
      module_invoke_all('node_deploy_check', $plan_node);
    }
  }

  // Ditto the user
  $uid = $comment->uid;
  if (!deploy_item_is_in_plan($pid, 'user', $uid) && $uid > 1) {
    $account = user_load(array(
      'uid' => $uid,
    ));

    // Does this user exist on the remote server?
    $remote_key = deploy_get_remote_key($account->uuid, 'users');

    // If not we're going to add it to the deployment plan, with a weight
    // of min(weight) - 1.
    if (!$remote_key) {
      deploy_add_to_plan($pid, 'user', 'User: ' . $account->name, $uid, deploy_get_min_weight($pid) - 1, DEPLOY_USER_GROUP_WEIGHT);

      // Now that we're deploying a user, we need to check all of its
      // dependencies (might be able to skip this now that we've eliminated roles)
      module_invoke_all('user_deploy_check', $account);
    }
  }

  // And the parent comment if there is one.
  if ($comment->pid) {
    if (!deploy_item_is_in_plan($pid, 'comment', $comment->pid)) {
      deploy_add_to_plan(variable_get('deploy_pid', 0), 'comment', 'Comment: ' . $comment->pid, $comment->pid, deploy_get_min_weight($pid) - 1, DEPLOY_COMMENT_GROUP_WEIGHT);
      comment_deploy_check($comment->pid);
    }
  }
}