{"action":"created","comment":{"url":"https://api.github.com/repos/woocommerce/woocommerce/pulls/comments/88935611","pull_request_review_id":9491590,"id":88935611,"diff_hunk":"@@ -33,136 +33,111 @@ public static function init() {\n \t * Check if we need to download a file and check validity.\n \t */\n \tpublic static function download_product() {\n-\t\t$product_id    = absint( $_GET['download_file'] );\n-\t\t$_product      = wc_get_product( $product_id );\n-\t\t$download_data = self::get_download_data( array(\n-\t\t\t'product_id'  => $product_id,\n-\t\t\t'order_key'   => wc_clean( $_GET['order'] ),\n-\t\t\t'email'       => sanitize_email( str_replace( ' ', '+', $_GET['email'] ) ),\n-\t\t\t'download_id' => wc_clean( isset( $_GET['key'] ) ? preg_replace( '/\\s+/', ' ', $_GET['key'] ) : '' ),\n-\t\t) );\n+\t\t$product_id   = absint( $_GET['download_file'] );\n+\t\t$product      = wc_get_product( $product_id );\n+\t\t$data_store   = WC_Data_Store::load( 'customer-download' );\n \n-\t\tif ( $_product && $download_data ) {\n-\t\t\tself::check_current_user_can_download( $download_data );\n-\n-\t\t\tdo_action( 'woocommerce_download_product', $download_data->user_email, $download_data->order_key, $download_data->product_id, $download_data->user_id, $download_data->download_id, $download_data->order_id );\n-\n-\t\t\tself::count_download( $download_data );\n-\t\t\tself::download( $_product->get_file_download_path( $download_data->download_id ), $download_data->product_id );\n-\t\t} else {\n+\t\tif ( ! $product || ! isset( $_GET['key'], $_GET['order'] ) ) {\n \t\t\tself::download_error( __( 'Invalid download link.', 'woocommerce' ) );\n \t\t}\n-\t}\n-\n-\t/**\n-\t * Get a download from the database.\n-\t *\n-\t * @param  array  $args Contains email, order key, product id and download id\n-\t * @return object\n-\t * @access private\n-\t */\n-\tprivate static function get_download_data( $args = array() ) {\n-\t\tglobal $wpdb;\n \n-\t\t$query = \"SELECT * FROM \" . $wpdb->prefix . \"woocommerce_downloadable_product_permissions \";\n-\t\t$query .= \"WHERE user_email = %s \";\n-\t\t$query .= \"AND order_key = %s \";\n-\t\t$query .= \"AND product_id = %s \";\n+\t\t$download_ids = $data_store->get_downloads( array(\n+\t\t\t'user_email'  => sanitize_email( str_replace( ' ', '+', $_GET['email'] ) ),","path":"includes/class-wc-download-handler.php","position":44,"original_position":44,"commit_id":"32de28355a717011c1276eeb642b48f8a66b1a62","original_commit_id":"32de28355a717011c1276eeb642b48f8a66b1a62","user":{"login":"mikejolley","id":90977,"avatar_url":"https://avatars.githubusercontent.com/u/90977?v=3","gravatar_id":"","url":"https://api.github.com/users/mikejolley","html_url":"https://github.com/mikejolley","followers_url":"https://api.github.com/users/mikejolley/followers","following_url":"https://api.github.com/users/mikejolley/following{/other_user}","gists_url":"https://api.github.com/users/mikejolley/gists{/gist_id}","starred_url":"https://api.github.com/users/mikejolley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikejolley/subscriptions","organizations_url":"https://api.github.com/users/mikejolley/orgs","repos_url":"https://api.github.com/users/mikejolley/repos","events_url":"https://api.github.com/users/mikejolley/events{/privacy}","received_events_url":"https://api.github.com/users/mikejolley/received_events","type":"User","site_admin":false},"body":"No, but if the + has been removed due to sanitization, this puts it back.","created_at":"2016-11-21T16:42:45Z","updated_at":"2016-11-21T16:42:45Z","html_url":"https://github.com/woocommerce/woocommerce/pull/12386#discussion_r88935611","pull_request_url":"https://api.github.com/repos/woocommerce/woocommerce/pulls/12386","_links":{"self":{"href":"https://api.github.com/repos/woocommerce/woocommerce/pulls/comments/88935611"},"html":{"href":"https://github.com/woocommerce/woocommerce/pull/12386#discussion_r88935611"},"pull_request":{"href":"https://api.github.com/repos/woocommerce/woocommerce/pulls/12386"}}},"pull_request":{"url":"https://api.github.com/repos/woocommerce/woocommerce/pulls/12386","id":94209135,"html_url":"https://github.com/woocommerce/woocommerce/pull/12386","diff_url":"https://github.com/woocommerce/woocommerce/pull/12386.diff","patch_url":"https://github.com/woocommerce/woocommerce/pull/12386.patch","issue_url":"https://api.github.com/repos/woocommerce/woocommerce/issues/12386","number":12386,"state":"open","locked":false,"title":"Order data stores","user":{"login":"mikejolley","id":90977,"avatar_url":"https://avatars.githubusercontent.com/u/90977?v=3","gravatar_id":"","url":"https://api.github.com/users/mikejolley","html_url":"https://github.com/mikejolley","followers_url":"https://api.github.com/users/mikejolley/followers","following_url":"https://api.github.com/users/mikejolley/following{/other_user}","gists_url":"https://api.github.com/users/mikejolley/gists{/gist_id}","starred_url":"https://api.github.com/users/mikejolley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikejolley/subscriptions","organizations_url":"https://api.github.com/users/mikejolley/orgs","repos_url":"https://api.github.com/users/mikejolley/repos","events_url":"https://api.github.com/users/mikejolley/events{/privacy}","received_events_url":"https://api.github.com/users/mikejolley/received_events","type":"User","site_admin":false},"body":"This is the order data store for #12320. This also takes care of refunds.\r\n\r\nTodo:\r\n\r\n- [x] Order functions\r\n- [x] Unit tests need to pass","created_at":"2016-11-17T17:06:51Z","updated_at":"2016-11-21T16:42:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4a309ab1211c2cce091a723fe445991264857352","assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/woocommerce/woocommerce/milestones/59","html_url":"https://github.com/woocommerce/woocommerce/milestones/[2.7]%20Sprint%20-%20CRUD%20","labels_url":"https://api.github.com/repos/woocommerce/woocommerce/milestones/59/labels","id":2129833,"number":59,"title":"[2.7] Sprint - CRUD ","description":"Sprint Goal - All CRUD classes and data stores complete, with passing unit tests.","creator":{"login":"mikejolley","id":90977,"avatar_url":"https://avatars.githubusercontent.com/u/90977?v=3","gravatar_id":"","url":"https://api.github.com/users/mikejolley","html_url":"https://github.com/mikejolley","followers_url":"https://api.github.com/users/mikejolley/followers","following_url":"https://api.github.com/users/mikejolley/following{/other_user}","gists_url":"https://api.github.com/users/mikejolley/gists{/gist_id}","starred_url":"https://api.github.com/users/mikejolley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikejolley/subscriptions","organizations_url":"https://api.github.com/users/mikejolley/orgs","repos_url":"https://api.github.com/users/mikejolley/repos","events_url":"https://api.github.com/users/mikejolley/events{/privacy}","received_events_url":"https://api.github.com/users/mikejolley/received_events","type":"User","site_admin":false},"open_issues":11,"closed_issues":23,"state":"open","created_at":"2016-11-11T17:15:29Z","updated_at":"2016-11-21T16:35:34Z","due_on":"2016-11-22T00:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/woocommerce/woocommerce/pulls/12386/commits","review_comments_url":"https://api.github.com/repos/woocommerce/woocommerce/pulls/12386/comments","review_comment_url":"https://api.github.com/repos/woocommerce/woocommerce/pulls/comments{/number}","comments_url":"https://api.github.com/repos/woocommerce/woocommerce/issues/12386/comments","statuses_url":"https://api.github.com/repos/woocommerce/woocommerce/statuses/32de28355a717011c1276eeb642b48f8a66b1a62","head":{"label":"woocommerce:order-data-store","ref":"order-data-store","sha":"32de28355a717011c1276eeb642b48f8a66b1a62","user":{"login":"woocommerce","id":473596,"avatar_url":"https://avatars.githubusercontent.com/u/473596?v=3","gravatar_id":"","url":"https://api.github.com/users/woocommerce","html_url":"https://github.com/woocommerce","followers_url":"https://api.github.com/users/woocommerce/followers","following_url":"https://api.github.com/users/woocommerce/following{/other_user}","gists_url":"https://api.github.com/users/woocommerce/gists{/gist_id}","starred_url":"https://api.github.com/users/woocommerce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/woocommerce/subscriptions","organizations_url":"https://api.github.com/users/woocommerce/orgs","repos_url":"https://api.github.com/users/woocommerce/repos","events_url":"https://api.github.com/users/woocommerce/events{/privacy}","received_events_url":"https://api.github.com/users/woocommerce/received_events","type":"Organization","site_admin":false},"repo":{"id":2179920,"name":"woocommerce","full_name":"woocommerce/woocommerce","owner":{"login":"woocommerce","id":473596,"avatar_url":"https://avatars.githubusercontent.com/u/473596?v=3","gravatar_id":"","url":"https://api.github.com/users/woocommerce","html_url":"https://github.com/woocommerce","followers_url":"https://api.github.com/users/woocommerce/followers","following_url":"https://api.github.com/users/woocommerce/following{/other_user}","gists_url":"https://api.github.com/users/woocommerce/gists{/gist_id}","starred_url":"https://api.github.com/users/woocommerce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/woocommerce/subscriptions","organizations_url":"https://api.github.com/users/woocommerce/orgs","repos_url":"https://api.github.com/users/woocommerce/repos","events_url":"https://api.github.com/users/woocommerce/events{/privacy}","received_events_url":"https://api.github.com/users/woocommerce/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/woocommerce/woocommerce","description":"An open source eCommerce plugin for WordPress.","fork":false,"url":"https://api.github.com/repos/woocommerce/woocommerce","forks_url":"https://api.github.com/repos/woocommerce/woocommerce/forks","keys_url":"https://api.github.com/repos/woocommerce/woocommerce/keys{/key_id}","collaborators_url":"https://api.github.com/repos/woocommerce/woocommerce/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/woocommerce/woocommerce/teams","hooks_url":"https://api.github.com/repos/woocommerce/woocommerce/hooks","issue_events_url":"https://api.github.com/repos/woocommerce/woocommerce/issues/events{/number}","events_url":"https://api.github.com/repos/woocommerce/woocommerce/events","assignees_url":"https://api.github.com/repos/woocommerce/woocommerce/assignees{/user}","branches_url":"https://api.github.com/repos/woocommerce/woocommerce/branches{/branch}","tags_url":"https://api.github.com/repos/woocommerce/woocommerce/tags","blobs_url":"https://api.github.com/repos/woocommerce/woocommerce/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/woocommerce/woocommerce/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/woocommerce/woocommerce/git/refs{/sha}","trees_url":"https://api.github.com/repos/woocommerce/woocommerce/git/trees{/sha}","statuses_url":"https://api.github.com/repos/woocommerce/woocommerce/statuses/{sha}","languages_url":"https://api.github.com/repos/woocommerce/woocommerce/languages","stargazers_url":"https://api.github.com/repos/woocommerce/woocommerce/stargazers","contributors_url":"https://api.github.com/repos/woocommerce/woocommerce/contributors","subscribers_url":"https://api.github.com/repos/woocommerce/woocommerce/subscribers","subscription_url":"https://api.github.com/repos/woocommerce/woocommerce/subscription","commits_url":"https://api.github.com/repos/woocommerce/woocommerce/commits{/sha}","git_commits_url":"https://api.github.com/repos/woocommerce/woocommerce/git/commits{/sha}","comments_url":"https://api.github.com/repos/woocommerce/woocommerce/comments{/number}","issue_comment_url":"https://api.github.com/repos/woocommerce/woocommerce/issues/comments{/number}","contents_url":"https://api.github.com/repos/woocommerce/woocommerce/contents/{+path}","compare_url":"https://api.github.com/repos/woocommerce/woocommerce/compare/{base}...{head}","merges_url":"https://api.github.com/repos/woocommerce/woocommerce/merges","archive_url":"https://api.github.com/repos/woocommerce/woocommerce/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/woocommerce/woocommerce/downloads","issues_url":"https://api.github.com/repos/woocommerce/woocommerce/issues{/number}","pulls_url":"https://api.github.com/repos/woocommerce/woocommerce/pulls{/number}","milestones_url":"https://api.github.com/repos/woocommerce/woocommerce/milestones{/number}","notifications_url":"https://api.github.com/repos/woocommerce/woocommerce/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/woocommerce/woocommerce/labels{/name}","releases_url":"https://api.github.com/repos/woocommerce/woocommerce/releases{/id}","deployments_url":"https://api.github.com/repos/woocommerce/woocommerce/deployments","created_at":"2011-08-09T15:12:11Z","updated_at":"2016-11-21T01:12:10Z","pushed_at":"2016-11-21T16:12:53Z","git_url":"git://github.com/woocommerce/woocommerce.git","ssh_url":"git@github.com:woocommerce/woocommerce.git","clone_url":"https://github.com/woocommerce/woocommerce.git","svn_url":"https://github.com/woocommerce/woocommerce","homepage":"http://www.woocommerce.com/","size":139790,"stargazers_count":2990,"watchers_count":2990,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2536,"mirror_url":null,"open_issues_count":63,"forks":2536,"open_issues":63,"watchers":2990,"default_branch":"master"}},"base":{"label":"woocommerce:master","ref":"master","sha":"4bbe1d39dc5753ecf6be736ed7bdcdd5ec77c09d","user":{"login":"woocommerce","id":473596,"avatar_url":"https://avatars.githubusercontent.com/u/473596?v=3","gravatar_id":"","url":"https://api.github.com/users/woocommerce","html_url":"https://github.com/woocommerce","followers_url":"https://api.github.com/users/woocommerce/followers","following_url":"https://api.github.com/users/woocommerce/following{/other_user}","gists_url":"https://api.github.com/users/woocommerce/gists{/gist_id}","starred_url":"https://api.github.com/users/woocommerce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/woocommerce/subscriptions","organizations_url":"https://api.github.com/users/woocommerce/orgs","repos_url":"https://api.github.com/users/woocommerce/repos","events_url":"https://api.github.com/users/woocommerce/events{/privacy}","received_events_url":"https://api.github.com/users/woocommerce/received_events","type":"Organization","site_admin":false},"repo":{"id":2179920,"name":"woocommerce","full_name":"woocommerce/woocommerce","owner":{"login":"woocommerce","id":473596,"avatar_url":"https://avatars.githubusercontent.com/u/473596?v=3","gravatar_id":"","url":"https://api.github.com/users/woocommerce","html_url":"https://github.com/woocommerce","followers_url":"https://api.github.com/users/woocommerce/followers","following_url":"https://api.github.com/users/woocommerce/following{/other_user}","gists_url":"https://api.github.com/users/woocommerce/gists{/gist_id}","starred_url":"https://api.github.com/users/woocommerce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/woocommerce/subscriptions","organizations_url":"https://api.github.com/users/woocommerce/orgs","repos_url":"https://api.github.com/users/woocommerce/repos","events_url":"https://api.github.com/users/woocommerce/events{/privacy}","received_events_url":"https://api.github.com/users/woocommerce/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/woocommerce/woocommerce","description":"An open source eCommerce plugin for WordPress.","fork":false,"url":"https://api.github.com/repos/woocommerce/woocommerce","forks_url":"https://api.github.com/repos/woocommerce/woocommerce/forks","keys_url":"https://api.github.com/repos/woocommerce/woocommerce/keys{/key_id}","collaborators_url":"https://api.github.com/repos/woocommerce/woocommerce/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/woocommerce/woocommerce/teams","hooks_url":"https://api.github.com/repos/woocommerce/woocommerce/hooks","issue_events_url":"https://api.github.com/repos/woocommerce/woocommerce/issues/events{/number}","events_url":"https://api.github.com/repos/woocommerce/woocommerce/events","assignees_url":"https://api.github.com/repos/woocommerce/woocommerce/assignees{/user}","branches_url":"https://api.github.com/repos/woocommerce/woocommerce/branches{/branch}","tags_url":"https://api.github.com/repos/woocommerce/woocommerce/tags","blobs_url":"https://api.github.com/repos/woocommerce/woocommerce/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/woocommerce/woocommerce/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/woocommerce/woocommerce/git/refs{/sha}","trees_url":"https://api.github.com/repos/woocommerce/woocommerce/git/trees{/sha}","statuses_url":"https://api.github.com/repos/woocommerce/woocommerce/statuses/{sha}","languages_url":"https://api.github.com/repos/woocommerce/woocommerce/languages","stargazers_url":"https://api.github.com/repos/woocommerce/woocommerce/stargazers","contributors_url":"https://api.github.com/repos/woocommerce/woocommerce/contributors","subscribers_url":"https://api.github.com/repos/woocommerce/woocommerce/subscribers","subscription_url":"https://api.github.com/repos/woocommerce/woocommerce/subscription","commits_url":"https://api.github.com/repos/woocommerce/woocommerce/commits{/sha}","git_commits_url":"https://api.github.com/repos/woocommerce/woocommerce/git/commits{/sha}","comments_url":"https://api.github.com/repos/woocommerce/woocommerce/comments{/number}","issue_comment_url":"https://api.github.com/repos/woocommerce/woocommerce/issues/comments{/number}","contents_url":"https://api.github.com/repos/woocommerce/woocommerce/contents/{+path}","compare_url":"https://api.github.com/repos/woocommerce/woocommerce/compare/{base}...{head}","merges_url":"https://api.github.com/repos/woocommerce/woocommerce/merges","archive_url":"https://api.github.com/repos/woocommerce/woocommerce/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/woocommerce/woocommerce/downloads","issues_url":"https://api.github.com/repos/woocommerce/woocommerce/issues{/number}","pulls_url":"https://api.github.com/repos/woocommerce/woocommerce/pulls{/number}","milestones_url":"https://api.github.com/repos/woocommerce/woocommerce/milestones{/number}","notifications_url":"https://api.github.com/repos/woocommerce/woocommerce/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/woocommerce/woocommerce/labels{/name}","releases_url":"https://api.github.com/repos/woocommerce/woocommerce/releases{/id}","deployments_url":"https://api.github.com/repos/woocommerce/woocommerce/deployments","created_at":"2011-08-09T15:12:11Z","updated_at":"2016-11-21T01:12:10Z","pushed_at":"2016-11-21T16:12:53Z","git_url":"git://github.com/woocommerce/woocommerce.git","ssh_url":"git@github.com:woocommerce/woocommerce.git","clone_url":"https://github.com/woocommerce/woocommerce.git","svn_url":"https://github.com/woocommerce/woocommerce","homepage":"http://www.woocommerce.com/","size":139790,"stargazers_count":2990,"watchers_count":2990,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2536,"mirror_url":null,"open_issues_count":63,"forks":2536,"open_issues":63,"watchers":2990,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/woocommerce/woocommerce/pulls/12386"},"html":{"href":"https://github.com/woocommerce/woocommerce/pull/12386"},"issue":{"href":"https://api.github.com/repos/woocommerce/woocommerce/issues/12386"},"comments":{"href":"https://api.github.com/repos/woocommerce/woocommerce/issues/12386/comments"},"review_comments":{"href":"https://api.github.com/repos/woocommerce/woocommerce/pulls/12386/comments"},"review_comment":{"href":"https://api.github.com/repos/woocommerce/woocommerce/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/woocommerce/woocommerce/pulls/12386/commits"},"statuses":{"href":"https://api.github.com/repos/woocommerce/woocommerce/statuses/32de28355a717011c1276eeb642b48f8a66b1a62"}}}}
{"actor":{"display_login":"mikejolley"}}