{"action":"created","comment":{"url":"https://api.github.com/repos/openscholar/openscholar/pulls/comments/59670105","id":59670105,"diff_hunk":"@@ -2825,3 +2833,216 @@ function os_page_build(&$page) {\n     $main_content_display = TRUE;\n   }\n }\n+\n+\n+/**\n+ * The callback function to declare the os user migration ownership form.\n+ *\n+ * @param $form\n+ * @param $form_state\n+ */\n+function os_user_migration_ownership($form, &$form_state) {\n+\n+  $form['primary_user'] = array(\n+    '#type' => 'textfield',\n+    '#required' => TRUE,\n+    '#title' => t('Primary user'),\n+    '#description' => t('The target content user'),\n+    '#size' => 30,\n+    '#maxlength' => 60,\n+    '#autocomplete_path' => 'user/autocomplete',\n+  );\n+\n+  $form['secondary_user'] = array(\n+    '#type' => 'textfield',\n+    '#required' => TRUE,\n+    '#title' => t('Secondary user'),\n+    '#description' => t('The target user that will be the new content owner'),\n+    '#size' => 30,\n+    '#maxlength' => 60,\n+    '#autocomplete_path' => 'user/autocomplete',\n+  );\n+\n+  $form['batch_cycles'] = array(\n+    '#type' => 'textfield',\n+    '#required' => TRUE,\n+    '#title' => t('Number of items'),\n+    '#description' => t('Set a limit of how many items to process for each content migration batch.'),\n+    '#size' => 30,\n+    '#maxlength' => 60,\n+    '#default_value' => 250,\n+  );\n+\n+  # a drupal form submit button\n+  $form['submit'] = array(\n+    '#value' => t('Change ownership'),\n+    '#description' => t('Change the content ownership from primary user into secondary user'),\n+    '#type' => 'submit',\n+  );\n+\n+  return $form;\n+}\n+\n+\n+/**\n+ * Add a validate handler/function to the form.\n+ */\n+function os_user_migration_ownership_validate($form, &$form_state) {\n+  global $user;\n+\n+  // The primary user name.\n+  $primary_name = trim($form_state['values']['primary_user']);\n+\n+  // The secondary user name.\n+  $secondary_name = trim($form_state['values']['secondary_user']);\n+\n+  // The number of items.\n+  $items_number = trim($form_state['values']['batch_cycles']);\n+\n+  // Return early in case one of the fields is empty.\n+  if (empty($primary_name) || empty($secondary_name) || empty($items_number)) {\n+    return;\n+  }\n+\n+  //  In case the \"primary\" user does not exists.\n+  if (!$primary_user = user_load_by_name($primary_name)) {\n+    form_set_error('primary_user', t('Primary user does not exists'));\n+  }\n+\n+  //  In case the \"secondary\" user does not exists.\n+  if (!$secondary_user = user_load_by_name($secondary_name)) {\n+    form_set_error('secondary_user', t('Secondary user does not exists'));\n+  }\n+\n+  // Exit early in case one of the users does not exists.\n+  if (empty($primary_user) || empty($secondary_user)) {\n+    return;\n+  }\n+\n+  // In case the \"secondary user\" and the current logged in user are the same user.\n+  if ($secondary_user->uid == $user->uid) {\n+    form_set_error('secondary_user', t('The secondary user must not be yourself, You cannot change ownership of your own content.'));\n+    return;\n+  }\n+\n+  // In case both users are the same user.\n+  if ($primary_user->uid === $secondary_user->uid) {\n+    form_set_error('secondary_user', t('The secondary user must not be the same as the primary user'));\n+    return;\n+  }\n+\n+  // In case we have no errors then add the users objects.\n+  $form_state['values']['primary_user'] = $primary_user;\n+  $form_state['values']['secondary_user'] = $secondary_user;\n+}\n+\n+/**\n+ * Add a submit handler/function to the form.\n+ *\n+ * This will add a completion message to the screen when the\n+ * form successfully processes\n+ */\n+function os_user_migration_ownership_submit($form, &$form_state) {\n+  drupal_set_message('Done!');\n+  return;\n+\n+  // The primary user.\n+  $primary_user = $form_state['values']['primary_user'];\n+\n+  // The secondary user.\n+  $secondary_user = $form_state['values']['secondary_user'];\n+\n+  // Get all of the users content.\n+  foreach (array('node', 'taxonomy_term') as $entity_type) {\n+    $entities = os_user_get_user_content($secondary_user->uid, $entity_type);\n+\n+    // Exit early in case we have no entities.\n+    if (!$entities) {\n+      return;\n+    }\n+\n+    // Process and change the entity ownership in batches.\n+    $batches = array_chunk($entities, $form_state['values']['batch_cycles']);\n+    foreach ($batches as $batch) {\n+      $operations = array(\n+        array('os_user_block_user', array($secondary->uid)),\n+//        array('os_user_change_content_ownership', array($secondary->uid, 'node', $batch)),\n+      );\n+\n+      $batch = array(\n+        'operations' => $operations,\n+        'finished' => '',\n+        'title' => t('Processing...'),\n+        'init_message' => t('Starting to switch content ownership from: @primary to: @secondary', array('@primary' => $primary_user->name, '@secondary' => $secondary_user->name)),\n+        'progress_message' => t('Processed @current out of @total.'),\n+        'error_message' => t('Changing ownership process failed.'),\n+      );\n+      batch_set($batch);\n+    }\n+  }\n+}\n+\n+/**\n+ * Change the content author.\n+ *\n+ * @param $uid\n+ *   The content author - user ID.\n+ * @param $entity_type\n+ *   The target entity type.\n+ * @return array|bool\n+ */\n+function os_user_get_user_content($uid, $entity_type) {\n+\n+  // Get all of the target entities.\n+  $query = new EntityFieldQuery();\n+  $query\n+    ->entityCondition('entity_type', $entity_type)\n+    ->propertyCondition('uid', $uid);\n+\n+  $result = $query->execute();\n+\n+  // In case their is no related content.\n+  if (!$result[$entity_type]) {\n+    return FALSE;\n+  }\n+\n+  return array_keys($result[$entity_type]);\n+}\n+\n+/**\n+ * Callback to handle the batch cycle.\n+ *\n+ * @param $uid\n+ *  The new entity owner - user ID","path":"openscholar/modules/os/os.module","position":199,"original_position":199,"commit_id":"a4faf61c8cbc48251ae1adf0be89e83bd7d02f4b","original_commit_id":"a4faf61c8cbc48251ae1adf0be89e83bd7d02f4b","user":{"login":"RoySegall","id":1222368,"avatar_url":"https://avatars.githubusercontent.com/u/1222368?v=3","gravatar_id":"","url":"https://api.github.com/users/RoySegall","html_url":"https://github.com/RoySegall","followers_url":"https://api.github.com/users/RoySegall/followers","following_url":"https://api.github.com/users/RoySegall/following{/other_user}","gists_url":"https://api.github.com/users/RoySegall/gists{/gist_id}","starred_url":"https://api.github.com/users/RoySegall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RoySegall/subscriptions","organizations_url":"https://api.github.com/users/RoySegall/orgs","repos_url":"https://api.github.com/users/RoySegall/repos","events_url":"https://api.github.com/users/RoySegall/events{/privacy}","received_events_url":"https://api.github.com/users/RoySegall/received_events","type":"User","site_admin":false},"body":"Wrong indentation.","created_at":"2016-04-14T06:54:04Z","updated_at":"2016-04-14T06:54:04Z","html_url":"https://github.com/openscholar/openscholar/pull/8280#discussion_r59670105","pull_request_url":"https://api.github.com/repos/openscholar/openscholar/pulls/8280","_links":{"self":{"href":"https://api.github.com/repos/openscholar/openscholar/pulls/comments/59670105"},"html":{"href":"https://github.com/openscholar/openscholar/pull/8280#discussion_r59670105"},"pull_request":{"href":"https://api.github.com/repos/openscholar/openscholar/pulls/8280"}}},"pull_request":{"url":"https://api.github.com/repos/openscholar/openscholar/pulls/8280","id":66311563,"html_url":"https://github.com/openscholar/openscholar/pull/8280","diff_url":"https://github.com/openscholar/openscholar/pull/8280.diff","patch_url":"https://github.com/openscholar/openscholar/pull/8280.patch","issue_url":"https://api.github.com/repos/openscholar/openscholar/issues/8280","number":8280,"state":"open","locked":false,"title":"WIP: Migration of user id in a single install","user":{"login":"YaronMiro","id":3907724,"avatar_url":"https://avatars.githubusercontent.com/u/3907724?v=3","gravatar_id":"","url":"https://api.github.com/users/YaronMiro","html_url":"https://github.com/YaronMiro","followers_url":"https://api.github.com/users/YaronMiro/followers","following_url":"https://api.github.com/users/YaronMiro/following{/other_user}","gists_url":"https://api.github.com/users/YaronMiro/gists{/gist_id}","starred_url":"https://api.github.com/users/YaronMiro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/YaronMiro/subscriptions","organizations_url":"https://api.github.com/users/YaronMiro/orgs","repos_url":"https://api.github.com/users/YaronMiro/repos","events_url":"https://api.github.com/users/YaronMiro/events{/privacy}","received_events_url":"https://api.github.com/users/YaronMiro/received_events","type":"User","site_admin":false},"body":"#7961","created_at":"2016-04-13T12:21:12Z","updated_at":"2016-04-14T06:54:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"30b0bcc5d59b21bb067fbb33cb7f40b74d16598a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/openscholar/openscholar/pulls/8280/commits","review_comments_url":"https://api.github.com/repos/openscholar/openscholar/pulls/8280/comments","review_comment_url":"https://api.github.com/repos/openscholar/openscholar/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openscholar/openscholar/issues/8280/comments","statuses_url":"https://api.github.com/repos/openscholar/openscholar/statuses/a4faf61c8cbc48251ae1adf0be89e83bd7d02f4b","head":{"label":"openscholar:7961","ref":"7961","sha":"a4faf61c8cbc48251ae1adf0be89e83bd7d02f4b","user":{"login":"openscholar","id":611073,"avatar_url":"https://avatars.githubusercontent.com/u/611073?v=3","gravatar_id":"","url":"https://api.github.com/users/openscholar","html_url":"https://github.com/openscholar","followers_url":"https://api.github.com/users/openscholar/followers","following_url":"https://api.github.com/users/openscholar/following{/other_user}","gists_url":"https://api.github.com/users/openscholar/gists{/gist_id}","starred_url":"https://api.github.com/users/openscholar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openscholar/subscriptions","organizations_url":"https://api.github.com/users/openscholar/orgs","repos_url":"https://api.github.com/users/openscholar/repos","events_url":"https://api.github.com/users/openscholar/events{/privacy}","received_events_url":"https://api.github.com/users/openscholar/received_events","type":"Organization","site_admin":false},"repo":{"id":1440092,"name":"openscholar","full_name":"openscholar/openscholar","owner":{"login":"openscholar","id":611073,"avatar_url":"https://avatars.githubusercontent.com/u/611073?v=3","gravatar_id":"","url":"https://api.github.com/users/openscholar","html_url":"https://github.com/openscholar","followers_url":"https://api.github.com/users/openscholar/followers","following_url":"https://api.github.com/users/openscholar/following{/other_user}","gists_url":"https://api.github.com/users/openscholar/gists{/gist_id}","starred_url":"https://api.github.com/users/openscholar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openscholar/subscriptions","organizations_url":"https://api.github.com/users/openscholar/orgs","repos_url":"https://api.github.com/users/openscholar/repos","events_url":"https://api.github.com/users/openscholar/events{/privacy}","received_events_url":"https://api.github.com/users/openscholar/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openscholar/openscholar","description":"OpenScholar project ","fork":false,"url":"https://api.github.com/repos/openscholar/openscholar","forks_url":"https://api.github.com/repos/openscholar/openscholar/forks","keys_url":"https://api.github.com/repos/openscholar/openscholar/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openscholar/openscholar/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openscholar/openscholar/teams","hooks_url":"https://api.github.com/repos/openscholar/openscholar/hooks","issue_events_url":"https://api.github.com/repos/openscholar/openscholar/issues/events{/number}","events_url":"https://api.github.com/repos/openscholar/openscholar/events","assignees_url":"https://api.github.com/repos/openscholar/openscholar/assignees{/user}","branches_url":"https://api.github.com/repos/openscholar/openscholar/branches{/branch}","tags_url":"https://api.github.com/repos/openscholar/openscholar/tags","blobs_url":"https://api.github.com/repos/openscholar/openscholar/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openscholar/openscholar/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openscholar/openscholar/git/refs{/sha}","trees_url":"https://api.github.com/repos/openscholar/openscholar/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openscholar/openscholar/statuses/{sha}","languages_url":"https://api.github.com/repos/openscholar/openscholar/languages","stargazers_url":"https://api.github.com/repos/openscholar/openscholar/stargazers","contributors_url":"https://api.github.com/repos/openscholar/openscholar/contributors","subscribers_url":"https://api.github.com/repos/openscholar/openscholar/subscribers","subscription_url":"https://api.github.com/repos/openscholar/openscholar/subscription","commits_url":"https://api.github.com/repos/openscholar/openscholar/commits{/sha}","git_commits_url":"https://api.github.com/repos/openscholar/openscholar/git/commits{/sha}","comments_url":"https://api.github.com/repos/openscholar/openscholar/comments{/number}","issue_comment_url":"https://api.github.com/repos/openscholar/openscholar/issues/comments{/number}","contents_url":"https://api.github.com/repos/openscholar/openscholar/contents/{+path}","compare_url":"https://api.github.com/repos/openscholar/openscholar/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openscholar/openscholar/merges","archive_url":"https://api.github.com/repos/openscholar/openscholar/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openscholar/openscholar/downloads","issues_url":"https://api.github.com/repos/openscholar/openscholar/issues{/number}","pulls_url":"https://api.github.com/repos/openscholar/openscholar/pulls{/number}","milestones_url":"https://api.github.com/repos/openscholar/openscholar/milestones{/number}","notifications_url":"https://api.github.com/repos/openscholar/openscholar/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openscholar/openscholar/labels{/name}","releases_url":"https://api.github.com/repos/openscholar/openscholar/releases{/id}","deployments_url":"https://api.github.com/repos/openscholar/openscholar/deployments","created_at":"2011-03-04T16:39:08Z","updated_at":"2016-04-10T12:03:58Z","pushed_at":"2016-04-14T06:51:52Z","git_url":"git://github.com/openscholar/openscholar.git","ssh_url":"git@github.com:openscholar/openscholar.git","clone_url":"https://github.com/openscholar/openscholar.git","svn_url":"https://github.com/openscholar/openscholar","homepage":"http://theopenscholar.org","size":189265,"stargazers_count":158,"watchers_count":158,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":78,"mirror_url":null,"open_issues_count":420,"forks":78,"open_issues":420,"watchers":158,"default_branch":"SCHOLAR-3.x"}},"base":{"label":"openscholar:SCHOLAR-3.x","ref":"SCHOLAR-3.x","sha":"cda2ff814c2d3cf269813ef4c28ef6e4594e958a","user":{"login":"openscholar","id":611073,"avatar_url":"https://avatars.githubusercontent.com/u/611073?v=3","gravatar_id":"","url":"https://api.github.com/users/openscholar","html_url":"https://github.com/openscholar","followers_url":"https://api.github.com/users/openscholar/followers","following_url":"https://api.github.com/users/openscholar/following{/other_user}","gists_url":"https://api.github.com/users/openscholar/gists{/gist_id}","starred_url":"https://api.github.com/users/openscholar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openscholar/subscriptions","organizations_url":"https://api.github.com/users/openscholar/orgs","repos_url":"https://api.github.com/users/openscholar/repos","events_url":"https://api.github.com/users/openscholar/events{/privacy}","received_events_url":"https://api.github.com/users/openscholar/received_events","type":"Organization","site_admin":false},"repo":{"id":1440092,"name":"openscholar","full_name":"openscholar/openscholar","owner":{"login":"openscholar","id":611073,"avatar_url":"https://avatars.githubusercontent.com/u/611073?v=3","gravatar_id":"","url":"https://api.github.com/users/openscholar","html_url":"https://github.com/openscholar","followers_url":"https://api.github.com/users/openscholar/followers","following_url":"https://api.github.com/users/openscholar/following{/other_user}","gists_url":"https://api.github.com/users/openscholar/gists{/gist_id}","starred_url":"https://api.github.com/users/openscholar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openscholar/subscriptions","organizations_url":"https://api.github.com/users/openscholar/orgs","repos_url":"https://api.github.com/users/openscholar/repos","events_url":"https://api.github.com/users/openscholar/events{/privacy}","received_events_url":"https://api.github.com/users/openscholar/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openscholar/openscholar","description":"OpenScholar project ","fork":false,"url":"https://api.github.com/repos/openscholar/openscholar","forks_url":"https://api.github.com/repos/openscholar/openscholar/forks","keys_url":"https://api.github.com/repos/openscholar/openscholar/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openscholar/openscholar/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openscholar/openscholar/teams","hooks_url":"https://api.github.com/repos/openscholar/openscholar/hooks","issue_events_url":"https://api.github.com/repos/openscholar/openscholar/issues/events{/number}","events_url":"https://api.github.com/repos/openscholar/openscholar/events","assignees_url":"https://api.github.com/repos/openscholar/openscholar/assignees{/user}","branches_url":"https://api.github.com/repos/openscholar/openscholar/branches{/branch}","tags_url":"https://api.github.com/repos/openscholar/openscholar/tags","blobs_url":"https://api.github.com/repos/openscholar/openscholar/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openscholar/openscholar/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openscholar/openscholar/git/refs{/sha}","trees_url":"https://api.github.com/repos/openscholar/openscholar/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openscholar/openscholar/statuses/{sha}","languages_url":"https://api.github.com/repos/openscholar/openscholar/languages","stargazers_url":"https://api.github.com/repos/openscholar/openscholar/stargazers","contributors_url":"https://api.github.com/repos/openscholar/openscholar/contributors","subscribers_url":"https://api.github.com/repos/openscholar/openscholar/subscribers","subscription_url":"https://api.github.com/repos/openscholar/openscholar/subscription","commits_url":"https://api.github.com/repos/openscholar/openscholar/commits{/sha}","git_commits_url":"https://api.github.com/repos/openscholar/openscholar/git/commits{/sha}","comments_url":"https://api.github.com/repos/openscholar/openscholar/comments{/number}","issue_comment_url":"https://api.github.com/repos/openscholar/openscholar/issues/comments{/number}","contents_url":"https://api.github.com/repos/openscholar/openscholar/contents/{+path}","compare_url":"https://api.github.com/repos/openscholar/openscholar/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openscholar/openscholar/merges","archive_url":"https://api.github.com/repos/openscholar/openscholar/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openscholar/openscholar/downloads","issues_url":"https://api.github.com/repos/openscholar/openscholar/issues{/number}","pulls_url":"https://api.github.com/repos/openscholar/openscholar/pulls{/number}","milestones_url":"https://api.github.com/repos/openscholar/openscholar/milestones{/number}","notifications_url":"https://api.github.com/repos/openscholar/openscholar/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openscholar/openscholar/labels{/name}","releases_url":"https://api.github.com/repos/openscholar/openscholar/releases{/id}","deployments_url":"https://api.github.com/repos/openscholar/openscholar/deployments","created_at":"2011-03-04T16:39:08Z","updated_at":"2016-04-10T12:03:58Z","pushed_at":"2016-04-14T06:51:52Z","git_url":"git://github.com/openscholar/openscholar.git","ssh_url":"git@github.com:openscholar/openscholar.git","clone_url":"https://github.com/openscholar/openscholar.git","svn_url":"https://github.com/openscholar/openscholar","homepage":"http://theopenscholar.org","size":189265,"stargazers_count":158,"watchers_count":158,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":78,"mirror_url":null,"open_issues_count":420,"forks":78,"open_issues":420,"watchers":158,"default_branch":"SCHOLAR-3.x"}},"_links":{"self":{"href":"https://api.github.com/repos/openscholar/openscholar/pulls/8280"},"html":{"href":"https://github.com/openscholar/openscholar/pull/8280"},"issue":{"href":"https://api.github.com/repos/openscholar/openscholar/issues/8280"},"comments":{"href":"https://api.github.com/repos/openscholar/openscholar/issues/8280/comments"},"review_comments":{"href":"https://api.github.com/repos/openscholar/openscholar/pulls/8280/comments"},"review_comment":{"href":"https://api.github.com/repos/openscholar/openscholar/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openscholar/openscholar/pulls/8280/commits"},"statuses":{"href":"https://api.github.com/repos/openscholar/openscholar/statuses/a4faf61c8cbc48251ae1adf0be89e83bd7d02f4b"}}}}