{"action":"opened","number":41,"pull_request":{"url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/pulls/41","id":64009708,"html_url":"https://github.com/d8-contrib-modules/field_encrypt/pull/41","diff_url":"https://github.com/d8-contrib-modules/field_encrypt/pull/41.diff","patch_url":"https://github.com/d8-contrib-modules/field_encrypt/pull/41.patch","issue_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/issues/41","number":41,"state":"open","locked":false,"title":"Issue #37 - implement cleaner method for encryption entities","user":{"login":"svendecabooter","id":201144,"avatar_url":"https://avatars.githubusercontent.com/u/201144?v=3","gravatar_id":"","url":"https://api.github.com/users/svendecabooter","html_url":"https://github.com/svendecabooter","followers_url":"https://api.github.com/users/svendecabooter/followers","following_url":"https://api.github.com/users/svendecabooter/following{/other_user}","gists_url":"https://api.github.com/users/svendecabooter/gists{/gist_id}","starred_url":"https://api.github.com/users/svendecabooter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/svendecabooter/subscriptions","organizations_url":"https://api.github.com/users/svendecabooter/orgs","repos_url":"https://api.github.com/users/svendecabooter/repos","events_url":"https://api.github.com/users/svendecabooter/events{/privacy}","received_events_url":"https://api.github.com/users/svendecabooter/received_events","type":"User","site_admin":false},"body":"The reported issue #37 exposed problems with the somewhat clunky way the field_encrypt module was saving the encrypted fields.\r\n\r\nThe main problem is that entity IDs and / or revision IDs are not known yet in hook_presave(), where the fields get encrypted. Thus the EncryptedFieldValue entities that get created with the encrypted data, cannot be linked to their parent entity at that point.\r\n\r\nInitially I solved this by reloading the entity after insert / update, and processing the field encryption then.\r\nHowever, this caused problems with the workbench_moderation module, enforcing new revisions, even when the field_encrypt module wanted to update the current revision for the encrypted fields, when we don't want to save a new revision.\r\n\r\nLong story short, I have found a cleaner and less error-prone way to handle this.\r\nIn case the parent entity (revision) IDs are known, we can just save the EncryptedFieldValue entities containing the encrypted data.\r\nIn case the parent entity (revision) IDs are not known, we mark the field data as encrypted, and create the accompanying EncryptedFieldValue entities, but not yet saving them - we just attach them to the parent entity object.\r\nWhen the parent entity object gets passed to hook_entity_insert() or hook_entity_update(), we DO have the proper (revision) IDs, so we set them on the EncryptedFieldValue entities, and save those.\r\n\r\nThis works with the different tested variations of entities having revisions and / or translations.\r\nIt also works with the workbench_moderation module now.","created_at":"2016-03-24T09:42:10Z","updated_at":"2016-03-24T09:42:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/pulls/41/commits","review_comments_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/pulls/41/comments","review_comment_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/pulls/comments{/number}","comments_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/issues/41/comments","statuses_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/statuses/e0d14a0e2b0e03bcda7e6317d0ba741b35eaab33","head":{"label":"svendecabooter:issue-37","ref":"issue-37","sha":"e0d14a0e2b0e03bcda7e6317d0ba741b35eaab33","user":{"login":"svendecabooter","id":201144,"avatar_url":"https://avatars.githubusercontent.com/u/201144?v=3","gravatar_id":"","url":"https://api.github.com/users/svendecabooter","html_url":"https://github.com/svendecabooter","followers_url":"https://api.github.com/users/svendecabooter/followers","following_url":"https://api.github.com/users/svendecabooter/following{/other_user}","gists_url":"https://api.github.com/users/svendecabooter/gists{/gist_id}","starred_url":"https://api.github.com/users/svendecabooter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/svendecabooter/subscriptions","organizations_url":"https://api.github.com/users/svendecabooter/orgs","repos_url":"https://api.github.com/users/svendecabooter/repos","events_url":"https://api.github.com/users/svendecabooter/events{/privacy}","received_events_url":"https://api.github.com/users/svendecabooter/received_events","type":"User","site_admin":false},"repo":{"id":52284749,"name":"field_encrypt","full_name":"svendecabooter/field_encrypt","owner":{"login":"svendecabooter","id":201144,"avatar_url":"https://avatars.githubusercontent.com/u/201144?v=3","gravatar_id":"","url":"https://api.github.com/users/svendecabooter","html_url":"https://github.com/svendecabooter","followers_url":"https://api.github.com/users/svendecabooter/followers","following_url":"https://api.github.com/users/svendecabooter/following{/other_user}","gists_url":"https://api.github.com/users/svendecabooter/gists{/gist_id}","starred_url":"https://api.github.com/users/svendecabooter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/svendecabooter/subscriptions","organizations_url":"https://api.github.com/users/svendecabooter/orgs","repos_url":"https://api.github.com/users/svendecabooter/repos","events_url":"https://api.github.com/users/svendecabooter/events{/privacy}","received_events_url":"https://api.github.com/users/svendecabooter/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/svendecabooter/field_encrypt","description":"D8 port for field_encrypt module","fork":true,"url":"https://api.github.com/repos/svendecabooter/field_encrypt","forks_url":"https://api.github.com/repos/svendecabooter/field_encrypt/forks","keys_url":"https://api.github.com/repos/svendecabooter/field_encrypt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/svendecabooter/field_encrypt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/svendecabooter/field_encrypt/teams","hooks_url":"https://api.github.com/repos/svendecabooter/field_encrypt/hooks","issue_events_url":"https://api.github.com/repos/svendecabooter/field_encrypt/issues/events{/number}","events_url":"https://api.github.com/repos/svendecabooter/field_encrypt/events","assignees_url":"https://api.github.com/repos/svendecabooter/field_encrypt/assignees{/user}","branches_url":"https://api.github.com/repos/svendecabooter/field_encrypt/branches{/branch}","tags_url":"https://api.github.com/repos/svendecabooter/field_encrypt/tags","blobs_url":"https://api.github.com/repos/svendecabooter/field_encrypt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/svendecabooter/field_encrypt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/svendecabooter/field_encrypt/git/refs{/sha}","trees_url":"https://api.github.com/repos/svendecabooter/field_encrypt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/svendecabooter/field_encrypt/statuses/{sha}","languages_url":"https://api.github.com/repos/svendecabooter/field_encrypt/languages","stargazers_url":"https://api.github.com/repos/svendecabooter/field_encrypt/stargazers","contributors_url":"https://api.github.com/repos/svendecabooter/field_encrypt/contributors","subscribers_url":"https://api.github.com/repos/svendecabooter/field_encrypt/subscribers","subscription_url":"https://api.github.com/repos/svendecabooter/field_encrypt/subscription","commits_url":"https://api.github.com/repos/svendecabooter/field_encrypt/commits{/sha}","git_commits_url":"https://api.github.com/repos/svendecabooter/field_encrypt/git/commits{/sha}","comments_url":"https://api.github.com/repos/svendecabooter/field_encrypt/comments{/number}","issue_comment_url":"https://api.github.com/repos/svendecabooter/field_encrypt/issues/comments{/number}","contents_url":"https://api.github.com/repos/svendecabooter/field_encrypt/contents/{+path}","compare_url":"https://api.github.com/repos/svendecabooter/field_encrypt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/svendecabooter/field_encrypt/merges","archive_url":"https://api.github.com/repos/svendecabooter/field_encrypt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/svendecabooter/field_encrypt/downloads","issues_url":"https://api.github.com/repos/svendecabooter/field_encrypt/issues{/number}","pulls_url":"https://api.github.com/repos/svendecabooter/field_encrypt/pulls{/number}","milestones_url":"https://api.github.com/repos/svendecabooter/field_encrypt/milestones{/number}","notifications_url":"https://api.github.com/repos/svendecabooter/field_encrypt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/svendecabooter/field_encrypt/labels{/name}","releases_url":"https://api.github.com/repos/svendecabooter/field_encrypt/releases{/id}","deployments_url":"https://api.github.com/repos/svendecabooter/field_encrypt/deployments","created_at":"2016-02-22T15:50:32Z","updated_at":"2016-02-22T15:50:33Z","pushed_at":"2016-03-24T09:34:34Z","git_url":"git://github.com/svendecabooter/field_encrypt.git","ssh_url":"git@github.com:svendecabooter/field_encrypt.git","clone_url":"https://github.com/svendecabooter/field_encrypt.git","svn_url":"https://github.com/svendecabooter/field_encrypt","homepage":null,"size":393,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"d8-contrib-modules:master","ref":"master","sha":"539f2f05840a100da9561ce4061a1ce2f349936c","user":{"login":"d8-contrib-modules","id":13561676,"avatar_url":"https://avatars.githubusercontent.com/u/13561676?v=3","gravatar_id":"","url":"https://api.github.com/users/d8-contrib-modules","html_url":"https://github.com/d8-contrib-modules","followers_url":"https://api.github.com/users/d8-contrib-modules/followers","following_url":"https://api.github.com/users/d8-contrib-modules/following{/other_user}","gists_url":"https://api.github.com/users/d8-contrib-modules/gists{/gist_id}","starred_url":"https://api.github.com/users/d8-contrib-modules/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/d8-contrib-modules/subscriptions","organizations_url":"https://api.github.com/users/d8-contrib-modules/orgs","repos_url":"https://api.github.com/users/d8-contrib-modules/repos","events_url":"https://api.github.com/users/d8-contrib-modules/events{/privacy}","received_events_url":"https://api.github.com/users/d8-contrib-modules/received_events","type":"Organization","site_admin":false},"repo":{"id":40326766,"name":"field_encrypt","full_name":"d8-contrib-modules/field_encrypt","owner":{"login":"d8-contrib-modules","id":13561676,"avatar_url":"https://avatars.githubusercontent.com/u/13561676?v=3","gravatar_id":"","url":"https://api.github.com/users/d8-contrib-modules","html_url":"https://github.com/d8-contrib-modules","followers_url":"https://api.github.com/users/d8-contrib-modules/followers","following_url":"https://api.github.com/users/d8-contrib-modules/following{/other_user}","gists_url":"https://api.github.com/users/d8-contrib-modules/gists{/gist_id}","starred_url":"https://api.github.com/users/d8-contrib-modules/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/d8-contrib-modules/subscriptions","organizations_url":"https://api.github.com/users/d8-contrib-modules/orgs","repos_url":"https://api.github.com/users/d8-contrib-modules/repos","events_url":"https://api.github.com/users/d8-contrib-modules/events{/privacy}","received_events_url":"https://api.github.com/users/d8-contrib-modules/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/d8-contrib-modules/field_encrypt","description":"D8 port for field_encrypt module","fork":false,"url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt","forks_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/forks","keys_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/teams","hooks_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/hooks","issue_events_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/issues/events{/number}","events_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/events","assignees_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/assignees{/user}","branches_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/branches{/branch}","tags_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/tags","blobs_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/git/refs{/sha}","trees_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/statuses/{sha}","languages_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/languages","stargazers_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/stargazers","contributors_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/contributors","subscribers_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/subscribers","subscription_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/subscription","commits_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/commits{/sha}","git_commits_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/git/commits{/sha}","comments_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/comments{/number}","issue_comment_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/issues/comments{/number}","contents_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/contents/{+path}","compare_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/merges","archive_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/downloads","issues_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/issues{/number}","pulls_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/pulls{/number}","milestones_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/milestones{/number}","notifications_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/labels{/name}","releases_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/releases{/id}","deployments_url":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/deployments","created_at":"2015-08-06T21:01:26Z","updated_at":"2016-02-29T14:41:52Z","pushed_at":"2016-03-23T14:29:02Z","git_url":"git://github.com/d8-contrib-modules/field_encrypt.git","ssh_url":"git@github.com:d8-contrib-modules/field_encrypt.git","clone_url":"https://github.com/d8-contrib-modules/field_encrypt.git","svn_url":"https://github.com/d8-contrib-modules/field_encrypt","homepage":null,"size":387,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":12,"forks":7,"open_issues":12,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/pulls/41"},"html":{"href":"https://github.com/d8-contrib-modules/field_encrypt/pull/41"},"issue":{"href":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/issues/41"},"comments":{"href":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/issues/41/comments"},"review_comments":{"href":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/pulls/41/comments"},"review_comment":{"href":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/pulls/41/commits"},"statuses":{"href":"https://api.github.com/repos/d8-contrib-modules/field_encrypt/statuses/e0d14a0e2b0e03bcda7e6317d0ba741b35eaab33"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":1,"additions":79,"deletions":48,"changed_files":6}}