Skip to content

Commit

Permalink
Update insert values() functions.
Browse files Browse the repository at this point in the history
MySQL 8.0 does not like values(); gradually move away.
  • Loading branch information
kohler committed Dec 10, 2021
1 parent 8174d17 commit 01a100b
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@

"suppress_issue_types" => [
"PhanUnusedPublicMethodParameter",
"PhanParamReqAfterOpt"
"PhanParamReqAfterOpt", // remove when PHP 7.0 is not supported
"PhanUndeclaredClassAttribute"
],

"plugins" => [
Expand Down
2 changes: 1 addition & 1 deletion autoassign.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/backupdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
5 changes: 3 additions & 2 deletions src/api/api_requestreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/assigners/a_conflict.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/assigners/a_preference.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/assigners/a_tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, ':')) {
Expand Down
38 changes: 22 additions & 16 deletions src/conference.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/paperapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 01a100b

Please sign in to comment.