Skip to content
Permalink
Browse files

Use new CSV interface for assignments.

  • Loading branch information...
kohler committed May 30, 2019
1 parent da4979d commit 3209b22e4e0bfbf58f494b85b1be85b6314b2c81
@@ -19,7 +19,7 @@ function load($file = null) {
if (($s = file_get_contents($file)) === false)
return false;
$csv = new CsvParser($s);
while (($x = $csv->next())) {
while (($x = $csv->next_array())) {
list($name, $type, $count) = $x;
if ((string) $type === "")
continue;
@@ -104,7 +104,7 @@ function setTagIndexes($qreq) {
$tag = $tagger->check(trim(substr($l, ($l[0] == "#" ? 6 : 4))), Tagger::NOVALUE);
} else if (trim($l) !== "" && $l[0] !== "#") {
$csvp->unshift($l);
$line = $csvp->next();
$line = $csvp->next_array();
if ($line && check_tag_index_line($line)) {
if (isset($settings[$line[1]]))
$errors[$lineno] = "Paper #$line[1] already given on line " . $linenos[$line[1]];
@@ -140,14 +140,10 @@ function parseUploadedPreferences($text, $filename, $apply) {
$text = preg_replace('/^==-== /m', '#', $text);
$csv = new CsvParser($text, CsvParser::TYPE_GUESS);
$csv->set_comment_chars("#");
$line = $csv->next();
// “CSV” downloads use “ID” and “Preference” columns; adjust header
if ($line && array_search("paper", $line) === false)
$line = array_map(function ($x) { return $x === "ID" ? "paper" : $x; }, $line);
if ($line && array_search("preference", $line) === false)
$line = array_map(function ($x) { return $x === "Preference" ? "preference" : $x; }, $line);
$line = $csv->next_array();
// Parse header
if ($line && array_search("paper", $line) !== false)
if ($line && preg_grep('{\A(?:paper|pid|paper[\s_]*id|id)\z}i', $line))
$csv->set_header($line);
else {
if (count($line) >= 2 && ctype_digit($line[0])) {
@@ -50,7 +50,9 @@ function apply(PaperInfo $prow, Contact $contact, &$req, AssignmentState $state)
$ct = CONFLICT_CONTACTAUTHOR;
else {
$ct = 1000;
$cts = get($req, "conflicttype", get($req, "conflict"));
$cts = $req["conflicttype"];
if (!isset($cts))
$cts = $req["conflict"];
if ($cts !== null && ($ct = Conflict::parse($cts, 1000)) === false)
return "Bad conflict type.";
if ($ct !== 1000)
@@ -80,9 +80,7 @@ static function parse($str) {
}
}
function apply(PaperInfo $prow, Contact $contact, &$req, AssignmentState $state) {
foreach (array("preference", "pref", "revpref") as $k)
if (($pref = get($req, $k)) !== null)
break;
$pref = $req["preference"];
if ($pref === null)
return "Missing preference.";
$ppref = self::parse($pref);
@@ -98,9 +96,7 @@ function apply(PaperInfo $prow, Contact $contact, &$req, AssignmentState $state)
if ($prow->timeWithdrawn > 0)
$state->warning($prow->make_whynot(["withdrawn" => 1]));
foreach (array("expertise", "revexp") as $k)
if (($exp = get($req, $k)) !== null)
break;
$exp = $req["expertise"];
if ($exp && ($exp = trim($exp)) !== "") {
if (($pexp = self::parse($exp)) === null || $pexp[0])
return "Invalid expertise “" . htmlspecialchars($exp) . "”.";
@@ -76,8 +76,10 @@ function apply(PaperInfo $prow, Contact $contact, &$req, AssignmentState $state)
$state->finishers[] = new Withdraw_AssignmentFinisher($prow->paperId);
}
}
$r = (string) get($req, "withdraw_reason", get($req, "reason", null));
if ($r !== "")
$r = $req["withdraw_reason"];
if ($r === null)
$r = $req["reason"];
if ((string) $r !== "")
$res["_withdraw_reason"] = $r;
} else if ($this->xtype === "revive") {
if ($res["_withdrawn"] !== 0) {
@@ -86,7 +86,7 @@ private function cannot_view_error(PaperInfo $prow, $tag, AssignmentState $state
}
function apply(PaperInfo $prow, Contact $contact, &$req, AssignmentState $state) {
// tag argument (can have multiple space-separated tags)
if (($tag = trim(get($req, "tag", ""))) === "")
if (($tag = trim((string) $req["tag"])) === "")
return "Tag missing.";
$tags = preg_split('/\s+/', $tag);
while (count($tags) > 1) {
@@ -96,9 +96,9 @@ function apply(PaperInfo $prow, Contact $contact, &$req, AssignmentState $state)
$tag = $tags[0];
// index argument
$xindex = get($req, "value");
$xindex = $req["value"];
if ($xindex === null)
$xindex = get($req, "index");
$xindex = $req["index"];
if ($xindex !== null
&& ($xindex = trim($xindex)) !== "") {
$tag = preg_replace(',\A([-+]?#?.+)(?:[=!<>]=?|#|≠|≤|≥)(?:|-?\d+(?:\.\d*)?|-?\.\d+|any|all|none|clear)\z,i', '$1', $tag);
@@ -351,7 +351,7 @@ function user_by_email($email, $create = false, $req = null) {
assert(validate_email($email) || preg_match('/\Aanonymous\d*\z/', $email));
$cargs = ["contactId" => self::$next_fake_id, "roles" => 0, "email" => $email];
foreach (["firstName", "lastName", "affiliation"] as $k)
if ($req && get($req, $k))
if ($req && $req[$k])
$cargs[$k] = $req[$k];
if (preg_match('/\Aanonymous\d*\z/', $email)) {
$cargs["firstName"] = "Jane Q.";
@@ -598,7 +598,7 @@ class ReviewAssigner_Data {
public $creator = true;
public $error = false;
static function separate($key, $req, $state, $rtype) {
$a0 = $a1 = trim(get_s($req, $key));
$a0 = $a1 = trim((string) $req[$key]);
$require_match = $rtype ? false : $a0 !== "";
if ($a0 === "" && $rtype != 0)
$a0 = $a1 = get($state->defaults, $key);
@@ -638,7 +638,7 @@ function __construct($req, AssignmentState $state, $rtype) {
&& ($this->newround = $state->conf->sanitize_round_name($rarg1)) === false)
$this->error = Conf::round_name_error($rarg1);
if ($rarg0 !== "" && $rarg1 !== null)
$this->explicitround = (string) get($req, "round") !== "";
$this->explicitround = (string) $req["round"] !== "";
if ($rarg0 === "")
$rmatch = false;
if ($this->oldtype === null && $rtype > 0 && $rmatch)
@@ -928,12 +928,12 @@ function allow_contact(PaperInfo $prow, Contact $contact, &$req, AssignmentState
}
function apply(PaperInfo $prow, Contact $contact, &$req, AssignmentState $state) {
// parse round and reviewtype arguments
$rarg0 = trim(get_s($req, "round"));
$rarg0 = trim((string) $req["round"]);
$oldround = null;
if ($rarg0 !== "" && strcasecmp($rarg0, "any") != 0
&& ($oldround = $state->conf->sanitize_round_name($rarg0)) === false)
return Conf::round_name_error($rarg0);
$targ0 = trim(get_s($req, "reviewtype"));
$targ0 = trim((string) $req["reviewtype"]);
$oldtype = null;
if ($targ0 !== ""
&& ($oldtype = ReviewInfo::parse_type($targ0)) === false)
@@ -1109,7 +1109,7 @@ function json_result($linenos = false) {
}
private static function req_user_html($req) {
return Text::user_html_nolink(get($req, "firstName"), get($req, "lastName"), get($req, "email"));
return Text::user_html_nolink($req["firstName"], $req["lastName"], $req["email"]);
}
private function set_my_conflicts() {
@@ -1122,7 +1122,7 @@ private function set_my_conflicts() {
private static function apply_user_parts(&$req, $a) {
foreach (array("firstName", "lastName", "email") as $i => $k)
if (!get($req, $k) && get($a, $i))
if (!$req[$k] && get($a, $i))
$req[$k] = $a[$i];
}
@@ -1131,15 +1131,15 @@ private function lookup_users(&$req, $assigner) {
if (isset($req["name"]))
self::apply_user_parts($req, Text::split_name($req["name"]));
if (isset($req["user"]) && strpos($req["user"], " ") === false) {
if (!get($req, "email"))
if (!$req["email"])
$req["email"] = $req["user"];
} else if (isset($req["user"]))
self::apply_user_parts($req, Text::split_name($req["user"], true));
// extract email, first, last
$first = get($req, "firstName");
$last = get($req, "lastName");
$email = trim((string) get($req, "email"));
$first = $req["firstName"];
$last = $req["lastName"];
$email = trim((string) $req["email"]);
$lemail = strtolower($email);
$special = null;
if ($lemail)
@@ -1215,7 +1215,7 @@ private function lookup_users(&$req, $assigner) {
}
static private function is_csv_header($req) {
foreach (array("action", "assignment", "paper", "pid", "paperId") as $k)
foreach (["action", "assignment", "paper", "pid", "paperId", "ID"] as $k)
if (array_search($k, $req) !== false)
return true;
return false;
@@ -1231,48 +1231,42 @@ private function install_csv_header($csv, $req) {
$req = ["paper", "user"];
else
$req = ["paper", "action", "user", "round"];
} else {
$cleans = array("paper", "pid", "paper", "paperId",
"firstName", "first", "lastName", "last",
"firstName", "firstname", "lastName", "lastname",
"preference", "pref");
for ($i = 0; $i < count($cleans); $i += 2)
if (array_search($cleans[$i], $req) === false
&& ($j = array_search($cleans[$i + 1], $req)) !== false)
$req[$j] = $cleans[$i];
}
$has_action = array_search("action", $req) !== false
|| array_search("assignment", $req) !== false;
$csv->set_header($req);
foreach ([["action", "assignment"], ["action", "type"],
["paper", "pid"], ["paper", "paperid"], ["paper", "id"],
["firstName", "first"], ["firstName", "first_name"],
["firstName", "firstname"], ["lastName", "last"],
["lastName", "last_name"], ["lastName", "lastname"],
["lastName", "surname"],
["preference", "pref"], ["preference", "revpref"],
["expertise", "prefexp"]] as $sp)
$csv->add_synonym($sp[0], $sp[1]);
$has_action = $csv->has_column("action");
if (!$has_action && !isset($this->astate->defaults["action"])) {
$defaults = $modifications = [];
if (array_search("tag", $req) !== false)
$defaults = [];
if ($csv->has_column("tag"))
$defaults[] = "tag";
if (array_search("preference", $req) !== false)
if ($csv->has_column("preference"))
$defaults[] = "preference";
if (($j = array_search("lead", $req)) !== false) {
if ($csv->has_column("lead"))
$defaults[] = "lead";
$modifications = [$j, "user"];
}
if (($j = array_search("shepherd", $req)) !== false) {
if ($csv->has_column("shepherd"))
$defaults[] = "shepherd";
$modifications = [$j, "user"];
}
if (($j = array_search("decision", $req)) !== false) {
if ($csv->has_column("decision"))
$defaults[] = "decision";
$modifications = [$j, "decision"];
}
if (count($defaults) == 1) {
$this->astate->defaults["action"] = $defaults[0];
for ($i = 0; $i < count($modifications); $i += 2)
$req[$modifications[$i]] = $modifications[$i + 1];
if (in_array($defaults[0], ["lead", "shepherd", "manager"]))
$csv->add_synonym("user", $defaults[0]);
}
}
$csv->set_header($req);
if (!$has_action && !get($this->astate->defaults, "action"))
return $this->error_at($csv->lineno(), "“assignment” column missing");
else if (array_search("paper", $req) === false)
else if (!$csv->has_column("paper"))
return $this->error_at($csv->lineno(), "“paper” column missing");
else {
if (!isset($this->astate->defaults["action"]))
@@ -1333,9 +1327,7 @@ private function collect_papers($pfield, &$pids, $report_error) {
}
private function collect_parser($req) {
if (($action = get($req, "action")) === null
&& ($action = get($req, "assignment")) === null
&& ($action = get($req, "type")) === null)
if (($action = $req["action"]) === null)
$action = $this->astate->defaults["action"];
$action = strtolower(trim($action));
return $this->conf->assignment_parser($action, $this->user);
@@ -1363,7 +1355,7 @@ private function expand_special_user($user, AssignmentParser $aparser, PaperInfo
private function apply($aparser, $req) {
// parse paper
$pids = [];
$x = $this->collect_papers((string) get($req, "paper"), $pids, true);
$x = $this->collect_papers((string) $req["paper"], $pids, true);
if (empty($pids))
return false;
$pfield_straight = $x == 2;
@@ -1480,7 +1472,7 @@ function parse($text, $filename = null, $defaults = null, $alertf = null) {
$csv->set_comment_chars("%#");
$csv->set_comment_function(array($this, "parse_csv_comment"));
}
if (!($req = $csv->header() ? : $csv->next()))
if (!($req = $csv->header() ? : $csv->next_array()))
return $this->error_at($csv->lineno(), "empty file");
if (!$this->install_csv_header($csv, $req))
return false;
@@ -1489,9 +1481,9 @@ function parse($text, $filename = null, $defaults = null, $alertf = null) {
// parse file, load papers all at once
$lines = $pids = [];
while (($req = $csv->next()) !== false) {
while (($req = $csv->next_row()) !== false) {
$aparser = $this->collect_parser($req);
$this->collect_papers((string) get($req, "paper"), $pids, false);
$this->collect_papers((string) $req["paper"], $pids, false);
if ($aparser
&& ($pfield = $aparser->expand_papers($req, $this->astate)))
$this->collect_papers($pfield, $pids, false);

0 comments on commit 3209b22

Please sign in to comment.
You can’t perform that action at this time.