{"action":"created","comment":{"url":"https://api.github.com/repos/Wikia/app/pulls/comments/32981885","id":32981885,"diff_hunk":"@@ -0,0 +1,62 @@\n+<?php\n+/**\n+ *\n+ * User preference service.\n+ * Assumptions:\n+ *\t- The user exists (persisted in the database) and we have a valid user id.\n+ *\t- Only the currently logged in user as set in the gateway WikiaUserId is\n+ *\t  able to change their preferences\n+ *\n+ * Open questions:\n+ *\t- How do we handle the preference white list on this side? Do we?\n+ *\t- How do we standardize on a set of exceptions that will cross the libraries we use?\n+ *\t  Things that could go wrong:\n+ *\t  - gateway error e.g. 500 with API or database exception locally\n+ *\t  - request error e.g. 400\n+ *\t  - user not found 404\n+ *\t  - unauthorized\n+ *\t  - success 200\n+ *\n+ */\n+namespace Wikia\\Service\\User;\n+\n+use Wikia\\Domain\\User\\PreferenceValue;\n+\n+class Preference implements PreferenceService {\n+\n+\tprivate $gateway;\n+\n+\tfunction __construct( PreferencePersistence $gateway ) {\n+\t\t$this->gateway = $gateway;\n+\t}\n+\n+\tpublic function setPreferences( $userId, $preferences ) {\n+\t\tif ( !is_array( $preferences ) || empty( $preferences ) ) {\n+\t\t\treturn false;\n+\t\t}\n+\n+\t\treturn $this->gateway->save( $userId, $preferences );\n+\t}\n+\n+\tpublic function getPreferences( $userId ) {\n+\t\t$result = $this->gateway->get( $userId );\n+\t\tif (!is_array($result)) {\n+\t\t\treturn [];\n+\t\t}\n+\n+\t\t$preferences = $this->gatewayResultToPreferenceArray( $result );\n+\n+\t\treturn $preferences;\n+\t}\n+\n+\tpublic function gatewayResultToPreferenceArray(array $result) {\n+\t\t$preferences = [];\n+\t\tforeach( $result as $index => $row ) {\n+\t\t\tif (isset($row[\"name\"]) && isset($row[\"value\"])) {\n+\t\t\t\t$preferences[] = new Preference($row[\"name\"], $row[\"value\"]);","path":"lib/Wikia/src/Service/User/Preference.php","position":56,"original_position":56,"commit_id":"45d077eb089f255a015b255b81148da7a6ee710e","original_commit_id":"45d077eb089f255a015b255b81148da7a6ee710e","user":{"login":"nmonterroso","id":325800,"avatar_url":"https://avatars.githubusercontent.com/u/325800?v=3","gravatar_id":"","url":"https://api.github.com/users/nmonterroso","html_url":"https://github.com/nmonterroso","followers_url":"https://api.github.com/users/nmonterroso/followers","following_url":"https://api.github.com/users/nmonterroso/following{/other_user}","gists_url":"https://api.github.com/users/nmonterroso/gists{/gist_id}","starred_url":"https://api.github.com/users/nmonterroso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nmonterroso/subscriptions","organizations_url":"https://api.github.com/users/nmonterroso/orgs","repos_url":"https://api.github.com/users/nmonterroso/repos","events_url":"https://api.github.com/users/nmonterroso/events{/privacy}","received_events_url":"https://api.github.com/users/nmonterroso/received_events","type":"User","site_admin":false},"body":"shouldn't this be `new PreferenceValue`?","created_at":"2015-06-22T20:51:49Z","updated_at":"2015-06-22T20:51:49Z","html_url":"https://github.com/Wikia/app/pull/7572#discussion_r32981885","pull_request_url":"https://api.github.com/repos/Wikia/app/pulls/7572","_links":{"self":{"href":"https://api.github.com/repos/Wikia/app/pulls/comments/32981885"},"html":{"href":"https://github.com/Wikia/app/pull/7572#discussion_r32981885"},"pull_request":{"href":"https://api.github.com/repos/Wikia/app/pulls/7572"}}},"pull_request":{"url":"https://api.github.com/repos/Wikia/app/pulls/7572","id":38063884,"html_url":"https://github.com/Wikia/app/pull/7572","diff_url":"https://github.com/Wikia/app/pull/7572.diff","patch_url":"https://github.com/Wikia/app/pull/7572.patch","issue_url":"https://api.github.com/repos/Wikia/app/issues/7572","number":7572,"state":"open","locked":false,"title":"Proof of concept user preference service interface","user":{"login":"drsnyder","id":21621,"avatar_url":"https://avatars.githubusercontent.com/u/21621?v=3","gravatar_id":"","url":"https://api.github.com/users/drsnyder","html_url":"https://github.com/drsnyder","followers_url":"https://api.github.com/users/drsnyder/followers","following_url":"https://api.github.com/users/drsnyder/following{/other_user}","gists_url":"https://api.github.com/users/drsnyder/gists{/gist_id}","starred_url":"https://api.github.com/users/drsnyder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drsnyder/subscriptions","organizations_url":"https://api.github.com/users/drsnyder/orgs","repos_url":"https://api.github.com/users/drsnyder/repos","events_url":"https://api.github.com/users/drsnyder/events{/privacy}","received_events_url":"https://api.github.com/users/drsnyder/received_events","type":"User","site_admin":false},"body":"Add a user preference \"service\" interface that we can use to replace the SQL call sites using the `user_properties` table. For example, the logic [here](https://github.com/Wikia/app/blob/dev/includes/User.php#L4406-4424) would be replaced (approximately) by:\r\n\r\n```php\r\n$service = \\Wikia\\Services\\ServiceRegistry::instance()->getUserPreferenceService();\r\n$res = $service->getPreferences($this->getId())\r\n```\r\n\r\nThis is associated with [SERVICES-441](https://wikia-inc.atlassian.net/browse/SERVICES-441). See also this [blog post](https://one.wikia-inc.com/wiki/User_blog:Damon_Snyder/Replacing_%22preferences%22_in_MW_with_the_user_preference_service) for the rational.\r\n\r\n/cc @Wikia/services-team @garthwebb @cmiller-wikia ","created_at":"2015-06-18T23:25:28Z","updated_at":"2015-06-22T20:51:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"11fc14c4f233b69731acd5e6dc5b72b1526f53a5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Wikia/app/pulls/7572/commits","review_comments_url":"https://api.github.com/repos/Wikia/app/pulls/7572/comments","review_comment_url":"https://api.github.com/repos/Wikia/app/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Wikia/app/issues/7572/comments","statuses_url":"https://api.github.com/repos/Wikia/app/statuses/45d077eb089f255a015b255b81148da7a6ee710e","head":{"label":"Wikia:services-441-up-interface","ref":"services-441-up-interface","sha":"45d077eb089f255a015b255b81148da7a6ee710e","user":{"login":"Wikia","id":1171011,"avatar_url":"https://avatars.githubusercontent.com/u/1171011?v=3","gravatar_id":"","url":"https://api.github.com/users/Wikia","html_url":"https://github.com/Wikia","followers_url":"https://api.github.com/users/Wikia/followers","following_url":"https://api.github.com/users/Wikia/following{/other_user}","gists_url":"https://api.github.com/users/Wikia/gists{/gist_id}","starred_url":"https://api.github.com/users/Wikia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wikia/subscriptions","organizations_url":"https://api.github.com/users/Wikia/orgs","repos_url":"https://api.github.com/users/Wikia/repos","events_url":"https://api.github.com/users/Wikia/events{/privacy}","received_events_url":"https://api.github.com/users/Wikia/received_events","type":"Organization","site_admin":false},"repo":{"id":5532313,"name":"app","full_name":"Wikia/app","owner":{"login":"Wikia","id":1171011,"avatar_url":"https://avatars.githubusercontent.com/u/1171011?v=3","gravatar_id":"","url":"https://api.github.com/users/Wikia","html_url":"https://github.com/Wikia","followers_url":"https://api.github.com/users/Wikia/followers","following_url":"https://api.github.com/users/Wikia/following{/other_user}","gists_url":"https://api.github.com/users/Wikia/gists{/gist_id}","starred_url":"https://api.github.com/users/Wikia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wikia/subscriptions","organizations_url":"https://api.github.com/users/Wikia/orgs","repos_url":"https://api.github.com/users/Wikia/repos","events_url":"https://api.github.com/users/Wikia/events{/privacy}","received_events_url":"https://api.github.com/users/Wikia/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Wikia/app","description":"Wikia Application Code","fork":false,"url":"https://api.github.com/repos/Wikia/app","forks_url":"https://api.github.com/repos/Wikia/app/forks","keys_url":"https://api.github.com/repos/Wikia/app/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Wikia/app/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Wikia/app/teams","hooks_url":"https://api.github.com/repos/Wikia/app/hooks","issue_events_url":"https://api.github.com/repos/Wikia/app/issues/events{/number}","events_url":"https://api.github.com/repos/Wikia/app/events","assignees_url":"https://api.github.com/repos/Wikia/app/assignees{/user}","branches_url":"https://api.github.com/repos/Wikia/app/branches{/branch}","tags_url":"https://api.github.com/repos/Wikia/app/tags","blobs_url":"https://api.github.com/repos/Wikia/app/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Wikia/app/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Wikia/app/git/refs{/sha}","trees_url":"https://api.github.com/repos/Wikia/app/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Wikia/app/statuses/{sha}","languages_url":"https://api.github.com/repos/Wikia/app/languages","stargazers_url":"https://api.github.com/repos/Wikia/app/stargazers","contributors_url":"https://api.github.com/repos/Wikia/app/contributors","subscribers_url":"https://api.github.com/repos/Wikia/app/subscribers","subscription_url":"https://api.github.com/repos/Wikia/app/subscription","commits_url":"https://api.github.com/repos/Wikia/app/commits{/sha}","git_commits_url":"https://api.github.com/repos/Wikia/app/git/commits{/sha}","comments_url":"https://api.github.com/repos/Wikia/app/comments{/number}","issue_comment_url":"https://api.github.com/repos/Wikia/app/issues/comments{/number}","contents_url":"https://api.github.com/repos/Wikia/app/contents/{+path}","compare_url":"https://api.github.com/repos/Wikia/app/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Wikia/app/merges","archive_url":"https://api.github.com/repos/Wikia/app/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Wikia/app/downloads","issues_url":"https://api.github.com/repos/Wikia/app/issues{/number}","pulls_url":"https://api.github.com/repos/Wikia/app/pulls{/number}","milestones_url":"https://api.github.com/repos/Wikia/app/milestones{/number}","notifications_url":"https://api.github.com/repos/Wikia/app/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Wikia/app/labels{/name}","releases_url":"https://api.github.com/repos/Wikia/app/releases{/id}","created_at":"2012-08-23T20:55:58Z","updated_at":"2015-06-01T12:38:38Z","pushed_at":"2015-06-22T20:45:28Z","git_url":"git://github.com/Wikia/app.git","ssh_url":"git@github.com:Wikia/app.git","clone_url":"https://github.com/Wikia/app.git","svn_url":"https://github.com/Wikia/app","homepage":"http://dev.wikia.com","size":1379822,"stargazers_count":79,"watchers_count":79,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":57,"mirror_url":null,"open_issues_count":78,"forks":57,"open_issues":78,"watchers":79,"default_branch":"dev"}},"base":{"label":"Wikia:dev","ref":"dev","sha":"f3ac6db22de65a3543b39d8cba1c450c92cc2c6f","user":{"login":"Wikia","id":1171011,"avatar_url":"https://avatars.githubusercontent.com/u/1171011?v=3","gravatar_id":"","url":"https://api.github.com/users/Wikia","html_url":"https://github.com/Wikia","followers_url":"https://api.github.com/users/Wikia/followers","following_url":"https://api.github.com/users/Wikia/following{/other_user}","gists_url":"https://api.github.com/users/Wikia/gists{/gist_id}","starred_url":"https://api.github.com/users/Wikia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wikia/subscriptions","organizations_url":"https://api.github.com/users/Wikia/orgs","repos_url":"https://api.github.com/users/Wikia/repos","events_url":"https://api.github.com/users/Wikia/events{/privacy}","received_events_url":"https://api.github.com/users/Wikia/received_events","type":"Organization","site_admin":false},"repo":{"id":5532313,"name":"app","full_name":"Wikia/app","owner":{"login":"Wikia","id":1171011,"avatar_url":"https://avatars.githubusercontent.com/u/1171011?v=3","gravatar_id":"","url":"https://api.github.com/users/Wikia","html_url":"https://github.com/Wikia","followers_url":"https://api.github.com/users/Wikia/followers","following_url":"https://api.github.com/users/Wikia/following{/other_user}","gists_url":"https://api.github.com/users/Wikia/gists{/gist_id}","starred_url":"https://api.github.com/users/Wikia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wikia/subscriptions","organizations_url":"https://api.github.com/users/Wikia/orgs","repos_url":"https://api.github.com/users/Wikia/repos","events_url":"https://api.github.com/users/Wikia/events{/privacy}","received_events_url":"https://api.github.com/users/Wikia/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Wikia/app","description":"Wikia Application Code","fork":false,"url":"https://api.github.com/repos/Wikia/app","forks_url":"https://api.github.com/repos/Wikia/app/forks","keys_url":"https://api.github.com/repos/Wikia/app/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Wikia/app/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Wikia/app/teams","hooks_url":"https://api.github.com/repos/Wikia/app/hooks","issue_events_url":"https://api.github.com/repos/Wikia/app/issues/events{/number}","events_url":"https://api.github.com/repos/Wikia/app/events","assignees_url":"https://api.github.com/repos/Wikia/app/assignees{/user}","branches_url":"https://api.github.com/repos/Wikia/app/branches{/branch}","tags_url":"https://api.github.com/repos/Wikia/app/tags","blobs_url":"https://api.github.com/repos/Wikia/app/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Wikia/app/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Wikia/app/git/refs{/sha}","trees_url":"https://api.github.com/repos/Wikia/app/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Wikia/app/statuses/{sha}","languages_url":"https://api.github.com/repos/Wikia/app/languages","stargazers_url":"https://api.github.com/repos/Wikia/app/stargazers","contributors_url":"https://api.github.com/repos/Wikia/app/contributors","subscribers_url":"https://api.github.com/repos/Wikia/app/subscribers","subscription_url":"https://api.github.com/repos/Wikia/app/subscription","commits_url":"https://api.github.com/repos/Wikia/app/commits{/sha}","git_commits_url":"https://api.github.com/repos/Wikia/app/git/commits{/sha}","comments_url":"https://api.github.com/repos/Wikia/app/comments{/number}","issue_comment_url":"https://api.github.com/repos/Wikia/app/issues/comments{/number}","contents_url":"https://api.github.com/repos/Wikia/app/contents/{+path}","compare_url":"https://api.github.com/repos/Wikia/app/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Wikia/app/merges","archive_url":"https://api.github.com/repos/Wikia/app/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Wikia/app/downloads","issues_url":"https://api.github.com/repos/Wikia/app/issues{/number}","pulls_url":"https://api.github.com/repos/Wikia/app/pulls{/number}","milestones_url":"https://api.github.com/repos/Wikia/app/milestones{/number}","notifications_url":"https://api.github.com/repos/Wikia/app/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Wikia/app/labels{/name}","releases_url":"https://api.github.com/repos/Wikia/app/releases{/id}","created_at":"2012-08-23T20:55:58Z","updated_at":"2015-06-01T12:38:38Z","pushed_at":"2015-06-22T20:45:28Z","git_url":"git://github.com/Wikia/app.git","ssh_url":"git@github.com:Wikia/app.git","clone_url":"https://github.com/Wikia/app.git","svn_url":"https://github.com/Wikia/app","homepage":"http://dev.wikia.com","size":1379822,"stargazers_count":79,"watchers_count":79,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":57,"mirror_url":null,"open_issues_count":78,"forks":57,"open_issues":78,"watchers":79,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/Wikia/app/pulls/7572"},"html":{"href":"https://github.com/Wikia/app/pull/7572"},"issue":{"href":"https://api.github.com/repos/Wikia/app/issues/7572"},"comments":{"href":"https://api.github.com/repos/Wikia/app/issues/7572/comments"},"review_comments":{"href":"https://api.github.com/repos/Wikia/app/pulls/7572/comments"},"review_comment":{"href":"https://api.github.com/repos/Wikia/app/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Wikia/app/pulls/7572/commits"},"statuses":{"href":"https://api.github.com/repos/Wikia/app/statuses/45d077eb089f255a015b255b81148da7a6ee710e"}}}}