Skip to content

Commit

Permalink
Deprecate global $Now in favor of Conf::$now.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Jun 14, 2020
1 parent 2cd7755 commit c64a77f
Show file tree
Hide file tree
Showing 51 changed files with 205 additions and 288 deletions.
11 changes: 6 additions & 5 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
8 changes: 3 additions & 5 deletions batch/cleandocstore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand All @@ -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 {
Expand All @@ -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) {
Expand Down
11 changes: 5 additions & 6 deletions buzzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,28 @@
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;
});
$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);
}
// 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;
}
}
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions deadlines.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions doc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions lib/csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -649,15 +649,14 @@ function add_string($text) {
}

private function _flush_stream() {
global $Now;
if ($this->stream === null) {
$this->stream = false;
if (($dir = Filer::docstore_tmpdir() ?? tempdir())) {
if (!str_ends_with($dir, "/")) {
$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;
Expand Down
9 changes: 4 additions & 5 deletions lib/filer.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static function download_file($filename, $mimetype, $no_accel = false) {
}
/** @param DocumentInfo|list<DocumentInfo> $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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
Expand All @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions lib/mincostmaxflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 5 additions & 6 deletions lib/redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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 = [];
}

Expand Down Expand Up @@ -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] = "";
Expand Down
5 changes: 2 additions & 3 deletions lib/s3client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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];
Expand Down
4 changes: 1 addition & 3 deletions lib/zipdocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion manualassign.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@


function saveAssignments($qreq, $reviewer) {
global $Conf, $Me, $Now;
global $Conf, $Me;
$round_number = null;
$rcid = $reviewer->contactId;

Expand Down
6 changes: 3 additions & 3 deletions profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion review.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Loading

0 comments on commit c64a77f

Please sign in to comment.