{"action":"created","comment":{"url":"https://api.github.com/repos/doctrine/phpcr-odm/pulls/comments/42097185","id":42097185,"diff_hunk":"@@ -0,0 +1,228 @@\n+<?php\n+\n+namespace Doctrine\\ODM\\PHPCR\\Tools\\Helper;\n+\n+use Doctrine\\ODM\\PHPCR\\Exception\\InvalidArgumentException;\n+use Doctrine\\ODM\\PHPCR\\PHPCRExceptionInterface;\n+use Doctrine\\ODM\\PHPCR\\Translation\\Translation;\n+use Doctrine\\ODM\\PHPCR\\Translation\\TranslationStrategy\\ChildTranslationStrategy;\n+use Doctrine\\ODM\\PHPCR\\Translation\\TranslationStrategy\\NonTranslatedStrategy;\n+use Doctrine\\ODM\\PHPCR\\Translation\\TranslationStrategy\\TranslationStrategyInterface;\n+use Doctrine\\ODM\\PHPCR\\DocumentManagerInterface;\n+use Doctrine\\ODM\\PHPCR\\Mapping\\ClassMetadata;\n+\n+/**\n+ * Migrate a field that has become translated or changed its translation\n+ * strategy.\n+ *\n+ * To avoid problems with large repositories, the converter is operating in a\n+ * batched mode. Call it repeatedly and call flush and clear between calls.\n+ *\n+ * You need to call `save()` on the PHPCR session, rather than `flush()` on\n+ * the document maanger. To avoid unexpected results, it is recommended to\n+ * `clear()` the document manager before starting to convert and after having\n+ * saved the PHPCR session.\n+ *\n+ * @author David Buchmann <mail@davidbu.ch>\n+ */\n+class TranslationConverter\n+{\n+    /**\n+     * @var DocumentManagerInterface\n+     */\n+    private $dm;\n+\n+    /**\n+     * @var int Number of documents to process per batch.\n+     */\n+    private $batchSize;\n+\n+    /**\n+     * @param DocumentManagerInterface $dm\n+     * @param int                      $batchSize\n+     */\n+    public function __construct(DocumentManagerInterface $dm, $batchSize = 200)\n+    {\n+        $this->dm = $dm;\n+        $this->batchSize = $batchSize;\n+    }\n+\n+    /**\n+     * Migrate content into the new translation form and remove the old properties.\n+     *\n+     * This does not commit the changes to the repository. Call save on the\n+     * PHPCR session *after each batch*. Calling flush on the document manager\n+     * *is not enough*.\n+     *\n+     * When un-translating, the current locale and language fallback is used.\n+     * When translating, the new properties are copied into all languages.\n+     *\n+     * To convert all fields into a translation, you can pass an empty array\n+     * for $fields and the information is read from the metadata. The fields\n+     * are mandatory when converting fields back to non-translated.\n+     *\n+     * To convert a single field from translated to non-translated, simply\n+     * specify that field.\n+     *\n+     * @param string       $class                FQN of the document class\n+     * @param string|null  $previousStrategyName Name of previous strategy or null if field was not\n+     *                                           previously translated\n+     * @param array        $fields               List of fields to convert. Required when making a\n+     *                                           field not translated anymore\n+     *\n+     * @return boolean true if there are more documents to convert and this method needs to be\n+     *                      called again.\n+     *\n+     * @throws PHPCRExceptionInterface if the document can not be found.\n+     */\n+    public function convert(\n+        $class,\n+        $previousStrategyName = null,","path":"lib/Doctrine/ODM/PHPCR/Tools/Helper/TranslationConverter.php","position":80,"original_position":80,"commit_id":"312ddd8c394f846c76298a8f403ff3db2ae00aa8","original_commit_id":"312ddd8c394f846c76298a8f403ff3db2ae00aa8","user":{"login":"liquorvicar","id":5172753,"avatar_url":"https://avatars.githubusercontent.com/u/5172753?v=3","gravatar_id":"","url":"https://api.github.com/users/liquorvicar","html_url":"https://github.com/liquorvicar","followers_url":"https://api.github.com/users/liquorvicar/followers","following_url":"https://api.github.com/users/liquorvicar/following{/other_user}","gists_url":"https://api.github.com/users/liquorvicar/gists{/gist_id}","starred_url":"https://api.github.com/users/liquorvicar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liquorvicar/subscriptions","organizations_url":"https://api.github.com/users/liquorvicar/orgs","repos_url":"https://api.github.com/users/liquorvicar/repos","events_url":"https://api.github.com/users/liquorvicar/events{/privacy}","received_events_url":"https://api.github.com/users/liquorvicar/received_events","type":"User","site_admin":false},"body":"As I understand it, this takes the string value representing the strategy (i.e. \"attribute\" or \"child\" unless a custom strategy has been implemented). Would it be better if these were constants? Or perhaps that this method accepted the class name?","created_at":"2015-10-15T08:48:04Z","updated_at":"2015-10-15T08:48:04Z","html_url":"https://github.com/doctrine/phpcr-odm/pull/655#discussion_r42097185","pull_request_url":"https://api.github.com/repos/doctrine/phpcr-odm/pulls/655","_links":{"self":{"href":"https://api.github.com/repos/doctrine/phpcr-odm/pulls/comments/42097185"},"html":{"href":"https://github.com/doctrine/phpcr-odm/pull/655#discussion_r42097185"},"pull_request":{"href":"https://api.github.com/repos/doctrine/phpcr-odm/pulls/655"}}},"pull_request":{"url":"https://api.github.com/repos/doctrine/phpcr-odm/pulls/655","id":43331666,"html_url":"https://github.com/doctrine/phpcr-odm/pull/655","diff_url":"https://github.com/doctrine/phpcr-odm/pull/655.diff","patch_url":"https://github.com/doctrine/phpcr-odm/pull/655.patch","issue_url":"https://api.github.com/repos/doctrine/phpcr-odm/issues/655","number":655,"state":"open","locked":false,"title":"add a tool to convert translations","user":{"login":"dbu","id":76576,"avatar_url":"https://avatars.githubusercontent.com/u/76576?v=3","gravatar_id":"","url":"https://api.github.com/users/dbu","html_url":"https://github.com/dbu","followers_url":"https://api.github.com/users/dbu/followers","following_url":"https://api.github.com/users/dbu/following{/other_user}","gists_url":"https://api.github.com/users/dbu/gists{/gist_id}","starred_url":"https://api.github.com/users/dbu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbu/subscriptions","organizations_url":"https://api.github.com/users/dbu/orgs","repos_url":"https://api.github.com/users/dbu/repos","events_url":"https://api.github.com/users/dbu/events{/privacy}","received_events_url":"https://api.github.com/users/dbu/received_events","type":"User","site_admin":false},"body":"fix https://github.com/symfony-cmf/CoreBundle/issues/164\r\ntests need a sql2 bugfix for hyphens in phpcr-utils: https://github.com/phpcr/phpcr-utils/pull/157\r\n\r\nthe trick for reverting a translated property to untranslated could be dangerous. at least the doc should clearly state to test conversions before doing on production, and have a backup ready.","created_at":"2015-08-25T20:20:43Z","updated_at":"2015-10-15T08:48:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"92934fc8edbdf80109c83220b0b679e916dc068b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/doctrine/phpcr-odm/pulls/655/commits","review_comments_url":"https://api.github.com/repos/doctrine/phpcr-odm/pulls/655/comments","review_comment_url":"https://api.github.com/repos/doctrine/phpcr-odm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/doctrine/phpcr-odm/issues/655/comments","statuses_url":"https://api.github.com/repos/doctrine/phpcr-odm/statuses/312ddd8c394f846c76298a8f403ff3db2ae00aa8","head":{"label":"doctrine:translation-conversion","ref":"translation-conversion","sha":"312ddd8c394f846c76298a8f403ff3db2ae00aa8","user":{"login":"doctrine","id":209254,"avatar_url":"https://avatars.githubusercontent.com/u/209254?v=3","gravatar_id":"","url":"https://api.github.com/users/doctrine","html_url":"https://github.com/doctrine","followers_url":"https://api.github.com/users/doctrine/followers","following_url":"https://api.github.com/users/doctrine/following{/other_user}","gists_url":"https://api.github.com/users/doctrine/gists{/gist_id}","starred_url":"https://api.github.com/users/doctrine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doctrine/subscriptions","organizations_url":"https://api.github.com/users/doctrine/orgs","repos_url":"https://api.github.com/users/doctrine/repos","events_url":"https://api.github.com/users/doctrine/events{/privacy}","received_events_url":"https://api.github.com/users/doctrine/received_events","type":"Organization","site_admin":false},"repo":{"id":1352419,"name":"phpcr-odm","full_name":"doctrine/phpcr-odm","owner":{"login":"doctrine","id":209254,"avatar_url":"https://avatars.githubusercontent.com/u/209254?v=3","gravatar_id":"","url":"https://api.github.com/users/doctrine","html_url":"https://github.com/doctrine","followers_url":"https://api.github.com/users/doctrine/followers","following_url":"https://api.github.com/users/doctrine/following{/other_user}","gists_url":"https://api.github.com/users/doctrine/gists{/gist_id}","starred_url":"https://api.github.com/users/doctrine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doctrine/subscriptions","organizations_url":"https://api.github.com/users/doctrine/orgs","repos_url":"https://api.github.com/users/doctrine/repos","events_url":"https://api.github.com/users/doctrine/events{/privacy}","received_events_url":"https://api.github.com/users/doctrine/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/doctrine/phpcr-odm","description":"Doctrine2 PHPCR ODM","fork":false,"url":"https://api.github.com/repos/doctrine/phpcr-odm","forks_url":"https://api.github.com/repos/doctrine/phpcr-odm/forks","keys_url":"https://api.github.com/repos/doctrine/phpcr-odm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/doctrine/phpcr-odm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/doctrine/phpcr-odm/teams","hooks_url":"https://api.github.com/repos/doctrine/phpcr-odm/hooks","issue_events_url":"https://api.github.com/repos/doctrine/phpcr-odm/issues/events{/number}","events_url":"https://api.github.com/repos/doctrine/phpcr-odm/events","assignees_url":"https://api.github.com/repos/doctrine/phpcr-odm/assignees{/user}","branches_url":"https://api.github.com/repos/doctrine/phpcr-odm/branches{/branch}","tags_url":"https://api.github.com/repos/doctrine/phpcr-odm/tags","blobs_url":"https://api.github.com/repos/doctrine/phpcr-odm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/doctrine/phpcr-odm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/doctrine/phpcr-odm/git/refs{/sha}","trees_url":"https://api.github.com/repos/doctrine/phpcr-odm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/doctrine/phpcr-odm/statuses/{sha}","languages_url":"https://api.github.com/repos/doctrine/phpcr-odm/languages","stargazers_url":"https://api.github.com/repos/doctrine/phpcr-odm/stargazers","contributors_url":"https://api.github.com/repos/doctrine/phpcr-odm/contributors","subscribers_url":"https://api.github.com/repos/doctrine/phpcr-odm/subscribers","subscription_url":"https://api.github.com/repos/doctrine/phpcr-odm/subscription","commits_url":"https://api.github.com/repos/doctrine/phpcr-odm/commits{/sha}","git_commits_url":"https://api.github.com/repos/doctrine/phpcr-odm/git/commits{/sha}","comments_url":"https://api.github.com/repos/doctrine/phpcr-odm/comments{/number}","issue_comment_url":"https://api.github.com/repos/doctrine/phpcr-odm/issues/comments{/number}","contents_url":"https://api.github.com/repos/doctrine/phpcr-odm/contents/{+path}","compare_url":"https://api.github.com/repos/doctrine/phpcr-odm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/doctrine/phpcr-odm/merges","archive_url":"https://api.github.com/repos/doctrine/phpcr-odm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/doctrine/phpcr-odm/downloads","issues_url":"https://api.github.com/repos/doctrine/phpcr-odm/issues{/number}","pulls_url":"https://api.github.com/repos/doctrine/phpcr-odm/pulls{/number}","milestones_url":"https://api.github.com/repos/doctrine/phpcr-odm/milestones{/number}","notifications_url":"https://api.github.com/repos/doctrine/phpcr-odm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/doctrine/phpcr-odm/labels{/name}","releases_url":"https://api.github.com/repos/doctrine/phpcr-odm/releases{/id}","created_at":"2011-02-10T21:22:18Z","updated_at":"2015-09-14T10:29:38Z","pushed_at":"2015-10-12T16:28:14Z","git_url":"git://github.com/doctrine/phpcr-odm.git","ssh_url":"git@github.com:doctrine/phpcr-odm.git","clone_url":"https://github.com/doctrine/phpcr-odm.git","svn_url":"https://github.com/doctrine/phpcr-odm","homepage":"http://www.doctrine-project.org/projects/phpcr-odm.html","size":9367,"stargazers_count":134,"watchers_count":134,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":75,"mirror_url":null,"open_issues_count":65,"forks":75,"open_issues":65,"watchers":134,"default_branch":"master"}},"base":{"label":"doctrine:master","ref":"master","sha":"ccb47713b53508fcc4355ba4b46acfa09cb7ae05","user":{"login":"doctrine","id":209254,"avatar_url":"https://avatars.githubusercontent.com/u/209254?v=3","gravatar_id":"","url":"https://api.github.com/users/doctrine","html_url":"https://github.com/doctrine","followers_url":"https://api.github.com/users/doctrine/followers","following_url":"https://api.github.com/users/doctrine/following{/other_user}","gists_url":"https://api.github.com/users/doctrine/gists{/gist_id}","starred_url":"https://api.github.com/users/doctrine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doctrine/subscriptions","organizations_url":"https://api.github.com/users/doctrine/orgs","repos_url":"https://api.github.com/users/doctrine/repos","events_url":"https://api.github.com/users/doctrine/events{/privacy}","received_events_url":"https://api.github.com/users/doctrine/received_events","type":"Organization","site_admin":false},"repo":{"id":1352419,"name":"phpcr-odm","full_name":"doctrine/phpcr-odm","owner":{"login":"doctrine","id":209254,"avatar_url":"https://avatars.githubusercontent.com/u/209254?v=3","gravatar_id":"","url":"https://api.github.com/users/doctrine","html_url":"https://github.com/doctrine","followers_url":"https://api.github.com/users/doctrine/followers","following_url":"https://api.github.com/users/doctrine/following{/other_user}","gists_url":"https://api.github.com/users/doctrine/gists{/gist_id}","starred_url":"https://api.github.com/users/doctrine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doctrine/subscriptions","organizations_url":"https://api.github.com/users/doctrine/orgs","repos_url":"https://api.github.com/users/doctrine/repos","events_url":"https://api.github.com/users/doctrine/events{/privacy}","received_events_url":"https://api.github.com/users/doctrine/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/doctrine/phpcr-odm","description":"Doctrine2 PHPCR ODM","fork":false,"url":"https://api.github.com/repos/doctrine/phpcr-odm","forks_url":"https://api.github.com/repos/doctrine/phpcr-odm/forks","keys_url":"https://api.github.com/repos/doctrine/phpcr-odm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/doctrine/phpcr-odm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/doctrine/phpcr-odm/teams","hooks_url":"https://api.github.com/repos/doctrine/phpcr-odm/hooks","issue_events_url":"https://api.github.com/repos/doctrine/phpcr-odm/issues/events{/number}","events_url":"https://api.github.com/repos/doctrine/phpcr-odm/events","assignees_url":"https://api.github.com/repos/doctrine/phpcr-odm/assignees{/user}","branches_url":"https://api.github.com/repos/doctrine/phpcr-odm/branches{/branch}","tags_url":"https://api.github.com/repos/doctrine/phpcr-odm/tags","blobs_url":"https://api.github.com/repos/doctrine/phpcr-odm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/doctrine/phpcr-odm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/doctrine/phpcr-odm/git/refs{/sha}","trees_url":"https://api.github.com/repos/doctrine/phpcr-odm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/doctrine/phpcr-odm/statuses/{sha}","languages_url":"https://api.github.com/repos/doctrine/phpcr-odm/languages","stargazers_url":"https://api.github.com/repos/doctrine/phpcr-odm/stargazers","contributors_url":"https://api.github.com/repos/doctrine/phpcr-odm/contributors","subscribers_url":"https://api.github.com/repos/doctrine/phpcr-odm/subscribers","subscription_url":"https://api.github.com/repos/doctrine/phpcr-odm/subscription","commits_url":"https://api.github.com/repos/doctrine/phpcr-odm/commits{/sha}","git_commits_url":"https://api.github.com/repos/doctrine/phpcr-odm/git/commits{/sha}","comments_url":"https://api.github.com/repos/doctrine/phpcr-odm/comments{/number}","issue_comment_url":"https://api.github.com/repos/doctrine/phpcr-odm/issues/comments{/number}","contents_url":"https://api.github.com/repos/doctrine/phpcr-odm/contents/{+path}","compare_url":"https://api.github.com/repos/doctrine/phpcr-odm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/doctrine/phpcr-odm/merges","archive_url":"https://api.github.com/repos/doctrine/phpcr-odm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/doctrine/phpcr-odm/downloads","issues_url":"https://api.github.com/repos/doctrine/phpcr-odm/issues{/number}","pulls_url":"https://api.github.com/repos/doctrine/phpcr-odm/pulls{/number}","milestones_url":"https://api.github.com/repos/doctrine/phpcr-odm/milestones{/number}","notifications_url":"https://api.github.com/repos/doctrine/phpcr-odm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/doctrine/phpcr-odm/labels{/name}","releases_url":"https://api.github.com/repos/doctrine/phpcr-odm/releases{/id}","created_at":"2011-02-10T21:22:18Z","updated_at":"2015-09-14T10:29:38Z","pushed_at":"2015-10-12T16:28:14Z","git_url":"git://github.com/doctrine/phpcr-odm.git","ssh_url":"git@github.com:doctrine/phpcr-odm.git","clone_url":"https://github.com/doctrine/phpcr-odm.git","svn_url":"https://github.com/doctrine/phpcr-odm","homepage":"http://www.doctrine-project.org/projects/phpcr-odm.html","size":9367,"stargazers_count":134,"watchers_count":134,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":75,"mirror_url":null,"open_issues_count":65,"forks":75,"open_issues":65,"watchers":134,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/doctrine/phpcr-odm/pulls/655"},"html":{"href":"https://github.com/doctrine/phpcr-odm/pull/655"},"issue":{"href":"https://api.github.com/repos/doctrine/phpcr-odm/issues/655"},"comments":{"href":"https://api.github.com/repos/doctrine/phpcr-odm/issues/655/comments"},"review_comments":{"href":"https://api.github.com/repos/doctrine/phpcr-odm/pulls/655/comments"},"review_comment":{"href":"https://api.github.com/repos/doctrine/phpcr-odm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/doctrine/phpcr-odm/pulls/655/commits"},"statuses":{"href":"https://api.github.com/repos/doctrine/phpcr-odm/statuses/312ddd8c394f846c76298a8f403ff3db2ae00aa8"}}}}