From c64a77fb14ff5274e6932fe66dc15a7e0e5b7865 Mon Sep 17 00:00:00 2001 From: Eddie Kohler Date: Sun, 14 Jun 2020 09:45:37 -0400 Subject: [PATCH] Deprecate global $Now in favor of Conf::$now. --- api.php | 11 +-- batch/cleandocstore.php | 8 +- buzzer.php | 11 ++- deadlines.php | 6 +- doc.php | 3 +- lib/csv.php | 3 +- lib/filer.php | 9 +-- lib/mincostmaxflow.php | 7 +- lib/redirect.php | 11 ++- lib/s3client.php | 5 +- lib/zipdocument.php | 4 +- manualassign.php | 2 +- profile.php | 6 +- review.php | 2 +- src/api/api_requestreview.php | 11 +-- src/api/api_searchconfig.php | 6 +- src/api/api_user.php | 3 +- src/assigners/a_decision.php | 4 +- src/assigners/a_status.php | 8 +- src/assignmentset.php | 4 +- src/capabilities/cap_reviewaccept.php | 7 +- src/checkformat.php | 3 +- src/commentinfo.php | 17 ++--- src/conference.php | 94 ++++++++++++------------ src/contact.php | 91 ++++++++++------------- src/formula.php | 5 +- src/helpers.php | 6 +- src/init.php | 2 +- src/initweb.php | 4 +- src/mailclasses.php | 3 +- src/meetingtracker.php | 27 ++----- src/papercolumns/pc_reviewdelegation.php | 1 - src/paperstatus.php | 16 ++-- src/papertable.php | 10 +-- src/partials/p_signin.php | 8 +- src/review.php | 3 +- src/reviewinfo.php | 3 +- src/sessionlist.php | 3 +- src/settings/s_decisionvisibility.php | 4 +- src/settings/s_finalversions.php | 3 +- src/settings/s_reviewform.php | 3 +- src/settings/s_reviews.php | 5 +- src/settings/s_subform.php | 3 +- src/settings/s_submissions.php | 3 +- src/settingvalues.php | 4 - src/userstatus.php | 3 +- test/setup.php | 1 - test/test01.php | 20 ++--- test/test02.php | 3 +- test/test04.php | 10 +-- test/test05.php | 4 +- 51 files changed, 205 insertions(+), 288 deletions(-) diff --git a/api.php b/api.php index c358dfa73..0ab321211 100644 --- a/api.php +++ b/api.php @@ -49,9 +49,9 @@ if (!$Me->has_account_here() && ($key = $Me->capability("tracker_kiosk"))) { $kiosks = $Conf->setting_json("__tracker_kiosk") ? : (object) array(); - if (isset($kiosks->$key) && $kiosks->$key->update_at >= $Now - 172800) { - if ($kiosks->$key->update_at < $Now - 3600) { - $kiosks->$key->update_at = $Now; + if (isset($kiosks->$key) && $kiosks->$key->update_at >= Conf::$now - 172800) { + if ($kiosks->$key->update_at < Conf::$now - 3600) { + $kiosks->$key->update_at = Conf::$now; $Conf->save_setting("__tracker_kiosk", 1, $kiosks); } $Me->tracker_kiosk_state = $kiosks->$key->show_papers ? 2 : 1; @@ -70,8 +70,9 @@ if (!$Me->is_reviewer()) json_exit(403, ["ok" => false]); $from = $Qreq->from; - if (!$from || !ctype_digit($from)) - $from = $Now; + if (!$from || !ctype_digit($from)) { + $from = Conf::$now; + } $when = $from; $rf = $Conf->review_form(); $events = new PaperEvents($Me); diff --git a/batch/cleandocstore.php b/batch/cleandocstore.php index 0777fb73a..7bdf088db 100644 --- a/batch/cleandocstore.php +++ b/batch/cleandocstore.php @@ -31,7 +31,6 @@ class Batch_CleanDocstore { public $ftrees = []; function fparts_random_match() { - global $Now; $fmatches = []; for ($i = 0; $i !== count($this->ftrees); ++$i) { if (!($ftree = $this->ftrees[$i])) { @@ -44,7 +43,7 @@ function fparts_random_match() { $fm = $ftree->random_match(); if ($fm->is_complete() && (($fm->treeid & 1) === 0 - || max($fm->atime(), $fm->mtime()) < $Now - 86400)) { + || max($fm->atime(), $fm->mtime()) < Conf::$now - 86400)) { ++$n; $fmatches[] = $fm; } else { @@ -56,14 +55,13 @@ function fparts_random_match() { } } usort($fmatches, function ($a, $b) { - global $Now; // week-old temporary files should be removed first $at = $a->atime(); - if (($a->treeid & 1) && $at < $Now - 604800) { + if (($a->treeid & 1) && $at < Conf::$now - 604800) { $at = 1; } $bt = $b->atime(); - if (($b->treeid & 1) && $bt < $Now - 604800) { + if (($b->treeid & 1) && $bt < Conf::$now - 604800) { $bt = 1; } if ($at !== false && $bt !== false) { diff --git a/buzzer.php b/buzzer.php index 04550ce7c..f59fefc74 100644 --- a/buzzer.php +++ b/buzzer.php @@ -6,7 +6,6 @@ require_once("src/initweb.php"); function kiosk_manager(Contact $user, Qrequest $qreq) { - global $Now; $kiosks = (array) ($user->conf->setting_json("__tracker_kiosk") ? : array()); uasort($kiosks, function ($a, $b) { return $a->update_at - $b->update_at; @@ -14,7 +13,7 @@ function kiosk_manager(Contact $user, Qrequest $qreq) { $kchange = false; // delete old kiosks while (!empty($kiosks) - && (count($kiosks) > 12 || current($kiosks)->update_at <= $Now - 172800)) { + && (count($kiosks) > 12 || current($kiosks)->update_at <= Conf::$now - 172800)) { array_shift($kiosks); $kchange = true; reset($kiosks); @@ -22,13 +21,13 @@ function kiosk_manager(Contact $user, Qrequest $qreq) { // look for new kiosks $kiosk_keys = [null, null]; foreach ($kiosks as $k => $kj) { - if ($kj->update_at >= $Now - 7200) + if ($kj->update_at >= Conf::$now - 7200) $kiosk_keys[$kj->show_papers ? 1 : 0] = $k; } for ($i = 0; $i <= 1; ++$i) { if (!$kiosk_keys[$i]) { $key = hotcrp_random_password(); - $kiosks[$key] = (object) ["update_at" => $Now, "show_papers" => !!$i]; + $kiosks[$key] = (object) ["update_at" => Conf::$now, "show_papers" => !!$i]; $kiosk_keys[$i] = $kchange = $key; } } @@ -50,9 +49,9 @@ function kiosk_manager(Contact $user, Qrequest $qreq) { } function kiosk_lookup($key) { - global $Conf, $Now; + global $Conf; $kiosks = (array) ($Conf->setting_json("__tracker_kiosk") ? : []); - if (isset($kiosks[$key]) && $kiosks[$key]->update_at >= $Now - 604800) { + if (isset($kiosks[$key]) && $kiosks[$key]->update_at >= Conf::$now - 604800) { return $kiosks[$key]; } else { return null; diff --git a/deadlines.php b/deadlines.php index 28de01bb5..25a71f9b7 100644 --- a/deadlines.php +++ b/deadlines.php @@ -49,7 +49,7 @@ function printDeadline($time, $phrase, $description) { if ($dl->resps ?? false) { foreach ($dl->resps as $rname => $dlr) { if (($dlr->open ?? false) - && $dlr->open <= $Now + && $dlr->open <= Conf::$now && ($dlr->done ?? false)) { if ($rname == 1) { printDeadline($dlr->done, $Conf->_("Response deadline"), @@ -75,14 +75,14 @@ function printDeadline($time, $phrase, $description) { if ($Viewer->isPC) { $ps = +$Conf->setting("pcrev_soft$isuf"); $ph = +$Conf->setting("pcrev_hard$isuf"); - if ($ph && ($ph < $Now || $ps < $Now)) { + if ($ph && ($ph < Conf::$now || $ps < Conf::$now)) { $thisdl[] = "PH" . $ph; } else if ($ps) { $thisdl[] = "PS" . $ps; } } if ($es != $ps || $eh != $ph) { - if ($eh && ($eh < $Now || $es < $Now)) { + if ($eh && ($eh < Conf::$now || $es < Conf::$now)) { $thisdl[] = "EH" . $eh; } else if ($es) { $thisdl[] = "ES" . $es; diff --git a/doc.php b/doc.php index 0e9fa82a2..429decc92 100644 --- a/doc.php +++ b/doc.php @@ -63,7 +63,6 @@ function document_history(Contact $user, PaperInfo $prow, $dtype) { } function document_download(Contact $user, $qreq) { - global $Now; try { $dr = new DocumentRequest($qreq, $qreq->path(), $user); } catch (Exception $e) { @@ -90,7 +89,7 @@ function document_download(Contact $user, $qreq) { if (ctype_digit($qreq->at)) { $time = intval($qreq->at); } else if (!($time = $user->conf->parse_time($qreq->at))) { - $time = $Now; + $time = Conf::$now; } $want_pj = null; foreach (document_history($user, $prow, $dr->dtype) as $pj) { diff --git a/lib/csv.php b/lib/csv.php index 9d5843848..e26d6da58 100644 --- a/lib/csv.php +++ b/lib/csv.php @@ -649,7 +649,6 @@ function add_string($text) { } private function _flush_stream() { - global $Now; if ($this->stream === null) { $this->stream = false; if (($dir = Filer::docstore_tmpdir() ?? tempdir())) { @@ -657,7 +656,7 @@ private function _flush_stream() { $dir .= "/"; } for ($i = 0; $i !== 100; ++$i) { - $fn = $dir . "csvtmp-$Now-" . mt_rand(0, 99999999) . ".csv"; + $fn = $dir . "csvtmp-" . time() . "-" . mt_rand(0, 99999999) . ".csv"; if (($this->stream = @fopen($fn, "xb"))) { $this->stream_filename = $fn; break; diff --git a/lib/filer.php b/lib/filer.php index 4508a54d9..1588d3587 100644 --- a/lib/filer.php +++ b/lib/filer.php @@ -139,7 +139,7 @@ static function download_file($filename, $mimetype, $no_accel = false) { } /** @param DocumentInfo|list $doc */ static function multidownload($doc, $downloadname = null, $opts = null) { - global $Now, $zlib_output_compression; + global $zlib_output_compression; if (is_array($doc) && count($doc) == 1) { $doc = $doc[0]; $downloadname = null; @@ -182,7 +182,7 @@ static function multidownload($doc, $downloadname = null, $opts = null) { header("Content-Disposition: " . ($attachment ? "attachment" : "inline") . "; filename=" . mime_quote_string($downloadname)); if (is_array($opts) && ($opts["cacheable"] ?? false)) { header("Cache-Control: max-age=315576000, private"); - header("Expires: " . gmdate("D, d M Y H:i:s", $Now + 315576000) . " GMT"); + header("Expires: " . gmdate("D, d M Y H:i:s", Conf::$now + 315576000) . " GMT"); } // reduce likelihood of XSS attacks in IE header("X-Content-Type-Options: nosniff"); @@ -226,7 +226,6 @@ static function sha1_hash_as_text($str) { const FPATH_EXISTS = 1; const FPATH_MKDIR = 2; static function docstore_path(DocumentInfo $doc, $flags = 0) { - global $Now; if ($doc->error || !($pattern = $doc->conf->docstore())) { return null; } @@ -245,8 +244,8 @@ static function docstore_path(DocumentInfo $doc, $flags = 0) { return null; } } - if (filemtime($path) < $Now - 172800 && !self::$no_touch) { - @touch($path, $Now); + if (filemtime($path) < Conf::$now - 172800 && !self::$no_touch) { + @touch($path, Conf::$now); } } if (($flags & self::FPATH_MKDIR) diff --git a/lib/mincostmaxflow.php b/lib/mincostmaxflow.php index a51d0ad90..a889b2cac 100644 --- a/lib/mincostmaxflow.php +++ b/lib/mincostmaxflow.php @@ -796,14 +796,13 @@ function shuffle() { } private function make_debug_file() { - global $Conf, $Now; - if (!($dir = $Conf->opt("minCostMaxFlowDebug"))) { + if (!($dir = Conf::$g->opt("minCostMaxFlowDebug"))) { return null; } $f = null; $time = time(); - while (!$f && $time < $Now + 20) { - $f = @fopen($dir . "/mcmf-{$Conf->dbname}-{$time}.txt", "xb"); + while (!$f && $time < Conf::$now + 20) { + $f = @fopen("$dir/mcmf-".Conf::$g->dbname."-{$time}.txt", "xb"); ++$time; } return $f; diff --git a/lib/redirect.php b/lib/redirect.php index 9e282b9f1..7174e8bd5 100644 --- a/lib/redirect.php +++ b/lib/redirect.php @@ -91,7 +91,7 @@ function set_session_name(Conf $conf) { } function ensure_session($flags = 0) { - global $Conf, $Now; + global $Conf; if (session_id() !== "" && !($flags & ENSURE_SESSION_REGENERATE_ID)) { return; @@ -111,13 +111,13 @@ function ensure_session($flags = 0) { } $session_data = $_SESSION ? : []; $new_sid = session_create_id(); - $_SESSION["deletedat"] = $Now; + $_SESSION["deletedat"] = Conf::$now; session_commit(); session_id($new_sid); if (!isset($_COOKIE[$sn]) || $_COOKIE[$sn] !== $new_sid) { $params = session_get_cookie_params(); - $params["expires"] = $Now + $params["lifetime"]; + $params["expires"] = Conf::$now + $params["lifetime"]; unset($params["lifetime"]); hotcrp_setcookie($sn, $new_sid, $params); } @@ -127,7 +127,7 @@ function ensure_session($flags = 0) { // maybe kill old session if (isset($_SESSION["deletedat"]) - && $_SESSION["deletedat"] < $Now - 30) { + && $_SESSION["deletedat"] < Conf::$now - 30) { $_SESSION = []; } @@ -167,14 +167,13 @@ function post_value($allow_empty = false) { } function kill_session() { - global $Now; if (($sn = session_name()) && isset($_COOKIE[$sn])) { if (session_id() !== "") { session_commit(); } $params = session_get_cookie_params(); - $params["expires"] = $Now - 86400; + $params["expires"] = Conf::$now - 86400; unset($params["lifetime"]); hotcrp_setcookie($sn, "", $params); $_COOKIE[$sn] = ""; diff --git a/lib/s3client.php b/lib/s3client.php index ba5baa671..5b9545107 100644 --- a/lib/s3client.php +++ b/lib/s3client.php @@ -56,7 +56,6 @@ function check_key_secret_bucket($key, $secret, $bucket) { /** @return array{string,string} */ function scope_and_signing_key($time) { - global $Now; if ($this->s3_scope === null && $this->setting_cache) { $this->s3_scope = $this->setting_cache->setting_data($this->setting_cache_prefix . "_scope"); @@ -73,8 +72,8 @@ function scope_and_signing_key($time) { $service_key = hash_hmac("sha256", "s3", $region_key, true); $this->s3_signing_key = hash_hmac("sha256", "aws4_request", $service_key, true); if ($this->setting_cache) { - $this->setting_cache->__save_setting($this->setting_cache_prefix . "_scope", $Now, $this->s3_scope); - $this->setting_cache->__save_setting($this->setting_cache_prefix . "_signing_key", $Now, $this->s3_signing_key); + $this->setting_cache->__save_setting($this->setting_cache_prefix . "_scope", Conf::$now, $this->s3_scope); + $this->setting_cache->__save_setting($this->setting_cache_prefix . "_signing_key", Conf::$now, $this->s3_signing_key); } } return [$this->s3_scope, $this->s3_signing_key]; diff --git a/lib/zipdocument.php b/lib/zipdocument.php index 65e19b801..57fb67c95 100644 --- a/lib/zipdocument.php +++ b/lib/zipdocument.php @@ -178,8 +178,6 @@ private function _make_document($error_html = false) { /** @return DocumentInfo */ function create() { - global $Now; - if (!empty($this->warnings)) { $this->add_as(join("\n", $this->warnings) . "\n", "README-warnings.txt"); } @@ -197,7 +195,7 @@ function create() { $this->filestore = $dstore_tmp . hash("sha256", $signature, false) . ".zip"; // maybe zipfile with that signature already exists if (file_exists($this->filestore)) { - if (@filemtime($this->filestore) < $Now - 21600) { + if (@filemtime($this->filestore) < Conf::$now - 21600) { @touch($this->filestore); } return $this->_make_document(); diff --git a/manualassign.php b/manualassign.php index e61eba208..6fd144dbc 100644 --- a/manualassign.php +++ b/manualassign.php @@ -46,7 +46,7 @@ function saveAssignments($qreq, $reviewer) { - global $Conf, $Me, $Now; + global $Conf, $Me; $round_number = null; $rcid = $reviewer->contactId; diff --git a/profile.php b/profile.php index 3bc4e51ef..c94f244c2 100644 --- a/profile.php +++ b/profile.php @@ -222,7 +222,7 @@ function change_email_by_capability($Qreq) { /** @param UserStatus $user_status * @param ?Contact $Acct */ function save_user($cj, $user_status, $Acct, $allow_modification) { - global $Conf, $Me, $Now, $newProfile; + global $Conf, $Me, $newProfile; if ($newProfile) { $Acct = null; } @@ -417,7 +417,7 @@ function parseBulkFile($text, $filename) { $success = parseBulkFile($Qreq->bulkentry, ""); } if (!$success) { - $Me->save_session("profile_bulkentry", array($Now, $Qreq->bulkentry)); + $Me->save_session("profile_bulkentry", array(Conf::$now, $Qreq->bulkentry)); } $Conf->self_redirect($Qreq, ["anchor" => "bulk"]); } else if (isset($Qreq->save)) { @@ -664,7 +664,7 @@ function parseBulkFile($text, $filename) { if ($Qreq->bulkentry === null && ($session_bulkentry = $Me->session("profile_bulkentry")) && is_array($session_bulkentry) - && $session_bulkentry[0] > $Now - 5) { + && $session_bulkentry[0] > Conf::$now - 5) { $Qreq->bulkentry = $session_bulkentry[1]; $Me->save_session("profile_bulkentry", null); } diff --git a/review.php b/review.php index 8afb38fd5..31d31f41b 100644 --- a/review.php +++ b/review.php @@ -285,7 +285,7 @@ function download_one_text_review(ReviewInfo $rrow) { if ($rrow->reviewModified <= 0) { Dbl::qe("update PaperReview set reviewModified=1, timeRequestNotified=greatest(?,timeRequestNotified) where paperId=? and reviewId=? and coalesce(reviewModified,0)<=0", - $Now, $prow->paperId, $rrow->reviewId); + Conf::$now, $prow->paperId, $rrow->reviewId); if ($Me->is_signed_in()) { $rrow->delete_acceptor(); } diff --git a/src/api/api_requestreview.php b/src/api/api_requestreview.php index d9fc1ddb9..c253ee0ae 100644 --- a/src/api/api_requestreview.php +++ b/src/api/api_requestreview.php @@ -7,7 +7,6 @@ class RequestReview_API { * @param Qrequest $qreq * @param PaperInfo $prow */ static function requestreview($user, $qreq, $prow) { - global $Now; $round = null; if ((string) $qreq->round !== "" && ($rname = $user->conf->sanitize_round_name($qreq->round)) !== false) { @@ -100,7 +99,7 @@ static function requestreview($user, $qreq, $prow) { || ($extrev_chairreq === 2 && $potconflict)) { $prow->conf->qe("insert into ReviewRequest set paperId=?, email=?, firstName=?, lastName=?, affiliation=?, requestedBy=?, timeRequested=?, reason=?, reviewRound=? on duplicate key update paperId=paperId", $prow->paperId, $email, $xreviewer->firstName, $xreviewer->lastName, - $xreviewer->affiliation, $user->contactId, $Now, $reason, $round); + $xreviewer->affiliation, $user->contactId, Conf::$now, $reason, $round); if ($user->can_administer($prow)) { $msg = "

" . $xreviewer->name_h(NAME_E) . " has a potential conflict with this submission, so you must approve this request for it to take effect.

" . PaperInfo::potential_conflict_tooltip_html($potconflict); @@ -178,7 +177,6 @@ static function requestreview_anonymous($user, $qreq, $prow) { * @param Qrequest $qreq * @param PaperInfo $prow */ static function denyreview($user, $qreq, $prow) { - global $Now; if (!$user->allow_administer($prow)) { return new JsonResult(403, "Permission error."); } @@ -201,7 +199,7 @@ static function denyreview($user, $qreq, $prow) { $prow->paperId, $email, $reviewer ? $reviewer->contactId : 0, $request->firstName, $request->lastName, $request->affiliation, $request->requestedBy, $request->timeRequested, - $user->contactId, $Now, $reason, REVIEW_EXTERNAL, + $user->contactId, Conf::$now, $reason, REVIEW_EXTERNAL, $request->reviewRound); Dbl::qx_raw("unlock tables"); @@ -228,7 +226,6 @@ static function denyreview($user, $qreq, $prow) { * @param Qrequest $qreq * @param PaperInfo $prow */ static function declinereview($user, $qreq, $prow) { - global $Now; $xrrows = $refusals = []; $email = trim($qreq->email); if ($email === "" || $email === "me") { @@ -290,7 +287,7 @@ static function declinereview($user, $qreq, $prow) { on duplicate key update reason=coalesce(values(reason),reason)", $prow->paperId, $rrow->email, $rrow->contactId, $rrow->requestedBy, $rrow->timeRequested, - $user->contactId, $Now, $reason, $rrow->reviewType, + $user->contactId, Conf::$now, $reason, $rrow->reviewType, $rrow->reviewRound, $rrow->data); $user->conf->qe("delete from PaperReview where paperId=? and reviewId=?", $prow->paperId, $rrow->reviewId); @@ -343,7 +340,6 @@ static function declinereview($user, $qreq, $prow) { * @param Qrequest $qreq * @param PaperInfo $prow */ static function retractreview($user, $qreq, $prow) { - global $Now; $xrrows = $xrequests = []; $email = trim($qreq->email); if ($email === "") { @@ -424,7 +420,6 @@ static function retractreview($user, $qreq, $prow) { * @param Qrequest $qreq * @param ?PaperInfo $prow */ static function undeclinereview($user, $qreq, $prow) { - global $Now; $refusals = []; $email = trim($qreq->email); if ($email === "" || $email === "me") { diff --git a/src/api/api_searchconfig.php b/src/api/api_searchconfig.php index b50e88eff..956f7928e 100644 --- a/src/api/api_searchconfig.php +++ b/src/api/api_searchconfig.php @@ -60,8 +60,6 @@ static function namedformula(Contact $user, Qrequest $qreq) { } static function save_namedformula(Contact $user, Qrequest $qreq) { - global $Now; - // capture current formula set $new_formula_by_id = $formula_by_id = $user->conf->named_formulas(); $max_id = array_reduce($formula_by_id, function ($max, $f) { @@ -161,10 +159,10 @@ static function save_namedformula(Contact $user, Qrequest $qreq) { $fdef = $formula_by_id[$f->formulaId] ?? null; if (!$fdef) { $q[] = "insert into Formula set name=?, expression=?, createdBy=?, timeModified=?"; - array_push($qv, $f->name, $f->expression, $user->privChair ? -$user->contactId : $user->contactId, $Now); + array_push($qv, $f->name, $f->expression, $user->privChair ? -$user->contactId : $user->contactId, Conf::$now); } else if ($f->name !== $fdef->name || $f->expression !== $fdef->expression) { $q[] = "update Formula set name=?, expression=?, timeModified=? where formulaId=?"; - array_push($qv, $f->name, $f->expression, $Now, $f->formulaId); + array_push($qv, $f->name, $f->expression, Conf::$now, $f->formulaId); } } if (empty($new_formula_by_id)) { diff --git a/src/api/api_user.php b/src/api/api_user.php index 35010dccc..c94f87795 100644 --- a/src/api/api_user.php +++ b/src/api/api_user.php @@ -56,7 +56,6 @@ static function user(Contact $user, Qrequest $qreq) { } static function clickthrough(Contact $user, Qrequest $qreq) { - global $Now; if ($qreq->accept && $qreq->clickthrough_id && ($hash = Filer::sha1_hash_as_text($qreq->clickthrough_id))) { @@ -70,7 +69,7 @@ static function clickthrough(Contact $user, Qrequest $qreq) { return new JsonResult(400, "No such user."); } $dest_user->activate_database_account(); - $dest_user->merge_and_save_data(["clickthrough" => [$hash => $Now]]); + $dest_user->merge_and_save_data(["clickthrough" => [$hash => Conf::$now]]); $user->log_activity_for($dest_user, "Terms agreed " . substr($hash, 0, 10) . "..."); return ["ok" => true]; } else if ($qreq->clickthrough_accept) { diff --git a/src/assigners/a_decision.php b/src/assigners/a_decision.php index 58d1e603b..9d59d5e4e 100644 --- a/src/assigners/a_decision.php +++ b/src/assigners/a_decision.php @@ -55,12 +55,11 @@ function apply(PaperInfo $prow, Contact $contact, $req, AssignmentState $state) $decyes = 0; // accepted papers are always submitted if ($dec > 0) { - global $Now; Status_AssignmentParser::load_status_state($state); $sm = $state->remove(["type" => "status", "pid" => $prow->paperId]); $sres = $sm[0]; if ($sres["_submitted"] === 0) { - $sres["_submitted"] = ($sres["_withdrawn"] > 0 ? -$Now : $Now); + $sres["_submitted"] = ($sres["_withdrawn"] > 0 ? -Conf::$now : Conf::$now); } $state->add($sres); if ($sres["_submitted"] > 0) { @@ -115,7 +114,6 @@ function add_locks(AssignmentSet $aset, &$locks) { $locks["Paper"] = "write"; } function execute(AssignmentSet $aset) { - global $Now; $dec = $this->item->deleted() ? 0 : $this->item["_decision"]; $aset->stage_qe("update Paper set outcome=? where paperId=?", $dec, $this->pid); if ($dec > 0 || $this->item->pre("_decision") > 0) { diff --git a/src/assigners/a_status.php b/src/assigners/a_status.php index a46d820ad..ba75e0d62 100644 --- a/src/assigners/a_status.php +++ b/src/assigners/a_status.php @@ -58,7 +58,6 @@ function load_state(AssignmentState $state) { Status_AssignmentParser::load_status_state($state); } function apply(PaperInfo $prow, Contact $contact, $req, AssignmentState $state) { - global $Now; $m = $state->remove(["type" => "status", "pid" => $prow->paperId]); $res = $m[0]; $ch = false; @@ -66,7 +65,7 @@ function apply(PaperInfo $prow, Contact $contact, $req, AssignmentState $state) if ($res["_submitted"] === 0) { if (($whynot = $state->user->perm_finalize_paper($prow))) return whyNotText($whynot); - $res["_submitted"] = ($res["_withdrawn"] > 0 ? -$Now : $Now); + $res["_submitted"] = ($res["_withdrawn"] > 0 ? -Conf::$now : Conf::$now); } } else if ($this->xtype === "unsubmit") { if ($res["_submitted"] !== 0) { @@ -79,7 +78,7 @@ function apply(PaperInfo $prow, Contact $contact, $req, AssignmentState $state) assert($res["_submitted"] >= 0); if (($whynot = $state->user->perm_withdraw_paper($prow))) return whyNotText($whynot); - $res["_withdrawn"] = $Now; + $res["_withdrawn"] = Conf::$now; $res["_submitted"] = -$res["_submitted"]; if ($state->conf->tags()->has_votish) { Tag_AssignmentParser::load_tag_state($state); @@ -97,7 +96,7 @@ function apply(PaperInfo $prow, Contact $contact, $req, AssignmentState $state) return whyNotText($whynot); $res["_withdrawn"] = 0; if ($res["_submitted"] === -100) - $res["_submitted"] = $Now; + $res["_submitted"] = Conf::$now; else $res["_submitted"] = -$res["_submitted"]; $res["_withdraw_reason"] = null; @@ -147,7 +146,6 @@ function add_locks(AssignmentSet $aset, &$locks) { $locks["Paper"] = "write"; } function execute(AssignmentSet $aset) { - global $Now; $submitted = $this->item["_submitted"]; $old_submitted = $this->item->pre("_submitted"); $withdrawn = $this->item["_withdrawn"]; diff --git a/src/assignmentset.php b/src/assignmentset.php index 8b2307277..217d8d99c 100644 --- a/src/assignmentset.php +++ b/src/assignmentset.php @@ -1394,7 +1394,6 @@ private function collect_parser($req) { } private function expand_special_user($user, AssignmentParser $aparser, PaperInfo $prow, $req) { - global $Now; if ($user === "any") { $u = $aparser->expand_any_user($prow, $req, $this->astate); } else if ($user === "missing") { @@ -1785,7 +1784,6 @@ function prow($pid) { } function execute($verbose = false) { - global $Now; if ($this->has_error() || empty($this->assigners)) { if ($verbose && $this->astate->has_messages()) { $this->report_errors(); @@ -1830,7 +1828,7 @@ function execute($verbose = false) { $this->conf->qe("unlock tables"); // confirmation message - if ($verbose && $this->conf->setting("pcrev_assigntime") == $Now) { + if ($verbose && $this->conf->setting("pcrev_assigntime") == Conf::$now) { $this->conf->confirmMsg("Assignments saved! You may want to " . $this->conf->hotlink("send mail about the new assignments", "mail", "template=newpcrev") . "."); } else if ($verbose) { $this->conf->confirmMsg("Assignments saved!"); diff --git a/src/capabilities/cap_reviewaccept.php b/src/capabilities/cap_reviewaccept.php index a9f2be987..d483f0c4c 100644 --- a/src/capabilities/cap_reviewaccept.php +++ b/src/capabilities/cap_reviewaccept.php @@ -4,8 +4,7 @@ class ReviewAccept_Capability { private static function make_review_acceptor($user, $at, $pid, $cid, $uf) { - global $Now; - if ($at && $at >= $Now - 2592000) { + if ($at && $at >= Conf::$now - 2592000) { $user->set_capability("@ra$pid", $cid); if ($user->is_activated()) { ensure_session(); @@ -17,8 +16,6 @@ private static function make_review_acceptor($user, $at, $pid, $cid, $uf) { } static function apply_review_acceptor(Contact $user, $uf, $isadd) { - global $Now; - $result = $user->conf->qe("select * from PaperReview where reviewId=?", $uf->match_data[1]); $rrow = ReviewInfo::fetch($result, $user->conf); Dbl::free($result); @@ -27,7 +24,7 @@ static function apply_review_acceptor(Contact $user, $uf, $isadd) { return; } - $result = $user->conf->qe("select * from PaperReviewRefused where `data` is not null and timeRefused>=?", $Now - 604800); + $result = $user->conf->qe("select * from PaperReviewRefused where `data` is not null and timeRefused>=?", Conf::$now - 604800); while (($refusal = $result->fetch_object())) { $data = json_decode((string) $refusal->data); if ($data diff --git a/src/checkformat.php b/src/checkformat.php index 92c5c7f43..411c64734 100644 --- a/src/checkformat.php +++ b/src/checkformat.php @@ -338,7 +338,6 @@ private function compress_bj($bj) { } function check(CheckFormat $cf, FormatSpec $spec, PaperInfo $prow, $doc) { - global $Now; $bj = null; if (($m = $doc->metadata()) && isset($m->banal)) { $bj = $m->banal; @@ -347,7 +346,7 @@ function check(CheckFormat $cf, FormatSpec $spec, PaperInfo $prow, $doc) { && get($bj, "args") == self::$banal_args; if (!$bj_ok) ++$cf->need_run; - if (!$bj_ok || $bj->at < $Now - 86400) { + if (!$bj_ok || $bj->at < Conf::$now - 86400) { $cf->possible_run = true; if ($cf->allow_run == CheckFormat::RUN_YES || (!$bj_ok && $cf->allow_run == CheckFormat::RUN_PREFER_NO)) diff --git a/src/commentinfo.php b/src/commentinfo.php index 9febb2738..dad9cb6e9 100644 --- a/src/commentinfo.php +++ b/src/commentinfo.php @@ -514,7 +514,6 @@ private function save_ordinal($cmtid, $ctype, $Table, $LinkTable, $LinkColumn) { } function save($req, Contact $acting_contact) { - global $Now; if (is_array($req)) { $req = (object) $req; } @@ -622,7 +621,7 @@ function save($req, Contact $acting_contact) { } else if (!$this->commentId) { $change = true; $qa = ["contactId, $LinkColumn, commentType, comment, commentOverflow, timeModified, replyTo"]; - $qb = [$contact->contactId, $this->prow->$LinkColumn, $ctype, "?", "?", $Now, 0]; + $qb = [$contact->contactId, $this->prow->$LinkColumn, $ctype, "?", "?", Conf::$now, 0]; if (strlen($text) <= 32000) { array_push($qv, $text, null); } else { @@ -639,7 +638,7 @@ function save($req, Contact $acting_contact) { } if ($displayed) { $qa[] = "timeDisplayed, timeNotified"; - $qb[] = "$Now, $Now"; + $qb[] = Conf::$now . ", " . Conf::$now; } $q = "insert into $Table (" . join(", ", $qa) . ") select " . join(", ", $qb) . "\n"; if ($is_response) { @@ -652,24 +651,24 @@ function save($req, Contact $acting_contact) { } } else { $change = ($this->commentType >= COMMENTTYPE_AUTHOR) != ($ctype >= COMMENTTYPE_AUTHOR); - if ($this->timeModified >= $Now) { - $Now = $this->timeModified + 1; + if ($this->timeModified >= Conf::$now) { + Conf::advance_current_time($this->timeModified); } // do not notify on updates within 3 hours $qa = ""; - if ($this->timeNotified + 10800 < $Now + if ($this->timeNotified + 10800 < Conf::$now || (($ctype & COMMENTTYPE_RESPONSE) && !($ctype & COMMENTTYPE_DRAFT) && ($this->commentType & COMMENTTYPE_DRAFT))) { - $qa .= ", timeNotified=$Now"; + $qa .= ", timeNotified=" . Conf::$now; } // reset timeDisplayed if you change the comment type if ((!$this->timeDisplayed || $this->ordinal_missing($ctype)) && ($text !== "" || $docids) && $displayed) { - $qa .= ", timeDisplayed=$Now"; + $qa .= ", timeDisplayed=" . Conf::$now; } - $q = "update $Table set timeModified=$Now$qa, commentType=$ctype, comment=?, commentOverflow=?, commentTags=? where commentId=$this->commentId"; + $q = "update $Table set timeModified=" . Conf::$now . $qa . ", commentType=$ctype, comment=?, commentOverflow=?, commentTags=? where commentId=$this->commentId"; if (strlen($text) <= 32000) { array_push($qv, $text, null); } else { diff --git a/src/conference.php b/src/conference.php index 0602378ba..2441a303a 100644 --- a/src/conference.php +++ b/src/conference.php @@ -50,7 +50,6 @@ class ResponseRound { /** @var ?PaperSearch */ public $search; function relevant(Contact $user, PaperInfo $prow = null) { - global $Now; if ($user->allow_administer($prow) && ($this->done || $this->search || $this->name !== "1")) { return true; @@ -58,20 +57,19 @@ function relevant(Contact $user, PaperInfo $prow = null) { return $this->open > 0; } else { return $this->open > 0 - && $this->open < $Now + && $this->open < Conf::$now && (!$this->search || $this->search->filter($prow ? [$prow] : $user->authored_papers())); } } function time_allowed($with_grace) { - global $Now; - if ($this->open === null || $this->open <= 0 || $this->open > $Now) { + if ($this->open === null || $this->open <= 0 || $this->open > Conf::$now) { return false; } $t = $this->done; if ($t !== null && $t > 0 && $with_grace && $this->grace) { $t += $this->grace; } - return $t === null || $t <= 0 || $t >= $Now; + return $t === null || $t <= 0 || $t >= Conf::$now; } function instructions(Conf $conf) { $m = $conf->_i("resp_instrux_$this->number", false, $this->words); @@ -243,6 +241,10 @@ class Conf { /** @var Conf */ static public $g; + + /** @var int */ + static public $now; + static public $no_invalidate_caches = false; static public $next_xt_subposition = 0; static private $xt_require_resolved = []; @@ -292,14 +294,23 @@ function __construct($options, $make_dsn) { } } + /** @param int $t */ + static function set_current_time($t) { + global $Now; + $Now = Conf::$now = $t; + } + + /** @param int $advance_past */ + static function advance_current_time($advance_past) { + self::set_current_time(max(Conf::$now, $advance_past + 1)); + } + // // Initialization functions // function load_settings() { - global $Now; - // load settings from database $this->settings = array(); $this->settingTexts = array(); @@ -354,7 +365,7 @@ function load_settings() { } // GC old capabilities - if (($this->settings["__capability_gc"] ?? 0) < $Now - 86400) { + if (($this->settings["__capability_gc"] ?? 0) < Conf::$now - 86400) { $this->cleanup_capabilities(); } @@ -363,8 +374,6 @@ function load_settings() { } private function crosscheck_settings() { - global $Now; - // enforce invariants foreach (["pcrev_any", "extrev_view"] as $x) { if (!isset($this->settings[$x])) { @@ -438,9 +447,9 @@ private function crosscheck_settings() { $this->_pc_see_pdf = true; if (($this->settings["sub_freeze"] ?? 0) <= 0 && ($so = $this->settings["sub_open"] ?? 0) > 0 - && $so < $Now + && $so < Conf::$now && ($ss = $this->settings["sub_sub"] ?? 0) > 0 - && $ss > $Now + && $ss > Conf::$now && (($this->settings["pc_seeallpdf"] ?? 0) <= 0 || !$this->can_pc_see_active_submissions())) { $this->_pc_see_pdf = false; @@ -684,7 +693,6 @@ function crosscheck_options() { } private function cleanup_capabilities() { - global $Now; $ctmap = $this->capability_type_map(); $ct_cleanups = []; foreach ($ctmap as $ctj) { @@ -692,15 +700,15 @@ private function cleanup_capabilities() { $ct_cleanups[] = $ctj->type; } if (!empty($ct_cleanups)) { - $result = $this->ql("select * from Capability where timeExpires>0 and timeExpires<$Now and capabilityType?a", $ct_cleanups); + $result = $this->ql("select * from Capability where timeExpires>0 and timeExpirescapabilityType]->cleanup_callback, $cap); } Dbl::free($result); } - $this->ql("delete from Capability where timeExpires>0 and timeExpires<$Now"); - $this->ql("insert into Settings set name='__capability_gc', value=$Now on duplicate key update value=values(value)"); - $this->settings["__capability_gc"] = $Now; + $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->settings["__capability_gc"] = Conf::$now; } @@ -956,7 +964,6 @@ function docstore() { /** @return ?S3Client */ function s3_docstore() { - global $Now; if ($this->_s3_client === false) { if ($this->setting_data("s3_bucket")) { $opts = [ @@ -2844,10 +2851,7 @@ function parseableTime($value, $include_zone) { return $d; } function parse_time($d, $reference = null) { - global $Now; - if ($reference === null) { - $reference = $Now; - } + $reference = $reference ?? Conf::$now; if (!isset($this->opt["dateFormatTimezoneRemover"])) { $x = array(); if (function_exists("timezone_abbreviations_list")) { @@ -2949,8 +2953,7 @@ function unparse_time_log($timestamp) { /** @param int $timestamp * @param int $now */ function unparse_time_relative($timestamp, $now = 0, $format = 0) { - global $Now; - $d = abs($timestamp - ($now ? : $Now)); + $d = abs($timestamp - ($now ? : Conf::$now)); if ($d >= 5227200) { if (!($format & 1)) { return ($format & 8 ? "on " : "") . date($this->_dateFormat("obscure"), $timestamp); @@ -2984,7 +2987,7 @@ function unparse_time_relative($timestamp, $now = 0, $format = 0) { if ($format & 2) { return $d; } else { - return $timestamp < ($now ? : $Now) ? $d . " ago" : "in " . $d; + return $timestamp < ($now ? : Conf::$now) ? $d . " ago" : "in " . $d; } } @@ -3000,24 +3003,21 @@ function printableDeadlineSetting($what, $useradjust = false, $preadjust = null) } function settingsAfter($name) { - global $Now; $t = $this->settings[$name] ?? null; - return $t !== null && $t > 0 && $t <= $Now; + return $t !== null && $t > 0 && $t <= Conf::$now; } function deadlinesAfter($name, $grace = null) { - global $Now; $t = $this->settings[$name] ?? null; if ($t !== null && $t > 0 && $grace && ($g = $this->settings[$grace] ?? null)) { $t += $g; } - return $t !== null && $t > 0 && $t <= $Now; + return $t !== null && $t > 0 && $t <= Conf::$now; } function deadlinesBetween($name1, $name2, $grace = null) { // see also ResponseRound::time_allowed - global $Now; $t = $this->settings[$name1] ?? null; - if (($t === null || $t <= 0 || $t > $Now) && $name1) { + if (($t === null || $t <= 0 || $t > Conf::$now) && $name1) { return false; } $t = $this->settings[$name2] ?? null; @@ -3025,7 +3025,7 @@ function deadlinesBetween($name1, $name2, $grace = null) { && ($g = $this->settings[$grace] ?? null)) { $t += $g; } - return $t === null || $t <= 0 || $t >= $Now; + return $t === null || $t <= 0 || $t >= Conf::$now; } function timeStartPaper() { @@ -3058,9 +3058,8 @@ function can_some_author_view_decision() { return $this->setting("seedec") == self::SEEDEC_ALL; } function time_review_open() { - global $Now; $rev_open = $this->settings["rev_open"] ?? 0; - return 0 < $rev_open && $rev_open <= $Now; + return 0 < $rev_open && $rev_open <= Conf::$now; } function review_deadline($round, $isPC, $hard) { if ($round === null) { @@ -3072,14 +3071,13 @@ function review_deadline($round, $isPC, $hard) { . ($round ? "_$round" : ""); } function missed_review_deadline($round, $isPC, $hard) { - global $Now; $rev_open = $this->settings["rev_open"] ?? 0; - if (!(0 < $rev_open && $rev_open <= $Now)) { + if (!(0 < $rev_open && $rev_open <= Conf::$now)) { return "rev_open"; } $dn = $this->review_deadline($round, $isPC, $hard); $dv = $this->settings[$dn] ?? 0; - if ($dv > 0 && $dv < $Now) { + if ($dv > 0 && $dv < Conf::$now) { return $dn; } return false; @@ -4010,11 +4008,11 @@ function set_cookie($name, $value, $expires_at) { } function header_head($title, $extra = []) { - global $Me, $Now, $ConfSitePATH; + global $Me; // clear session list cookies foreach ($_COOKIE as $k => $v) { if (str_starts_with($k, "hotlist-info")) - $this->set_cookie($k, "", $Now - 86400); + $this->set_cookie($k, "", Conf::$now - 86400); } echo " @@ -4159,17 +4157,16 @@ function header_head($title, $extra = []) { /** @return bool */ function has_interesting_deadline($my_deadlines) { - global $Now; if ($my_deadlines->sub->open ?? false) { foreach (["reg", "update", "sub"] as $k) { - if ($Now <= get($my_deadlines->sub, $k, 0) || get($my_deadlines->sub, "{$k}_ingrace")) + if (Conf::$now <= get($my_deadlines->sub, $k, 0) || get($my_deadlines->sub, "{$k}_ingrace")) return true; } } if (($my_deadlines->is_author ?? false) && ($my_deadlines->resps ?? false)) { foreach ($my_deadlines->resps as $r) { - if ($r->open && ($Now <= $r->done || ($r->ingrace ?? false))) + if ($r->open && (Conf::$now <= $r->done || ($r->ingrace ?? false))) return true; } } @@ -4177,7 +4174,7 @@ function has_interesting_deadline($my_deadlines) { } function header_body($title, $id, $extra = []) { - global $Me, $Now; + global $Me; echo "\n"; // initial load (JS's timezone offsets are negative of PHP's) - Ht::stash_script("hotcrp_load.time(" . (-(int) date("Z", $Now) / 60) . "," . ($this->opt("time24hour") ? 1 : 0) . ")"); + Ht::stash_script("hotcrp_load.time(" . (-(int) date("Z", Conf::$now) / 60) . "," . ($this->opt("time24hour") ? 1 : 0) . ")"); // deadlines settings $my_deadlines = null; @@ -4323,7 +4320,7 @@ function header_body($title, $id, $extra = []) { $this->msg($t, $m[1]); } } - hotcrp_setcookie("hotcrpmessage", "", ["expires" => $Now - 3600]); + hotcrp_setcookie("hotcrpmessage", "", ["expires" => Conf::$now - 3600]); } } echo "\n"; @@ -4339,7 +4336,7 @@ function header_body($title, $id, $extra = []) { if ($Me && $Me->privChair && (!isset($_SESSION["updatecheck"]) - || $_SESSION["updatecheck"] + 3600 <= $Now) + || $_SESSION["updatecheck"] + 3600 <= Conf::$now) && (!isset($this->opt["updatesSite"]) || $this->opt["updatesSite"])) { $m = isset($this->opt["updatesSite"]) ? $this->opt["updatesSite"] : "//hotcrp.lcdf.org/updates"; $m .= (strpos($m, "?") === false ? "?" : "&") @@ -4360,7 +4357,7 @@ function header_body($title, $id, $extra = []) { } } Ht::stash_script("check_version(\"$m\",\"$v\")"); - $_SESSION["updatecheck"] = $Now; + $_SESSION["updatecheck"] = Conf::$now; } } @@ -4598,7 +4595,6 @@ function log_for($user, $dest_user, $text, $pids = null) { /** @return list> */ private static function format_log_values($text, $user, $dest_user, $true_user, $pids) { - global $Now; if (empty($pids)) { $pids = [null]; } @@ -4638,7 +4634,7 @@ private static function format_log_values($text, $user, $dest_user, $true_user, $pid = null; $t = substr($t, 0, 4096); } - $result[] = [$addr, $user, $dest_user, $true_user, $pid, $Now, $t]; + $result[] = [$addr, $user, $dest_user, $true_user, $pid, Conf::$now, $t]; $l = $r; } return $result; diff --git a/src/contact.php b/src/contact.php index a24149317..a31db4c9a 100644 --- a/src/contact.php +++ b/src/contact.php @@ -529,7 +529,6 @@ private function actas_user($x) { /** @return Contact */ function activate($qreq, $signin = false) { - global $Now; $this->_activated = true; // Handle actas requests @@ -574,8 +573,8 @@ function activate($qreq, $signin = false) { if (!self::$true_user && $this->email) { $trueuser_aucheck = $this->session("trueuser_author_check", 0); if (!$this->has_account_here() - && $trueuser_aucheck + 600 < $Now) { - $this->save_session("trueuser_author_check", $Now); + && $trueuser_aucheck + 600 < Conf::$now) { + $this->save_session("trueuser_author_check", Conf::$now); $aupapers = self::email_authored_papers($this->conf, $this->email, $this); if (!empty($aupapers)) $this->activate_database_account(); @@ -585,7 +584,7 @@ function activate($qreq, $signin = false) { foreach ($_SESSION as $k => $v) { if (is_array($v) && isset($v["trueuser_author_check"]) - && $v["trueuser_author_check"] + 600 < $Now) + && $v["trueuser_author_check"] + 600 < Conf::$now) unset($_SESSION[$k]["trueuser_author_check"]); } } @@ -670,9 +669,8 @@ function contactdb_user($refresh = false) { } private function _contactdb_save_roles($cdbur) { - global $Now; 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)", $cdbur->contactDbId, $cdbur->confid, $roles, $Now); + 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)", $cdbur->contactDbId, $cdbur->confid, $roles, Conf::$now); } else { Dbl::ql($this->conf->contactdb(), "delete from Roles where contactDbId=? and confid=? and roles=0", $cdbur->contactDbId, $cdbur->confid); } @@ -1247,7 +1245,7 @@ function apply_capability_text($text) { function escape($qreq = null) { - global $Qreq, $Now; + global $Qreq; $qreq = $qreq ? : $Qreq; if ($qreq->ajax) { @@ -1271,7 +1269,7 @@ function escape($qreq = null) { $x["anchor"] = $qreq->anchor; } $url = $this->conf->selfurl($qreq, $x, Conf::HOTURL_RAW | Conf::HOTURL_SITE_RELATIVE); - $_SESSION["login_bounce"] = [$this->conf->dsn, $url, Navigation::page(), $_POST, $Now + 120]; + $_SESSION["login_bounce"] = [$this->conf->dsn, $url, Navigation::page(), $_POST, Conf::$now + 120]; if ($qreq->post_ok()) { error_go(false, "You must sign in to access that page. Your changes were not saved; after signing in, you may submit them again."); } else { @@ -1442,7 +1440,6 @@ private function _make_create_updater($reg, $is_cdb) { } function apply_updater($updater, $is_cdb) { - global $Now; if ($is_cdb) { $db = $this->conf->contactdb(); $idk = "contactDbId"; @@ -1463,10 +1460,10 @@ function apply_updater($updater, $is_cdb) { assert(isset($updater["email"])); if (!isset($updater["password"])) { $updater["password"] = validate_email($updater["email"]) ? " unset" : " nologin"; - $updater["passwordTime"] = $Now; + $updater["passwordTime"] = Conf::$now; } if (!$is_cdb) { - $updater["creationTime"] = $Now; + $updater["creationTime"] = Conf::$now; } $result = Dbl::qe_apply($db, "insert into ContactInfo set " . join("=?, ", array_keys($updater)) . "=? on duplicate key update firstName=firstName", array_values($updater)); if ($result->affected_rows) { @@ -1698,7 +1695,6 @@ private function hash_password($input) { /** @param string $input * @return array{ok:bool} */ function check_password_info($input, $options = []) { - global $Now; assert(!$this->conf->external_login()); $cdbu = $this->contactdb_user(); @@ -1752,7 +1748,7 @@ function check_password_info($input, $options = []) { $x["local_password"] = $this->password; } if ($this->passwordTime > 0) { - $x["local_password_age"] = ceil(($Now - $this->passwordTime) / 8640) / 10; + $x["local_password_age"] = ceil((Conf::$now - $this->passwordTime) / 8640) / 10; } } if ($cdbu && $cdbu->password) { @@ -1761,7 +1757,7 @@ function check_password_info($input, $options = []) { $x["cdbu_password"] = $cdbu->password; } if ($cdbu->passwordTime > 0) { - $x["cdb_password_age"] = ceil(($Now - $cdbu->passwordTime) / 8640) / 10; + $x["cdb_password_age"] = ceil((Conf::$now - $cdbu->passwordTime) / 8640) / 10; } } return $x; @@ -1785,37 +1781,37 @@ function check_password_info($input, $options = []) { // update cdb password if ($cdb_ok || ($cdbu && (string) $cdbu->password === "")) { - $updater = ["passwordUseTime" => $Now]; + $updater = ["passwordUseTime" => Conf::$now]; if (!$cdb_ok || $this->password_needs_rehash($cdbu->password)) { $updater["password"] = $this->hash_password($input); } if (!$cdb_ok || !$cdbu->passwordTime) { - $updater["passwordTime"] = $Now; + $updater["passwordTime"] = Conf::$now; } $cdbu->apply_updater($updater, true); // clear local password if ($this->contactId > 0 && (string) $this->password !== "") { - $this->apply_updater(["passwordUseTime" => $Now, "password" => "", "passwordTime" => $Now], false); + $this->apply_updater(["passwordUseTime" => Conf::$now, "password" => "", "passwordTime" => Conf::$now], false); $local_ok = false; } } // update local password if ($local_ok) { - $updater = ["passwordUseTime" => $Now]; + $updater = ["passwordUseTime" => Conf::$now]; if ($this->password_needs_rehash($this->password)) { $updater["password"] = $this->hash_password($input); } if (!$this->passwordTime) { - $updater["passwordTime"] = $Now; + $updater["passwordTime"] = Conf::$now; } $this->apply_updater($updater, false); // complain about local password use if ($cdbu) { - $t0 = $this->passwordTime ? ceil(($Now - $this->passwordTime) / 8640) / 10 : -1; - $t1 = $cdbu->passwordTime ? ceil(($Now - $cdbu->passwordTime) / 8640) / 10 : -1; + $t0 = $this->passwordTime ? ceil((Conf::$now - $this->passwordTime) / 8640) / 10 : -1; + $t1 = $cdbu->passwordTime ? ceil((Conf::$now - $cdbu->passwordTime) / 8640) / 10 : -1; error_log("{$this->conf->dbname}: user {$this->email}: signing in with local password, which is " . ($this->passwordTime < $cdbu->passwordTime ? "older" : "newer") . " than cdb [{$t0}d/{$t1}d]"); } } @@ -1831,13 +1827,12 @@ function check_password($input) { } function change_password($new) { - global $Now; assert(!$this->conf->external_login()); assert($new !== null); if ($new && $new[0] !== " ") { $hash = $this->hash_password($new); - $use_time = $Now; + $use_time = Conf::$now; } else { $hash = $new; $use_time = 0; @@ -1845,12 +1840,12 @@ function change_password($new) { $cdbu = $this->contactdb_user(); if ($cdbu) { - $cdbu->apply_updater(["passwordUseTime" => $use_time, "password" => $hash, "passwordTime" => $Now], true); + $cdbu->apply_updater(["passwordUseTime" => $use_time, "password" => $hash, "passwordTime" => Conf::$now], true); if ($this->contactId && (string) $this->password !== "") { - $this->apply_updater(["passwordUseTime" => $use_time, "password" => "", "passwordTime" => $Now], false); + $this->apply_updater(["passwordUseTime" => $use_time, "password" => "", "passwordTime" => Conf::$now], false); } } else if ($this->contactId) { - $this->apply_updater(["passwordUseTime" => $use_time, "password" => $hash, "passwordTime" => $Now], false); + $this->apply_updater(["passwordUseTime" => $use_time, "password" => $hash, "passwordTime" => Conf::$now], false); } return true; } @@ -1870,26 +1865,24 @@ function send_mail($template, $rest = []) { function mark_login() { - global $Now; // at least one login every 30 days is marked as activity - if ((int) $this->activity_at <= $Now - 2592000 + if ((int) $this->activity_at <= Conf::$now - 2592000 || (($cdbu = $this->contactdb_user()) - && ((int) $cdbu->activity_at <= $Now - 2592000))) { + && ((int) $cdbu->activity_at <= Conf::$now - 2592000))) { $this->mark_activity(); } } function mark_activity() { - global $Now; - if ((!$this->activity_at || $this->activity_at < $Now) + if ((!$this->activity_at || $this->activity_at < Conf::$now) && !$this->is_anonymous_user()) { - $this->activity_at = $Now; + $this->activity_at = Conf::$now; if ($this->contactId) { - $this->conf->ql("update ContactInfo set lastLogin=$Now where contactId=$this->contactId"); + $this->conf->ql("update ContactInfo set lastLogin=".Conf::$now." where contactId=$this->contactId"); } if (($cdbu = $this->contactdb_user()) && $cdbu->confid - && (int) $cdbu->activity_at <= $Now - 604800) { + && (int) $cdbu->activity_at <= Conf::$now - 604800) { $this->_contactdb_save_roles($cdbu); } } @@ -3762,12 +3755,11 @@ function can_comment(PaperInfo $prow, $crow, $submit = false) { /** @param ?CommentInfo $crow */ function can_finalize_comment(PaperInfo $prow, $crow) { - global $Now; return $crow && ($crow->commentType & (COMMENTTYPE_RESPONSE | COMMENTTYPE_DRAFT)) === (COMMENTTYPE_RESPONSE | COMMENTTYPE_DRAFT) && ($rrd = get($prow->conf->resp_rounds(), $crow->commentRound)) && $rrd->open > 0 - && $rrd->open < $Now + && $rrd->open < Conf::$now && $prow->conf->setting("resp_active") > 0; } @@ -4287,8 +4279,7 @@ function following_reviews(PaperInfo $prow, $watch) { function my_deadlines($prows = null) { // Return cleaned deadline-relevant settings that this user can see. - global $Now; - $dl = (object) ["now" => $Now, "email" => $this->email ? : null]; + $dl = (object) ["now" => Conf::$now, "email" => $this->email ? : null]; if ($this->privChair) { $dl->is_admin = true; } else if ($this->is_track_manager()) { @@ -4352,7 +4343,7 @@ function my_deadlines($prows = null) { if ($this->conf->setting("final_open") > 0) { $dl->final = (object) array("open" => true); $final_soft = +$this->conf->setting("final_soft"); - if ($final_soft > $Now) { + if ($final_soft > Conf::$now) { $dl->final->done = $final_soft; } else { $dl->final->done = +$this->conf->setting("final_done"); @@ -4366,7 +4357,7 @@ function my_deadlines($prows = null) { // reviewer deadlines $revtypes = array(); $rev_open = +$this->conf->setting("rev_open"); - $rev_open = $rev_open > 0 && $rev_open <= $Now; + $rev_open = $rev_open > 0 && $rev_open <= Conf::$now; if ($this->is_reviewer() && $rev_open) { $dl->rev = (object) ["open" => true]; } else if ($this->privChair) { @@ -4383,7 +4374,7 @@ function my_deadlines($prows = null) { if ($rev_open) { $dlround->open = true; } - if ($h && ($h < $Now || $s < $Now)) { + if ($h && ($h < Conf::$now || $s < Conf::$now)) { $dlround->done = $h; $dlround->ishard = true; } else if ($s) { @@ -4405,8 +4396,8 @@ function my_deadlines($prows = null) { $dlx = $graces[$i]; foreach ($graces[$i + 2] as $k) { if ($dlx->$k - && $dlx->$k - 30 < $Now - && $dlx->$k + $graces[$i + 1] >= $Now) { + && $dlx->$k - 30 < Conf::$now + && $dlx->$k + $graces[$i + 1] >= Conf::$now) { $kgrace = "{$k}_ingrace"; $dlx->$kgrace = true; } @@ -4491,18 +4482,17 @@ function my_deadlines($prows = null) { } function has_reportable_deadline() { - global $Now; $dl = $this->my_deadlines(); if (isset($dl->sub->reg) || isset($dl->sub->update) || isset($dl->sub->sub)) { return true; } if (isset($dl->resps)) { foreach ($dl->resps as $dlr) { - if (isset($dlr->open) && $dlr->open < $Now && ($dlr->done ?? null)) + if (isset($dlr->open) && $dlr->open < Conf::$now && ($dlr->done ?? null)) return true; } } - if (isset($dl->rev) && isset($dl->rev->open) && $dl->rev->open < $Now) { + if (isset($dl->rev) && isset($dl->rev->open) && $dl->rev->open < Conf::$now) { foreach ($dl->revs as $dlr) { if ($dlr->done ?? null) return true; @@ -4572,7 +4562,6 @@ private function assign_review_explanation($type, $round) { * @param int $reviewer_cid * @param int $type */ function assign_review($pid, $reviewer_cid, $type, $extra = []) { - global $Now; $result = $this->conf->qe("select reviewId, reviewType, reviewRound, reviewModified, reviewToken, requestedBy, reviewSubmitted from PaperReview where paperId=? and contactId=?", $pid, $reviewer_cid); $rrow = $result->fetch_object(); Dbl::free($result); @@ -4603,7 +4592,7 @@ function assign_review($pid, $reviewer_cid, $type, $extra = []) { if ($type && !$oldtype) { $qa = ""; if ($extra["mark_notify"] ?? null) { - $qa .= ", timeRequestNotified=$Now"; + $qa .= ", timeRequestNotified=" . Conf::$now; } if ($extra["token"] ?? null) { $qa .= $this->unassigned_review_token(); @@ -4611,7 +4600,7 @@ function assign_review($pid, $reviewer_cid, $type, $extra = []) { if (($new_requester = $extra["requester_contact"] ?? null)) { $new_requester_cid = $new_requester->contactId; } - $q = "insert into PaperReview set paperId=$pid, contactId=$reviewer_cid, reviewType=$type, reviewRound=$round, timeRequested=$Now$qa, requestedBy=$new_requester_cid"; + $q = "insert into PaperReview set paperId=$pid, contactId=$reviewer_cid, reviewType=$type, reviewRound=$round, timeRequested=".Conf::$now."$qa, requestedBy=$new_requester_cid"; } else if ($type && ($oldtype != $type || $rrow->reviewRound != $round)) { $q = "update PaperReview set reviewType=$type, reviewRound=$round"; if (!$rrow->reviewSubmitted) @@ -4649,8 +4638,8 @@ function assign_review($pid, $reviewer_cid, $type, $extra = []) { $this->update_review_delegation($pid, $new_requester_cid, 1); } if ($type >= REVIEW_PC - && $this->conf->setting("pcrev_assigntime", 0) < $Now) { - $this->conf->save_setting("pcrev_assigntime", $Now); + && $this->conf->setting("pcrev_assigntime", 0) < Conf::$now) { + $this->conf->save_setting("pcrev_assigntime", Conf::$now); } } else if (!$type) { if ($oldtype < REVIEW_SECONDARY && $rrow->requestedBy > 0) { diff --git a/src/formula.php b/src/formula.php index 4291438e1..76793bc5d 100644 --- a/src/formula.php +++ b/src/formula.php @@ -1050,10 +1050,7 @@ function _add_tags() { return '$tags'; } function _add_now() { - if ($this->check_gvar('$now')) { - $this->gstmt[] = "global \$Now;"; - } - return '$Now'; + return 'Conf::$now'; } function loop_cid($aggregate = false) { diff --git a/src/helpers.php b/src/helpers.php index e7a81c4ce..dd32b24c8 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -457,7 +457,7 @@ function filter_whynot($whyNot, $keys) { /** @param array{conf:Conf,paperId?:int,reviewId?:int,option?:PaperOption} $whyNot */ function whyNotText($whyNot, $text_only = false) { - global $Conf, $Now; + global $Conf; if (is_string($whyNot)) { $whyNot = array($whyNot => 1); } @@ -569,9 +569,9 @@ function whyNotText($whyNot, $text_only = false) { } } else if ($start <= 0 || $start == $end) { $ms[] = $conf->_c("etime", "Action not available.", $open_dname, $paperId); - } else if ($start > 0 && $Now < $start) { + } else if ($start > 0 && Conf::$now < $start) { $ms[] = $conf->_c("etime", "Action not available until %3\$s.", $open_dname, $paperId, $conf->unparse_time($start)); - } else if ($end > 0 && $Now > $end) { + } else if ($end > 0 && Conf::$now > $end) { $ms[] = $conf->_c("etime", "Deadline passed.", $dname, $paperId, $conf->unparse_time($end)); } else { $ms[] = $conf->_c("etime", "Action not available.", $dname, $paperId); diff --git a/src/init.php b/src/init.php index 0ce04e721..43e83ed9c 100644 --- a/src/init.php +++ b/src/init.php @@ -62,7 +62,6 @@ define("TAG_INDEXBOUND", 2147483646); global $Now, $ConfSitePATH; -$Now = time(); require_once(SiteLoader::find("lib/navigation.php")); require_once(SiteLoader::find("lib/polyfills.php")); @@ -72,6 +71,7 @@ require_once(SiteLoader::find("src/helpers.php")); require_once(SiteLoader::find("src/conference.php")); require_once(SiteLoader::find("src/contact.php")); +Conf::set_current_time(time()); // Set locale to C (so that, e.g., strtolower() on UTF-8 data doesn't explode) diff --git a/src/initweb.php b/src/initweb.php index b5c621143..0a301e37c 100644 --- a/src/initweb.php +++ b/src/initweb.php @@ -69,7 +69,7 @@ function initialize_user_redirect($nav, $uindex, $nusers) { } function initialize_user() { - global $Conf, $Me, $Now, $Qreq; + global $Conf, $Me, $Qreq; $nav = Navigation::get(); // set up session @@ -155,7 +155,7 @@ function initialize_user() { // if bounced through login, add post data if (isset($_SESSION["login_bounce"][4]) - && $_SESSION["login_bounce"][4] <= $Now) { + && $_SESSION["login_bounce"][4] <= Conf::$now) { unset($_SESSION["login_bounce"]); } diff --git a/src/mailclasses.php b/src/mailclasses.php index 29a733909..306072a19 100644 --- a/src/mailclasses.php +++ b/src/mailclasses.php @@ -25,7 +25,6 @@ private function defsel($name, $description, $flags = 0) { } function __construct($contact, $type, $papersel, $newrev_since) { - global $Now; $this->conf = $contact->conf; $this->contact = $contact; assert(!!$contact->isPC); @@ -158,7 +157,7 @@ function __construct($contact, $type, $papersel, $newrev_since) { if (preg_match(',\A(?:|n/a|\(?all\)?|0)\z,i', $t)) { $this->newrev_since = 0; } else if (($this->newrev_since = $this->conf->parse_time($t)) !== false) { - if ($this->newrev_since > $Now) { + if ($this->newrev_since > Conf::$now) { $this->conf->warnMsg("That time is in the future."); } } else { diff --git a/src/meetingtracker.php b/src/meetingtracker.php index d525c2034..989ec5630 100644 --- a/src/meetingtracker.php +++ b/src/meetingtracker.php @@ -4,10 +4,9 @@ class MeetingTracker { static function lookup(Conf $conf) { - global $Now; $tracker = $conf->setting_json("tracker"); if ($tracker - && (!$tracker->trackerid || $tracker->update_at >= $Now - 150)) { + && (!$tracker->trackerid || $tracker->update_at >= Conf::$now - 150)) { return $tracker; } else { $when = $tracker ? $tracker->update_at + 0.1 : 0; @@ -16,11 +15,10 @@ static function lookup(Conf $conf) { } static function expand($tracker) { - global $Now; if (isset($tracker->ts)) { $ts = []; foreach ($tracker->ts as $tr) { - if ($tr->update_at >= $Now - 150) + if ($tr->update_at >= Conf::$now - 150) $ts[] = $tr; } return $ts; @@ -65,8 +63,6 @@ static function session_owns_tracker(Conf $conf) { static function contact_tracker_comet(Conf $conf, $pids = null) { - global $Now; - $comet_dir = $conf->opt("trackerCometUpdateDirectory"); $comet_url = $conf->opt("trackerCometSite"); if (!$comet_dir && !$comet_url) { @@ -90,7 +86,7 @@ static function contact_tracker_comet(Conf $conf, $pids = null) { } $suffix = ""; $count = 0; - while (($f = @fopen($comet_dir . $Now . $suffix, "x")) === false + while (($f = @fopen($comet_dir . Conf::$now . $suffix, "x")) === false && $count < 20) { $suffix = "x" . mt_rand(0, 65535); ++$count; @@ -225,7 +221,6 @@ static private function compute_default_visibility(Contact $user, $admin_perm) { static private function tracker_new(Contact $user, $trackerid, $xlist, $start_at, $position, $position_at) { - global $Now; if ($xlist instanceof SessionList) { $url = $xlist->full_site_relative_url(); } else { @@ -239,7 +234,7 @@ static private function tracker_new(Contact $user, $trackerid, $xlist, "description" => $xlist->description, "start_at" => $start_at, "position_at" => $position_at, - "update_at" => max($Now, $position_at), + "update_at" => max(Conf::$now, $position_at), "owner" => $user->contactId, "sessionid" => session_id(), "position" => $position @@ -247,7 +242,6 @@ static private function tracker_new(Contact $user, $trackerid, $xlist, } static private function tracker_save(Conf $conf, $trs, $tracker, $position_at) { - global $Now; if (empty($trs)) { $tracker = (object) [ "trackerid" => false, @@ -263,7 +257,7 @@ static private function tracker_save(Conf $conf, $trs, $tracker, $position_at) { $tracker = (object) [ "trackerid" => $tracker->trackerid, "position_at" => $position_at, - "update_at" => max($Now, $position_at), + "update_at" => max(Conf::$now, $position_at), "ts" => $trs ]; } @@ -275,7 +269,6 @@ static function track_api(Contact $user, $qreq) { // NB: This is a special API function; it should either return nothing // (in which case the result of a `status` api call is returned), // or call `json_exit` on error. - global $Now; // track="IDENTIFIER POSITION" or track="IDENTIFIER stop" or track=stop if (!$user->is_track_manager() || !$qreq->post_ok()) { @@ -378,7 +371,7 @@ static function track_api(Contact $user, $qreq) { $position_at = $trs[$match]->position_at; } } else { - $start_at = $Now; + $start_at = Conf::$now; } ensure_session(); @@ -414,8 +407,6 @@ static function track_api(Contact $user, $qreq) { } static function trackerconfig_api(Contact $user, $qreq) { - global $Now; - if (!$user->is_track_manager() || !$qreq->post_ok()) { return json_exit(403, "Permission error."); } @@ -514,7 +505,7 @@ static function trackerconfig_api(Contact $user, $qreq) { $new_trackerid = mt_rand(1, 9999999); } while (self::tracker_search($new_trackerid, $trs) !== false); - $tr = self::tracker_new($user, $new_trackerid, $xlist, $Now, $position, $position_at); + $tr = self::tracker_new($user, $new_trackerid, $xlist, Conf::$now, $position, $position_at); if ($name !== "") { $tr->name = $name; } @@ -595,7 +586,6 @@ static function trackerconfig_api(Contact $user, $qreq) { static private function trinfo($tr, Contact $user) { - global $Now; $ti = (object) [ "trackerid" => $tr->trackerid, "listid" => $tr->listid, @@ -603,7 +593,7 @@ static private function trinfo($tr, Contact $user) { "start_at" => $tr->start_at, "position_at" => $tr->position_at, "url" => $tr->url, - "calculated_at" => $Now, + "calculated_at" => Conf::$now, "listinfo" => json_encode_browser([ "listid" => $tr->listid, "ids" => SessionList::encode_ids($tr->ids), @@ -732,7 +722,6 @@ static private function trinfo_papers($tis, $trs, Contact $user) { } static function my_deadlines($dl, Contact $user) { - global $Now; $tracker = self::lookup($user->conf); if ($tracker->trackerid && $user->can_view_tracker()) { $tis = $trs = []; diff --git a/src/papercolumns/pc_reviewdelegation.php b/src/papercolumns/pc_reviewdelegation.php index a51a22d3e..abdb426b2 100644 --- a/src/papercolumns/pc_reviewdelegation.php +++ b/src/papercolumns/pc_reviewdelegation.php @@ -16,7 +16,6 @@ function prepare(PaperList $pl, $visible) { return true; } function content(PaperList $pl, PaperInfo $row) { - global $Now; $rx = []; $row->ensure_reviewer_names(); $old_overrides = $pl->user->add_overrides(Contact::OVERRIDE_CONFLICT); diff --git a/src/paperstatus.php b/src/paperstatus.php index a23af723c..147970504 100644 --- a/src/paperstatus.php +++ b/src/paperstatus.php @@ -596,7 +596,6 @@ private function valid_contact($email) { private function normalize($pj) { // Errors prevent saving - global $Now; // Authors $au_by_lemail = []; @@ -648,12 +647,12 @@ private function normalize($pj) { if (is_numeric($pj->$k)) { $pj->$k = (int) $pj->$k; } else if (is_string($pj->$k)) { - $pj->$k = $this->conf->parse_time($pj->$k, $Now); + $pj->$k = $this->conf->parse_time($pj->$k, Conf::$now); } else { $pj->$k = false; } if ($pj->$k === false || $pj->$k < 0) { - $pj->$k = $Now; + $pj->$k = Conf::$now; } } } @@ -853,7 +852,6 @@ static function check_one_pdf(PaperOption $opt, PaperStatus $ps, $pj) { } static function check_status(PaperStatus $ps, $pj) { - global $Now; $pj_withdrawn = get($pj, "withdrawn"); $pj_submitted = get($pj, "submitted"); $pj_draft = get($pj, "draft"); @@ -883,7 +881,7 @@ static function check_status(PaperStatus $ps, $pj) { $submitted_at = -$submitted_at; } if (!$ps->prow || $ps->prow->timeWithdrawn <= 0) { - $ps->save_paperf("timeWithdrawn", get($pj, "withdrawn_at") ? : $Now); + $ps->save_paperf("timeWithdrawn", get($pj, "withdrawn_at") ? : Conf::$now); $ps->save_paperf("timeSubmitted", $submitted_at); $ps->mark_diff("status"); } else if (($ps->prow->submitted_at() > 0) !== $pj_submitted) { @@ -894,7 +892,7 @@ static function check_status(PaperStatus $ps, $pj) { if (!$ps->prow || $ps->prow->timeSubmitted <= 0) { if ($submitted_at <= 0 || $submitted_at === PaperInfo::SUBMITTED_AT_FOR_WITHDRAWN) { - $submitted_at = $Now; + $submitted_at = Conf::$now; } $ps->save_paperf("timeSubmitted", $submitted_at); $ps->mark_diff("status"); @@ -912,10 +910,9 @@ static function check_status(PaperStatus $ps, $pj) { } static function check_final_status(PaperStatus $ps, $pj) { - global $Now; if (isset($pj->final_submitted)) { if ($pj->final_submitted) { - $time = get($pj, "final_submitted_at") ? : $Now; + $time = get($pj, "final_submitted_at") ? : Conf::$now; } else { $time = 0; } @@ -1371,7 +1368,6 @@ static function postexecute_check_required_options(PaperStatus $ps) { } function execute_save() { - global $Now; $dataOverflow = $this->prow ? $this->prow->dataOverflow : null; if (!empty($this->_paper_overflow_upd)) { $dataOverflow = $dataOverflow ?? []; @@ -1436,7 +1432,7 @@ function execute_save() { } } - $this->save_paperf("timeModified", $Now); + $this->save_paperf("timeModified", Conf::$now); if (!$need_insert) { $qv = array_values($this->_paper_upd); diff --git a/src/papertable.php b/src/papertable.php index 1f47f1b6f..8f8592016 100644 --- a/src/papertable.php +++ b/src/papertable.php @@ -2014,11 +2014,10 @@ private function papstripWatch() { // Functions for editing function deadline_setting_is($dname, $dl = "deadline") { - global $Now; $deadline = $this->conf->printableTimeSetting($dname, "span"); if ($deadline === "N/A") { return ""; - } else if ($Now < $this->conf->setting($dname)) { + } else if (Conf::$now < $this->conf->setting($dname)) { return " The $dl is $deadline."; } else { return " The $dl was $deadline."; @@ -2041,11 +2040,10 @@ private function _forceShow_message() { } private function _edit_message_new_paper() { - global $Now; $msg = ""; if (!$this->conf->timeStartPaper()) { $sub_open = $this->conf->setting("sub_open"); - if ($sub_open <= 0 || $sub_open > $Now) { + if ($sub_open <= 0 || $sub_open > Conf::$now) { $msg = "The site is not open for submissions." . $this->_deadline_override_message(); } else { $msg = 'The deadline for registering submissions has passed.' . $this->deadline_setting_is("sub_reg") . $this->_deadline_override_message(); @@ -2382,13 +2380,13 @@ private function _paptabBeginKnown() { } static private function _echo_clickthrough($ctype) { - global $Conf, $Now; + global $Conf; $data = $Conf->_i("clickthrough_$ctype"); $buttons = [Ht::submit("Agree", ["class" => "btnbig btn-success ui js-clickthrough"])]; echo Ht::form("", ["class" => "ui"]), '
', $data, Ht::hidden("clickthrough_type", $ctype), Ht::hidden("clickthrough_id", sha1($data)), - Ht::hidden("clickthrough_time", $Now), + Ht::hidden("clickthrough_time", Conf::$now), Ht::actions($buttons, ["class" => "aab aabig aabr"]), "
"; } diff --git a/src/partials/p_signin.php b/src/partials/p_signin.php index cc5156d1d..fd68fe4a2 100644 --- a/src/partials/p_signin.php +++ b/src/partials/p_signin.php @@ -96,10 +96,9 @@ static function render_signin_head(Contact $user, Qrequest $qreq, $gx) { } static function render_signin_form(Contact $user, Qrequest $qreq, $gx) { - global $Now; $conf = $user->conf; if (($password_reset = $user->session("password_reset"))) { - if ($password_reset->time < $Now - 900) { + if ($password_reset->time < Conf::$now - 900) { $user->save_session("password_reset", null); } else if (!isset($qreq->email)) { $qreq->email = $password_reset->email; @@ -383,7 +382,6 @@ function render_forgot_form_actions() { // Password reset function reset_request(Contact $user, Qrequest $qreq) { - global $Now; ensure_session(); $conf = $user->conf; if ($qreq->cancel) { @@ -456,7 +454,9 @@ function reset_request(Contact $user, Qrequest $qreq) { $conf->msg("Password changed. Use the new password to sign in below.", "xconfirm"); $this->_reset_capdata->delete(); $user->save_session("password_reset", (object) [ - "time" => $Now, "email" => $this->_reset_user->email, "password" => $p1 + "time" => Conf::$now, + "email" => $this->_reset_user->email, + "password" => $p1 ]); Navigation::redirect($conf->hoturl("signin")); } diff --git a/src/review.php b/src/review.php index 4fd0683d3..1292cff9b 100644 --- a/src/review.php +++ b/src/review.php @@ -794,14 +794,13 @@ static function update_review_author_seen() { static private function check_review_author_seen($prow, $rrow, $contact, $no_update = false) { - global $Now; if ($rrow && !$rrow->reviewAuthorSeen && $contact->act_author_view($prow) && !$contact->is_actas_user()) { // XXX combination of review tokens & authorship gets weird assert($rrow->reviewAuthorModified > 0); - $rrow->reviewAuthorSeen = $Now; + $rrow->reviewAuthorSeen = Conf::$now; if (!$no_update) { if (!self::$review_author_seen) { register_shutdown_function("ReviewForm::update_review_author_seen"); diff --git a/src/reviewinfo.php b/src/reviewinfo.php index 34c96f1ce..a76b9d038 100644 --- a/src/reviewinfo.php +++ b/src/reviewinfo.php @@ -446,13 +446,12 @@ private function _save_data() { } function acceptor() { - global $Now; if ($this->_data === null) { $this->_load_data(); } if (!isset($this->_data->acceptor)) { $text = base48_encode(random_bytes(10)); - $this->_data->acceptor = (object) ["text" => $text, "at" => $Now]; + $this->_data->acceptor = (object) ["text" => $text, "at" => Conf::$now]; $this->_save_data(); } return $this->_data->acceptor; diff --git a/src/sessionlist.php b/src/sessionlist.php index 9cf0c49bc..15a437423 100644 --- a/src/sessionlist.php +++ b/src/sessionlist.php @@ -318,9 +318,8 @@ static function load_cookie(Contact $user, $type) { } function set_cookie(Contact $user) { - global $Now; $t = round(microtime(true) * 1000); - $user->conf->set_cookie("hotlist-info-" . $t, $this->info_string(), $Now + 20); + $user->conf->set_cookie("hotlist-info-" . $t, $this->info_string(), Conf::$now + 20); } /** @param int $id */ diff --git a/src/settings/s_decisionvisibility.php b/src/settings/s_decisionvisibility.php index ea56cf146..bd91e3f56 100644 --- a/src/settings/s_decisionvisibility.php +++ b/src/settings/s_decisionvisibility.php @@ -20,8 +20,6 @@ static function render(SettingValues $sv) { } static function crosscheck(SettingValues $sv) { - global $Now; - if ($sv->has_interest("seedec") && $sv->newv("seedec") == Conf::SEEDEC_ALL && $sv->newv("au_seerev") == Conf::AUSEEREV_NO) { @@ -30,7 +28,7 @@ static function crosscheck(SettingValues $sv) { if (($sv->has_interest("seedec") || $sv->has_interest("sub_sub")) && $sv->newv("sub_open") - && $sv->newv("sub_sub") > $Now + && $sv->newv("sub_sub") > Conf::$now && $sv->newv("seedec") != Conf::SEEDEC_ALL && $sv->conf->fetch_value("select paperId from Paper where outcome<0 limit 1") > 0) { $sv->warning_at(null, "Updates will not be allowed for rejected submissions. This exposes decision information that would otherwise be hidden from authors."); diff --git a/src/settings/s_finalversions.php b/src/settings/s_finalversions.php index b9d4ead92..180b49bf3 100644 --- a/src/settings/s_finalversions.php +++ b/src/settings/s_finalversions.php @@ -20,11 +20,10 @@ static function render(SettingValues $sv) { } static function crosscheck(SettingValues $sv) { - global $Now; if ($sv->has_interest("final_open") && $sv->newv("final_open") && ($sv->newv("final_soft") || $sv->newv("final_done")) - && (!$sv->newv("final_done") || $sv->newv("final_done") > $Now) + && (!$sv->newv("final_done") || $sv->newv("final_done") > Conf::$now) && $sv->newv("seedec") != Conf::SEEDEC_ALL) { $sv->warning_at(null, "The system is set to collect final versions, but authors cannot submit final versions until they can see decisions. You may want to update the " . $sv->setting_link("“Who can see decisions” setting", "seedec") . "."); } diff --git a/src/settings/s_reviewform.php b/src/settings/s_reviewform.php index 50f43d1a6..28cefc869 100644 --- a/src/settings/s_reviewform.php +++ b/src/settings/s_reviewform.php @@ -295,7 +295,6 @@ private function clear_nonexisting_options($fields, Conf $conf) { } function save(SettingValues $sv, Si $si) { - global $Now; if (!$sv->update("review_form", json_encode_db($this->nrfj))) { return; } @@ -363,7 +362,7 @@ function save(SettingValues $sv, Si $si) { } $max_ordinal = $sv->conf->fetch_ivalue("select coalesce(max(reviewOrdinal), 0) from PaperReview where paperId=? group by paperId", $rrow->paperId); if ($max_ordinal !== null) { - $sv->conf->qe("update PaperReview set reviewOrdinal=?, timeDisplayed=? where paperId=? and reviewId=?", $max_ordinal + 1, $Now, $rrow->paperId, $rrow->reviewId); + $sv->conf->qe("update PaperReview set reviewOrdinal=?, timeDisplayed=? where paperId=? and reviewId=?", $max_ordinal + 1, Conf::$now, $rrow->paperId, $rrow->reviewId); } } } diff --git a/src/settings/s_reviews.php b/src/settings/s_reviews.php index 3172f255b..0a0d321d6 100644 --- a/src/settings/s_reviews.php +++ b/src/settings/s_reviews.php @@ -266,13 +266,12 @@ static function render_ratings(SettingValues $sv) { } static function crosscheck(SettingValues $sv) { - global $Now; $errored = false; foreach ($sv->conf->round_list() as $i => $rname) { $suf = $i ? "_$i" : ""; foreach (Conf::$review_deadlines as $deadline) { if ($sv->has_interest($deadline . $suf) - && $sv->newv($deadline . $suf) > $Now + && $sv->newv($deadline . $suf) > Conf::$now && $sv->newv("rev_open") <= 0 && !$errored) { $sv->warning_at("rev_open", "A review deadline is set in the future, but the site is not open for reviewing. This is sometimes unintentional."); @@ -286,7 +285,7 @@ static function crosscheck(SettingValues $sv) { && $sv->newv("au_seerev") != Conf::AUSEEREV_NO && $sv->newv("au_seerev") != Conf::AUSEEREV_TAGS && $sv->newv("pcrev_soft") > 0 - && $Now < $sv->newv("pcrev_soft") + && Conf::$now < $sv->newv("pcrev_soft") && !$sv->has_error()) { $sv->warning_at(null, "Authors can see reviews and comments although it is before the review deadline. This is sometimes unintentional."); } diff --git a/src/settings/s_subform.php b/src/settings/s_subform.php index 6e37bc64a..95f61f8be 100644 --- a/src/settings/s_subform.php +++ b/src/settings/s_subform.php @@ -68,7 +68,6 @@ static private function check_banal($sv) { } } static function parse($suffix, $sv, $check) { - global $Now; if (!$sv->has_reqv("sub_banal$suffix")) { $fs = new FormatSpec($sv->newv("sub_banal_opt$suffix")); $sv->save("sub_banal$suffix", $fs->is_banal_empty() ? 0 : -1); @@ -208,7 +207,7 @@ static function parse($suffix, $sv, $check) { $unparse = ""; $sv->save("sub_banal_data$suffix", $unparse); if ($old_unparse !== $unparse || $sv->oldv("sub_banal$suffix") <= 0) { - $sv->save("sub_banal$suffix", $unparse !== "" ? $Now : 0); + $sv->save("sub_banal$suffix", $unparse !== "" ? Conf::$now : 0); } else { $sv->save("sub_banal$suffix", $unparse === "" ? 0 : $sv->oldv("sub_banal$suffix")); } diff --git a/src/settings/s_submissions.php b/src/settings/s_submissions.php index 74826a62f..ba8686f93 100644 --- a/src/settings/s_submissions.php +++ b/src/settings/s_submissions.php @@ -46,13 +46,12 @@ static function crosscheck(SettingValues $sv) { class Submissions_SettingParser extends SettingParser { function validate(SettingValues $sv, Si $si) { - global $Now; $d1 = $sv->newv($si->name); if ($si->name === "sub_open") { if ($d1 <= 0 && $sv->oldv("sub_open") > 0 && $sv->newv("sub_sub") <= 0) { - $sv->save("sub_close", $Now); + $sv->save("sub_close", Conf::$now); } } else if ($si->name === "sub_sub") { $sv->check_date_before("sub_reg", "sub_sub", true); diff --git a/src/settingvalues.php b/src/settingvalues.php index f8d7d6b78..4f748f33b 100644 --- a/src/settingvalues.php +++ b/src/settingvalues.php @@ -1204,8 +1204,6 @@ function setting_link($html, $si, $js = null) { function parse_value(Si $si) { - global $Now; - $v = $this->reqv($si->name); if ($v === null) { if (in_array($si->type, ["cdate", "checkbox"])) @@ -1350,8 +1348,6 @@ private function account(Si $si1) { } function execute() { - global $Now; - // parse and validate settings foreach (Si::si_map($this->conf) as $si) { $this->account($si); diff --git a/src/userstatus.php b/src/userstatus.php index 2b255c003..fae9042ab 100644 --- a/src/userstatus.php +++ b/src/userstatus.php @@ -679,7 +679,6 @@ private function maybe_assign($user, $cj, $cu, $fields, $userval = true) { /** @param object $cj * @param ?Contact $old_user */ function save($cj, $old_user = null) { - global $Now; assert(is_object($cj)); assert(!$old_user || (!$this->no_create && !$this->no_modify)); $msgcount = $this->message_count(); @@ -865,7 +864,7 @@ function save($cj, $old_user = null) { // Changes to the above fields also change the updateTime // (changes to the below fields do not). if (!empty($cu->qv)) { - $user->save_assign_field("updateTime", $Now, $cu); + $user->save_assign_field("updateTime", Conf::$now, $cu); } // Follow diff --git a/test/setup.php b/test/setup.php index d4496d50b..b8fddff10 100644 --- a/test/setup.php +++ b/test/setup.php @@ -545,4 +545,3 @@ function xassert_paper_status(PaperStatus $ps) { } MailChecker::clear(); -echo "* Tests initialized.\n"; diff --git a/test/test01.php b/test/test01.php index 480be3991..0c2c4163d 100644 --- a/test/test01.php +++ b/test/test01.php @@ -6,8 +6,8 @@ $Conf->check_invariants(); $Conf->save_setting("sub_open", 1); -$Conf->save_setting("sub_update", $Now + 10); -$Conf->save_setting("sub_sub", $Now + 10); +$Conf->save_setting("sub_update", Conf::$now + 10); +$Conf->save_setting("sub_sub", Conf::$now + 10); // load users $user_chair = $Conf->checked_user_by_email("chair@_.com"); @@ -128,8 +128,8 @@ function check_paper1($paper1) { xassert_eq($Conf->setting("paperacc", 0), 0); // change submission date -$Conf->save_setting("sub_update", $Now - 5); -$Conf->save_setting("sub_sub", $Now - 5); +$Conf->save_setting("sub_update", Conf::$now - 5); +$Conf->save_setting("sub_sub", Conf::$now - 5); xassert($user_chair->can_update_paper($paper1)); xassert(!$user_chair->call_with_overrides(Contact::OVERRIDE_CHECK_TIME, "can_update_paper", $paper1)); xassert(!$user_estrin->can_update_paper($paper1)); @@ -816,8 +816,8 @@ function sorted_conflicts(PaperInfo $prow, $contacts) { xassert_eqq(sorted_conflicts($paper3, false), "mgbaker@cs.stanford.edu sclin@leland.stanford.edu"); $user_sclin = $Conf->checked_user_by_email("sclin@leland.stanford.edu"); -$Conf->save_setting("sub_update", $Now + 10); -$Conf->save_setting("sub_sub", $Now + 10); +$Conf->save_setting("sub_update", Conf::$now + 10); +$Conf->save_setting("sub_sub", Conf::$now + 10); xassert($user_sclin->can_update_paper($paper3)); xassert_assign($user_sclin, "paper,action,user\n3,conflict,rguerin@ibm.com\n"); $paper3 = $user_chair->checked_paper_by_id(3); @@ -869,8 +869,8 @@ function sorted_conflicts(PaperInfo $prow, $contacts) { $paper3->load_conflicts(false); xassert_eqq($paper3->conflict_type($user_rguerin), 4); -$Conf->save_setting("sub_update", $Now - 5); -$Conf->save_setting("sub_sub", $Now - 5); +$Conf->save_setting("sub_update", Conf::$now - 5); +$Conf->save_setting("sub_sub", Conf::$now - 5); xassert_assign_fail($user_sclin, "paper,action,user\n3,clearconflict,rguerin@ibm.com\n"); $paper3 = $user_chair->checked_paper_by_id(3); xassert_eqq(sorted_conflicts($paper3, false), "mgbaker@cs.stanford.edu rguerin@ibm.com sclin@leland.stanford.edu"); @@ -1126,7 +1126,7 @@ function sorted_conflicts(PaperInfo $prow, $contacts) { xassert(!$user_author2->can_view_review($paper2, $review2b)); $Conf->save_setting("resp_active", 1); $Conf->save_setting("resp_open", 1); -$Conf->save_setting("resp_done", $Now + 100); +$Conf->save_setting("resp_done", Conf::$now + 100); xassert($user_author2->can_view_review($paper2, $review2b)); $Conf->save_setting("au_seerev", Conf::AUSEEREV_NO); xassert($user_author2->can_view_review($paper2, $review2b)); @@ -1190,7 +1190,7 @@ function sorted_conflicts(PaperInfo $prow, $contacts) { xassert($paper16->timeWithdrawn > 0); xassert_eqq($paper16->withdrawReason, "Sucky"); xassert_assign_fail($user_mogul, "paper,action,reason\n16,revive,Sucky\n"); -$Conf->save_setting("sub_sub", $Now + 5); +$Conf->save_setting("sub_sub", Conf::$now + 5); xassert_assign($user_mogul, "paper,action,reason\n16,revive,Sucky\n"); $paper16 = $user_mogul->checked_paper_by_id(16); xassert($paper16->timeSubmitted > 0); diff --git a/test/test02.php b/test/test02.php index fde38df6b..760a455e9 100644 --- a/test/test02.php +++ b/test/test02.php @@ -11,8 +11,7 @@ "bucket" => null, "fixed_time" => gmmktime(0, 0, 0, 5, 24, 2013) ]); -global $Now; -$Now = gmmktime(0, 0, 0, 5, 24, 2013); +Conf::set_current_time(gmmktime(0, 0, 0, 5, 24, 2013)); $sig = $s3d->signature("GET", "https://examplebucket.s3.amazonaws.com/test.txt", diff --git a/test/test04.php b/test/test04.php index f9d087d95..5a2356c48 100644 --- a/test/test04.php +++ b/test/test04.php @@ -19,10 +19,10 @@ function password($email, $iscdb = false) { } function save_password($email, $encoded_password, $iscdb = false) { - global $Conf, $Now; + global $Conf; $dblink = $iscdb ? $Conf->contactdb() : $Conf->dblink; - Dbl::qe($dblink, "update ContactInfo set password=?, passwordTime=?, passwordUseTime=? where email=?", $encoded_password, $Now + 1, $Now + 1, $email); - $Now += 2; + Dbl::qe($dblink, "update ContactInfo set password=?, passwordTime=?, passwordUseTime=? where email=?", $encoded_password, Conf::$now + 1, Conf::$now + 1, $email); + Conf::advance_current_time(Conf::$now + 2); } if (!$Conf->contactdb()) { @@ -68,9 +68,9 @@ function save_password($email, $encoded_password, $iscdb = false) { xassert(user($marina)->check_password("ncurses")); // logging in with global password makes local password obsolete -$Now += 3; +Conf::advance_current_time(Conf::$now + 3); xassert(user($marina)->check_password("isdevitch")); -$Now += 3; +Conf::advance_current_time(Conf::$now + 3); xassert(!user($marina)->check_password("ncurses")); // null contactdb password => password is unset diff --git a/test/test05.php b/test/test05.php index 12ddd3625..ccff629fd 100644 --- a/test/test05.php +++ b/test/test05.php @@ -4,8 +4,8 @@ require_once(preg_replace('/\/test\/[^\/]+/', '/test/setup.php', __FILE__)); $Conf->save_setting("sub_open", 1); -$Conf->save_setting("sub_update", $Now + 100); -$Conf->save_setting("sub_sub", $Now + 100); +$Conf->save_setting("sub_update", Conf::$now + 100); +$Conf->save_setting("sub_sub", Conf::$now + 100); $Conf->save_setting("opt.contentHashMethod", 1, "sha1"); // load users