{"action":"created","comment":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/comments/155598991","pull_request_review_id":81943515,"id":155598991,"diff_hunk":"@@ -0,0 +1,102 @@\n+\"\"\"\n+Migrates user preferences from one language code to another in batches. Dark lang preferences are not affected.\n+\"\"\"\n+from __future__ import print_function\n+\n+import logging\n+from time import sleep\n+\n+from django.conf import settings\n+from django.core.management.base import BaseCommand, CommandError\n+from django.db import transaction\n+from django.db.models import Q, Max\n+\n+from openedx.core.djangoapps.dark_lang.models import DarkLangConfig\n+from openedx.core.djangoapps.user_api.models import UserPreference\n+\n+\n+DEFAULT_CHUNK_SIZE = 10000\n+DEFAULT_SLEEP_TIME_SECS = 10\n+\n+LOGGER = logging.getLogger(__name__)\n+\n+\n+class Command(BaseCommand):\n+    \"\"\"\n+    Implementation of the migrate command\n+    \"\"\"\n+    help = 'Migrate all user language preferences (excluding dark languages) from one language code to another.'\n+\n+    def add_arguments(self, parser):\n+        parser.add_argument('old_lang_code',\n+                            help='Original language code, ex. \"zh-cn\"')\n+        parser.add_argument('new_lang_code',\n+                            help='New language code, ex. \"zh-hans\"')\n+        parser.add_argument('--start_id',\n+                            type=int,\n+                            default=1,\n+                            help='ID to begin from, in case a run needs to be restarted from the middle.')\n+        parser.add_argument('--chunk_size',\n+                            type=int,\n+                            default=DEFAULT_CHUNK_SIZE,\n+                            help='Number of users whose preferences will be updated per batch.')\n+        parser.add_argument('--sleep_time_secs',\n+                            type=int,\n+                            default=DEFAULT_SLEEP_TIME_SECS,\n+                            help='Number of users whose preferences will be updated per batch.')\n+\n+    def handle(self, *args, **options):\n+        \"\"\"\n+        Execute the command.\n+        \"\"\"\n+        old_lang_code = options['old_lang_code']\n+        new_lang_code = options['new_lang_code']\n+        chunk_size = options['chunk_size']\n+        sleep_time_secs = options['sleep_time_secs']\n+        start = options['start_id']\n+        end = start + chunk_size\n+\n+        # Make sure we're changing to a code that actually exists. Presumably it's safe to move away from a code that\n+        # doesn't.\n+        langs = [lang_code[0] for lang_code in settings.LANGUAGES]\n+        langs += DarkLangConfig.current().released_languages_list\n+\n+        if new_lang_code not in langs:\n+            raise CommandError('{} is not a configured language code in settings.LANGUAGES '\n+                               'or the current DarkLangCongig.'.format(new_lang_code))\n+\n+        max_id = UserPreference.objects.all().aggregate(Max('id'))['id__max']\n+\n+        print('Updating user language preferences from {} to {}. '\n+              'Start id is {}, current max id is {}. '\n+              'Chunk size is of {}'.format(old_lang_code, new_lang_code, start, max_id, chunk_size))\n+\n+        updated_count = 0\n+\n+        while True:\n+            # On the last time through catch any new rows added since this run began\n+            if end >= max_id:\n+                print('Last round, includes all new rows added since this run started.')\n+                id_query = Q(id__gte=start)\n+            else:\n+                id_query = Q(id__gte=start) & Q(id__lt=end)\n+\n+            with transaction.atomic():","path":"openedx/core/djangoapps/user_api/management/commands/migrate_user_profile_langs.py","position":84,"original_position":84,"commit_id":"54e3a3b42c468093aa2bdcf1adbfe10120b33047","original_commit_id":"54e3a3b42c468093aa2bdcf1adbfe10120b33047","user":{"login":"jmbowman","id":1005375,"avatar_url":"https://avatars2.githubusercontent.com/u/1005375?v=4","gravatar_id":"","url":"https://api.github.com/users/jmbowman","html_url":"https://github.com/jmbowman","followers_url":"https://api.github.com/users/jmbowman/followers","following_url":"https://api.github.com/users/jmbowman/following{/other_user}","gists_url":"https://api.github.com/users/jmbowman/gists{/gist_id}","starred_url":"https://api.github.com/users/jmbowman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmbowman/subscriptions","organizations_url":"https://api.github.com/users/jmbowman/orgs","repos_url":"https://api.github.com/users/jmbowman/repos","events_url":"https://api.github.com/users/jmbowman/events{/privacy}","received_events_url":"https://api.github.com/users/jmbowman/received_events","type":"User","site_admin":false},"body":"The following update should be performed as a single SQL query; do we need the additional transaction wrapper?","created_at":"2017-12-07T18:14:43Z","updated_at":"2017-12-07T18:17:52Z","html_url":"https://github.com/edx/edx-platform/pull/16814#discussion_r155598991","pull_request_url":"https://api.github.com/repos/edx/edx-platform/pulls/16814","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments/155598991"},"html":{"href":"https://github.com/edx/edx-platform/pull/16814#discussion_r155598991"},"pull_request":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/16814"}}},"pull_request":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/16814","id":156829640,"html_url":"https://github.com/edx/edx-platform/pull/16814","diff_url":"https://github.com/edx/edx-platform/pull/16814.diff","patch_url":"https://github.com/edx/edx-platform/pull/16814.patch","issue_url":"https://api.github.com/repos/edx/edx-platform/issues/16814","number":16814,"state":"open","locked":false,"title":"Add command to bulk move user language prefs from one code to another","user":{"login":"bmedx","id":24231382,"avatar_url":"https://avatars3.githubusercontent.com/u/24231382?v=4","gravatar_id":"","url":"https://api.github.com/users/bmedx","html_url":"https://github.com/bmedx","followers_url":"https://api.github.com/users/bmedx/followers","following_url":"https://api.github.com/users/bmedx/following{/other_user}","gists_url":"https://api.github.com/users/bmedx/gists{/gist_id}","starred_url":"https://api.github.com/users/bmedx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bmedx/subscriptions","organizations_url":"https://api.github.com/users/bmedx/orgs","repos_url":"https://api.github.com/users/bmedx/repos","events_url":"https://api.github.com/users/bmedx/events{/privacy}","received_events_url":"https://api.github.com/users/bmedx/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-12-06T20:19:53Z","updated_at":"2017-12-07T18:17:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c7c82cf6845e83415b2459a5e9b86b17eefca303","assignee":null,"assignees":[],"requested_reviewers":[{"login":"macdiesel","id":67862,"avatar_url":"https://avatars3.githubusercontent.com/u/67862?v=4","gravatar_id":"","url":"https://api.github.com/users/macdiesel","html_url":"https://github.com/macdiesel","followers_url":"https://api.github.com/users/macdiesel/followers","following_url":"https://api.github.com/users/macdiesel/following{/other_user}","gists_url":"https://api.github.com/users/macdiesel/gists{/gist_id}","starred_url":"https://api.github.com/users/macdiesel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/macdiesel/subscriptions","organizations_url":"https://api.github.com/users/macdiesel/orgs","repos_url":"https://api.github.com/users/macdiesel/repos","events_url":"https://api.github.com/users/macdiesel/events{/privacy}","received_events_url":"https://api.github.com/users/macdiesel/received_events","type":"User","site_admin":false},{"login":"pwnage101","id":85151,"avatar_url":"https://avatars1.githubusercontent.com/u/85151?v=4","gravatar_id":"","url":"https://api.github.com/users/pwnage101","html_url":"https://github.com/pwnage101","followers_url":"https://api.github.com/users/pwnage101/followers","following_url":"https://api.github.com/users/pwnage101/following{/other_user}","gists_url":"https://api.github.com/users/pwnage101/gists{/gist_id}","starred_url":"https://api.github.com/users/pwnage101/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pwnage101/subscriptions","organizations_url":"https://api.github.com/users/pwnage101/orgs","repos_url":"https://api.github.com/users/pwnage101/repos","events_url":"https://api.github.com/users/pwnage101/events{/privacy}","received_events_url":"https://api.github.com/users/pwnage101/received_events","type":"User","site_admin":false},{"login":"doctoryes","id":7285237,"avatar_url":"https://avatars2.githubusercontent.com/u/7285237?v=4","gravatar_id":"","url":"https://api.github.com/users/doctoryes","html_url":"https://github.com/doctoryes","followers_url":"https://api.github.com/users/doctoryes/followers","following_url":"https://api.github.com/users/doctoryes/following{/other_user}","gists_url":"https://api.github.com/users/doctoryes/gists{/gist_id}","starred_url":"https://api.github.com/users/doctoryes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doctoryes/subscriptions","organizations_url":"https://api.github.com/users/doctoryes/orgs","repos_url":"https://api.github.com/users/doctoryes/repos","events_url":"https://api.github.com/users/doctoryes/events{/privacy}","received_events_url":"https://api.github.com/users/doctoryes/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/edx/edx-platform/pulls/16814/commits","review_comments_url":"https://api.github.com/repos/edx/edx-platform/pulls/16814/comments","review_comment_url":"https://api.github.com/repos/edx/edx-platform/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/edx-platform/issues/16814/comments","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/54e3a3b42c468093aa2bdcf1adbfe10120b33047","head":{"label":"edx:bmedx/course_lang_bulk_update_cmd","ref":"bmedx/course_lang_bulk_update_cmd","sha":"54e3a3b42c468093aa2bdcf1adbfe10120b33047","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars3.githubusercontent.com/u/3179841?v=4","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":10391073,"name":"edx-platform","full_name":"edx/edx-platform","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars3.githubusercontent.com/u/3179841?v=4","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-platform","description":"The Open edX platform, the software that powers edX!","fork":false,"url":"https://api.github.com/repos/edx/edx-platform","forks_url":"https://api.github.com/repos/edx/edx-platform/forks","keys_url":"https://api.github.com/repos/edx/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-platform/teams","hooks_url":"https://api.github.com/repos/edx/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-platform/events","assignees_url":"https://api.github.com/repos/edx/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-platform/tags","blobs_url":"https://api.github.com/repos/edx/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-platform/languages","stargazers_url":"https://api.github.com/repos/edx/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-platform/subscription","commits_url":"https://api.github.com/repos/edx/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-platform/merges","archive_url":"https://api.github.com/repos/edx/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-platform/downloads","issues_url":"https://api.github.com/repos/edx/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-platform/releases{/id}","deployments_url":"https://api.github.com/repos/edx/edx-platform/deployments","created_at":"2013-05-30T20:20:38Z","updated_at":"2017-12-07T12:01:08Z","pushed_at":"2017-12-07T18:13:29Z","git_url":"git://github.com/edx/edx-platform.git","ssh_url":"git@github.com:edx/edx-platform.git","clone_url":"https://github.com/edx/edx-platform.git","svn_url":"https://github.com/edx/edx-platform","homepage":"http://open.edx.org/","size":866329,"stargazers_count":3432,"watchers_count":3432,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1944,"mirror_url":null,"archived":false,"open_issues_count":215,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0"},"forks":1944,"open_issues":215,"watchers":3432,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"63d7f87f4f397a4eef29c887dd7e5b575a5ef76e","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars3.githubusercontent.com/u/3179841?v=4","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":10391073,"name":"edx-platform","full_name":"edx/edx-platform","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars3.githubusercontent.com/u/3179841?v=4","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-platform","description":"The Open edX platform, the software that powers edX!","fork":false,"url":"https://api.github.com/repos/edx/edx-platform","forks_url":"https://api.github.com/repos/edx/edx-platform/forks","keys_url":"https://api.github.com/repos/edx/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-platform/teams","hooks_url":"https://api.github.com/repos/edx/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-platform/events","assignees_url":"https://api.github.com/repos/edx/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-platform/tags","blobs_url":"https://api.github.com/repos/edx/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-platform/languages","stargazers_url":"https://api.github.com/repos/edx/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-platform/subscription","commits_url":"https://api.github.com/repos/edx/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-platform/merges","archive_url":"https://api.github.com/repos/edx/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-platform/downloads","issues_url":"https://api.github.com/repos/edx/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-platform/releases{/id}","deployments_url":"https://api.github.com/repos/edx/edx-platform/deployments","created_at":"2013-05-30T20:20:38Z","updated_at":"2017-12-07T12:01:08Z","pushed_at":"2017-12-07T18:13:29Z","git_url":"git://github.com/edx/edx-platform.git","ssh_url":"git@github.com:edx/edx-platform.git","clone_url":"https://github.com/edx/edx-platform.git","svn_url":"https://github.com/edx/edx-platform","homepage":"http://open.edx.org/","size":866329,"stargazers_count":3432,"watchers_count":3432,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1944,"mirror_url":null,"archived":false,"open_issues_count":215,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0"},"forks":1944,"open_issues":215,"watchers":3432,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/16814"},"html":{"href":"https://github.com/edx/edx-platform/pull/16814"},"issue":{"href":"https://api.github.com/repos/edx/edx-platform/issues/16814"},"comments":{"href":"https://api.github.com/repos/edx/edx-platform/issues/16814/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/16814/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/16814/commits"},"statuses":{"href":"https://api.github.com/repos/edx/edx-platform/statuses/54e3a3b42c468093aa2bdcf1adbfe10120b33047"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"jmbowman"}}