{"action":"created","comment":{"url":"https://api.github.com/repos/bugcache/bugcache/pulls/comments/59725157","id":59725157,"diff_hunk":"@@ -53,9 +64,88 @@ public function submit(Request $req) {\n \t\t\treturn null;\n \t\t}\n \n-\t\t$info = yield $this->submit->execute([\"title\" => $title, \"data\" => $data]);\n+\t\t$add = [];\n+\t\t$promises = [];\n+\t\tforeach ($this->fields as $field => $info) {\n+\t\t\t$attrs = array_filter($body->getArray($field), function ($x) { return $x != \"\"; });\n+\n+\t\t\tif (empty($info[\"multi\"]) && count($attrs) > 1) {\n+\t\t\t\treturn null;\n+\t\t\t}\n+\n+\t\t\tif (count($attrs) < ($info[\"required\"] ?? 0)) {\n+\t\t\t\treturn null;\n+\t\t\t}\n+\n+\t\t\tforeach ($attrs as $attr) {\n+\t\t\t\tswitch ($info[\"type\"]) {\n+\t\t\t\t\tcase self::USER:\n+\t\t\t\t\t\tif (filter_var($attr, FILTER_VALIDATE_INT)) {\n+\t\t\t\t\t\t\t$promises[] = \\Amp\\pipe($this->db->prepare(\"SELECT id FROM users WHERE id = ?\", [$attr]), function($val) {\n+\t\t\t\t\t\t\t\treturn \\Amp\\pipe($val->rowCount(), function($count) {\n+\t\t\t\t\t\t\t\t\tif ($count == 0) {\n+\t\t\t\t\t\t\t\t\t\treturn 1; // error, add identifier for message\n+\t\t\t\t\t\t\t\t\t}\n+\t\t\t\t\t\t\t\t});\n+\t\t\t\t\t\t\t});\n+\t\t\t\t\t\t}\n+\t\t\t\t\t\t$promises[] = \\Amp\\pipe($this->db->prepare(\"SELECT id FROM users WHERE name = ?\", [$attr]), function($val) use (&$attr) {\n+\t\t\t\t\t\t\treturn \\Amp\\pipe($val->fetchObject(), function($row) use (&$attr) {\n+\t\t\t\t\t\t\t\tif ($row) {\n+\t\t\t\t\t\t\t\t\t$attr = $row->id;\n+\t\t\t\t\t\t\t\t} else {\n+\t\t\t\t\t\t\t\t\treturn 1; // error, add identifier for message\n+\t\t\t\t\t\t\t\t}\n+\t\t\t\t\t\t\t});\n+\t\t\t\t\t\t});\n+\t\t\t\t\t\tbreak;\n+\t\t\t\t\tcase self::INT:\n+\t\t\t\t\t\tif (($attr = filter_var($attr, FILTER_VALIDATE_INT)) === false) {\n+\t\t\t\t\t\t\treturn null;\n+\t\t\t\t\t\t}\n+\t\t\t\t\tcase self::ENUM:\n+\t\t\t\t\t\tforeach ($info[\"values\"] as $val) {\n+\t\t\t\t\t\t\tif ($attr == $val[\"name\"]) {\n+\t\t\t\t\t\t\t\tbreak 2;\n+\t\t\t\t\t\t\t}\n+\t\t\t\t\t\t}\n+\t\t\t\t\t\treturn null;\n+\t\t\t\t}\n+\n+\t\t\t\t$add[] = &$id;\n+\t\t\t\t$add[] = $field;\n+\t\t\t\t$add[] = &$attr;\n+\t\t\t\tunset($attr);\n+\t\t\t}\n+\t\t}\n+\n+\t\tif ($errors = yield \\Amp\\filter($promises)) {\n+\t\t\treturn null;\n+\t\t}\n \n-\t\treturn [\"id\" => $info->insertId];\n+\t\t$conn = yield $this->db->getConnection();\n+\t\t$conn->query(\"START TRANSACTION\");\n+\t\t\n+\t\tif ($id = $routed[\"id\"] ?? 0) {\n+\t\t\t$info = yield $conn->prepare(\"UPDATE bugs SET title = :title, data = :data WHERE id = :id\", [\"id\" => $id, \"title\" => $title, \"data\" => $data]);\n+\t\t\tif (!$info->affectedRows) {\n+\t\t\t\treturn null;\n+\t\t\t}\n+\t\t\tyield $conn->prepare(\"DELETE FROM bugattrs WHERE bug = :id\", [\"id\" => $id]);\n+\t\t} else {\n+\t\t\t$session = $req->getLocalVar(RequestKeys::SESSION);\n+\t\t\t$uid = $session->get(SessionKeys::LOGIN);\n+\t\t\t$info = yield $conn->prepare(\"INSERT INTO bugs (title, data, submitter) VALUES (:title, :data, :submitter)\", [\"title\" => $title, \"data\" => $data, \"submitter\" => $uid]);\n+\t\t\t$id = $info->insertId;\n+\t\t}\n+\n+\t\tif ($add) {\n+\t\t\tyield $conn->prepare(\"INSERT INTO bugattrs (bug, attribute, value) VALUES (?, ?, ?)\" . str_repeat(\", (?, ?, ?)\", count($add) / 3 - 1), $add);\n+\t\t}\n+\t\t\n+\t\t$conn->query(\"COMMIT\");","path":"src/BugManager.php","position":135,"original_position":135,"commit_id":"452c89eb9565755be44898328101e7b5a21d042c","original_commit_id":"452c89eb9565755be44898328101e7b5a21d042c","user":{"login":"staabm","id":120441,"avatar_url":"https://avatars.githubusercontent.com/u/120441?v=3","gravatar_id":"","url":"https://api.github.com/users/staabm","html_url":"https://github.com/staabm","followers_url":"https://api.github.com/users/staabm/followers","following_url":"https://api.github.com/users/staabm/following{/other_user}","gists_url":"https://api.github.com/users/staabm/gists{/gist_id}","starred_url":"https://api.github.com/users/staabm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/staabm/subscriptions","organizations_url":"https://api.github.com/users/staabm/orgs","repos_url":"https://api.github.com/users/staabm/repos","events_url":"https://api.github.com/users/staabm/events{/privacy}","received_events_url":"https://api.github.com/users/staabm/received_events","type":"User","site_admin":false},"body":"the changes are only visible within your transaction for you, but not for the outside.","created_at":"2016-04-14T14:19:29Z","updated_at":"2016-04-14T14:19:29Z","html_url":"https://github.com/bugcache/bugcache/pull/12#discussion_r59725157","pull_request_url":"https://api.github.com/repos/bugcache/bugcache/pulls/12","_links":{"self":{"href":"https://api.github.com/repos/bugcache/bugcache/pulls/comments/59725157"},"html":{"href":"https://github.com/bugcache/bugcache/pull/12#discussion_r59725157"},"pull_request":{"href":"https://api.github.com/repos/bugcache/bugcache/pulls/12"}}},"pull_request":{"url":"https://api.github.com/repos/bugcache/bugcache/pulls/12","id":66351841,"html_url":"https://github.com/bugcache/bugcache/pull/12","diff_url":"https://github.com/bugcache/bugcache/pull/12.diff","patch_url":"https://github.com/bugcache/bugcache/pull/12.patch","issue_url":"https://api.github.com/repos/bugcache/bugcache/issues/12","number":12,"state":"open","locked":false,"title":"Add attributes and edit/submit per UI","user":{"login":"bwoebi","id":3154871,"avatar_url":"https://avatars.githubusercontent.com/u/3154871?v=3","gravatar_id":"","url":"https://api.github.com/users/bwoebi","html_url":"https://github.com/bwoebi","followers_url":"https://api.github.com/users/bwoebi/followers","following_url":"https://api.github.com/users/bwoebi/following{/other_user}","gists_url":"https://api.github.com/users/bwoebi/gists{/gist_id}","starred_url":"https://api.github.com/users/bwoebi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bwoebi/subscriptions","organizations_url":"https://api.github.com/users/bwoebi/orgs","repos_url":"https://api.github.com/users/bwoebi/repos","events_url":"https://api.github.com/users/bwoebi/events{/privacy}","received_events_url":"https://api.github.com/users/bwoebi/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-04-13T16:30:57Z","updated_at":"2016-04-14T14:19:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4864cc1668f2cf20d51c1f60c322c59ba356a476","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bugcache/bugcache/pulls/12/commits","review_comments_url":"https://api.github.com/repos/bugcache/bugcache/pulls/12/comments","review_comment_url":"https://api.github.com/repos/bugcache/bugcache/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bugcache/bugcache/issues/12/comments","statuses_url":"https://api.github.com/repos/bugcache/bugcache/statuses/452c89eb9565755be44898328101e7b5a21d042c","head":{"label":"bugcache:attributes","ref":"attributes","sha":"452c89eb9565755be44898328101e7b5a21d042c","user":{"login":"bugcache","id":18289415,"avatar_url":"https://avatars.githubusercontent.com/u/18289415?v=3","gravatar_id":"","url":"https://api.github.com/users/bugcache","html_url":"https://github.com/bugcache","followers_url":"https://api.github.com/users/bugcache/followers","following_url":"https://api.github.com/users/bugcache/following{/other_user}","gists_url":"https://api.github.com/users/bugcache/gists{/gist_id}","starred_url":"https://api.github.com/users/bugcache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bugcache/subscriptions","organizations_url":"https://api.github.com/users/bugcache/orgs","repos_url":"https://api.github.com/users/bugcache/repos","events_url":"https://api.github.com/users/bugcache/events{/privacy}","received_events_url":"https://api.github.com/users/bugcache/received_events","type":"Organization","site_admin":false},"repo":{"id":55307886,"name":"bugcache","full_name":"bugcache/bugcache","owner":{"login":"bugcache","id":18289415,"avatar_url":"https://avatars.githubusercontent.com/u/18289415?v=3","gravatar_id":"","url":"https://api.github.com/users/bugcache","html_url":"https://github.com/bugcache","followers_url":"https://api.github.com/users/bugcache/followers","following_url":"https://api.github.com/users/bugcache/following{/other_user}","gists_url":"https://api.github.com/users/bugcache/gists{/gist_id}","starred_url":"https://api.github.com/users/bugcache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bugcache/subscriptions","organizations_url":"https://api.github.com/users/bugcache/orgs","repos_url":"https://api.github.com/users/bugcache/repos","events_url":"https://api.github.com/users/bugcache/events{/privacy}","received_events_url":"https://api.github.com/users/bugcache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bugcache/bugcache","description":"A modern bug tracker.","fork":false,"url":"https://api.github.com/repos/bugcache/bugcache","forks_url":"https://api.github.com/repos/bugcache/bugcache/forks","keys_url":"https://api.github.com/repos/bugcache/bugcache/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bugcache/bugcache/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bugcache/bugcache/teams","hooks_url":"https://api.github.com/repos/bugcache/bugcache/hooks","issue_events_url":"https://api.github.com/repos/bugcache/bugcache/issues/events{/number}","events_url":"https://api.github.com/repos/bugcache/bugcache/events","assignees_url":"https://api.github.com/repos/bugcache/bugcache/assignees{/user}","branches_url":"https://api.github.com/repos/bugcache/bugcache/branches{/branch}","tags_url":"https://api.github.com/repos/bugcache/bugcache/tags","blobs_url":"https://api.github.com/repos/bugcache/bugcache/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bugcache/bugcache/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bugcache/bugcache/git/refs{/sha}","trees_url":"https://api.github.com/repos/bugcache/bugcache/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bugcache/bugcache/statuses/{sha}","languages_url":"https://api.github.com/repos/bugcache/bugcache/languages","stargazers_url":"https://api.github.com/repos/bugcache/bugcache/stargazers","contributors_url":"https://api.github.com/repos/bugcache/bugcache/contributors","subscribers_url":"https://api.github.com/repos/bugcache/bugcache/subscribers","subscription_url":"https://api.github.com/repos/bugcache/bugcache/subscription","commits_url":"https://api.github.com/repos/bugcache/bugcache/commits{/sha}","git_commits_url":"https://api.github.com/repos/bugcache/bugcache/git/commits{/sha}","comments_url":"https://api.github.com/repos/bugcache/bugcache/comments{/number}","issue_comment_url":"https://api.github.com/repos/bugcache/bugcache/issues/comments{/number}","contents_url":"https://api.github.com/repos/bugcache/bugcache/contents/{+path}","compare_url":"https://api.github.com/repos/bugcache/bugcache/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bugcache/bugcache/merges","archive_url":"https://api.github.com/repos/bugcache/bugcache/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bugcache/bugcache/downloads","issues_url":"https://api.github.com/repos/bugcache/bugcache/issues{/number}","pulls_url":"https://api.github.com/repos/bugcache/bugcache/pulls{/number}","milestones_url":"https://api.github.com/repos/bugcache/bugcache/milestones{/number}","notifications_url":"https://api.github.com/repos/bugcache/bugcache/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bugcache/bugcache/labels{/name}","releases_url":"https://api.github.com/repos/bugcache/bugcache/releases{/id}","deployments_url":"https://api.github.com/repos/bugcache/bugcache/deployments","created_at":"2016-04-02T17:41:57Z","updated_at":"2016-04-08T16:00:35Z","pushed_at":"2016-04-14T06:20:49Z","git_url":"git://github.com/bugcache/bugcache.git","ssh_url":"git@github.com:bugcache/bugcache.git","clone_url":"https://github.com/bugcache/bugcache.git","svn_url":"https://github.com/bugcache/bugcache","homepage":null,"size":107,"stargazers_count":3,"watchers_count":3,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":7,"forks":0,"open_issues":7,"watchers":3,"default_branch":"master"}},"base":{"label":"bugcache:master","ref":"master","sha":"b4ca2cfafbb5b7e372930f060a8b7ad7d66f18fa","user":{"login":"bugcache","id":18289415,"avatar_url":"https://avatars.githubusercontent.com/u/18289415?v=3","gravatar_id":"","url":"https://api.github.com/users/bugcache","html_url":"https://github.com/bugcache","followers_url":"https://api.github.com/users/bugcache/followers","following_url":"https://api.github.com/users/bugcache/following{/other_user}","gists_url":"https://api.github.com/users/bugcache/gists{/gist_id}","starred_url":"https://api.github.com/users/bugcache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bugcache/subscriptions","organizations_url":"https://api.github.com/users/bugcache/orgs","repos_url":"https://api.github.com/users/bugcache/repos","events_url":"https://api.github.com/users/bugcache/events{/privacy}","received_events_url":"https://api.github.com/users/bugcache/received_events","type":"Organization","site_admin":false},"repo":{"id":55307886,"name":"bugcache","full_name":"bugcache/bugcache","owner":{"login":"bugcache","id":18289415,"avatar_url":"https://avatars.githubusercontent.com/u/18289415?v=3","gravatar_id":"","url":"https://api.github.com/users/bugcache","html_url":"https://github.com/bugcache","followers_url":"https://api.github.com/users/bugcache/followers","following_url":"https://api.github.com/users/bugcache/following{/other_user}","gists_url":"https://api.github.com/users/bugcache/gists{/gist_id}","starred_url":"https://api.github.com/users/bugcache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bugcache/subscriptions","organizations_url":"https://api.github.com/users/bugcache/orgs","repos_url":"https://api.github.com/users/bugcache/repos","events_url":"https://api.github.com/users/bugcache/events{/privacy}","received_events_url":"https://api.github.com/users/bugcache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bugcache/bugcache","description":"A modern bug tracker.","fork":false,"url":"https://api.github.com/repos/bugcache/bugcache","forks_url":"https://api.github.com/repos/bugcache/bugcache/forks","keys_url":"https://api.github.com/repos/bugcache/bugcache/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bugcache/bugcache/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bugcache/bugcache/teams","hooks_url":"https://api.github.com/repos/bugcache/bugcache/hooks","issue_events_url":"https://api.github.com/repos/bugcache/bugcache/issues/events{/number}","events_url":"https://api.github.com/repos/bugcache/bugcache/events","assignees_url":"https://api.github.com/repos/bugcache/bugcache/assignees{/user}","branches_url":"https://api.github.com/repos/bugcache/bugcache/branches{/branch}","tags_url":"https://api.github.com/repos/bugcache/bugcache/tags","blobs_url":"https://api.github.com/repos/bugcache/bugcache/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bugcache/bugcache/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bugcache/bugcache/git/refs{/sha}","trees_url":"https://api.github.com/repos/bugcache/bugcache/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bugcache/bugcache/statuses/{sha}","languages_url":"https://api.github.com/repos/bugcache/bugcache/languages","stargazers_url":"https://api.github.com/repos/bugcache/bugcache/stargazers","contributors_url":"https://api.github.com/repos/bugcache/bugcache/contributors","subscribers_url":"https://api.github.com/repos/bugcache/bugcache/subscribers","subscription_url":"https://api.github.com/repos/bugcache/bugcache/subscription","commits_url":"https://api.github.com/repos/bugcache/bugcache/commits{/sha}","git_commits_url":"https://api.github.com/repos/bugcache/bugcache/git/commits{/sha}","comments_url":"https://api.github.com/repos/bugcache/bugcache/comments{/number}","issue_comment_url":"https://api.github.com/repos/bugcache/bugcache/issues/comments{/number}","contents_url":"https://api.github.com/repos/bugcache/bugcache/contents/{+path}","compare_url":"https://api.github.com/repos/bugcache/bugcache/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bugcache/bugcache/merges","archive_url":"https://api.github.com/repos/bugcache/bugcache/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bugcache/bugcache/downloads","issues_url":"https://api.github.com/repos/bugcache/bugcache/issues{/number}","pulls_url":"https://api.github.com/repos/bugcache/bugcache/pulls{/number}","milestones_url":"https://api.github.com/repos/bugcache/bugcache/milestones{/number}","notifications_url":"https://api.github.com/repos/bugcache/bugcache/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bugcache/bugcache/labels{/name}","releases_url":"https://api.github.com/repos/bugcache/bugcache/releases{/id}","deployments_url":"https://api.github.com/repos/bugcache/bugcache/deployments","created_at":"2016-04-02T17:41:57Z","updated_at":"2016-04-08T16:00:35Z","pushed_at":"2016-04-14T06:20:49Z","git_url":"git://github.com/bugcache/bugcache.git","ssh_url":"git@github.com:bugcache/bugcache.git","clone_url":"https://github.com/bugcache/bugcache.git","svn_url":"https://github.com/bugcache/bugcache","homepage":null,"size":107,"stargazers_count":3,"watchers_count":3,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":7,"forks":0,"open_issues":7,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bugcache/bugcache/pulls/12"},"html":{"href":"https://github.com/bugcache/bugcache/pull/12"},"issue":{"href":"https://api.github.com/repos/bugcache/bugcache/issues/12"},"comments":{"href":"https://api.github.com/repos/bugcache/bugcache/issues/12/comments"},"review_comments":{"href":"https://api.github.com/repos/bugcache/bugcache/pulls/12/comments"},"review_comment":{"href":"https://api.github.com/repos/bugcache/bugcache/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bugcache/bugcache/pulls/12/commits"},"statuses":{"href":"https://api.github.com/repos/bugcache/bugcache/statuses/452c89eb9565755be44898328101e7b5a21d042c"}}}}