From bba565f0e820eaa69b5a7252760efd802b223c45 Mon Sep 17 00:00:00 2001 From: Eddie Kohler Date: Sat, 7 Oct 2023 15:25:44 -0400 Subject: [PATCH] Internal: Storage of wordlimit settings. --- scripts/script.js | 24 +++++++++++----------- src/commentinfo.php | 7 ++----- src/conference.php | 40 +++++-------------------------------- src/schema.sql | 2 +- src/settings/s_response.php | 6 +++--- src/updateschema.php | 23 +++++++++++++++++++++ 6 files changed, 46 insertions(+), 56 deletions(-) diff --git a/scripts/script.js b/scripts/script.js index 5f983acfb4..acc3f6087a 100644 --- a/scripts/script.js +++ b/scripts/script.js @@ -6376,7 +6376,7 @@ function cmt_render_form(cj) { bnote = cmt_is_editable(cj) ? "" : '
(admin only)
'; if (btnbox.length) hc.push('
' + btnbox.join("") + '
'); - if (cj.response && resp_rounds[cj.response].wordlimit > 0) + if (cj.response && resp_rounds[cj.response].wl > 0) hc.push('
'); hc.push('
', '
'); hc.push('
'); @@ -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]); @@ -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, diff --git a/src/commentinfo.php b/src/commentinfo.php index d662f15516..586852c4ac 100644 --- a/src/commentinfo.php +++ b/src/commentinfo.php @@ -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)) { diff --git a/src/conference.php b/src/conference.php index 3c34794cfb..6312d2d8e4 100644 --- a/src/conference.php +++ b/src/conference.php @@ -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); @@ -1722,17 +1722,13 @@ function round_setting($name, $round) { /** @return list */ 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 */ - private function _new_response_rounds() { + private function _response_rounds() { $rrds = []; $active = ($this->settings["resp_active"] ?? 0) > 0; $jresp = json_decode($this->settingTexts["responses"] ?? "[{}]"); @@ -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; @@ -1758,32 +1754,6 @@ private function _new_response_rounds() { return $rrds; } - /** @return list */ - 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) { diff --git a/src/schema.sql b/src/schema.sql index 4f8a582098..b3a447e30a 100644 --- a/src/schema.sql +++ b/src/schema.sql @@ -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 diff --git a/src/settings/s_response.php b/src/settings/s_response.php index 98fe99bb05..945f4e0dc6 100644 --- a/src/settings/s_response.php +++ b/src/settings/s_response.php @@ -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") { diff --git a/src/updateschema.php b/src/updateschema.php index 9da8f58347..5f1bd6309b 100644 --- a/src/updateschema.php +++ b/src/updateschema.php @@ -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; @@ -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;