function allRecordsProcessed($projectid) { // The status field in the submission table may have the value 0, 1, 2 or 3. // 0 means queued, but not yet (or no longer) processing. // 1 means processing. // 2 means done processing, did call do_submit. // 3 means done processing, did not call do_submit. // // This function returns 1 if there are exactly 0 records in the submission // table with status=0 or 1. // // This function returns 0 if any record in the table has status=0 or 1. $c0 = pdo_get_field_value("SELECT COUNT(*) AS c FROM submission WHERE status=0 AND projectid='{$projectid}'", 'c', ''); $c1 = pdo_get_field_value("SELECT COUNT(*) AS c FROM submission WHERE status=1 AND projectid='{$projectid}'", 'c', ''); $c2 = pdo_get_field_value("SELECT COUNT(*) AS c FROM submission WHERE status=2 AND projectid='{$projectid}'", 'c', ''); $c3 = pdo_get_field_value("SELECT COUNT(*) AS c FROM submission WHERE status=3 AND projectid='{$projectid}'", 'c', ''); $c_total = pdo_get_field_value("SELECT COUNT(*) AS c FROM submission WHERE projectid='{$projectid}'", 'c', ''); echo "Counts of submission status values:\n"; echo "===================================\n"; echo " (for projectid='{$projectid}')\n"; echo "c0='{$c0}'\n"; echo "c1='{$c1}'\n"; echo "c2='{$c2}'\n"; echo "c3='{$c3}'\n"; echo "c_total='{$c_total}'\n"; if ($c0 == 0 && $c1 == 0) { return 1; } return 0; }
function Insert() { $text = pdo_real_escape_string($this->Text); // Get this->Id from the database if text is already in the label table: $this->Id = pdo_get_field_value("SELECT id FROM label WHERE text='{$text}'", 'id', 0); // Or, if necessary, insert a new row, then get the id of the inserted row: if (0 == $this->Id) { $query = "INSERT INTO label (text) VALUES ('{$text}')"; if (!pdo_query($query)) { add_last_sql_error('Label::Insert'); return false; } $this->Id = pdo_insert_id('label'); } // Insert relationship records, too, but only for those relationships // established by callers. (If coming from test.php, for example, TestId // will be set, but none of the others will. Similarly for other callers.) $this->InsertAssociation('label2build', 'buildid', $this->BuildId); $this->InsertAssociation('label2buildfailure', 'buildfailureid', $this->BuildFailureId); $this->InsertAssociation('label2coveragefile', 'buildid', $this->CoverageFileBuildId, 'coveragefileid', $this->CoverageFileId); $this->InsertAssociation('label2dynamicanalysis', 'dynamicanalysisid', $this->DynamicAnalysisId); $this->InsertAssociation('label2test', 'buildid', $this->TestBuildId, 'testid', $this->TestId); // TODO: Implement this: // //$this->InsertAssociation($this->UpdateFileKey, // 'label2updatefile', 'updatefilekey'); return true; }
function ProcessOwnsLock($projectid, $pid) { $owner_pid = pdo_get_field_value("SELECT pid FROM submissionprocessor WHERE projectid='" . $projectid . "'", 'pid', 0); return $owner_pid == $pid; }
echo "\n"; foreach ($rows as $row) { echo $row['name'] . $sep . $row['covsize'] / 1000000 . "\n"; } echo '</pre>'; echo '<br/>'; $sql = "SELECT p.name, SUM(LENGTH(da.log)) AS dasize " . "FROM project AS p, build AS b, dynamicanalysis AS da " . "WHERE p.id=b.projectid AND b.id=da.buildid " . "GROUP BY p.name"; $rows = pdo_all_rows_query($sql); echo '<pre>'; echo 'project name, dynamic analysis size' . "\n"; echo "\n"; foreach ($rows as $row) { echo $row['name'] . $sep . $row['dasize'] / 1000000 . "\n"; } echo '</pre>'; echo '<br/>'; } if ($session_OK) { $userid = $_SESSION['cdash']['loginid']; $user_is_admin = pdo_get_field_value("SELECT admin FROM " . qid("user") . " WHERE id='{$userid}'", 'admin', 0); if ($user_is_admin) { echo_currently_processing_submissions(); echo_pending_submissions(); echo_project_data_sizes(); echo_average_wait_times(); echo_submissionprocessor_table(); echo_submission_table(); } else { echo 'Admin login required to display monitoring info.'; } }
require_once "cdash/pdo.php"; echo '<?xml version="1.0" encoding="UTF-8"?>'; echo "<userid>"; if (!isset($_GET['author'])) { echo "error<no-author-param/></userid>"; return; } if (strlen($_GET['author']) == 0) { echo "error<empty-author-param/></userid>"; return; } $author = htmlspecialchars(pdo_real_escape_string($_GET['author'])); // First, try the simplest query, where the author string is simply exactly // equal to the user's email: // $userid = pdo_get_field_value("SELECT id FROM " . qid("user") . " WHERE email='{$author}'", 'id', '-1'); if ($userid !== '-1') { echo $userid . "</userid>"; return; } // If no exact email match, fall back to the more complicated project-based // repository credentials lookup: // if (!isset($_GET['project'])) { echo "error<no-project-param/></userid>"; return; } if (strlen($_GET['project']) == 0) { echo "error<empty-project-param/></userid>"; return; }
public function ProjectAllowed($projectid) { // By default, all projects are allowed: // $allowed = true; $count = pdo_get_field_value('SELECT COUNT(*) AS c FROM client_site2project ' . ' WHERE siteid=' . qnum($this->SiteId), 'c', 0); if ($count > 0) { // If some records contain siteid, only listed projects are allowed: // $projectid_count = pdo_get_field_value('SELECT COUNT(*) AS c FROM client_site2project ' . ' WHERE siteid=' . qnum($this->SiteId) . ' AND projectid=' . qnum($projectid), 'c', 0); if ($projectid_count > 0) { $allowed = true; } else { $allowed = false; } } return $allowed; }
} function echo_file_contents($filename) { // Emit the contents of the named file, but only if it exists. // If it doesn't exist, emit nothing. // if (file_exists($filename)) { $contents = file_get_contents($filename); echo '<h3>contents of "' . $filename . '"</h3>'; echo '<pre>'; echo htmlentities($contents); echo '</pre>'; echo '<br/>'; } } if ($session_OK) { $userid = $_SESSION['cdash']['loginid']; $user_is_admin = pdo_get_field_value('SELECT admin FROM ' . qid('user') . " WHERE id='{$userid}'", 'admin', 0); if ($user_is_admin) { echo_svn_output('--version'); echo_svn_output('remote -v'); echo_svn_output('status'); echo_svn_output('diff'); global $CDASH_ROOT_DIR; echo_file_contents($CDASH_ROOT_DIR . '/config/config.local.php'); echo_file_contents($CDASH_ROOT_DIR . '/tests/config.test.local.php'); echo '<br/>'; } else { echo 'Admin login required to display svn info.'; } }
function LookupIP() { $this->Ip = $_SERVER['REMOTE_ADDR']; // In the async case, look up the IP recorded when the file was // originally submitted... global $PHP_ERROR_SUBMISSION_ID; $submission_id = $PHP_ERROR_SUBMISSION_ID; if ($submission_id) { $this->Ip = pdo_get_field_value("SELECT ip FROM submission2ip WHERE submissionid=" . qnum($submission_id), 'ip', ''); } }
/** endElement function */ public function endElement($parser, $name) { parent::endElement($parser, $name); global $CDASH_DELETE_OLD_SUBPROJECTS; if (!$this->ProjectNameMatches) { return; } if ($name == 'PROJECT') { foreach ($this->SubProjects as $subproject) { if ($CDASH_DELETE_OLD_SUBPROJECTS) { // Remove dependencies that do not exist anymore, // but only for those relationships where both sides // are present in $this->SubProjects. // $dependencyids = $subproject->GetDependencies(); $removeids = array_diff($dependencyids, $this->Dependencies[$subproject->GetId()]); foreach ($removeids as $removeid) { if (array_key_exists($removeid, $this->SubProjects)) { $subproject->RemoveDependency($removeid); } else { $dep = pdo_get_field_value("SELECT name FROM subproject WHERE id='{$removeid}'", 'name', "{$removeid}"); add_log("Not removing dependency {$dep}({$removeid}) from " . $subproject->GetName() . 'because it is not a SubProject element in this Project.xml file', 'ProjectHandler:endElement', LOG_WARNING, $this->projectid); } } } // Add dependencies that were queued up as we processed the DEPENDENCY // elements: // foreach ($this->Dependencies[$subproject->GetId()] as $addid) { if (array_key_exists($addid, $this->SubProjects)) { $subproject->AddDependency($addid); } else { add_log('impossible condition: should NEVER see this: unknown DEPENDENCY clause should prevent this case', 'ProjectHandler:endElement', LOG_WARNING, $this->projectid); } } } if ($CDASH_DELETE_OLD_SUBPROJECTS) { // Delete old subprojects that weren't included in this file. $previousSubProjectIds = $this->Project->GetSubProjects(); foreach ($previousSubProjectIds as $previousId) { $found = false; foreach ($this->SubProjects as $subproject) { if ($subproject->GetId() == $previousId) { $found = true; break; } } if (!$found) { $subProjectToRemove = new SubProject(); $subProjectToRemove->SetId($previousId); $subProjectToRemove->Delete(); add_log("Deleted " . $subProjectToRemove->GetName() . " because it was not mentioned in Project.xml", 'ProjectHandler:endElement', LOG_WARNING, $this->projectid); } } } } elseif ($name == 'SUBPROJECT') { // Insert the SubProject. $this->SubProject->Save(); // Insert the label. $Label = new Label(); $Label->Text = $this->SubProject->GetName(); $Label->Insert(); $this->SubProjects[$this->SubProject->GetId()] = $this->SubProject; // Handle dependencies here too. $this->Dependencies[$this->SubProject->GetId()] = array(); foreach ($this->CurrentDependencies as $dependencyid) { $added = false; if ($dependencyid !== false && is_numeric($dependencyid)) { if (array_key_exists($dependencyid, $this->SubProjects)) { $this->Dependencies[$this->SubProject->GetId()][] = $dependencyid; $added = true; } } if (!$added) { add_log('Project.xml DEPENDENCY of ' . $this->SubProject->GetName() . ' not mentioned earlier in file.', 'ProjectHandler:endElement', LOG_WARNING, $this->projectid); } } // Check if the user is in the database. $User = new User(); $posat = strpos($this->Email, '@'); if ($posat !== false) { $User->FirstName = substr($this->Email, 0, $posat); $User->LastName = substr($this->Email, $posat + 1); } else { $User->FirstName = $this->Email; $User->LastName = $this->Email; } $User->Email = $this->Email; $User->Password = md5($this->Email); $User->Admin = 0; $userid = $User->GetIdFromEmail($this->Email); if (!$userid) { $User->Save(); $userid = $User->Id; } // Insert into the UserProject $UserProject = new UserProject(); $UserProject->EmailType = 3; // any build $UserProject->EmailCategory = 54; // everything except warnings $UserProject->UserId = $userid; $UserProject->ProjectId = $this->projectid; $UserProject->Save(); // Insert the labels for this user $LabelEmail = new LabelEmail(); $LabelEmail->UserId = $userid; $LabelEmail->ProjectId = $this->projectid; $Label = new Label(); $Label->SetText($this->SubProject->GetName()); $labelid = $Label->GetIdFromText(); if (!empty($labelid)) { $LabelEmail->LabelId = $labelid; $LabelEmail->Insert(); } } }
/** endElement function */ public function endElement($parser, $name) { parent::endElement($parser, $name); if (!$this->ProjectNameMatches) { return; } if ($name == 'PROJECT') { foreach ($this->SubProjects as $subproject) { // Remove dependencies that do not exist anymore, but only for those // relationships where both sides are present in $this->SubProjects. // $dependencyids = $subproject->GetDependencies(); $removeids = array_diff($dependencyids, $this->Dependencies[$subproject->GetId()]); foreach ($removeids as $removeid) { if (array_key_exists($removeid, $this->SubProjects)) { $subproject->RemoveDependency($removeid); } else { $dep = pdo_get_field_value("SELECT name FROM subproject WHERE id='{$removeid}'", "name", "{$removeid}"); add_log("Not removing dependency {$dep}({$removeid}) from " . $subproject->GetName() . "because it is not a SubProject element in this Project.xml file", "ProjectHandler:endElement", LOG_WARNING, $this->projectid); } } // Add dependencies that were queued up as we processed the DEPENDENCY // elements: // foreach ($this->Dependencies[$subproject->GetId()] as $addid) { if (array_key_exists($addid, $this->SubProjects)) { $subproject->AddDependency($addid); } else { add_log("impossible condition: should NEVER see this: unknown DEPENDENCY clause should prevent this case", "ProjectHandler:endElement", LOG_WARNING, $this->projectid); } } } // Delete old subprojects that weren't included in this file. $previousSubProjectIds = $this->Project->GetSubProjects(); foreach ($previousSubProjectIds as $previousId) { $found = false; foreach ($this->SubProjects as $subproject) { if ($subproject->GetId() == $previousId) { $found = true; break; } } if (!$found) { $subProjectToRemove = new SubProject(); $subProjectToRemove->SetId($previousId); $subProjectToRemove->Delete(); } } } }
} echo '<?xml version="1.0" encoding="UTF-8"?>'; echo '<userid>'; if (!isset($_GET['author'])) { echo 'error<no-author-param/></userid>'; return; } if (strlen($_GET['author']) == 0) { echo 'error<empty-author-param/></userid>'; return; } $author = htmlspecialchars(pdo_real_escape_string($_GET['author'])); // First, try the simplest query, where the author string is simply exactly // equal to the user's email: // $userid = pdo_get_field_value('SELECT id FROM ' . qid('user') . " WHERE email='{$author}'", 'id', '-1'); if ($userid !== '-1') { echo $userid . '</userid>'; return; } // If no exact email match, fall back to the more complicated project-based // repository credentials lookup: // if (!isset($_GET['project'])) { echo 'error<no-project-param/></userid>'; return; } if (strlen($_GET['project']) == 0) { echo 'error<empty-project-param/></userid>'; return; }