private function db_load() { $this->repoid = (int) $this->repoid; $this->open = (int) $this->open; $this->opencheckat = (int) $this->opencheckat; if ($this->snapat !== null) { $this->snapat = (int) $this->snapat; } $this->snapcheckat = (int) $this->snapcheckat; $this->lastpset = (int) $this->lastpset; $this->working = (int) $this->working; $this->snapcommitat = (int) $this->snapcommitat; $this->analyzedsnapat = (int) $this->analyzedsnapat; if ($this->notes !== null) { $this->notes = json_decode($this->notes, true); } $this->reposite = RepositorySite::make($this->url, $this->conf); }
function validate_working(MessageSet $ms = null) { $status = RepositorySite::run_ls_remote($this->ssh_url(), $output); $answer = join("\n", $output); if ($status == 0 && $ms) { $ms->set_error_html("working", Messages::$main->expand_html("repo_unreadable", $this->message_defs($ms->user))); } if ($status > 0 && !preg_match(',^[0-9a-f]{40}\\s+refs/heads/master,m', $answer)) { if ($ms) { $ms->set_error_html("working", Messages::$main->expand_html("repo_nomaster", $this->message_defs($ms->user))); } $status = 0; } return $status; }
function render_pset_row(Pset $pset, $students, Contact $s, $row, $pcmembers, $anonymous) { global $Conf, $Me, $Now, $Profile; $row->sortprefix = ""; $ncol = 0; $t0 = $Profile ? microtime(true) : 0; $j = []; $j["username"] = $s->github_username ?: $s->seascode_username ?: ($s->email ?: $s->huid); if ($anonymous) { $j["anon_username"] = $s->anon_username; } $j["sorter"] = $s->sorter; ++$ncol; $j["name"] = Text::name_text($s); if ($s->extension) { $j["x"] = true; } if (!$anonymous) { ++$ncol; } if ($s->gradercid) { $j["gradercid"] = $s->gradercid; } ++$ncol; // are any commits committed? if (!$pset->gitless_grades) { if (($s->placeholder || $s->gradehash === null) && $s->repoid && ($s->placeholder_at < $Now - 3600 && rand(0, 2) == 0 || $s->placeholder_at < $Now - 600 && rand(0, 10) == 0) && (!$s->repoviewable || !$s->gradehash)) { // XXX this is slow given that most info is already loaded $info = ContactView::user_pset_info($s, $pset); $info->set_commit(null); $s->gradehash = $info->commit_hash() ?: null; $s->placeholder = 1; Dbl::qe("insert into RepositoryGrade (repoid, pset, gradehash, placeholder, placeholder_at) values (?, ?, ?, 1, ?) on duplicate key update gradehash=(if(placeholder=1,values(gradehash),gradehash)), placeholder_at=values(placeholder_at)", $s->repoid, $pset->id, $s->gradehash, $Now); if (!$s->repoviewable) { $s->repoviewable = $s->can_view_repo_contents($info->repo); } } if (!$s->gradehash || $s->dropped) { $row->sortprefix = "~1 "; } } if (count($pset->grades)) { $gi = null; if ($pset->gitless_grades) { $gi = $pset->contact_grade_for($s); } else { if ($s->gradehash && !$s->placeholder) { $gi = $pset->commit_notes($s->gradehash); } } $gi = $gi ? $gi->notes : null; if (!$pset->gitless_grades) { if ($gi && get($gi, "linenotes")) { $j["has_notes"] = true; } else { if ($Me->contactId == $s->gradercid) { $s->incomplete = true; } } if ($gi && $s->gradercid != get($gi, "gradercid") && $Me->privChair) { $j["has_nongrader_notes"] = true; } ++$ncol; } $garr = render_grades($pset, $gi, $s); $ncol += count($garr->all); $j["grades"] = $garr->allv; $j["total"] = $garr->totalv; if ($garr->differentk) { $j["highlight_grades"] = $garr->differentk; } } //echo "<td><a href=\"mailto:", htmlspecialchars($s->email), "\">", //htmlspecialchars($s->email), "</a></td>"; if (!$pset->gitless && $s->url) { $j["repo"] = RepositorySite::make_web_url($s->url, $Conf); if (!$s->working) { $j["repo_broken"] = true; } else { if (!$s->repoviewable) { $j["repo_unconfirmed"] = true; } } if ($s->open) { $j["repo_too_open"] = true; } if ($s->pcid != $s->rpcid || $s->pcid && (!isset($students[$s->pcid]) || $students[$s->pcid]->repoid != $s->repoid)) { $j["repo_partner_error"] = true; } } ++$ncol; if (!get($row, "ncol") || $ncol > $row->ncol) { $row->ncol = $ncol; } $s->visited = true; return $j; }
static function set_repo_action($user) { global $Conf, $Me, $ConfSitePATH; if (!($Me->has_database_account() && check_post() && ($pset = $Conf->pset_by_key(req("pset"))))) { return; } if (!$Me->can_set_repo($pset, $user)) { return Conf::msg_error("You can’t edit repository information for that problem set now."); } // clean up repo url $repo_url = trim(req("repo")); if ($pset->repo_guess_patterns) { for ($i = 0; $i + 1 < count($pset->repo_guess_patterns); $i += 2) { $x = preg_replace('`' . str_replace("`", "\\`", $pset->repo_guess_patterns[$i]) . '`s', $pset->repo_guess_patterns[$i + 1], $repo_url, -1, $nreplace); if ($x !== null && $nreplace) { $repo_url = $x; break; } } } // does it contain odd characters? if (preg_match('_[,;\\[\\](){}\\<>&#=\\000-\\027]_', $repo_url)) { return Conf::msg_error("That repository contains funny characters. Remove them."); } // record interested repositories $try_classes = []; foreach (RepositorySite::site_classes($user->conf) as $sitek) { $sniff = $sitek::sniff_url($repo_url); if ($sniff == 2) { $try_classes = [$sitek]; break; } else { if ($sniff) { $try_classes[] = $sitek; } } } if (empty($try_classes)) { return Conf::msg_error("Invalid repository URL “" . htmlspecialchars($repo_url) . "”."); } // check repositories $working = false; $ms = new MessageSet($user); foreach ($try_classes as $sitek) { $reposite = $sitek::make_url($repo_url, $user->conf); if ($reposite && $reposite->validate_working($ms) > 0) { $working = true; break; } } // if !working, complain if (!$working && !$ms->has_problems()) { return Conf::msg_error("Invalid repository URL “" . htmlspecialchars($repo_url) . "” (tried " . join(", ", array_map(function ($m) { return $m::global_friendly_siteclass(); }, $try_classes)) . ")."); } else { if (!$working) { $msgs = join("<br />", $ms->messages()) ?: "Repository unreachable at the moment."; return Conf::msg_error($msgs); } } // store repo $repo = Repository::find_or_create_url($reposite->url, $user->conf); $repo && $repo->check_open(); if ($user->set_repo($pset, $repo)) { redirectSelf(); } }