Skip to content

Commit

Permalink
Internal: Storage of wordlimit settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Oct 7, 2023
1 parent 418c1e4 commit bba565f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 56 deletions.
24 changes: 12 additions & 12 deletions scripts/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -6376,7 +6376,7 @@ function cmt_render_form(cj) {
bnote = cmt_is_editable(cj) ? "" : '<div class="hint">(admin only)</div>';
if (btnbox.length)
hc.push('<div class="aabut"><div class="btnbox">' + btnbox.join("") + '</div></div>');
if (cj.response && resp_rounds[cj.response].wordlimit > 0)
if (cj.response && resp_rounds[cj.response].wl > 0)
hc.push('<div class="aabut"><div class="words"></div></div>');
hc.push('<div class="aabr">', '</div>');
hc.push('<div class="aabut"><button type="button" name="cancel">Cancel</button></div>');
Expand Down Expand Up @@ -6546,8 +6546,8 @@ function cmt_start_edit(celt, cj) {
}

if (cj.response) {
if (resp_rounds[cj.response].wordlimit > 0) {
make_update_words(celt, resp_rounds[cj.response].wordlimit);
if (resp_rounds[cj.response].wl > 0) {
make_update_words(celt, resp_rounds[cj.response].wl);
}
var $ready = $(form.elements.ready).on("click", cmt_ready_change);
cmt_ready_change.call($ready[0]);
Expand Down Expand Up @@ -6928,24 +6928,24 @@ function cmt_render(cj, editing) {
function cmt_render_text(format, value, response, texte, chead) {
const rrd = response && resp_rounds[response];
let aftertexte = null;
if (rrd && rrd.wordlimit > 0) {
if (rrd && rrd.wl > 0) {
const wc = count_words(value);
if (wc > 0 && chead) {
chead[0].appendChild($e("div", "cmtthead words" + (wc > rrd.wordlimit ? " wordsover" : ""), plural(wc, "word")));
chead[0].appendChild($e("div", "cmtthead words" + (wc > rrd.wl ? " wordsover" : ""), plural(wc, "word")));
}
if ((rrd.hard_wordlimit || 0) > 0
&& wc > rrd.hard_wordlimit
if ((rrd.hwl || 0) > 0
&& wc > rrd.hwl
&& !hotcrp.status.myperm.allow_administer) {
const wcx = count_words_split(value, rrd.hard_wordlimit);
const wcx = count_words_split(value, rrd.hwl);
value = wcx[0].trimEnd() + "…";
aftertexte = $e("div", "overlong-expander",
$e("button", {type: "button", "class": "ui js-overlong-expand", disabled: true}, "Truncated for length"));
}
if (wc > rrd.wordlimit
&& ((rrd.hard_wordlimit || 0) <= 0
|| rrd.wordlimit < rrd.hard_wordlimit
if (wc > rrd.wl
&& ((rrd.hwl || 0) <= 0
|| rrd.wl < rrd.hwl
|| hotcrp.status.myperm.allow_administer)) {
const wcx = count_words_split(value, rrd.wordlimit),
const wcx = count_words_split(value, rrd.wl),
allowede = $e("div", "overlong-allowed"),
dividere = $e("div", "overlong-divider",
allowede,
Expand Down
7 changes: 2 additions & 5 deletions src/commentinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,9 @@ static function script($prow) {
$crow = new CommentInfo($prow);
$crow->commentType = self::CT_RESPONSE;
foreach ($prow->conf->response_rounds() as $rrd) {
$j = [
"wordlimit" => $rrd->wordlimit,
"words" => $rrd->wordlimit /* XXX compat */
];
$j = ["wl" => $rrd->wordlimit];
if ($rrd->hard_wordlimit >= $rrd->wordlimit) {
$j["hard_wordlimit"] = $rrd->hard_wordlimit;
$j["hwl"] = $rrd->hard_wordlimit;
}
$crow->commentRound = $rrd->id;
if (Contact::$main_user->can_edit_response($prow, $crow)) {
Expand Down
40 changes: 5 additions & 35 deletions src/conference.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ function __load_settings() {

function load_settings() {
$this->__load_settings();
if ($this->sversion < 280) {
if ($this->sversion < 281) {
$old_nerrors = Dbl::$nerrors;
while ((new UpdateSchema($this))->run()) {
usleep(50000);
Expand Down Expand Up @@ -1722,17 +1722,13 @@ function round_setting($name, $round) {
/** @return list<ResponseRound> */
function response_rounds() {
if ($this->_resp_rounds === null) {
if ($this->sversion >= 257) {
$this->_resp_rounds = $this->_new_response_rounds();
} else {
$this->_resp_rounds = $this->_old_response_rounds();
}
$this->_resp_rounds = $this->_response_rounds();
}
return $this->_resp_rounds;
}

/** @return list<ResponseRound> */
private function _new_response_rounds() {
private function _response_rounds() {
$rrds = [];
$active = ($this->settings["resp_active"] ?? 0) > 0;
$jresp = json_decode($this->settingTexts["responses"] ?? "[{}]");
Expand All @@ -1746,8 +1742,8 @@ private function _new_response_rounds() {
$rrd->grace = $rrj->grace ?? 0;
$rrd->open = $rrj->open
?? ($rrd->done && $rrd->done + $rrd->grace >= self::$now ? 1 : 0);
$rrd->wordlimit = $rrj->words ?? 500;
$rrd->hard_wordlimit = $rrj->hard_wordlimit
$rrd->wordlimit = $rrj->wl ?? $rrj->words ?? 500;
$rrd->hard_wordlimit = $rrj->hwl
?? ($rrj->truncate ?? false ? $rrd->wordlimit : 0);
if (($rrj->condition ?? "") !== "") {
$rrd->condition = $rrj->condition;
Expand All @@ -1758,32 +1754,6 @@ private function _new_response_rounds() {
return $rrds;
}

/** @return list<ResponseRound> */
private function _old_response_rounds() {
$rrds = [];
$x = $this->settingTexts["resp_rounds"] ?? "1";
$active = ($this->settings["resp_active"] ?? 0) > 0;
foreach (explode(" ", $x) as $i => $rname) {
$rrd = new ResponseRound;
$rrd->id = $i + 1;
$rrd->unnamed = $rname === "1";
$rrd->name = $rname;
$isuf = $i ? "_{$i}" : "";
$rrd->active = $active;
$rrd->done = $this->settings["resp_done{$isuf}"] ?? 0;
$rrd->grace = $this->settings["resp_grace{$isuf}"] ?? 0;
$rrd->open = $this->settings["resp_open{$isuf}"]
?? ($rrd->done && $rrd->done + $rrd->grace >= self::$now ? 1 : 0);
$rrd->wordlimit = $this->settings["resp_words{$isuf}"] ?? 500;
if (($condition = $this->settingTexts["resp_search{$isuf}"] ?? "") !== "") {
$rrd->condition = $condition;
}
$rrd->instructions = $this->settingTexts["msg.resp_instrux_{$i}"] ?? null;
$rrds[] = $rrd;
}
return $rrds;
}

/** @param string $rname
* @return string|false */
static function response_round_name_error($rname) {
Expand Down
2 changes: 1 addition & 1 deletion src/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ CREATE TABLE `TopicInterest` (
-- Initial settings
-- (each setting must be on its own line for createdb.sh)
insert into Settings (name, value, data) values
('allowPaperOption', 280, null), -- schema version
('allowPaperOption', 281, null), -- schema version
('setupPhase', 1, null), -- initial user is chair
('no_papersub', 1, null), -- no submissions yet
('sub_pcconf', 1, null), -- collect PC conflicts, not collaborators
Expand Down
6 changes: 3 additions & 3 deletions src/settings/s_response.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ function unparse_json(Conf $conf) {
}
$wl = $this->wordlimit ?? 0;
if (($this->hard_wordlimit ?? 0) > 0) {
$j->words = $wl <= 0 ? $this->hard_wordlimit : $wl;
$j->hard_wordlimit = $this->hard_wordlimit;
$j->wl = $wl <= 0 ? $this->hard_wordlimit : $wl;
$j->hwl = $this->hard_wordlimit;
} else if ($wl !== 500) {
$j->words = $wl;
$j->wl = $wl;
}
if (($this->condition ?? "") !== ""
&& $this->condition !== "all") {
Expand Down
23 changes: 23 additions & 0 deletions src/updateschema.php
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,25 @@ private function v280_filter_download_log() {
}
}

private function v281_update_response_rounds() {
$respv = $this->conf->setting("responses");
$jresp = json_decode($this->conf->setting_data("responses") ?? "[]");
$njresp = [];
foreach ($jresp ?? [] as $i => $rrj) {
if (isset($rrj->words)) {
$rrj->wl = $rrj->words;
}
if (isset($rrj->truncate)) {
$rrj->wl = $rrj->hwl = $rrj->wl ?? 500;
}
unset($rrj->words, $rrj->truncate);
$njresp[] = $rrj;
}
if (!empty($njresp)) {
$this->conf->save_setting("responses", $respv, json_encode_db($njresp));
}
}

/** @return bool */
function run() {
$conf = $this->conf;
Expand Down Expand Up @@ -2823,6 +2842,10 @@ function run() {
$this->v280_filter_download_log();
$conf->update_schema_version(280);
}
if ($conf->sversion === 280) {
$this->v281_update_response_rounds();
$conf->update_schema_version(281);
}

$conf->ql_ok("delete from Settings where name='__schema_lock'");
Conf::$main = $old_conf_g;
Expand Down

0 comments on commit bba565f

Please sign in to comment.