From 01a100b2b17875c273e6d5a44f9ee82ae63e9c1b Mon Sep 17 00:00:00 2001 From: Eddie Kohler Date: Thu, 9 Dec 2021 20:57:46 -0500 Subject: [PATCH] Update insert values() functions. MySQL 8.0 does not like values(); gradually move away. --- .phan/config.php | 3 ++- autoassign.php | 2 +- lib/backupdb.sh | 2 +- src/api/api_requestreview.php | 5 +++-- src/assigners/a_conflict.php | 2 +- src/assigners/a_preference.php | 4 ++-- src/assigners/a_tag.php | 2 +- src/conference.php | 38 ++++++++++++++++++++-------------- src/contact.php | 2 +- src/paperapi.php | 2 +- stylesheets/style.css | 2 +- 11 files changed, 36 insertions(+), 28 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index 2cbe2bab4..89e42ed40 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -111,7 +111,8 @@ "suppress_issue_types" => [ "PhanUnusedPublicMethodParameter", - "PhanParamReqAfterOpt" + "PhanParamReqAfterOpt", // remove when PHP 7.0 is not supported + "PhanUndeclaredClassAttribute" ], "plugins" => [ diff --git a/autoassign.php b/autoassign.php index fc64cb960..58c8cf4a6 100644 --- a/autoassign.php +++ b/autoassign.php @@ -75,7 +75,7 @@ if (count($x) || $Conf->setting_data("autoassign_badpairs") || (!isset($Qreq->badpairs) != !$Conf->setting("autoassign_badpairs"))) { - $Conf->q("insert into Settings (name, value, data) values ('autoassign_badpairs', ?, ?) on duplicate key update data=values(data), value=values(value)", isset($Qreq->badpairs) ? 1 : 0, join(" ", $x)); + $Conf->save_setting("autoassign_badpairs", isset($Qreq->badpairs) ? 1 : 0, join(" ", $x)); } } diff --git a/lib/backupdb.sh b/lib/backupdb.sh index 8a2e565aa..c1b72d74f 100755 --- a/lib/backupdb.sh +++ b/lib/backupdb.sh @@ -115,7 +115,7 @@ database_dump () { echo "--" echo "-- Force HotCRP to invalidate server caches" echo "--" - echo "INSERT INTO "'`Settings` (`name`,`value`)'" VALUES ('frombackup',UNIX_TIMESTAMP()) ON DUPLICATE KEY UPDATE value=greatest(value,values(value));" + echo "INSERT INTO "'`Settings` (`name`,`value`)'" VALUES ('frombackup',UNIX_TIMESTAMP()) ON DUPLICATE KEY UPDATE value=greatest(value,UNIX_TIMESTAMP());" } get_sversion () { diff --git a/src/api/api_requestreview.php b/src/api/api_requestreview.php index 0b623ee98..02f379d11 100644 --- a/src/api/api_requestreview.php +++ b/src/api/api_requestreview.php @@ -347,11 +347,12 @@ static function declinereview($user, $qreq, $prow) { // commit refusal to database if ($rrow) { $prow->conf->qe("insert into PaperReviewRefused set paperId=?, email=?, contactId=?, requestedBy=?, timeRequested=?, refusedBy=?, timeRefused=?, reason=?, refusedReviewType=?, refusedReviewId=?, reviewRound=?, data=? - on duplicate key update reason=coalesce(values(reason),reason)", + on duplicate key update reason=coalesce(?,reason)", $prow->paperId, $rrow->email, $rrow->contactId, $rrow->requestedBy, $rrow->timeRequested, $user->contactId, Conf::$now, $reason, $rrow->reviewType, - $rrid, $rrow->reviewRound, $rrow->data_string()); + $rrid, $rrow->reviewRound, $rrow->data_string(), + $reason); $prow->conf->qe("delete from PaperReview where paperId=? and reviewId=?", $prow->paperId, $rrid); diff --git a/src/assigners/a_conflict.php b/src/assigners/a_conflict.php index 94e1f0d62..2e0a34227 100644 --- a/src/assigners/a_conflict.php +++ b/src/assigners/a_conflict.php @@ -240,7 +240,7 @@ function add_locks(AssignmentSet $aset, &$locks) { } function execute(AssignmentSet $aset) { if ($this->ctype) { - $aset->stage_qe("insert into PaperConflict set paperId=?, contactId=?, conflictType=? on duplicate key update conflictType=values(conflictType)", $this->pid, $this->cid, $this->ctype); + $aset->stage_qe("insert into PaperConflict set paperId=?, contactId=?, conflictType=? on duplicate key update conflictType=?", $this->pid, $this->cid, $this->ctype, $this->ctype); } else { $aset->stage_qe("delete from PaperConflict where paperId=? and contactId=?", $this->pid, $this->cid); } diff --git a/src/assigners/a_preference.php b/src/assigners/a_preference.php index a71e5cd2f..0f3a79182 100644 --- a/src/assigners/a_preference.php +++ b/src/assigners/a_preference.php @@ -193,8 +193,8 @@ function execute(AssignmentSet $aset) { if (($p = $this->preference_data(false))) { $aset->stage_qe("insert into PaperReviewPreference set paperId=?, contactId=?, preference=?, expertise=? - on duplicate key update preference=values(preference), expertise=values(expertise)", - $this->pid, $this->cid, $p[0], $p[1]); + on duplicate key update preference=?, expertise=?", + $this->pid, $this->cid, $p[0], $p[1], $p[0], $p[1]); } else { $aset->stage_qe("delete from PaperReviewPreference where paperId=? and contactId=?", $this->pid, $this->cid); } diff --git a/src/assigners/a_tag.php b/src/assigners/a_tag.php index f59234ef6..593ad15e5 100644 --- a/src/assigners/a_tag.php +++ b/src/assigners/a_tag.php @@ -439,7 +439,7 @@ function execute(AssignmentSet $aset) { if ($this->index === null) { $aset->stage_qe("delete from PaperTag where paperId=? and tag=?", $this->pid, $this->tag); } else { - $aset->stage_qe("insert into PaperTag set paperId=?, tag=?, tagIndex=? on duplicate key update tagIndex=values(tagIndex)", $this->pid, $this->tag, $this->index); + $aset->stage_qe("insert into PaperTag set paperId=?, tag=?, tagIndex=? on duplicate key update tagIndex=?", $this->pid, $this->tag, $this->index, $this->index); } if ($this->index !== null && str_ends_with($this->tag, ':')) { diff --git a/src/conference.php b/src/conference.php index f4dd4e32a..5a87e9bad 100644 --- a/src/conference.php +++ b/src/conference.php @@ -735,7 +735,7 @@ private function clean_capabilities() { Dbl::free($result); } $this->ql("delete from Capability where timeExpires>0 and timeExpires<".Conf::$now); - $this->ql("insert into Settings set name='__capability_gc', value=".Conf::$now." on duplicate key update value=values(value)"); + $this->ql("insert into Settings set name='__capability_gc', value=? on duplicate key update value=?", Conf::$now, Conf::$now); $this->settings["__capability_gc"] = Conf::$now; } @@ -804,7 +804,7 @@ function save_setting($name, $value, $data = null) { if (is_array($dval) || is_object($dval)) { $dval = json_encode_db($dval); } - $result = $this->qe("insert into Settings set name=?, value=?, data=? on duplicate key update value=values(value), data=values(data)", $name, $value, $dval); + $result = $this->qe("insert into Settings (name, value, data) values (?, ?, ?) on duplicate key update value=values(value), data=values(data)", $name, $value, $dval); if (!Dbl::is_error($result)) { $this->settings[$name] = $value; $this->settingTexts[$name] = $dval; @@ -2502,21 +2502,31 @@ function save_session($name, $value) { } + /** @param string $name + * @param string $existsq + * @param int $adding */ + private function update_setting_exists($name, $existsq, $adding) { + if ($adding >= 0) { + $this->qe_raw("insert into Settings (name, value) select '$name', 1 from dual where $existsq on duplicate key update value=1"); + } + if ($adding <= 0) { + $this->qe_raw("delete from Settings where name='$name' and not ($existsq)"); + } + $this->settings[$name] = (int) $this->fetch_ivalue("select value from Settings where name='$name'"); + } + // update the 'papersub' setting: are there any submitted papers? /** @param int $adding */ function update_papersub_setting($adding) { - if (($this->setting("no_papersub") ?? 0) > 0 ? $adding >= 0 : $adding <= 0) { - $this->qe("delete from Settings where name='no_papersub'"); - $this->qe("insert into Settings (name, value) select 'no_papersub', 1 from dual where exists (select * from Paper where timeSubmitted>0) = 0"); - $this->settings["no_papersub"] = (int) $this->fetch_ivalue("select value from Settings where name='no_papersub'"); + if (($this->setting("no_papersub") ?? 0) <= 0 ? $adding <= 0 : $adding >= 0) { + $this->update_setting_exists("no_papersub", "not exists (select * from Paper where timeSubmitted>0)", -$adding); } } /** @param int $adding */ function update_paperacc_setting($adding) { if (($this->setting("paperacc") ?? 0) <= 0 ? $adding >= 0 : $adding <= 0) { - $this->qe_raw("insert into Settings (name, value) select 'paperacc', exists (select * from Paper where outcome>0 and timeSubmitted>0) on duplicate key update value=values(value)"); - $this->settings["paperacc"] = (int) $this->fetch_ivalue("select value from Settings where name='paperacc'"); + $this->update_setting_exists("paperacc", "exists (select * from Paper where outcome>0 and timeSubmitted>0)", $adding); } } @@ -2526,32 +2536,28 @@ function update_rev_tokens_setting($adding) { $adding = 0; } if (($this->setting("rev_tokens") ?? 0) <= 0 ? $adding >= 0 : $adding <= 0) { - $this->qe_raw("insert into Settings (name, value) select 'rev_tokens', exists (select * from PaperReview where reviewToken!=0) on duplicate key update value=values(value)"); - $this->settings["rev_tokens"] = (int) $this->fetch_ivalue("select value from Settings where name='rev_tokens'"); + $this->update_setting_exists("rev_tokens", "exists (select * from PaperReview where reviewToken!=0)", $adding); } } /** @param int $adding */ function update_paperlead_setting($adding) { if (($this->setting("paperlead") ?? 0) <= 0 ? $adding >= 0 : $adding <= 0) { - $this->qe_raw("insert into Settings (name, value) select 'paperlead', exists (select * from Paper where leadContactId>0 or shepherdContactId>0) on duplicate key update value=values(value)"); - $this->settings["paperlead"] = (int) $this->fetch_ivalue("select value from Settings where name='paperlead'"); + $this->update_setting_exists("paperlead", "exists (select * from Paper where leadContactId>0 or shepherdContactId>0)", $adding); } } /** @param int $adding */ function update_papermanager_setting($adding) { if (($this->setting("papermanager") ?? 0) <= 0 ? $adding >= 0 : $adding <= 0) { - $this->qe_raw("insert into Settings (name, value) select 'papermanager', exists (select * from Paper where managerContactId>0) on duplicate key update value=values(value)"); - $this->settings["papermanager"] = (int) $this->fetch_ivalue("select value from Settings where name='papermanager'"); + $this->update_setting_exists("papermanager", "exists (select * from Paper where managerContactId>0)", $adding); } } /** @param int $adding */ function update_metareviews_setting($adding) { if (($this->setting("metareviews") ?? 0) <= 0 ? $adding >= 0 : $adding <= 0) { - $this->qe_raw("insert into Settings (name, value) select 'metareviews', exists (select * from PaperReview where reviewType=" . REVIEW_META . ") on duplicate key update value=values(value)"); - $this->settings["metareviews"] = (int) $this->fetch_ivalue("select value from Settings where name='metareviews'"); + $this->update_setting_exists("metareviews", "exists (select * from PaperReview where reviewType=" . REVIEW_META . ")", $adding); } } diff --git a/src/contact.php b/src/contact.php index 5809ff783..cda0f6669 100644 --- a/src/contact.php +++ b/src/contact.php @@ -867,7 +867,7 @@ static function ensure_contactdb_users(Conf $conf, $users) { private function _contactdb_save_roles($cdbu) { if ($cdbu->cdb_confid > 0) { if (($roles = $this->contactdb_roles())) { - Dbl::ql($this->conf->contactdb(), "insert into Roles set contactDbId=?, confid=?, roles=?, activity_at=? on duplicate key update roles=values(roles), activity_at=values(activity_at)", $cdbu->contactDbId, $cdbu->cdb_confid, $roles, Conf::$now); + Dbl::ql($this->conf->contactdb(), "insert into Roles set contactDbId=?, confid=?, roles=?, activity_at=? on duplicate key update roles=?, activity_at=?", $cdbu->contactDbId, $cdbu->cdb_confid, $roles, Conf::$now, $roles, Conf::$now); } else { Dbl::ql($this->conf->contactdb(), "delete from Roles where contactDbId=? and confid=? and roles=0", $cdbu->contactDbId, $cdbu->cdb_confid); } diff --git a/src/paperapi.php b/src/paperapi.php index 79724389d..45738af71 100644 --- a/src/paperapi.php +++ b/src/paperapi.php @@ -111,7 +111,7 @@ static function reviewrating_api(Contact $user, Qrequest $qreq, PaperInfo $prow) if ($rating === 0) { $user->conf->qe("delete from ReviewRating where paperId=? and reviewId=? and contactId=?", $prow->paperId, $rrow->reviewId, $user->contactId); } else { - $user->conf->qe("insert into ReviewRating set paperId=?, reviewId=?, contactId=?, rating=? on duplicate key update rating=values(rating)", $prow->paperId, $rrow->reviewId, $user->contactId, $rating); + $user->conf->qe("insert into ReviewRating set paperId=?, reviewId=?, contactId=?, rating=? on duplicate key update rating=?", $prow->paperId, $rrow->reviewId, $user->contactId, $rating, $rating); } $rrow = $prow->fresh_review_by_id($rrow->reviewId); } diff --git a/stylesheets/style.css b/stylesheets/style.css index 996c4053b..792db2433 100644 --- a/stylesheets/style.css +++ b/stylesheets/style.css @@ -81,7 +81,7 @@ address { /* page background */ -body, .text-default { +html, .text-default { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";