/** * Copy table rows by assigning them a new buildid. **/ function copy_build_table($old_buildid, $new_buildid, $table) { $result = pdo_query("SELECT * FROM {$table} WHERE buildid={$old_buildid}"); while ($result_array = pdo_fetch_array($result)) { // Remove the old buildid from our SELECT results, as we will be replacing // that with the new buildid. unset($result_array['buildid']); // Generate an INSERT query by listing all of the table columns // and their values. This is slightly complicated by the fact that // our array has both string and integer keys. $keys = array(); $values = array(); foreach ($result_array as $key => $val) { if (!is_int($key)) { $keys[] = $key; $values[] = $val; } } $insert_query = "INSERT INTO {$table} (buildid,"; $insert_query .= implode(",", $keys) . ")"; $insert_query .= " VALUES ('{$new_buildid}','"; $insert_query .= implode("','", $values) . "')"; pdo_query($insert_query); } }
/** * Authenticate to the web API as a project admin * @param project the name of the project * @param key the web API key for that project */ function Authenticate() { include_once '../cdash/common.php'; if (!isset($this->Parameters['project'])) { return array('status' => false, 'message' => "You must specify a project parameter."); } $projectid = get_project_id($this->Parameters['project']); if (!is_numeric($projectid) || $projectid <= 0) { return array('status' => false, 'message' => 'Project not found.'); } if (!isset($this->Parameters['key']) || $this->Parameters['key'] == '') { return array('status' => false, 'message' => "You must specify a key parameter."); } $key = $this->Parameters['key']; $query = pdo_query("SELECT webapikey FROM project WHERE id={$projectid}"); if (pdo_num_rows($query) == 0) { return array('status' => false, 'message' => "Invalid projectid."); } $row = pdo_fetch_array($query); $realKey = $row['webapikey']; if ($key != $realKey) { return array('status' => false, 'message' => "Incorrect API key passed."); } $token = create_web_api_token($projectid); return array('status' => true, 'token' => $token); }
/** Get the number of tests that are failing */ function GetNumberOfFailures($checktesttiming, $testtimemaxstatus) { if (!$this->BuildId) { echo "BuildTest::GetNumberOfFailures(): BuildId not set"; return false; } $sql = "SELECT testfailed,testnotrun,testtimestatusfailed FROM build WHERE id=" . qnum($this->BuildId); $query = pdo_query($sql); if (!$query) { add_last_sql_error("BuildTest:GetNumberOfFailures", 0, $this->BuildId); return false; } $nfail_array = pdo_fetch_array($query); $sumerrors = 0; if ($nfail_array['testfailed'] > 0) { $sumerrors += $nfail_array['testfailed']; } if ($nfail_array['testnotrun'] > 0) { $sumerrors += $nfail_array['testnotrun']; } // Find if the build has any test failings if ($checktesttiming) { if ($nfail_array['testtimestatusfailed'] > 0) { $sumerrors += $nfail_array['testtimestatusfailed']; } } return $sumerrors; }
/** Get all the authors of a file */ public function GetAuthors($filename, $onlylast = false) { if (!$this->ProjectId) { echo 'DailyUpdate::GetAuthors(): ProjectId is not set<br>'; return false; } // Check if the note already exists $filename = pdo_real_escape_string($filename); // Remove if (substr($filename, 0, 2) == './') { $filename = substr($filename, 2); } $sql = ''; if ($onlylast) { $sql = ' ORDER BY dailyupdate.id DESC LIMIT 1'; } $query = pdo_query('SELECT DISTINCT up.userid,dailyupdate.id FROM user2project AS up,user2repository AS ur,dailyupdatefile,dailyupdate WHERE dailyupdatefile.dailyupdateid=dailyupdate.id AND dailyupdate.projectid=up.projectid AND ur.credential=dailyupdatefile.author AND up.projectid=' . qnum($this->ProjectId) . ' AND up.userid=ur.userid AND (ur.projectid=0 OR ur.projectid=' . qnum($this->ProjectId) . ")\n AND dailyupdatefile.filename LIKE '%" . $filename . "'" . $sql); if (!$query) { add_last_sql_error('DailyUpdate GetAuthors', $this->ProjectId); return false; } $authorids = array(); while ($query_array = pdo_fetch_array($query)) { $authorids[] = $query_array['userid']; } return $authorids; }
function get_related_dates($projectname, $basedate) { include "cdash/config.php"; require_once "cdash/pdo.php"; $dates = array(); $db = pdo_connect("{$CDASH_DB_HOST}", "{$CDASH_DB_LOGIN}", "{$CDASH_DB_PASS}"); pdo_select_db("{$CDASH_DB_NAME}", $db); $dbQuery = pdo_query("SELECT nightlytime FROM project WHERE name='{$projectname}'"); if (pdo_num_rows($dbQuery) > 0) { $project = pdo_fetch_array($dbQuery); $nightlytime = $project['nightlytime']; //echo "query result nightlytime: " . $nightlytime . "<br/>"; } else { $nightlytime = "00:00:00"; //echo "default nightlytime: " . $nightlytime . "<br/>"; } if (!isset($basedate) || strlen($basedate) == 0) { $basedate = gmdate(FMT_DATE); } // Convert the nightly time into GMT $nightlytime = gmdate(FMT_TIME, strtotime($nightlytime)); $nightlyhour = time2hour($nightlytime); $nightlyminute = time2minute($nightlytime); $nightlysecond = time2second($nightlytime); $basemonth = date2month($basedate); $baseday = date2day($basedate); $baseyear = date2year($basedate); $dates['nightly+2'] = gmmktime($nightlyhour, $nightlyminute, $nightlysecond, $basemonth, $baseday + 2, $baseyear); $dates['nightly+1'] = gmmktime($nightlyhour, $nightlyminute, $nightlysecond, $basemonth, $baseday + 1, $baseyear); $dates['nightly-0'] = gmmktime($nightlyhour, $nightlyminute, $nightlysecond, $basemonth, $baseday, $baseyear); $dates['nightly-1'] = gmmktime($nightlyhour, $nightlyminute, $nightlysecond, $basemonth, $baseday - 1, $baseyear); $dates['nightly-2'] = gmmktime($nightlyhour, $nightlyminute, $nightlysecond, $basemonth, $baseday - 2, $baseyear); // Snapshot of "now" // $currentgmtime = time(); $currentgmdate = gmdate(FMT_DATE, $currentgmtime); // Find the most recently past nightly time: // $todaymonth = date2month($currentgmdate); $todayday = date2day($currentgmdate); $todayyear = date2year($currentgmdate); $currentnightly = gmmktime($nightlyhour, $nightlyminute, $nightlysecond, $todaymonth, $todayday, $todayyear); while ($currentnightly > $currentgmtime) { $todayday = $todayday - 1; $currentnightly = gmmktime($nightlyhour, $nightlyminute, $nightlysecond, $todaymonth, $todayday, $todayyear); } $dates['now'] = $currentgmtime; $dates['most-recent-nightly'] = $currentnightly; $dates['today_utc'] = $currentgmdate; $dates['basedate'] = gmdate(FMT_DATE, $dates['nightly-0']); // CDash equivalent of DART1's "last rollup time" if ($dates['basedate'] === $dates['today_utc']) { // If it's today, it's now: $dates['last-rollup-time'] = $dates['now']; } else { // If it's not today, it's the nightly time on the basedate: $dates['last-rollup-time'] = $dates['nightly-0']; } return $dates; }
/** Return the coverage per directory with the number of lines * covered and not covered */ private function CoveragePerDirectory() { include_once '../cdash/common.php'; if (!isset($this->Parameters['project'])) { echo "Project not set"; return; } $projectid = get_project_id($this->Parameters['project']); if (!is_numeric($projectid) || $projectid <= 0) { echo "Project not found"; return; } // Select the last build that has coverage from the project $query = pdo_query("SELECT buildid FROM coveragesummary,build WHERE build.id=coveragesummary.buildid\n AND build.projectid='{$projectid}' ORDER BY buildid DESC LIMIT 1"); echo pdo_error(); if (pdo_num_rows($query) == 0) { echo "No coverage entries found for this project"; return; } $query_array = pdo_fetch_array($query); $buildid = $query_array['buildid']; // Find the coverage files $query = pdo_query("SELECT cf.fullpath,c.loctested,c.locuntested FROM coverage as c,coveragefile as cf\n WHERE c.fileid=cf.id AND c.buildid='" . $buildid . "' ORDER BY cf.fullpath ASC"); echo pdo_error(); $coveragearray = array(); while ($query_array = pdo_fetch_array($query)) { $fullpath = $query_array['fullpath']; $paths = explode('/', $fullpath); $current = array(); for ($i = 1; $i < count($paths) - 1; $i++) { if ($i == 1) { if (!isset($coveragearray[$paths[$i]])) { $coveragearray[$paths[$i]] = array(); } $current =& $coveragearray[$paths[$i]]; } else { if ($i == count($paths) - 2) { if (isset($current[$paths[$i]])) { $v = $current[$paths[$i]]['locuntested']; $current[$paths[$i]]['locuntested'] = (int) $v + $query_array['locuntested']; $v = $current[$paths[$i]]['loctested']; $current[$paths[$i]]['loctested'] = (int) $v + $query_array['loctested']; } else { @($current[$paths[$i]]['locuntested'] = $query_array['locuntested']); @($current[$paths[$i]]['loctested'] = $query_array['loctested']); } unset($current); } else { $current[$paths[$i]] = array(); $current[$paths[$i]]['locuntested'] = 0; $current[$paths[$i]]['loctested'] = 0; $current =& $current[$paths[$i]]; } } } } return $coveragearray; }
public function testTestHistory() { // Submit our testing data. $rep = dirname(__FILE__) . '/data/TestHistory'; if (!$this->submission('InsightExample', "{$rep}/Test_1.xml")) { $this->fail('Failed to submit Test_1.xml'); return 1; } if (!$this->submission('InsightExample', "{$rep}/Test_2.xml")) { $this->fail('Failed to submit Test_1.xml'); return 1; } // Get the IDs for the two builds that we just created. $result = pdo_query("SELECT id FROM build WHERE name='TestHistory'"); $num_builds = pdo_num_rows($result); if ($num_builds != 2) { $this->fail("Expected 2 builds, found {$num_builds}"); return 1; } $buildids = array(); while ($row = pdo_fetch_array($result)) { $buildids[] = $row['id']; } // Verify that testing history matches what we expect. $content = $this->connect($this->url . '/api/v1/viewTest.php?groupid=15&previous_builds=' . $buildids[1] . ',+' . $buildids[0] . '&projectid=5&tests%5B%5D=fails&tests%5B%5D=notrun&tests%5B%5D=flaky&tests%5B%5D=passes&time_begin=2015-11-16T01:00:00&time_end=2015-11-17T01:00:00'); $jsonobj = json_decode($content, true); $success = true; $error_message = ''; foreach ($jsonobj['tests'] as $test) { $history = $test['history']; if ($test['name'] == 'fails' && $history != 'Broken') { $error_message = "Expected history for test 'fails' to be 'Broken', instead found '{$history}'"; $success = false; } if ($test['name'] == 'notrun' && $history != 'Inactive') { $error_message = "Expected history for test 'notrun' to be 'Inactive', instead found '{$history}'"; $success = false; } if ($test['name'] == 'flaky' && $history != 'Unstable') { $error_message = "Expected history for test 'flaky' to be 'Unstable', instead found '{$history}'"; $success = false; } if ($test['name'] == 'passes' && $history != 'Stable') { $error_message = "Expected history for test 'passes' to be 'Stable', instead found '{$history}'"; $success = false; } } // Delete the builds that we created during this test. remove_build($buildids[0]); remove_build($buildids[1]); if ($success) { $this->pass('Test passed'); return 0; } else { $this->fail($error_message); return 1; } }
/** Return if exists */ public function Exists() { $query = pdo_query("SELECT count(*) AS c FROM test2image WHERE imgid='" . $this->Id . "' AND testid='" . $this->TestId . "' AND role='" . $this->Role . "'"); $query_array = pdo_fetch_array($query); if ($query_array['c'] > 0) { return true; } return false; }
/** Get the last file id dynamicanalysis */ function get_last_fileid_dynamicanalysis($filename, $projectid, $siteid, $buildtype, $buildname, $starttime) { $nextbuild = pdo_query("SELECT dynamicanalysis.id FROM build,dynamicanalysis\n WHERE build.siteid='{$siteid}' AND build.type='{$buildtype}' AND build.name='{$buildname}'\n AND build.projectid='{$projectid}' \n AND dynamicanalysis.buildid=build.id\n AND dynamicanalysis.name='{$filename}'\n ORDER BY build.starttime DESC LIMIT 1"); if (pdo_num_rows($nextbuild) > 0) { $nextbuild_array = pdo_fetch_array($nextbuild); return $nextbuild_array["id"]; } return 0; }
/** Return if exists */ function Exists() { $query = pdo_query("SELECT count(*) AS c FROM banner WHERE projectid=" . qnum($this->ProjectId)); $query_array = pdo_fetch_array($query); if ($query_array['c'] > 0) { return true; } return false; }
/** Return if exists */ function Exists() { $query = pdo_query("SELECT count(*) AS c FROM configureerrordiff WHERE buildid=" . qnum($this->BuildId)); $query_array = pdo_fetch_array($query); if ($query_array['c'] > 0) { return true; } return false; }
/** Get Site */ public function GetSite() { if (!$this->Id) { add_log('ClientJob::GetSite', 'Id not set'); return; } $sys = pdo_query('SELECT siteid FROM client_job WHERE id=' . qnum($this->Id)); $row = pdo_fetch_array($sys); return $row[0]; }
/** Find how many dynamic analysis tests were failed or notrun status */ public function GetNumberOfErrors() { if (strlen($this->BuildId) == 0) { echo 'DynamicAnalysis::GetNumberOfErrors BuildId not set'; return false; } $query = 'SELECT count(*) FROM dynamicanalysis WHERE buildid=' . qnum($this->BuildId) . " AND status IN ('notrun','failed')"; $errorcount = pdo_query($query); $error_array = pdo_fetch_array($errorcount); return $error_array[0]; }
public function Insert() { if (!$this->BuildId) { add_log('BuildId not set', 'BuildNote::Insert()', LOG_ERR, 0, $this->Id); return false; } if (!$this->Time) { add_log('Time not set', 'BuildNote::Insert()', LOG_ERR, 0, $this->Id); return false; } if (!$this->Name) { add_log('Name not set', 'BuildNote::Insert()', LOG_ERR, 0, $this->Id); return false; } if (!$this->Text) { add_log('Text not set', 'BuildNote::Insert()', LOG_ERR, 0, $this->Id); return false; } // Check if the note already exists $crc32 = $this->GetCrc32(); $text = pdo_real_escape_string($this->Text); $timestamp = pdo_real_escape_string($this->Time); $name = pdo_real_escape_string($this->Name); $notecrc32 = pdo_query("SELECT id FROM note WHERE crc32='{$crc32}'"); if (pdo_num_rows($notecrc32) == 0) { if ($this->Id) { $query = "INSERT INTO note (id,text,name,crc32) VALUES ('{$this->Id}','{$text}','{$name}','{$crc32}')"; } else { $query = "INSERT INTO note (text,name,crc32) VALUES ('{$text}','{$name}','{$crc32}')"; } if (!pdo_query($query)) { add_last_sql_error('BuildNote:Insert', 0, $this->BuildId); return false; } if (!$this->Id) { $this->Id = pdo_insert_id('note'); } } else { // already there $notecrc32_array = pdo_fetch_array($notecrc32); $this->Id = $notecrc32_array['id']; } if (!$this->Id) { echo 'BuildNote::Insert(): No NoteId'; return false; } $query = "INSERT INTO build2note (buildid,noteid,time)\n VALUES ('{$this->BuildId}','{$this->Id}','{$this->Time}')"; if (!pdo_query($query)) { add_last_sql_error('BuildNote:Insert', 0, $this->BuildId); return false; } return true; }
function Insert() { if (!$this->BuildId) { echo "BuildNote::Insert(): BuildId is not set<br>"; return false; } if (!$this->Time) { echo "BuildNote::Insert(): Time is not set<br>"; return false; } if (!$this->Name) { echo "BuildNote::Insert(): Name is not set<br>"; return false; } if (!$this->Text) { echo "BuildNote::Insert(): Text is not set<br>"; return false; } // Check if the note already exists $crc32 = $this->GetCrc32(); $text = pdo_real_escape_string($this->Text); $timestamp = pdo_real_escape_string($this->Time); $name = pdo_real_escape_string($this->Name); $notecrc32 = pdo_query("SELECT id FROM note WHERE crc32='{$crc32}'"); if (pdo_num_rows($notecrc32) == 0) { if ($this->Id) { $query = "INSERT INTO note (id,text,name,crc32) VALUES ('{$this->Id}','{$text}','{$name}','{$crc32}')"; } else { $query = "INSERT INTO note (text,name,crc32) VALUES ('{$text}','{$name}','{$crc32}')"; } if (!pdo_query($query)) { add_last_sql_error("BuildNote:Insert", 0, $this->BuildId); return false; } if (!$this->Id) { $this->Id = pdo_insert_id("note"); } } else { $notecrc32_array = pdo_fetch_array($notecrc32); $this->Id = $notecrc32_array["id"]; } if (!$this->Id) { echo "BuildNote::Insert(): No NoteId"; return false; } $query = "INSERT INTO build2note (buildid,noteid,time)\n VALUES ('{$this->BuildId}','{$this->Id}','{$this->Time}')"; if (!pdo_query($query)) { add_last_sql_error("BuildNote:Insert", 0, $this->BuildId); return false; } return true; }
/** Check if the rule already exists */ public function Exists() { // If no id specify return false if (empty($this->GroupId) || empty($this->BuildType) || empty($this->BuildName) || empty($this->SiteId)) { return false; } $query = pdo_query("SELECT count(*) AS c FROM build2grouprule WHERE\n groupid='" . $this->GroupId . "' AND buildtype='" . $this->BuildType . "'\n AND buildname='" . $this->BuildName . "'\n AND siteid='" . $this->SiteId . "'\n AND starttime='" . $this->StartTime . "'\n AND endtime='" . $this->EndTime . "'"); $query_array = pdo_fetch_array($query); if ($query_array['c'] == 0) { return false; } return true; }
/** Check if exists */ public function Exists() { // If no id specify return false if (!$this->DailyUpdateId || !$this->Filename) { return false; } $query = pdo_query("SELECT count(*) AS c FROM dailyupdatefile WHERE dailyupdateid='" . $this->DailyUpdateId . "' AND filename='" . $this->Filename . "'"); $query_array = pdo_fetch_array($query); if ($query_array['c'] == 0) { return false; } return true; }
/** Check if the position already exists */ function Exists() { // If no id specify return false if (!$this->GroupId) { return false; } $query = pdo_query("SELECT count(*) AS c FROM buildgroupposition WHERE \n buildgroupid='" . $this->GroupId . "' AND position='" . $this->Position . "'\n AND starttime='" . $this->StartTime . "'\n AND endtime='" . $this->EndTime . "'"); $query_array = pdo_fetch_array($query); if ($query_array['c'] == 0) { return false; } return true; }
function testBuildsRemovedOnSubmission() { $this->enableAutoRemoveConfigSetting(); $this->setAutoRemoveTimeFrame(); $this->deleteLog($this->logfilename); $this->startCodeCoverage(); $result = $this->db->query("SELECT id FROM project WHERE name = 'EmailProjectExample'"); $projectid = $result[0]['id']; // Submit the first build $rep = dirname(__FILE__) . "/data/EmailProjectExample"; $testxml1 = "{$rep}/1_test.xml"; if (!$this->submission('EmailProjectExample', $testxml1)) { $this->fail("submission 1 failed"); $this->stopCodeCoverage(); return; } // Check that the test is actually there if (!($query = pdo_query("SELECT name FROM build WHERE projectid='{$projectid}' AND stamp='20090223-0100-Nightly'"))) { $this->fail("pdo_query returned false"); return 1; } $query_array = pdo_fetch_array($query); if ($query_array[0] != 'Win32-MSVC2009') { echo $query_array[0]; $this->fail("First build not inserted correctly"); return 1; } // Looks like it's a new day $this->db->query("DELETE FROM dailyupdate WHERE projectid='{$projectid}'"); $testxml2 = "{$rep}/2_test.xml"; if (!$this->submission('EmailProjectExample', $testxml2)) { $this->fail("submission 2 failed"); $this->stopCodeCoverage(); return 1; } // The removal of the builds are done asynchronously so we might need to wait a little bit // in order for the process to be done sleep(10); // seconds // Check that the first test is gone if (!($query = pdo_query("SELECT id FROM build WHERE projectid='{$projectid}' AND stamp='20090223-0100-Nightly'"))) { $this->fail("pdo_query returned false"); return 1; } if (pdo_num_rows($query) > 0) { $this->fail("Auto remove build on submit failed"); return 1; } $this->pass("Passed"); $this->stopCodeCoverage(); }
/** List Defects */ private function ListDefects() { include_once 'cdash/common.php'; if (!isset($this->Parameters['project'])) { echo "Project not set"; return; } $projectid = get_project_id($this->Parameters['project']); if (!is_numeric($projectid) || $projectid <= 0) { echo "Project not found"; return; } // We need multiple queries (4 to be exact) // First for the build failures $users = array(); $query = pdo_query("SELECT SUM(errors) AS nerrors,SUM(nfiles) AS nfiles,author FROM(\n SELECT b.id,bed.difference_positive AS errors,u.author,\n COUNT(u.author) AS nfiles, COUNT(DISTINCT u.author) AS dauthor\n FROM build2group AS b2g, buildgroup AS bg,updatefile AS u,build2update AS b2u, builderrordiff AS bed, build AS b\n WHERE b.projectid=" . $projectid . " AND u.updateid=b2u.updateid AND b2u.buildid=b.id AND b2g.buildid=b.id AND b2g.groupid=bg.id AND bg.name!='Experimental'\n AND bed.buildid=b.id AND bed.difference_positive>0 AND bed.difference_negative!=bed.difference_positive\n AND b.starttime<NOW()\n GROUP BY b.id,bed.difference_positive,u.author HAVING COUNT(DISTINCT u.author)=1) AS q GROUP BY author"); echo pdo_error(); while ($query_array = pdo_fetch_array($query)) { $users[$query_array['author']]['builderrors'] = $query_array['nerrors']; $users[$query_array['author']]['builderrorsfiles'] = $query_array['nfiles']; } // Then for the build fixes $query = pdo_query("SELECT SUM(fixes) AS nfixes,SUM(nfiles) AS nfiles,author FROM(\n SELECT b.id,bed.difference_positive AS errors,bed.difference_negative AS fixes,u.author,\n COUNT(u.author) AS nfiles, COUNT(DISTINCT u.author) AS dauthor\n FROM build2group AS b2g, buildgroup AS bg,updatefile AS u,build2update AS b2u, builderrordiff AS bed, build AS b\n WHERE b.projectid=" . $projectid . " AND u.updateid=b2u.updateid AND b2u.buildid=b.id AND b2g.buildid=b.id AND b2g.groupid=bg.id AND bg.name!='Experimental'\n AND bed.buildid=b.id AND bed.difference_negative>0 AND bed.difference_positive<bed.difference_negative\n AND b.starttime<NOW()\n GROUP BY b.id,bed.difference_positive,bed.difference_negative,u.author HAVING COUNT(DISTINCT u.author)=1) AS q GROUP BY author"); echo pdo_error(); while ($query_array = pdo_fetch_array($query)) { $users[$query_array['author']]['buildfixes'] = $query_array['nfixes']; $users[$query_array['author']]['buildfixesfiles'] = $query_array['nfiles']; } // Then for the test failures $query = pdo_query("SELECT SUM(testerrors) AS ntesterrors,SUM(nfiles) AS nfiles,author FROM(SELECT b.id, td.difference_positive AS testerrors,\n u.author,COUNT(u.author) AS nfiles, COUNT(DISTINCT u.author) AS dauthor\n FROM build2group AS b2g, buildgroup AS bg,updatefile AS u, build2update AS b2u, build AS b, testdiff AS td\n WHERE b.projectid=" . $projectid . " AND u.updateid=b2u.updateid AND b2u.buildid=b.id AND b2g.buildid=b.id AND b2g.groupid=bg.id AND bg.name!='Experimental'\n AND td.buildid=b.id AND td.difference_positive>0 AND td.type=1\n AND b.starttime<NOW()\n GROUP BY b.id,td.difference_positive,u.author HAVING COUNT(DISTINCT u.author)=1) AS q GROUP BY author"); echo pdo_error(); while ($query_array = pdo_fetch_array($query)) { $users[$query_array['author']]['testerrors'] = $query_array['ntesterrors']; $users[$query_array['author']]['testerrorsfiles'] = $query_array['nfiles']; } // Then for the test fixes $query = pdo_query("SELECT SUM(testfixes) AS ntestfixes,SUM(nfiles) AS nfiles,author FROM(SELECT b.id, td.difference_positive AS testfixes,\n u.author,COUNT(u.author) AS nfiles, COUNT(DISTINCT u.author) AS dauthor\n FROM build2group AS b2g, buildgroup AS bg,updatefile AS u, build2update AS b2u, build AS b, testdiff AS td\n WHERE b.projectid=" . $projectid . " AND u.updateid=b2u.updateid AND b2u.buildid=b.id AND b2g.buildid=b.id AND b2g.groupid=bg.id AND bg.name!='Experimental'\n AND td.buildid=b.id AND td.difference_positive>0 AND td.type=2 AND td.difference_negative=0\n AND b.starttime<NOW()\n GROUP BY b.id,td.difference_positive,u.author HAVING COUNT(DISTINCT u.author)=1) AS q GROUP BY author"); echo pdo_error(); while ($query_array = pdo_fetch_array($query)) { $users[$query_array['author']]['testfixes'] = $query_array['ntestfixes']; $users[$query_array['author']]['testfixesfiles'] = $query_array['nfiles']; } // Another select for neutral $query = pdo_query("SELECT b.id, bed.difference_positive AS errors,\n u.author AS author,count(*) AS nfiles\n FROM build2group AS b2g, buildgroup AS bg,updatefile AS u, build2update AS b2u, build AS b\n LEFT JOIN builderrordiff AS bed ON (bed.buildid=b.id AND difference_positive!=difference_negative)\n LEFT JOIN testdiff AS t ON (t.buildid=b.id)\n WHERE b.projectid=" . $projectid . " AND u.updateid=b2u.updateid AND b2u.buildid=b.id AND b2g.buildid=b.id AND b2g.groupid=bg.id AND bg.name!='Experimental'\n AND bed.difference_positive IS NULL\n AND t.difference_positive IS NULL\n AND b.starttime<NOW() GROUP BY u.author,b.id,bed.difference_positive"); echo pdo_error(); while ($query_array = pdo_fetch_array($query)) { $users[$query_array['author']]['neutralfiles'] = $query_array['nfiles']; } return $users; }
function pdo_all_rows_query($qry) { $result = pdo_query($qry); if (FALSE === $result) { add_log('error: pdo_query failed: ' . pdo_error(), 'pdo_all_rows_query', LOG_ERR); return array(); } $all_rows = array(); while ($row = pdo_fetch_array($result)) { $all_rows[] = $row; } pdo_free_result($result); return $all_rows; }
function CreateRSSFeed($projectid) { // Checks if (!isset($projectid) || !is_numeric($projectid)) { echo 'Not a valid projectid!'; return; } // Find the project name $project = pdo_query("SELECT public,name FROM project WHERE id='{$projectid}'"); $project_array = pdo_fetch_array($project); $projectname = $project_array['name']; // Don't create RSS feed for private projects if ($project_array['public'] != 1) { return; } global $CDASH_ROOT_DIR; $filename = $CDASH_ROOT_DIR . '/public/rss/SubmissionRSS' . $projectname . '.xml'; $currentURI = get_server_URI(); $currenttime = time(); $feed = new Feed(); $channel = new Channel(); $channel->title("CDash for {$projectname}")->url("{$currentURI}/index.php?project={$projectname}")->description("Recent CDash submissions for {$projectname}")->language('en-US')->lastBuildDate($currenttime)->appendTo($feed); // Get the last 24hrs submissions $beginning_timestamp = $currenttime - 24 * 3600; $end_timestamp = $currenttime; $builds = pdo_query("SELECT * FROM build\n WHERE UNIX_TIMESTAMP(starttime)<{$end_timestamp} AND UNIX_TIMESTAMP(starttime)>{$beginning_timestamp}\n AND projectid='{$projectid}'\n "); while ($build_array = pdo_fetch_array($builds)) { $siteid = $build_array['siteid']; $buildid = $build_array['id']; $site_array = pdo_fetch_array(pdo_query("SELECT name FROM site WHERE id='{$siteid}'")); // Find the number of errors and warnings $nerrors = $build_array['builderrors']; $nwarnings = $build_array['buildwarnings']; $nnotrun = $build_array['testnotrun']; $nfail = $build_array['testfailed']; $title = 'CDash(' . $projectname . ') - ' . $site_array['name'] . ' - ' . $build_array['name'] . ' - ' . $build_array['type']; $title .= ' - ' . $build_array['submittime'] . ' - ' . $nerrors . ' errors, ' . $nwarnings . ' warnings, ' . $nnotrun . ' not run, ' . $nfail . ' failed.'; // Should link to the errors... $link = $currentURI . '/buildSummary.php?buildid=' . $buildid; $description = 'A new ' . $build_array['type'] . ' submission from ' . $site_array['name'] . ' - ' . $build_array['name'] . ' is available: '; $description .= $nerrors . ' errors, ' . $nwarnings . ' warnings, ' . $nnotrun . ' not run, ' . $nfail . ' failed.'; $item = new Item(); $item->guid($currentURI . '/buildSummary.php?buildid=' . $buildid)->title($title)->url($link)->description($description)->pubDate($currenttime)->appendTo($channel); } if (file_put_contents($filename, $feed) === false) { add_log('Cannot write file ' . $filename, 'CreateRSSFeed', LOG_ERR, $projectid); } }
function get_dynamic_builds($projectid, $end_UTCDate) { $builds = array(); // Get the build rules for each dynamic group belonging to this project. $rules = pdo_query("\n SELECT b2gr.buildname, b2gr.siteid, b2gr.parentgroupid, bg.id, bg.name,\n bg.type, gp.position\n FROM build2grouprule AS b2gr\n LEFT JOIN buildgroup AS bg ON (bg.id = b2gr.groupid)\n LEFT JOIN buildgroupposition AS gp ON (gp.buildgroupid=bg.id)\n WHERE bg.projectid='{$projectid}' AND bg.endtime='1980-01-01 00:00:00' AND\n bg.type != 'Daily'"); if (!$rules) { echo pdo_error(); return; } while ($rule = pdo_fetch_array($rules)) { $buildgroup_name = $rule['name']; $buildgroup_id = $rule['id']; $buildgroup_position = $rule['position']; if ($rule['type'] == 'Latest') { // optional fields: parentgroupid, site, and build name match. // Use these to construct a WHERE clause for our query. $where = ''; $whereClauses = array(); if (!empty($rule['parentgroupid'])) { $whereClauses[] = "b2g.groupid='" . $rule['parentgroupid'] . "'"; } if (!empty($rule['siteid'])) { $whereClauses[] = "s.id='" . $rule['siteid'] . "'"; } if (!empty($rule['buildname'])) { $whereClauses[] = "b.name LIKE '" . $rule['buildname'] . "'"; } if (!empty($whereClauses)) { $where = 'WHERE ' . implode($whereClauses, ' AND '); $where .= " AND b.starttime<'{$end_UTCDate}'"; } // We only want the most recent build. $order = 'ORDER BY b.submittime DESC LIMIT 1'; $sql = get_index_query(); $sql .= "{$where} {$order}"; $build = pdo_single_row_query($sql); if (empty($build)) { continue; } $build['groupname'] = $buildgroup_name; $build['groupid'] = $buildgroup_id; $build['position'] = $buildgroup_position; $builds[] = $build; } } return $builds; }
function get_dynamic_builds($projectid) { $builds = array(); // Get the build rules for each dynamic group belonging to this project. $rules = pdo_query("\n SELECT b2gr.buildname, b2gr.siteid, b2gr.parentgroupid, bg.id, bg.name,\n bg.type, gp.position\n FROM build2grouprule AS b2gr\n LEFT JOIN buildgroup AS bg ON (bg.id = b2gr.groupid)\n LEFT JOIN buildgroupposition AS gp ON (gp.buildgroupid=bg.id)\n WHERE bg.projectid='{$projectid}' AND bg.endtime='1980-01-01 00:00:00' AND\n bg.type != 'Daily'"); if (!$rules) { echo pdo_error(); return; } while ($rule = pdo_fetch_array($rules)) { $buildgroup_name = $rule['name']; $buildgroup_id = $rule['id']; $buildgroup_position = $rule['position']; if ($rule['type'] == 'Latest') { // optional fields: parentgroupid, site, and build name match. // Use these to construct a WHERE clause for our query. $where = ""; $whereClauses = array(); if (!empty($rule['parentgroupid'])) { $whereClauses[] = "b2g.groupid='" . $rule['parentgroupid'] . "'"; } if (!empty($rule['siteid'])) { $whereClauses[] = "s.id='" . $rule['siteid'] . "'"; } if (!empty($rule['buildname'])) { $whereClauses[] = "b.name LIKE '" . $rule['buildname'] . "'"; } if (!empty($whereClauses)) { $where = "WHERE " . implode($whereClauses, " AND "); } // We only want the most recent build. $order = "ORDER BY b.submittime DESC LIMIT 1"; // Copied from index.php. $sql = "SELECT b.id,b.siteid,b.parentid,\n bu.status AS updatestatus,\n i.osname AS osname,\n bu.starttime AS updatestarttime,\n bu.endtime AS updateendtime,\n bu.nfiles AS countupdatefiles,\n bu.warnings AS countupdatewarnings,\n c.status AS configurestatus,\n c.starttime AS configurestarttime,\n c.endtime AS configureendtime,\n be_diff.difference_positive AS countbuilderrordiffp,\n be_diff.difference_negative AS countbuilderrordiffn,\n bw_diff.difference_positive AS countbuildwarningdiffp,\n bw_diff.difference_negative AS countbuildwarningdiffn,\n ce_diff.difference AS countconfigurewarningdiff,\n btt.time AS testsduration,\n tnotrun_diff.difference_positive AS counttestsnotrundiffp,\n tnotrun_diff.difference_negative AS counttestsnotrundiffn,\n tfailed_diff.difference_positive AS counttestsfaileddiffp,\n tfailed_diff.difference_negative AS counttestsfaileddiffn,\n tpassed_diff.difference_positive AS counttestspasseddiffp,\n tpassed_diff.difference_negative AS counttestspasseddiffn,\n tstatusfailed_diff.difference_positive AS countteststimestatusfaileddiffp,\n tstatusfailed_diff.difference_negative AS countteststimestatusfaileddiffn,\n (SELECT count(buildid) FROM build2note WHERE buildid=b.id) AS countnotes,\n (SELECT count(buildid) FROM buildnote WHERE buildid=b.id) AS countbuildnotes,\n s.name AS sitename,\n s.outoforder AS siteoutoforder,\n b.stamp,b.name,b.type,b.generator,b.starttime,b.endtime,b.submittime,\n b.configureerrors AS countconfigureerrors,\n b.configurewarnings AS countconfigurewarnings,\n b.builderrors AS countbuilderrors,\n b.buildwarnings AS countbuildwarnings,\n b.testnotrun AS counttestsnotrun,\n b.testfailed AS counttestsfailed,\n b.testpassed AS counttestspassed,\n b.testtimestatusfailed AS countteststimestatusfailed,\n sp.id AS subprojectid,\n sp.groupid AS subprojectgroup,\n (SELECT count(buildid) FROM errorlog WHERE buildid=b.id) AS nerrorlog,\n (SELECT count(buildid) FROM build2uploadfile WHERE buildid=b.id) AS builduploadfiles\n FROM build AS b\n LEFT JOIN build2group AS b2g ON (b2g.buildid=b.id)\n LEFT JOIN buildgroup AS g ON (g.id=b2g.groupid)\n LEFT JOIN site AS s ON (s.id=b.siteid)\n LEFT JOIN build2update AS b2u ON (b2u.buildid=b.id)\n LEFT JOIN buildupdate AS bu ON (b2u.updateid=bu.id)\n LEFT JOIN configure AS c ON (c.buildid=b.id)\n LEFT JOIN buildinformation AS i ON (i.buildid=b.id)\n LEFT JOIN builderrordiff AS be_diff ON (be_diff.buildid=b.id AND be_diff.type=0)\n LEFT JOIN builderrordiff AS bw_diff ON (bw_diff.buildid=b.id AND bw_diff.type=1)\n LEFT JOIN configureerrordiff AS ce_diff ON (ce_diff.buildid=b.id AND ce_diff.type=1)\n LEFT JOIN buildtesttime AS btt ON (btt.buildid=b.id)\n LEFT JOIN testdiff AS tnotrun_diff ON (tnotrun_diff.buildid=b.id AND tnotrun_diff.type=0)\n LEFT JOIN testdiff AS tfailed_diff ON (tfailed_diff.buildid=b.id AND tfailed_diff.type=1)\n LEFT JOIN testdiff AS tpassed_diff ON (tpassed_diff.buildid=b.id AND tpassed_diff.type=2)\n LEFT JOIN testdiff AS tstatusfailed_diff ON (tstatusfailed_diff.buildid=b.id AND tstatusfailed_diff.type=3)\n LEFT JOIN subproject2build AS sp2b ON (sp2b.buildid = b.id)\n LEFT JOIN subproject as sp ON (sp2b.subprojectid = sp.id)\n LEFT JOIN label2build AS l2b ON (l2b.buildid = b.id)\n LEFT JOIN label AS l ON (l.id = l2b.labelid) {$where} {$order}"; $build = pdo_single_row_query($sql); if (empty($build)) { continue; } $build['groupname'] = $buildgroup_name; $build['groupid'] = $buildgroup_id; $build['position'] = $buildgroup_position; $builds[] = $build; } } return $builds; }
/** Return the name of a build */ function GetFiles() { if (!$this->BuildId) { echo "Coverage GetFiles(): BuildId not set"; return false; } $fileids = array(); $coverage = pdo_query("SELECT fileid FROM coverage WHERE buildid=" . qnum($this->BuildId)); if (!$coverage) { add_last_sql_error("Coverage GetFiles"); return false; } while ($coverage_array = pdo_fetch_array($coverage)) { $fileids[] = $coverage_array['fileid']; } return $fileids; }
/** Return if exists */ public function Exists() { if (!$this->BuildId || !is_numeric($this->BuildId)) { echo 'BuildErrorDiff::Save(): BuildId not set<br>'; return false; } if (!$this->Type || !is_numeric($this->Type)) { echo 'BuildErrorDiff::Save(): Type not set<br>'; return false; } $query = pdo_query("SELECT count(*) AS c FROM builderrordiff WHERE buildid='" . $this->BuildId . "' AND type='" . $this->Type . "'"); $query_array = pdo_fetch_array($query); if ($query_array['c'] > 0) { return true; } return false; }
public function Insert() { if (strlen($this->UpdateId) == 0) { echo 'BuildUpdateFile:Insert UpdateId not set'; return false; } $this->Filename = pdo_real_escape_string($this->Filename); // Sometimes the checkin date is not found in that case we put the usual date if ($this->CheckinDate == 'Unknown') { $this->CheckinDate = '1980-01-01'; } if (strtotime($this->CheckinDate) === false && is_numeric($this->CheckinDate)) { $this->CheckinDate = date(FMT_DATETIME, $this->CheckinDate); } elseif (strtotime($this->CheckinDate) !== false) { $this->CheckinDate = date(FMT_DATETIME, strtotime($this->CheckinDate)); } else { $this->CheckinDate = '1980-01-01'; } $this->Author = pdo_real_escape_string($this->Author); $this->UpdateId = pdo_real_escape_string($this->UpdateId); // Check if we have a robot file for this build $robot = pdo_query('SELECT authorregex FROM projectrobot,build,build2update WHERE projectrobot.projectid=build.projectid AND build2update.buildid=build.id AND build2update.updateid=' . qnum($this->UpdateId) . " AND robotname='" . $this->Author . "'"); if (pdo_num_rows($robot) > 0) { $robot_array = pdo_fetch_array($robot); $regex = $robot_array['authorregex']; preg_match($regex, $this->Log, $matches); if (isset($matches[1])) { $this->Author = $matches[1]; } } $this->Email = pdo_real_escape_string($this->Email); $this->Committer = pdo_real_escape_string($this->Committer); $this->CommitterEmail = pdo_real_escape_string($this->CommitterEmail); $this->Log = pdo_real_escape_string($this->Log); $this->Revision = pdo_real_escape_string($this->Revision); $this->PriorRevision = pdo_real_escape_string($this->PriorRevision); $query = 'INSERT INTO updatefile (updateid,filename,checkindate,author,email,log,revision,priorrevision,status,committer,committeremail) VALUES (' . qnum($this->UpdateId) . ",'{$this->Filename}','{$this->CheckinDate}','{$this->Author}','{$this->Email}',\n '{$this->Log}','{$this->Revision}','{$this->PriorRevision}','{$this->Status}','{$this->Committer}','{$this->CommitterEmail}')"; if (!pdo_query($query)) { add_last_sql_error('BuildUpdateFile Insert', 0, $this->UpdateId); return false; } }
/** Return if exists */ public function Exists() { if (!$this->BuildId || !is_numeric($this->BuildId)) { echo 'BuildConfigureError::Save(): BuildId not set'; return false; } if (!$this->Type || !is_numeric($this->Type)) { echo 'BuildConfigureError::Save(): Type not set'; return false; } $query = pdo_query("SELECT count(*) AS c FROM configureerror WHERE buildid='" . $this->BuildId . "'\n AND type='" . $this->Type . "' AND text='" . $this->Text . "'"); add_last_sql_error('BuildConfigureError:Exists', 0, $this->BuildId); $query_array = pdo_fetch_array($query); if ($query_array['c'] > 0) { return true; } return false; }
public function __construct() { parent::__construct(); $this->testDataDir = dirname(__FILE__) . '/data/BuildDetails'; $this->testDataFiles = array('Subbuild1.xml', 'Subbuild2.xml', 'Subbuild3.xml'); pdo_query("INSERT INTO project (name) VALUES ('BuildDetails')"); foreach ($this->testDataFiles as $testDataFile) { if (!$this->submission('BuildDetails', $this->testDataDir . '/' . $testDataFile)) { $this->fail('Failed to submit ' . $testDataFile); return 1; } } $this->builds = array(); $builds = pdo_query("SELECT * FROM build WHERE name = 'linux' ORDER BY id"); while ($build = pdo_fetch_array($builds)) { $this->builds[] = $build; } }
/** Check if exists */ public function Exists() { // If no id specify return false if ($this->Id) { $query = pdo_query("SELECT count(*) AS c FROM image WHERE id='" . $this->Id . "'"); $query_array = pdo_fetch_array($query); if ($query_array['c'] == 0) { return false; } return true; } else { // Check if the checksum exists $query = pdo_query("SELECT id FROM image WHERE checksum='" . $this->Checksum . "'"); if (pdo_num_rows($query) > 0) { $query_array = pdo_fetch_array($query); $this->Id = $query_array['id']; return true; } return false; } return true; }