user_deploy.module

Tracking 6.x-1.x branch
  1. drupal
    1. 6 contributions/deploy/modules/user_deploy/user_deploy.module

Deployment API which enables modules to deploy items between servers.

This module manages deployment-related issues for users.

@todo Need to expose a UI for user's to add users to plans by hand.

Functions & methods

NameDescription
user_deployImplementation of hook_deploy().
user_deploy_check_userCheck to see if a user should be added to the deployment plan currently being pushed.
user_deploy_node_deploy_checkImplementation of hook_node_deploy_check().

File

View source
  1. <?php
  2. /**
  3. * @file
  4. * Deployment API which enables modules to deploy items between servers.
  5. *
  6. * This module manages deployment-related issues for users.
  7. *
  8. * @todo
  9. * Need to expose a UI for user's to add users to plans by hand.
  10. */
  11. /**
  12. * Implementation of hook_node_deploy_check().
  13. *
  14. * This is the dependency checking hook for nodes, called when
  15. * a deployment has been requested that includes a node.
  16. *
  17. * @param $node
  18. * The node object being deployed
  19. */
  20. function user_deploy_node_deploy_check($node) {
  21. user_deploy_check_user($node->uid);
  22. }
  23. /**
  24. * Check to see if a user should be added to the deployment plan currently being pushed.
  25. *
  26. * This function goes through the motions of checking whether a user
  27. * should be deployed, or whether it can just be ignored. This is part of the
  28. * dependency checking mechanism for drupal items that refer to users (like for
  29. * instance nodes.)
  30. *
  31. * @param $uid
  32. * The unique identifier for the user being checked.
  33. */
  34. function user_deploy_check_user($uid) {
  35. // Get the remote server info.
  36. $url = variable_get('deploy_server_url', '');
  37. $pid = variable_get('deploy_pid', 0);
  38. // If this user is already in the deployment plan then either
  39. // a) it was added by the user and will get checked down the line or
  40. // b) it was added through dependency checks and its already been
  41. // dealt with. So we just move on in this case.
  42. //
  43. // Also skip past if uid > 1 (IE this is not the admin or anonymous user)
  44. // If anyone knows of a less-ugly way to say that then I'd love to hear
  45. // about it.
  46. if (!deploy_item_is_in_plan($pid, 'user', $uid) && $uid > 1) {
  47. $account = user_load(array('uid' => $uid));
  48. // Does this user exist on the remote server?
  49. $remote_key = deploy_get_remote_key($account->uuid, 'users');
  50. // If not we're going to add it to the deployment plan, with a weight
  51. // of min(weight) - 1.
  52. if (!$remote_key) {
  53. deploy_add_to_plan($pid, 'user', 'User: '. $account->name, $uid, deploy_get_min_weight($pid)-1, DEPLOY_USER_GROUP_WEIGHT);
  54. // Now that we're deploying a user, we need to check all of its
  55. // dependencies (might be able to skip this now that we've eliminated roles)
  56. module_invoke_all('user_deploy_check', $account);
  57. }
  58. }
  59. }
  60. /**
  61. * Implementation of hook_deploy().
  62. *
  63. * Called when an item is being deployed (as opposed to when we're checking
  64. * to see if it can be deployed.)
  65. *
  66. * @param $uid
  67. * Unique identifier for the user we're deploying.
  68. * @return
  69. * The results of our xmlrpc call.
  70. */
  71. function user_deploy($uid) {
  72. // Does this user exist? If not abort.
  73. $account = user_load($uid);
  74. if (empty($account)) {
  75. return xmlrpc_error($xmlrpcusererr + 1, t('User not found'));
  76. }
  77. // add in any authmap info if it exists
  78. $result = db_query("SELECT * from {authmap} WHERE uid = %d", $account->uid);
  79. while ($row = db_fetch_array($result)) {
  80. $auth = "authname_" .$row['module'];
  81. $account->{$auth} = $row['authname'];
  82. }
  83. // Check to see if the user exists on the remote site. If so, set our
  84. // user's UID to the remote user's UID and push. If not, then this will
  85. // be a new user on the other side.
  86. $remote_key = deploy_get_remote_key($account->uuid, 'users');
  87. if ($remote_key) {
  88. $account->uid = $remote_key['uid'];
  89. }
  90. else {
  91. unset($account->uid);
  92. }
  93. // There is some special action that needs to take place on the remote
  94. // server when a user is saved via deployment, so we add this flag to signal
  95. // where this user came from. This is similar to the method used in
  96. // node_deploy().
  97. $account->deploy = TRUE;
  98. return deploy_send(array('user.save'), array($account));
  99. }