{"action":"created","comment":{"url":"https://api.github.com/repos/DoSomething/phoenix/pulls/comments/114334224","pull_request_review_id":35791377,"id":114334224,"diff_hunk":"@@ -0,0 +1,303 @@\n+<?php\n+/**\n+ * Keeper-Upper Script to export Signups, Reportbacks, and whatever else from drupal into Rogue.\n+ * This is to be run on a recurring basis after the big migration has completed. \n+ *\n+ * to run:\n+ * drush --script-path=../scripts/ php-script rogue-keeper-upper.php\n+ */\n+\n+// 1. New signups\n+// Pick up from where we left off, if we want to\n+$last_saved = variable_get('dosomething_rogue_last_signup_kept_up', NULL);\n+\n+if ($last_saved) {\n+  $signups = db_query(\"SELECT signups.sid, signups.uid, signups.nid, signups.run_nid, signups.source, signups.timestamp, rb.quantity, rb.why_participated, rb.rbid, rb.flagged, rb.updated\n+                      FROM dosomething_signup signups\n+                      LEFT JOIN dosomething_reportback rb ON signups.uid = rb.uid AND signups.nid = rb.nid AND signups.run_nid = rb.run_nid\n+                      WHERE signups.sid > $last_saved AND signups.sid NOT IN (SELECT sid FROM dosomething_rogue_signups)\n+                      ORDER BY signups.sid\");\n+}\n+else {\n+  $signups = db_query('SELECT signups.sid, signups.uid, signups.nid, signups.run_nid, signups.source, signups.timestamp, rb.quantity, rb.why_participated, rb.rbid, rb.flagged, rb.updated\n+                      FROM dosomething_signup signups\n+                      LEFT JOIN dosomething_reportback rb ON signups.uid = rb.uid AND signups.nid = rb.nid AND signups.run_nid = rb.run_nid\n+                      WHERE signups.sid NOT IN (SELECT sid FROM dosomething_rogue_signups)\n+                      ORDER BY signups.sid');\n+}\n+\n+$client = dosomething_rogue_client();\n+\n+foreach ($signups as $signup) {\n+  $data = [];\n+\n+  echo 'Trying sid ' . $signup->sid . '...' . PHP_EOL;\n+\n+  $northstar_user = dosomething_northstar_get_user($signup->uid, 'drupal_id');\n+\n+  // Only try to send to Rogue if we have a Northstar ID\n+  if (isset($northstar_user)) {\n+    // Match Rogue's timestamp format\n+    $created_at = date('Y-m-d H:i:s', $signup->timestamp);\n+\n+    // Format signup data\n+    $data = [\n+      'northstar_id' => $northstar_user->id,\n+      'campaign_id' => $signup->nid,\n+      'campaign_run_id' => $signup->run_nid,\n+      'do_not_forward' => TRUE,\n+      'source' => $signup->source,\n+      'created_at' => $created_at,\n+      'updated_at' => $created_at, // Set updated same as created, will be overwritten if there was a RB submitted\n+    ];\n+\n+    // Include all the Reportback data and files if they exist\n+    if ($signup->rbid) {\n+      // Pull the quantity and why\n+      $data['quantity'] = $signup->quantity;\n+      $data['why_participated'] = $signup->why_participated;\n+\n+      // Match Rogue's timestamp format\n+      $updated_at = date('Y-m-d H:i:s', $signup->updated);\n+      $data['updated_at'] = $updated_at;\n+    }\n+\n+    // Send the request to Rogue\n+    try {\n+      $response = $client->postSignup($data);\n+\n+      // Make sure we get a successful response\n+      if ($response) {\n+        // Store signup reference\n+        dosomething_rogue_store_rogue_signup_references($signup->sid, $response);\n+\n+        echo 'Migrated signup ' . $signup->sid . ' to Rogue.' . PHP_EOL;\n+\n+        // Set where we left off so we don't keep trying this one forever\n+        variable_set('dosomething_rogue_last_signup_kept_up', $signup->sid);\n+\n+        // Send to StatHat\n+        if (module_exists('stathat')) {\n+          stathat_send_ez_count('drupal - Rogue - signup migrated - count', 1);\n+        }\n+      }\n+\n+      // Handle getting a 404\n+      if (!$response) {\n+        // Put request in failed table for future investigation\n+        dosomething_rogue_handle_migration_failure($data, $signup->sid, $signup->rbid, $fids);\n+\n+        // Set where we left off so we don't keep trying this one forever\n+        variable_set('dosomething_rogue_last_signup_kept_up', $signup->sid);\n+\n+      }\n+    }\n+    catch (GuzzleHttp\\Exception\\ServerException $e) {\n+      // These aren't yet caught by Gateway\n+\n+      // Put request in failed table for future investigation\n+      dosomething_rogue_handle_migration_failure($data, $signup->sid, $signup->rbid, $fids);\n+\n+      // Set where we left off so we don't keep trying this one forever\n+      variable_set('dosomething_rogue_last_signup_kept_up', $signup->sid);\n+    }\n+    catch (DoSomething\\Gateway\\Exceptions\\ApiException $e) {\n+      // Put request in failed table for future investigation\n+      dosomething_rogue_handle_migration_failure($data, $signup->sid, $signup->rbid, $fids);\n+\n+      // Set where we left off so we don't keep trying this one forever\n+      variable_set('dosomething_rogue_last_signup_kept_up', $signup->sid);\n+    }\n+  }\n+  else {\n+    echo 'No northstar id, that is terrible ' . $signup->sid . PHP_EOL;","path":"scripts/rogue-keeper-upper.php","position":113,"original_position":113,"commit_id":"6156b7d43a9ea7130977dda783eed52aef1a5802","original_commit_id":"6156b7d43a9ea7130977dda783eed52aef1a5802","user":{"login":"chloealee","id":9019452,"avatar_url":"https://avatars1.githubusercontent.com/u/9019452?v=3","gravatar_id":"","url":"https://api.github.com/users/chloealee","html_url":"https://github.com/chloealee","followers_url":"https://api.github.com/users/chloealee/followers","following_url":"https://api.github.com/users/chloealee/following{/other_user}","gists_url":"https://api.github.com/users/chloealee/gists{/gist_id}","starred_url":"https://api.github.com/users/chloealee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chloealee/subscriptions","organizations_url":"https://api.github.com/users/chloealee/orgs","repos_url":"https://api.github.com/users/chloealee/repos","events_url":"https://api.github.com/users/chloealee/events{/privacy}","received_events_url":"https://api.github.com/users/chloealee/received_events","type":"User","site_admin":false},"body":"love this message 😂 ","created_at":"2017-05-02T14:39:39Z","updated_at":"2017-05-02T14:39:39Z","html_url":"https://github.com/DoSomething/phoenix/pull/7368#discussion_r114334224","pull_request_url":"https://api.github.com/repos/DoSomething/phoenix/pulls/7368","_links":{"self":{"href":"https://api.github.com/repos/DoSomething/phoenix/pulls/comments/114334224"},"html":{"href":"https://github.com/DoSomething/phoenix/pull/7368#discussion_r114334224"},"pull_request":{"href":"https://api.github.com/repos/DoSomething/phoenix/pulls/7368"}}},"pull_request":{"url":"https://api.github.com/repos/DoSomething/phoenix/pulls/7368","id":118445447,"html_url":"https://github.com/DoSomething/phoenix/pull/7368","diff_url":"https://github.com/DoSomething/phoenix/pull/7368.diff","patch_url":"https://github.com/DoSomething/phoenix/pull/7368.patch","issue_url":"https://api.github.com/repos/DoSomething/phoenix/issues/7368","number":7368,"state":"open","locked":false,"title":"Keeper upper script","user":{"login":"katiecrane","id":4240292,"avatar_url":"https://avatars2.githubusercontent.com/u/4240292?v=3","gravatar_id":"","url":"https://api.github.com/users/katiecrane","html_url":"https://github.com/katiecrane","followers_url":"https://api.github.com/users/katiecrane/followers","following_url":"https://api.github.com/users/katiecrane/following{/other_user}","gists_url":"https://api.github.com/users/katiecrane/gists{/gist_id}","starred_url":"https://api.github.com/users/katiecrane/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/katiecrane/subscriptions","organizations_url":"https://api.github.com/users/katiecrane/orgs","repos_url":"https://api.github.com/users/katiecrane/repos","events_url":"https://api.github.com/users/katiecrane/events{/privacy}","received_events_url":"https://api.github.com/users/katiecrane/received_events","type":"User","site_admin":false},"body":"#### What's this PR do?\r\nThis is the keeper upper script. This script will be run regularly to keep Rogue up to date with the latest Phoenix data. There are 3 types of updates sent:\r\n1. New signup\r\n2. New reportback/signup update\r\n    - at least one new post\r\n    - updating the `quantity` on the signup\r\n    - updating the `why_participated` on the signup\r\n3. Quantity or why update\r\n    - In Phoenix, this would be an update on just the reportback without adding a new image\r\n    - In Rogue, this would be a signup update\r\n\r\nThere are also three parts to the migration that do those 3 things in that order. We can see if signups or posts are in Rogue by using the reference tables, but for type 3 we have to check on timestamps. This is done by logging the timestamp of the most recent item (in this category) we sent. This is the timestamp on the item, not when we sent it. Then we use that information to see if there are any new quantity or why updates that we need to send over.\r\n\r\n#### How should this be reviewed?\r\nI suggest looking through each piece of the script as its own unit because they don't really interact. \r\n\r\n#### Any background context you want to provide?\r\nDo it for the data 📈 \r\n\r\n#### Relevant tickets\r\nFixes #7367\r\n\r\n#### Checklist\r\n- [ ] Tested on staging.\r\n- [ ] Pinged a PM if this is a larger PR that would benefit from some additional testing love\r\n","created_at":"2017-05-01T21:31:30Z","updated_at":"2017-05-02T14:39:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"399ef53d8c15d3e194ed546f4b205a9155bdacf3","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/DoSomething/phoenix/pulls/7368/commits","review_comments_url":"https://api.github.com/repos/DoSomething/phoenix/pulls/7368/comments","review_comment_url":"https://api.github.com/repos/DoSomething/phoenix/pulls/comments{/number}","comments_url":"https://api.github.com/repos/DoSomething/phoenix/issues/7368/comments","statuses_url":"https://api.github.com/repos/DoSomething/phoenix/statuses/6156b7d43a9ea7130977dda783eed52aef1a5802","head":{"label":"DoSomething:keeper-upper","ref":"keeper-upper","sha":"6156b7d43a9ea7130977dda783eed52aef1a5802","user":{"login":"DoSomething","id":731685,"avatar_url":"https://avatars1.githubusercontent.com/u/731685?v=3","gravatar_id":"","url":"https://api.github.com/users/DoSomething","html_url":"https://github.com/DoSomething","followers_url":"https://api.github.com/users/DoSomething/followers","following_url":"https://api.github.com/users/DoSomething/following{/other_user}","gists_url":"https://api.github.com/users/DoSomething/gists{/gist_id}","starred_url":"https://api.github.com/users/DoSomething/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DoSomething/subscriptions","organizations_url":"https://api.github.com/users/DoSomething/orgs","repos_url":"https://api.github.com/users/DoSomething/repos","events_url":"https://api.github.com/users/DoSomething/events{/privacy}","received_events_url":"https://api.github.com/users/DoSomething/received_events","type":"Organization","site_admin":false},"repo":{"id":13592927,"name":"phoenix","full_name":"DoSomething/phoenix","owner":{"login":"DoSomething","id":731685,"avatar_url":"https://avatars1.githubusercontent.com/u/731685?v=3","gravatar_id":"","url":"https://api.github.com/users/DoSomething","html_url":"https://github.com/DoSomething","followers_url":"https://api.github.com/users/DoSomething/followers","following_url":"https://api.github.com/users/DoSomething/following{/other_user}","gists_url":"https://api.github.com/users/DoSomething/gists{/gist_id}","starred_url":"https://api.github.com/users/DoSomething/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DoSomething/subscriptions","organizations_url":"https://api.github.com/users/DoSomething/orgs","repos_url":"https://api.github.com/users/DoSomething/repos","events_url":"https://api.github.com/users/DoSomething/events{/privacy}","received_events_url":"https://api.github.com/users/DoSomething/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DoSomething/phoenix","description":":fire: The DoSomething.org website & content API.","fork":false,"url":"https://api.github.com/repos/DoSomething/phoenix","forks_url":"https://api.github.com/repos/DoSomething/phoenix/forks","keys_url":"https://api.github.com/repos/DoSomething/phoenix/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DoSomething/phoenix/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DoSomething/phoenix/teams","hooks_url":"https://api.github.com/repos/DoSomething/phoenix/hooks","issue_events_url":"https://api.github.com/repos/DoSomething/phoenix/issues/events{/number}","events_url":"https://api.github.com/repos/DoSomething/phoenix/events","assignees_url":"https://api.github.com/repos/DoSomething/phoenix/assignees{/user}","branches_url":"https://api.github.com/repos/DoSomething/phoenix/branches{/branch}","tags_url":"https://api.github.com/repos/DoSomething/phoenix/tags","blobs_url":"https://api.github.com/repos/DoSomething/phoenix/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DoSomething/phoenix/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DoSomething/phoenix/git/refs{/sha}","trees_url":"https://api.github.com/repos/DoSomething/phoenix/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DoSomething/phoenix/statuses/{sha}","languages_url":"https://api.github.com/repos/DoSomething/phoenix/languages","stargazers_url":"https://api.github.com/repos/DoSomething/phoenix/stargazers","contributors_url":"https://api.github.com/repos/DoSomething/phoenix/contributors","subscribers_url":"https://api.github.com/repos/DoSomething/phoenix/subscribers","subscription_url":"https://api.github.com/repos/DoSomething/phoenix/subscription","commits_url":"https://api.github.com/repos/DoSomething/phoenix/commits{/sha}","git_commits_url":"https://api.github.com/repos/DoSomething/phoenix/git/commits{/sha}","comments_url":"https://api.github.com/repos/DoSomething/phoenix/comments{/number}","issue_comment_url":"https://api.github.com/repos/DoSomething/phoenix/issues/comments{/number}","contents_url":"https://api.github.com/repos/DoSomething/phoenix/contents/{+path}","compare_url":"https://api.github.com/repos/DoSomething/phoenix/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DoSomething/phoenix/merges","archive_url":"https://api.github.com/repos/DoSomething/phoenix/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DoSomething/phoenix/downloads","issues_url":"https://api.github.com/repos/DoSomething/phoenix/issues{/number}","pulls_url":"https://api.github.com/repos/DoSomething/phoenix/pulls{/number}","milestones_url":"https://api.github.com/repos/DoSomething/phoenix/milestones{/number}","notifications_url":"https://api.github.com/repos/DoSomething/phoenix/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DoSomething/phoenix/labels{/name}","releases_url":"https://api.github.com/repos/DoSomething/phoenix/releases{/id}","deployments_url":"https://api.github.com/repos/DoSomething/phoenix/deployments","created_at":"2013-10-15T14:50:48Z","updated_at":"2017-04-27T15:34:50Z","pushed_at":"2017-05-02T13:57:16Z","git_url":"git://github.com/DoSomething/phoenix.git","ssh_url":"git@github.com:DoSomething/phoenix.git","clone_url":"https://github.com/DoSomething/phoenix.git","svn_url":"https://github.com/DoSomething/phoenix","homepage":"https://www.dosomething.org/","size":20768,"stargazers_count":28,"watchers_count":28,"language":"PHP","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":19,"mirror_url":null,"open_issues_count":66,"forks":19,"open_issues":66,"watchers":28,"default_branch":"dev"}},"base":{"label":"DoSomething:dev","ref":"dev","sha":"ca42f51d11d54f86fc6244f68b94a693247fca98","user":{"login":"DoSomething","id":731685,"avatar_url":"https://avatars1.githubusercontent.com/u/731685?v=3","gravatar_id":"","url":"https://api.github.com/users/DoSomething","html_url":"https://github.com/DoSomething","followers_url":"https://api.github.com/users/DoSomething/followers","following_url":"https://api.github.com/users/DoSomething/following{/other_user}","gists_url":"https://api.github.com/users/DoSomething/gists{/gist_id}","starred_url":"https://api.github.com/users/DoSomething/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DoSomething/subscriptions","organizations_url":"https://api.github.com/users/DoSomething/orgs","repos_url":"https://api.github.com/users/DoSomething/repos","events_url":"https://api.github.com/users/DoSomething/events{/privacy}","received_events_url":"https://api.github.com/users/DoSomething/received_events","type":"Organization","site_admin":false},"repo":{"id":13592927,"name":"phoenix","full_name":"DoSomething/phoenix","owner":{"login":"DoSomething","id":731685,"avatar_url":"https://avatars1.githubusercontent.com/u/731685?v=3","gravatar_id":"","url":"https://api.github.com/users/DoSomething","html_url":"https://github.com/DoSomething","followers_url":"https://api.github.com/users/DoSomething/followers","following_url":"https://api.github.com/users/DoSomething/following{/other_user}","gists_url":"https://api.github.com/users/DoSomething/gists{/gist_id}","starred_url":"https://api.github.com/users/DoSomething/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DoSomething/subscriptions","organizations_url":"https://api.github.com/users/DoSomething/orgs","repos_url":"https://api.github.com/users/DoSomething/repos","events_url":"https://api.github.com/users/DoSomething/events{/privacy}","received_events_url":"https://api.github.com/users/DoSomething/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DoSomething/phoenix","description":":fire: The DoSomething.org website & content API.","fork":false,"url":"https://api.github.com/repos/DoSomething/phoenix","forks_url":"https://api.github.com/repos/DoSomething/phoenix/forks","keys_url":"https://api.github.com/repos/DoSomething/phoenix/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DoSomething/phoenix/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DoSomething/phoenix/teams","hooks_url":"https://api.github.com/repos/DoSomething/phoenix/hooks","issue_events_url":"https://api.github.com/repos/DoSomething/phoenix/issues/events{/number}","events_url":"https://api.github.com/repos/DoSomething/phoenix/events","assignees_url":"https://api.github.com/repos/DoSomething/phoenix/assignees{/user}","branches_url":"https://api.github.com/repos/DoSomething/phoenix/branches{/branch}","tags_url":"https://api.github.com/repos/DoSomething/phoenix/tags","blobs_url":"https://api.github.com/repos/DoSomething/phoenix/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DoSomething/phoenix/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DoSomething/phoenix/git/refs{/sha}","trees_url":"https://api.github.com/repos/DoSomething/phoenix/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DoSomething/phoenix/statuses/{sha}","languages_url":"https://api.github.com/repos/DoSomething/phoenix/languages","stargazers_url":"https://api.github.com/repos/DoSomething/phoenix/stargazers","contributors_url":"https://api.github.com/repos/DoSomething/phoenix/contributors","subscribers_url":"https://api.github.com/repos/DoSomething/phoenix/subscribers","subscription_url":"https://api.github.com/repos/DoSomething/phoenix/subscription","commits_url":"https://api.github.com/repos/DoSomething/phoenix/commits{/sha}","git_commits_url":"https://api.github.com/repos/DoSomething/phoenix/git/commits{/sha}","comments_url":"https://api.github.com/repos/DoSomething/phoenix/comments{/number}","issue_comment_url":"https://api.github.com/repos/DoSomething/phoenix/issues/comments{/number}","contents_url":"https://api.github.com/repos/DoSomething/phoenix/contents/{+path}","compare_url":"https://api.github.com/repos/DoSomething/phoenix/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DoSomething/phoenix/merges","archive_url":"https://api.github.com/repos/DoSomething/phoenix/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DoSomething/phoenix/downloads","issues_url":"https://api.github.com/repos/DoSomething/phoenix/issues{/number}","pulls_url":"https://api.github.com/repos/DoSomething/phoenix/pulls{/number}","milestones_url":"https://api.github.com/repos/DoSomething/phoenix/milestones{/number}","notifications_url":"https://api.github.com/repos/DoSomething/phoenix/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DoSomething/phoenix/labels{/name}","releases_url":"https://api.github.com/repos/DoSomething/phoenix/releases{/id}","deployments_url":"https://api.github.com/repos/DoSomething/phoenix/deployments","created_at":"2013-10-15T14:50:48Z","updated_at":"2017-04-27T15:34:50Z","pushed_at":"2017-05-02T13:57:16Z","git_url":"git://github.com/DoSomething/phoenix.git","ssh_url":"git@github.com:DoSomething/phoenix.git","clone_url":"https://github.com/DoSomething/phoenix.git","svn_url":"https://github.com/DoSomething/phoenix","homepage":"https://www.dosomething.org/","size":20768,"stargazers_count":28,"watchers_count":28,"language":"PHP","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":19,"mirror_url":null,"open_issues_count":66,"forks":19,"open_issues":66,"watchers":28,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/DoSomething/phoenix/pulls/7368"},"html":{"href":"https://github.com/DoSomething/phoenix/pull/7368"},"issue":{"href":"https://api.github.com/repos/DoSomething/phoenix/issues/7368"},"comments":{"href":"https://api.github.com/repos/DoSomething/phoenix/issues/7368/comments"},"review_comments":{"href":"https://api.github.com/repos/DoSomething/phoenix/pulls/7368/comments"},"review_comment":{"href":"https://api.github.com/repos/DoSomething/phoenix/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/DoSomething/phoenix/pulls/7368/commits"},"statuses":{"href":"https://api.github.com/repos/DoSomething/phoenix/statuses/6156b7d43a9ea7130977dda783eed52aef1a5802"}}}}
{"actor":{"display_login":"chloealee"}}