/** Save */ public function Save() { $version = pdo_real_escape_string($this->Version); $path = pdo_real_escape_string($this->Path); // Check if the version already exists $query = pdo_query("SELECT id FROM client_cmake WHERE version='" . $version . "'"); if (pdo_num_rows($query) == 0) { $sql = "INSERT INTO client_cmake (version)\n VALUES ('" . $version . "')"; pdo_query($sql); $this->Id = pdo_insert_id('client_cmake'); add_last_sql_error('clientCMake::Save()'); } else { // update $query_array = pdo_fetch_array($query); $this->Id = $query_array['id']; $sql = "UPDATE client_cmake SET version='" . $version . "' WHERE id=" . qnum($this->Id); pdo_query($sql); add_last_sql_error('clientCMake::Save()'); } // Insert into the siteid $query = pdo_query('SELECT cmakeid FROM client_site2cmake WHERE cmakeid=' . qnum($this->Id) . ' AND siteid=' . qnum($this->SiteId)); if (pdo_num_rows($query) == 0) { $sql = 'INSERT INTO client_site2cmake (siteid,cmakeid,path) VALUES (' . qnum($this->SiteId) . ',' . qnum($this->Id) . ",'" . $path . "')"; pdo_query($sql); add_last_sql_error('clientCMake::Save()'); } else { // update $sql = "UPDATE client_site2cmake SET path='" . $path . "' WHERE cmakeid=" . qnum($this->Id) . ' AND siteid=' . qnum($this->SiteId); pdo_query($sql); add_last_sql_error('clientCMake::Save()'); } }
/** Insert the new user */ function Insert() { if (!isset($this->UserId) || $this->UserId < 1) { echo "CoverageFile2User:Insert: UserId not set"; return false; } if ($this->FullPath == '' || $this->ProjectId < 1) { echo "CoverageFile2User:Insert: FullPath or ProjectId not set"; return false; } // Check if is already in the database if (!$this->Exists()) { $this->FileId = $this->GetId(); if ($this->FileId == 0) { $query = "INSERT INTO coveragefilepriority (projectid,fullpath,priority)\n VALUES (" . qnum($this->ProjectId) . ",'" . $this->FullPath . "',0)"; if (!pdo_query($query)) { add_last_sql_error("CoverageFile2User:Insert"); return false; } $this->FileId = pdo_insert_id("coveragefilepriority"); } // Find the new position $query = pdo_query("SELECT count(*) AS c FROM coveragefile2user WHERE fileid=" . qnum($this->FileId)); $query_array = pdo_fetch_array($query); $position = $query_array['c'] + 1; $query = "INSERT INTO coveragefile2user (userid,fileid,position)\n VALUES (" . qnum($this->UserId) . "," . qnum($this->FileId) . "," . qnum($position) . ")"; if (!pdo_query($query)) { add_last_sql_error("CoverageFile2User:Insert"); return false; } return true; } return false; }
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; }
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; }
public function Insert() { if (!$this->BuildId) { add_log('BuildId is not set', __FILE__ . ':' . __LINE__ . ' - ' . __FUNCTION__, LOG_ERR); return false; } if (!$this->Filename) { add_log('Filename is not set', __FILE__ . ':' . __LINE__ . ' - ' . __FUNCTION__, LOG_ERR); return false; } if (!$this->Sha1Sum) { add_log('Sha1Sum is not set', __FILE__ . ':' . __LINE__ . ' - ' . __FUNCTION__, LOG_ERR); return false; } if (!$this->Filesize) { add_log('Filesize is not set', __FILE__ . ':' . __LINE__ . ' - ' . __FUNCTION__, LOG_ERR); return false; } if (empty($this->IsUrl)) { $this->IsUrl = 0; } if (!$this->IsUrl) { $filename = pdo_real_escape_string(basename($this->Filename)); } else { $filename = pdo_real_escape_string($this->Filename); } // Check if the file already exists $filequery = pdo_query("SELECT id FROM uploadfile WHERE sha1sum = '" . $this->Sha1Sum . "' AND filename ='{$filename}'"); if (pdo_num_rows($filequery) == 0) { // Insert the file into the database $query = "INSERT INTO uploadfile (filename, filesize, sha1sum, isurl) VALUES ('{$filename}','{$this->Filesize}','{$this->Sha1Sum}', '{$this->IsUrl}')"; if (!pdo_query($query)) { add_last_sql_error('Uploadfile::Insert', 0, $this->BuildId); return false; } $this->Id = pdo_insert_id('uploadfile'); } else { $filequery_array = pdo_fetch_array($filequery); $this->Id = $filequery_array['id']; } if (!$this->Id) { add_log('No Id', __FILE__ . ':' . __LINE__ . ' - ' . __FUNCTION__, LOG_ERR); return false; } if (!pdo_query("INSERT INTO build2uploadfile (fileid, buildid)\n VALUES ('{$this->Id}','{$this->BuildId}')")) { add_last_sql_error('UploadFile::Insert', 0, $this->BuildId); return false; } return true; }
/** Save a site */ function Save() { $name = $this->GetNameFromPlatform($this->Name); $version = $this->GetNameFromVersion($this->Version); if (strlen($name) == 0) { return false; } // Check if the name and bits system already exists $query = pdo_query("SELECT id FROM client_os WHERE name='" . $name . "' AND version='" . $version . "' AND bits='" . $this->Bits . "'"); if (pdo_num_rows($query) == 0) { $sql = "INSERT INTO client_os (name,version,bits) \n VALUES ('" . $name . "','" . $version . "','" . $this->Bits . "')"; pdo_query($sql); $this->Id = pdo_insert_id('client_os'); add_last_sql_error("ClientOS::Save()"); } else { $query_array = pdo_fetch_array($query); $this->Id = $query_array['id']; } }
/** Create a new build as a parent of $this. * Assumes many fields have been set prior to calling this function. **/ function CreateParentBuild($numErrors, $numWarnings) { if ($numErrors < 0) { $numErrors = 0; } if ($numWarnings < 0) { $numWarnings = 0; } // Check if there's an existing build that should be the parent. // This would be a standalone build (parent=0) with no subproject // that matches our name, site, and stamp. $query = "SELECT id FROM build\n WHERE parentid = 0 AND name = '{$this->Name}' AND\n siteid = '{$this->SiteId}' AND stamp = '{$this->Stamp}'"; $result = pdo_query($query); if (pdo_num_rows($result) > 0) { $result_array = pdo_fetch_array($result); $parentId = $result_array['id']; $this->ParentId = $parentId; // Mark it as a parent (parentid of -1) and update its tally of // build errors & warnings. pdo_query("UPDATE build SET parentid = -1 WHERE id = {$parentId}"); $this->UpdateParentBuild($numErrors, $numWarnings); } else { // Create the parent build here. Note how parent builds // are indicated by parentid == -1. $query = "INSERT INTO build\n (parentid, siteid, projectid, stamp, name, type, generator,\n starttime, endtime, submittime, builderrors, buildwarnings)\n VALUES\n ('-1','{$this->SiteId}','{$this->ProjectId}','{$this->Stamp}',\n '{$this->Name}','{$this->Type}','{$this->Generator}',\n '{$this->StartTime}','{$this->EndTime}','{$this->SubmitTime}',\n {$numErrors},{$numWarnings})"; if (!pdo_query($query)) { add_last_sql_error("Build Insert Parent", $this->ProjectId, $this->Id); return false; } $parentId = pdo_insert_id("build"); } // Since we just created a parent we should also update any existing // builds that should be a child of this parent but aren't yet. // This happens when Update.xml is parsed first, because it doesn't // contain info about what subproject it came from. // TODO: maybe we don't need this any more? $query = "UPDATE build SET parentid={$parentId}\n WHERE parentid=0 AND siteid='{$this->SiteId}' AND\n name='{$this->Name}' AND stamp='{$this->Stamp}'"; if (!pdo_query($query)) { add_last_sql_error("Build Insert Update Parent", $this->ProjectId, $parentId); } return $parentId; }
/** Save a job */ public function Save() { $sql = "INSERT INTO client_job (scheduleid,osid,siteid,startdate,enddate,status,output,cmakeid,compilerid)\n VALUES ('" . $this->ScheduleId . "','" . $this->OsId . "','" . $this->SiteId . "','" . $this->StartDate . "','" . $this->EndDate . "','" . $this->Status . "','" . $this->Output . "','" . $this->CMakeId . "','" . $this->CompilerId . "')"; pdo_query($sql); $this->Id = pdo_insert_id('client_job'); add_last_sql_error('ClientJob::Save'); }
function mysql_insert_id($link_identifier = NULL) { return pdo_insert_id(func_get_args()); }
/** Add daily changes if necessary */ function addDailyChanges($projectid) { include "cdash/config.php"; include_once "cdash/common.php"; include_once "cdash/sendemail.php"; $db = pdo_connect("{$CDASH_DB_HOST}", "{$CDASH_DB_LOGIN}", "{$CDASH_DB_PASS}"); pdo_select_db("{$CDASH_DB_NAME}", $db); $project_array = pdo_fetch_array(pdo_query("SELECT nightlytime,name,autoremovetimeframe,autoremovemaxbuilds,emailadministrator\n FROM project WHERE id='{$projectid}'")); $date = ""; // now list($previousdate, $currentstarttime, $nextdate) = get_dates($date, $project_array["nightlytime"]); $date = gmdate(FMT_DATE, $currentstarttime); // Check if we already have it somwhere $query = pdo_query("SELECT id FROM dailyupdate WHERE projectid='{$projectid}' AND date='{$date}'"); if (pdo_num_rows($query) == 0) { $cvsauthors = array(); pdo_query("INSERT INTO dailyupdate (projectid,date,command,type,status)\n VALUES ({$projectid},'{$date}','NA','NA','0')"); $updateid = pdo_insert_id("dailyupdate"); $dates = get_related_dates($project_array["nightlytime"], $date); $commits = get_repository_commits($projectid, $dates); // Insert the commits foreach ($commits as $commit) { $filename = $commit['directory'] . "/" . $commit['filename']; $checkindate = $commit['time']; $author = addslashes($commit['author']); $email = ''; if (isset($commit['email'])) { $email = addslashes($commit['email']); } $log = addslashes($commit['comment']); $revision = $commit['revision']; $priorrevision = $commit['priorrevision']; // Check if we have a robot file for this build $robot = pdo_query("SELECT authorregex FROM projectrobot\n WHERE projectid=" . qnum($projectid) . " AND robotname='" . $author . "'"); if (pdo_num_rows($robot) > 0) { $robot_array = pdo_fetch_array($robot); $regex = $robot_array['authorregex']; preg_match($regex, $commit['comment'], $matches); if (isset($matches[1])) { $author = addslashes($matches[1]); } } if (!in_array(stripslashes($author), $cvsauthors)) { $cvsauthors[] = stripslashes($author); } pdo_query("INSERT INTO dailyupdatefile (dailyupdateid,filename,checkindate,author,email,log,revision,priorrevision)\n VALUES ({$updateid},'{$filename}','{$checkindate}','{$author}','{$email}','{$log}','{$revision}','{$priorrevision}')"); add_last_sql_error("addDailyChanges", $projectid); } // end foreach commit // If the project has the option to send an email to the author if ($project_array['emailadministrator']) { sendEmailUnregisteredUsers($projectid, $cvsauthors); } // Send an email if some expected builds have not been submitting sendEmailExpectedBuilds($projectid, $currentstarttime); // cleanBuildEmail cleanBuildEmail(); cleanUserTemp(); // If the status of daily update is set to 2 that means we should send an email $query = pdo_query("SELECT status FROM dailyupdate WHERE projectid='{$projectid}' AND date='{$date}'"); $dailyupdate_array = pdo_fetch_array($query); $dailyupdate_status = $dailyupdate_array["status"]; if ($dailyupdate_status == 2) { // Find the groupid $group_query = pdo_query("SELECT buildid,groupid FROM summaryemail WHERE date='{$date}'"); while ($group_array = pdo_fetch_array($group_query)) { $groupid = $group_array["groupid"]; $buildid = $group_array["buildid"]; // Find if the build has any errors $builderror = pdo_query("SELECT count(buildid) FROM builderror WHERE buildid='{$buildid}' AND type='0'"); $builderror_array = pdo_fetch_array($builderror); $nbuilderrors = $builderror_array[0]; // Find if the build has any warnings $buildwarning = pdo_query("SELECT count(buildid) FROM builderror WHERE buildid='{$buildid}' AND type='1'"); $buildwarning_array = pdo_fetch_array($buildwarning); $nbuildwarnings = $buildwarning_array[0]; // Find if the build has any test failings if ($project_emailtesttimingchanged) { $sql = "SELECT count(testid) FROM build2test WHERE buildid='{$buildid}' AND (status='failed' OR timestatus>" . qnum($project_testtimemaxstatus) . ")"; } else { $sql = "SELECT count(testid) FROM build2test WHERE buildid='{$buildid}' AND status='failed'"; } $nfail_array = pdo_fetch_array(pdo_query($sql)); $nfailingtests = $nfail_array[0]; sendsummaryemail($projectid, $groupid, $nbuildwarnings, $nbuilderrors, $nfailingtests); } } pdo_query("UPDATE dailyupdate SET status='1' WHERE projectid='{$projectid}' AND date='{$date}'"); // Remove the old logs include_once "models/errorlog.php"; $ErrorLog = new ErrorLog(); $ErrorLog->Clean(10); // 10 days // Clean the backup directory clean_backup_directory(); // Remove the first builds of the project include_once "cdash/autoremove.php"; removeFirstBuilds($projectid, $project_array["autoremovetimeframe"], $project_array["autoremovemaxbuilds"]); removeBuildsGroupwise($projectid, $project_array["autoremovemaxbuilds"]); } }
/** Asynchronous submission */ function do_submit_asynchronous($filehandle, $projectid, $expected_md5 = '') { include 'cdash/config.php'; include 'cdash/version.php'; do { $filename = $CDASH_BACKUP_DIRECTORY . "/" . mt_rand() . ".xml"; $fp = @fopen($filename, 'x'); } while (!$fp); fclose($fp); unset($fp); $outfile = fopen($filename, 'w'); // Save the file in the backup directory while (!feof($filehandle)) { $content = fread($filehandle, 8192); if (fwrite($outfile, $content) === FALSE) { echo "ERROR: Cannot write to file ({$filename})"; add_log("Cannot write to file ({$filename})", "do_submit_asynchronous", LOG_ERR, $projectid); fclose($outfile); unset($outfile); return; } } fclose($outfile); unset($outfile); // Sends the file size to the local parser if ($CDASH_USE_LOCAL_DIRECTORY && file_exists("local/ctestparser.php")) { require_once "local/ctestparser.php"; $localParser = new LocalParser(); $filesize = filesize($filename); $localParser->SetFileSize($projectid, $filesize); } $md5sum = md5_file($filename); $md5error = false; echo "<cdash version=\"" . $CDASH_VERSION . "\">\n"; if ($expected_md5 == '' || $expected_md5 == $md5sum) { echo " <status>OK</status>\n"; echo " <message></message>\n"; } else { echo " <status>ERROR</status>\n"; echo " <message>Checksum failed for file. Expected {$expected_md5} but got {$md5sum}.</message>\n"; $md5error = true; } echo " <md5>{$md5sum}</md5>\n"; echo "</cdash>\n"; if ($md5error) { add_log("Checksum failure on file: {$filename}", "do_submit_asynchronous", LOG_ERR, $projectid); return; } $bytes = filesize($filename); // Insert the filename in the database $now_utc = gmdate(FMT_DATETIMESTD); pdo_query("INSERT INTO submission (filename,projectid,status,attempts,filesize,filemd5sum,created) " . "VALUES ('" . $filename . "','" . $projectid . "','0','0','{$bytes}','{$md5sum}','{$now_utc}')"); // Get the ID associated with this submission. We may need to reference it // later if this is a CDash@home (client) submission. $submissionid = pdo_insert_id('submission'); // We find the daily updates // If we have php curl we do it asynchronously if (function_exists("curl_init") == TRUE) { $currentURI = get_server_URI(true); $request = $currentURI . "/cdash/dailyupdatescurl.php?projectid=" . $projectid; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $request); curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 1); if ($CDASH_USE_HTTPS) { curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); } curl_exec($ch); curl_close($ch); $clientscheduleid = isset($_GET["clientscheduleid"]) ? pdo_real_escape_numeric($_GET["clientscheduleid"]) : 0; if ($clientscheduleid !== 0) { pdo_query("INSERT INTO client_jobschedule2submission (scheduleid,submissionid) " . "VALUES ('{$clientscheduleid}','{$submissionid}')"); } // Save submitter IP in the database in the async case, so we have a valid // IP at Site::Insert time when processing rather than 'localhost's IP: pdo_insert_query("INSERT INTO submission2ip (submissionid, ip) " . "VALUES ('{$submissionid}', '" . $_SERVER['REMOTE_ADDR'] . "')"); // Call process submissions via cURL. trigger_process_submissions($projectid); } else { add_log("Cannot submit asynchronously: php curl_init function does not exist", "do_submit_asynchronous", LOG_ERR, $projectid); } }
function Insert() { if (strlen($this->BuildId) == 0 || !is_numeric($this->BuildId)) { echo "BuildUpdate:Insert BuildId not set"; return false; } // Remove previous updates $query = pdo_query("SELECT updateid FROM build2update WHERE buildid=" . qnum($this->BuildId)); if (pdo_num_rows($query) == 1) { $query_array = pdo_fetch_array($query); $updateid = $query_array['updateid']; // If the buildupdate and updatefile are not shared we delete them as well $query = pdo_query("SELECT buildid FROM build2update WHERE updateid=" . qnum($updateid)); if (pdo_num_rows($query) == 1) { $query = "DELETE FROM buildupdate WHERE id=" . qnum($updateid); if (!pdo_query($query)) { add_last_sql_error("BuildUpdate Insert", 0, $this->BuildId); return false; } $query = "DELETE FROM updatefile WHERE updateid=" . qnum($updateid); if (!pdo_query($query)) { add_last_sql_error("BuildUpdate Insert", 0, $this->BuildId); return false; } } $query = "DELETE FROM build2update WHERE buildid=" . qnum($this->BuildId); if (!pdo_query($query)) { add_last_sql_error("BuildUpdate Insert", 0, $this->BuildId); return false; } } $this->StartTime = pdo_real_escape_string($this->StartTime); $this->EndTime = pdo_real_escape_string($this->EndTime); $this->Command = pdo_real_escape_string($this->Command); $this->Type = pdo_real_escape_string($this->Type); if (strlen($this->Type) > 4) { $this->Type = 'NA'; } $this->Status = pdo_real_escape_string($this->Status); $this->Revision = pdo_real_escape_string($this->Revision); $this->PriorRevision = pdo_real_escape_string($this->PriorRevision); $this->Path = pdo_real_escape_string($this->Path); $nfiles = count($this->Files); $nwarnings = 0; foreach ($this->Files as $file) { if ($file->Author == 'Local User' && $file->Revision == -1) { $nwarnings++; } } $query = "INSERT INTO buildupdate (starttime,endtime,command,type,status,nfiles,warnings,\n revision,priorrevision,path)\n VALUES ('{$this->StartTime}','{$this->EndTime}','{$this->Command}',\n '{$this->Type}','{$this->Status}',{$nfiles},{$nwarnings},\n '{$this->Revision}','{$this->PriorRevision}','{$this->Path}')"; if (!pdo_query($query)) { add_last_sql_error("BuildUpdate Insert", 0, $this->BuildId); return false; } $updateid = pdo_insert_id("buildupdate"); $query = "INSERT INTO build2update (buildid,updateid)\n VALUES (" . qnum($this->BuildId) . "," . qnum($updateid) . ")"; if (!pdo_query($query)) { add_last_sql_error("BuildUpdate Insert", 0, $this->BuildId); return false; } // If this is a parent build, make sure that all of its children // are also associated with a buildupdate. $query = "\n INSERT INTO build2update (buildid,updateid)\n SELECT id, '{$updateid}' FROM build\n LEFT JOIN build2update ON build.id = build2update.buildid\n WHERE build2update.buildid IS NULL\n and build.parentid=" . qnum($this->BuildId); if (!pdo_query($query)) { add_last_sql_error("BuildUpdate Child Insert", 0, $this->BuildId); return false; } foreach ($this->Files as $file) { $file->UpdateId = $updateid; $file->Insert(); } return true; }
public function Insert() { if (strlen($this->BuildId) == 0) { echo 'DynamicAnalysis::Insert BuildId not set'; return false; } $id = ''; $idvalue = ''; if ($this->Id) { $id = 'id,'; $idvalue = qnum($this->Id) . ','; } // Handle log decoding/decompression if (strtolower($this->LogEncoding) == 'base64') { $this->Log = str_replace(array("\r\n", "\n", "\r"), '', $this->Log); $this->Log = base64_decode($this->Log); } if (strtolower($this->LogCompression) == 'gzip') { $this->Log = gzuncompress($this->Log); } if ($this->Log === false) { add_log('Unable to decompress dynamic analysis log', 'DynamicAnalysis::Insert', LOG_ERR, 0, $this->BuildId, CDASH_OBJECT_DYNAMICANALYSIS, $this->Id); $this->Log = ''; } $this->Status = pdo_real_escape_string($this->Status); $this->Checker = pdo_real_escape_string($this->Checker); $this->Name = pdo_real_escape_string($this->Name); $path = pdo_real_escape_string(substr($this->Path, 0, 255)); $fullCommandLine = pdo_real_escape_string(substr($this->FullCommandLine, 0, 255)); $this->Log = pdo_real_escape_string($this->Log); $this->BuildId = pdo_real_escape_string($this->BuildId); $query = 'INSERT INTO dynamicanalysis (' . $id . 'buildid,status,checker,name,path,fullcommandline,log) VALUES (' . $idvalue . qnum($this->BuildId) . ",'{$this->Status}','{$this->Checker}','{$this->Name}','" . $path . "',\n '" . $fullCommandLine . "','{$this->Log}')"; if (!pdo_query($query)) { add_last_sql_error('DynamicAnalysis Insert', 0, $this->BuildId); return false; } if (!$this->Id) { $this->Id = pdo_insert_id('dynamicanalysis'); } // Add the defects if (!empty($this->Defects)) { foreach ($this->Defects as $defect) { $defect->DynamicAnalysisId = $this->Id; $defect->Insert(); } } // Add the labels $this->InsertLabelAssociations(); return true; }
function register_user($projectid, $email, $firstName, $lastName, $repositoryCredential) { include dirname(__DIR__) . '/config/config.php'; $UserProject = new UserProject(); $UserProject->ProjectId = $projectid; // Check if the user is already registered $user = pdo_query('SELECT id FROM ' . qid('user') . " WHERE email='{$email}'"); if (pdo_num_rows($user) > 0) { // Check if the user has been registered to the project $user_array2 = pdo_fetch_array($user); $userid = $user_array2['id']; $user = pdo_query("SELECT userid FROM user2project WHERE userid='{$userid}' AND projectid='{$projectid}'"); if (pdo_num_rows($user) == 0) { // not registered // We register the user to the project pdo_query("INSERT INTO user2project (userid,projectid,role,emailtype)\n VALUES ('{$userid}','{$projectid}','0','1')"); // We add the credentials if not already added $UserProject->UserId = $userid; $UserProject->AddCredential($repositoryCredential); $UserProject->ProjectId = 0; $UserProject->AddCredential($email); // Add the email by default echo pdo_error(); return false; } return '<error>User ' . $email . ' already registered.</error>'; } // already registered // Check if the repositoryCredential exists for this project $UserProject->RepositoryCredential = $repositoryCredential; if ($UserProject->FillFromRepositoryCredential() === true) { return '<error>' . $repositoryCredential . ' was already registered for this project under a different email address</error>'; } // Register the user // Create a new password $keychars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $length = 10; $pass = ''; $max = strlen($keychars) - 1; for ($i = 0; $i <= $length; $i++) { // random_int is available in PHP 7 and the random_compat PHP 5.x // polyfill included in the Composer package.json dependencies. $pass .= substr($keychars, random_int(0, $max), 1); } $encrypted = md5($pass); pdo_query('INSERT INTO ' . qid('user') . " (email,password,firstname,lastname,institution,admin)\n VALUES ('{$email}','{$encrypted}','{$firstName}','{$lastName}','','0')"); add_last_sql_error('register_user'); $userid = pdo_insert_id('user'); // Insert the user into the project pdo_query("INSERT INTO user2project (userid,projectid,role,emailtype)\n VALUES ('{$userid}','{$projectid}','0','1')"); add_last_sql_error('register_user'); // We add the credentials if not already added $UserProject->UserId = $userid; $UserProject->AddCredential($repositoryCredential); $UserProject->ProjectId = 0; $UserProject->AddCredential($email); // Add the email by default $currentURI = get_server_URI(); $prefix = ''; if (strlen($firstName) > 0) { $prefix = ' '; } $project = pdo_query("SELECT name FROM project WHERE id='{$projectid}'"); $project_array = pdo_fetch_array($project); $projectname = $project_array['name']; // Send the email $text = 'Hello' . $prefix . $firstName . ",\n\n"; $text .= 'You have been registered to CDash because you have CVS/SVN access to the repository for ' . $projectname . "\n"; $text .= 'To access your CDash account: ' . $currentURI . "/user.php\n"; $text .= 'Your login is: ' . $email . "\n"; $text .= 'Your password is: ' . $pass . "\n\n"; $text .= 'Generated by CDash.'; if (cdashmail("{$email}", 'CDash - ' . $projectname . ' : Subscription', "{$text}")) { echo 'Email sent to: ' . $email . '<br>'; } else { add_log("cannot send email to: {$email}", 'register_user', LOG_ERR); } return true; }
/** Insert a new feed */ public function Insert($projectid, $buildid, $type, $description = '') { $this->ProjectId = $projectid; $this->BuildId = $buildid; $this->Type = $type; $this->Description = $description; $this->Date = gmdate(FMT_DATETIME); if (pdo_query("INSERT INTO feed (projectid,buildid,type,date,description)\n VALUES ('{$this->ProjectId}','{$this->BuildId}','{$this->Type}','{$this->Date}','{$this->Description}')")) { $this->Id = pdo_insert_id('feed'); } else { add_last_sql_error('Feed Insert'); return false; } // Delete the old feed (30 days) $this->DeleteOld($projectid, 30); }
$trights = array(); foreach ($type['right_list'] as $key => $value) { if ($value) { $trights[] = $key; } } $type['rights'] = implode(",", $trights); } else { $type['rights'] = ""; } if ($continue) { if (!$type_id) { $pars = array(':type_name' => $type['type_name'], ':rights' => $type['rights']); $query = "INSERT INTO " . table('admin_types') . " \n\t\t\t\t\tSET type_name= :type_name,\n\t\t\t\t\trights= :rights"; $done = or_query($query, $pars); $type_id = pdo_insert_id(); } else { $done = orsee_db_save_array($type, "admin_types", $type_id, "type_id"); } if ($done) { message(lang('changes_saved')); redirect("admin/admin_type_edit.php?type_id=" . $type_id); $proceed = false; } else { message(lang('database_error')); } } } } if ($proceed) { $rights = array();
public function AddBlockedBuild($buildname, $sitename, $ip) { $pdo = get_link_identifier()->getPdo(); $stmt = $pdo->prepare('INSERT INTO blockbuild (projectid,buildname,sitename,ipaddress) VALUES (:projectid, :buildname, :sitename, :ip)'); $stmt->bindParam(':projectid', $this->Id); $stmt->bindParam(':buildname', $buildname); $stmt->bindParam(':sitename', $sitename); $stmt->bindParam(':ip', $ip); $stmt->execute(); $blocked_id = pdo_insert_id('blockbuild'); return $blocked_id; }
/** Add CVS/SVN repositories */ function AddRepositories($repositories, $usernames, $passwords, $branches) { // First we update/delete any registered repositories $currentRepository = 0; $repositories_query = pdo_query("SELECT repositoryid FROM project2repositories WHERE projectid=" . qnum($this->Id) . " ORDER BY repositoryid"); add_last_sql_error("Project AddRepositories", $this->Id); while ($repository_array = pdo_fetch_array($repositories_query)) { $repositoryid = $repository_array["repositoryid"]; if (!isset($repositories[$currentRepository]) || strlen($repositories[$currentRepository]) == 0) { $query = pdo_query("SELECT * FROM project2repositories WHERE repositoryid=" . qnum($repositoryid)); add_last_sql_error("Project AddRepositories", $this->Id); if (pdo_num_rows($query) == 1) { pdo_query("DELETE FROM repositories WHERE id='{$repositoryid}'"); add_last_sql_error("Project AddRepositories", $this->Id); } pdo_query("DELETE FROM project2repositories WHERE projectid=" . qnum($this->Id) . " AND repositoryid=" . qnum($repositoryid)); add_last_sql_error("Project AddRepositories", $this->Id); } else { // If the repository is not shared by any other project we update $count_query = pdo_query("SELECT count(*) as c FROM project2repositories WHERE repositoryid=" . qnum($repositoryid)); $count_array = pdo_fetch_array($count_query); if ($count_array['c'] == 1) { pdo_query("UPDATE repositories SET url='{$repositories[$currentRepository]}',\n username='******',\n password='******',\n branch='{$branches[$currentRepository]}'\n WHERE id=" . qnum($repositoryid)); add_last_sql_error("Project AddRepositories", $this->Id); } else { pdo_query("DELETE FROM project2repositories WHERE projectid=" . qnum($this->Id) . " AND repositoryid=" . qnum($repositoryid)); add_last_sql_error("Project AddRepositories", $this->Id); $repositories[] = $repositories[$currentRepository]; $usernames[] = $usernames[$currentRepository]; $passwords[] = $passwords[$currentRepository]; $branches[] = $branches[$currentRepository]; } } $currentRepository++; } // Then we add new repositories for ($i = $currentRepository; $i < count($repositories); $i++) { $url = $repositories[$i]; $username = $usernames[$i]; $password = $passwords[$i]; $branch = $branches[$i]; if (strlen($url) == 0) { continue; } // Insert into repositories if not any $repositories_query = pdo_query("SELECT id FROM repositories WHERE url='{$url}'"); if (pdo_num_rows($repositories_query) == 0) { pdo_query("INSERT INTO repositories (url, username, password, branch) VALUES ('{$url}', '{$username}', '{$password}','{$branch}')"); add_last_sql_error("Project AddRepositories", $this->Id); $repositoryid = pdo_insert_id("repositories"); } else { $repositories_array = pdo_fetch_array($repositories_query); $repositoryid = $repositories_array["id"]; } pdo_query("INSERT INTO project2repositories (projectid,repositoryid) VALUES (" . qnum($this->Id) . ",'{$repositoryid}')"); add_last_sql_error("Project AddRepositories", $this->Id); } // end add repository }
function register_user($projectid, $email, $firstName, $lastName, $repositoryCredential) { include "cdash/config.php"; $UserProject = new UserProject(); $UserProject->ProjectId = $projectid; // Check if the user is already registered $user = pdo_query("SELECT id FROM " . qid("user") . " WHERE email='{$email}'"); if (pdo_num_rows($user) > 0) { // Check if the user has been registered to the project $user_array2 = pdo_fetch_array($user); $userid = $user_array2["id"]; $user = pdo_query("SELECT userid FROM user2project WHERE userid='{$userid}' AND projectid='{$projectid}'"); if (pdo_num_rows($user) == 0) { // We register the user to the project pdo_query("INSERT INTO user2project (userid,projectid,role,emailtype)\n VALUES ('{$userid}','{$projectid}','0','1')"); // We add the credentials if not already added $UserProject->UserId = $userid; $UserProject->AddCredential($repositoryCredential); $UserProject->ProjectId = 0; $UserProject->AddCredential($email); // Add the email by default echo pdo_error(); return false; } return "<error>User " . $email . " already registered.</error>"; } // already registered // Check if the repositoryCredential exists for this project $UserProject->RepositoryCredential = $repositoryCredential; if ($UserProject->FillFromRepositoryCredential() === true) { return "<error>" . $repositoryCredential . " was already registered for this project under a different email address</error>"; } // Register the user // Create a new password $keychars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $length = 10; srand(make_seed_recoverpass()); $pass = ""; $max = strlen($keychars) - 1; for ($i = 0; $i <= $length; $i++) { $pass .= substr($keychars, rand(0, $max), 1); } $encrypted = md5($pass); pdo_query("INSERT INTO " . qid("user") . " (email,password,firstname,lastname,institution,admin)\n VALUES ('{$email}','{$encrypted}','{$firstName}','{$lastName}','','0')"); add_last_sql_error("register_user"); $userid = pdo_insert_id("user"); // Insert the user into the project pdo_query("INSERT INTO user2project (userid,projectid,role,emailtype)\n VALUES ('{$userid}','{$projectid}','0','1')"); add_last_sql_error("register_user"); // We add the credentials if not already added $UserProject->UserId = $userid; $UserProject->AddCredential($repositoryCredential); $UserProject->ProjectId = 0; $UserProject->AddCredential($email); // Add the email by default $currentURI = get_server_URI(); $prefix = ""; if (strlen($firstName) > 0) { $prefix = " "; } $project = pdo_query("SELECT name FROM project WHERE id='{$projectid}'"); $project_array = pdo_fetch_array($project); $projectname = $project_array['name']; // Send the email $text = "Hello" . $prefix . $firstName . ",<br><br>"; $text .= "You have been registered to CDash because you have CVS/SVN access to the repository for " . $projectname . " <br>"; $text .= "To access your CDash account: " . $currentURI . "/user.php<br>"; $text .= "Your login is: " . $email . "<br>"; $text .= "Your password is: " . $pass . "<br>"; $text .= "<br>Generated by CDash."; if (@cdashmail("{$email}", "CDash - " . $projectname . " : Subscription", "{$text}", "From: {$CDASH_EMAILADMIN}\nReply-To: no-reply\nContent-type: text/plain; charset=utf-8\nX-Mailer: PHP/" . phpversion() . "\nMIME-Version: 1.0\nContent-type: text/html; charset=UTF-8")) { echo "Email sent to: " . $email . "<br>"; } return true; }
public function Save() { // Assign it to the default group if necessary. if ($this->GroupId < 1) { $row = pdo_single_row_query('SELECT id from subprojectgroup WHERE projectid=' . qnum($this->ProjectId) . ' AND is_default=1'); if (!empty($row)) { $this->GroupId = $row['id']; } } // Check if the subproject already exists. if ($this->Exists()) { // Trim the name $this->Name = trim($this->Name); // Update the subproject $query = 'UPDATE subproject SET '; $query .= "name='" . $this->Name . "'"; $query .= ',projectid=' . qnum($this->ProjectId); $query .= ',groupid=' . qnum($this->GroupId); $query .= ",path='" . $this->Path . "'"; $query .= ' WHERE id=' . qnum($this->Id) . ''; if (!pdo_query($query)) { add_last_sql_error('SubProject Update'); return false; } } else { // insert the subproject $id = ''; $idvalue = ''; if ($this->Id) { $id = 'id,'; $idvalue = "'" . $this->Id . "',"; } // Trim the name $this->Name = trim($this->Name); // Double check that it's not already in the database. $select_query = "SELECT id FROM subproject WHERE name='{$this->Name}' AND\n projectid=" . qnum($this->ProjectId) . " AND\n endtime='1980-01-01 00:00:00'"; $result = pdo_query($select_query); if (!$result) { add_last_sql_error('SubProject Update'); return false; } if (pdo_num_rows($result) > 0) { $row = pdo_fetch_array($result); $this->Id = $row['id']; return true; } $starttime = gmdate(FMT_DATETIME); $endtime = '1980-01-01 00:00:00'; $insert_query = 'INSERT INTO subproject(' . $id . 'name,projectid,groupid,path,starttime,endtime) VALUES (' . $idvalue . "'{$this->Name}'," . qnum($this->ProjectId) . ',' . qnum($this->GroupId) . ",'{$this->Path}','{$starttime}','{$endtime}')"; if (!pdo_query($insert_query)) { $error = pdo_error(); // Check if the query failed due to a race condition during // parallel submission processing. $result = pdo_query($select_query); if (!$result || pdo_num_rows($result) == 0) { add_log("SQL error: {$error}", 'SubProject Create', LOG_ERR, $this->ProjectId); return false; } $row = pdo_fetch_array($result); $this->Id = $row['id']; } if ($this->Id < 1) { $this->Id = pdo_insert_id('subproject'); } } return true; }
/** Save the image */ public function Save($update = false) { // Get the data from the file if necessary $this->GetData(); $pdo = get_link_identifier()->getPdo(); if (!$this->Exists()) { $success = true; if ($this->Id) { $stmt = $pdo->prepare(' INSERT INTO image (id, img, extension, checksum) VALUES (:id, :img, :extension, :checksum)'); $stmt->bindParam(':id', $this->Id); $stmt->bindParam(':img', $this->Data, PDO::PARAM_LOB); $stmt->bindParam(':extension', $this->Extension); $stmt->bindParam(':checksum', $this->Checksum); $success = $stmt->execute(); } else { $stmt = $pdo->prepare(' INSERT INTO image (img, extension, checksum) VALUES (:img, :extension, :checksum)'); $stmt->bindParam(':img', $this->Data, PDO::PARAM_LOB); $stmt->bindParam(':extension', $this->Extension); $stmt->bindParam(':checksum', $this->Checksum); $success = $stmt->execute(); $this->Id = pdo_insert_id('image'); } if (!$success) { add_last_sql_error('Image::Save'); return false; } } elseif ($update) { // Update the current image. $stmt = $pdo->prepare('UPDATE image SET img=:img, extension=:extension, checksum=:checksum WHERE id=:id'); $stmt->bindParam(':img', $this->Data, PDO::PARAM_LOB); $stmt->bindParam(':extension', $this->Extension); $stmt->bindParam(':checksum', $this->Checksum); $stmt->bindParam(':id', $this->Id); if (!$stmt->execute()) { return false; } } return true; }
// Loop throught the projects $n = 0; $projects = pdo_query("SELECT id FROM project"); while ($project_array = pdo_fetch_array($projects)) { $projectid = $project_array["id"]; if (pdo_num_rows(pdo_query("SELECT projectid FROM buildgroup WHERE projectid='{$projectid}'")) == 0) { // Add the default groups pdo_query("INSERT INTO buildgroup(name,projectid,starttime,endtime,description)\n VALUES ('Nightly','{$projectid}','1980-01-01 00:00:00','1980-01-01 00:00:00','Nightly Builds')"); $id = pdo_insert_id("buildgroup"); pdo_query("INSERT INTO buildgroupposition(buildgroupid,position,starttime,endtime)\n VALUES ('{$id}','1','1980-01-01 00:00:00','1980-01-01 00:00:00')"); echo pdo_error(); pdo_query("INSERT INTO buildgroup(name,projectid,starttime,endtime,description)\n VALUES ('Continuous','{$projectid}','1980-01-01 00:00:00','1980-01-01 00:00:00','Continuous Builds')"); $id = pdo_insert_id("buildgroup"); pdo_query("INSERT INTO buildgroupposition(buildgroupid,position,starttime,endtime)\n VALUES ('{$id}','2','1980-01-01 00:00:00','1980-01-01 00:00:00')"); pdo_query("INSERT INTO buildgroup(name,projectid,starttime,endtime,description)\n VALUES ('Experimental','{$projectid}','1980-01-01 00:00:00','1980-01-01 00:00:00','Experimental Builds')"); $id = pdo_insert_id("buildgroup"); pdo_query("INSERT INTO buildgroupposition(buildgroupid,position,starttime,endtime)\n VALUES ('{$id}','3','1980-01-01 00:00:00','1980-01-01 00:00:00')"); $n++; } } $xml .= add_XML_value("alert", $n . " projects have now default groups."); } else { if ($AssignBuildToDefaultGroups) { // Loop throught the builds $builds = pdo_query("SELECT id,type,projectid FROM build WHERE id NOT IN (SELECT buildid as id FROM build2group)"); while ($build_array = pdo_fetch_array($builds)) { $buildid = $build_array["id"]; $buildtype = $build_array["type"]; $projectid = $build_array["projectid"]; $buildgroup_array = pdo_fetch_array(pdo_query("SELECT id FROM buildgroup WHERE name='{$buildtype}' AND projectid='{$projectid}'")); $groupid = $buildgroup_array["id"];
/** Insert a new site */ function Insert() { $justSetIP = false; if (strlen($this->Ip) == 0) { $this->LookupIP(); $justSetIP = true; } if ($this->Exists()) { if ($justSetIP) { $this->Update(); } return $this->Id; } // Get the geolocation if (strlen($this->Latitude) == 0) { $location = get_geolocation($this->Ip); $this->Latitude = $location['latitude']; $this->Longitude = $location['longitude']; } if (pdo_query("INSERT INTO site (name,ip,latitude,longitude)\n VALUES ('{$this->Name}','{$this->Ip}','{$this->Latitude}','{$this->Longitude}')")) { $this->Id = pdo_insert_id("site"); } else { add_last_sql_error("Site Insert"); return false; } }
public function Insert() { if ($this->Exists()) { return true; } include 'config/config.php'; $command = pdo_real_escape_string($this->Command); $name = pdo_real_escape_string($this->Name); $path = pdo_real_escape_string($this->Path); $details = pdo_real_escape_string($this->Details); $id = ''; $idvalue = ''; if ($this->Id) { $id = 'id,'; $idvalue = "'" . $this->Id . "',"; } if ($this->CompressedOutput) { if ($CDASH_DB_TYPE == 'pgsql') { $output = $this->Output; } else { $output = base64_decode($this->Output); } } elseif ($CDASH_USE_COMPRESSION) { $output = gzcompress($this->Output); if ($output === false) { $output = $this->Output; } else { if ($CDASH_DB_TYPE == 'pgsql') { if (strlen($this->Output) < 2000) { // compression doesn't help for small chunk $output = $this->Output; } $output = base64_encode($output); } } } else { $output = $this->Output; } // We check for mysql that the if ($CDASH_DB_TYPE == '' || $CDASH_DB_TYPE == 'mysql') { $query = pdo_query("SHOW VARIABLES LIKE 'max_allowed_packet'"); $query_array = pdo_fetch_array($query); $max = $query_array[1]; if (strlen($this->Output) > $max) { add_log('Output is bigger than max_allowed_packet', 'Test::Insert', LOG_ERR, $this->ProjectId); // We cannot truncate the output because it is compressed (too complicated) } } $pdo = get_link_identifier()->getPdo(); if ($this->Id) { $stmt = $pdo->prepare(' INSERT INTO test (id, projectid, crc32, name, path, command, details, output) VALUES (:id, :projectid, :crc32, :name, :path, :command, :details, :output)'); $stmt->bindParam(':id', $this->Id); $stmt->bindParam(':projectid', $this->ProjectId); $stmt->bindParam(':crc32', $this->Crc32); $stmt->bindParam(':name', $name); $stmt->bindParam(':path', $path); $stmt->bindParam(':command', $command); $stmt->bindParam(':details', $details); $stmt->bindParam(':output', $output, PDO::PARAM_LOB); $success = $stmt->execute(); } else { $stmt = $pdo->prepare(' INSERT INTO test (projectid, crc32, name, path, command, details, output) VALUES (:projectid, :crc32, :name, :path, :command, :details, :output)'); $stmt->bindParam(':projectid', $this->ProjectId); $stmt->bindParam(':crc32', $this->Crc32); $stmt->bindParam(':name', $name); $stmt->bindParam(':path', $path); $stmt->bindParam(':command', $command); $stmt->bindParam(':details', $details); $stmt->bindParam(':output', $output, PDO::PARAM_LOB); $success = $stmt->execute(); $this->Id = pdo_insert_id('test'); } if (!$success) { add_last_sql_error("Cannot insert test: {$name} into the database", $this->ProjectId); return false; } // Add the measurements foreach ($this->Measurements as $measurement) { $measurement->TestId = $this->Id; $measurement->Insert(); } // Add the images foreach ($this->Images as $image) { // Decode the data $imgStr = base64_decode($image->Data); $img = imagecreatefromstring($imgStr); ob_start(); switch ($image->Extension) { case 'image/jpg': imagejpeg($img); break; case 'image/jpeg': imagejpeg($img); break; case 'image/gif': imagegif($img); break; case 'image/png': imagepng($img); break; default: echo "Unknown image type: {$type}"; return; } $imageVariable = ob_get_contents(); ob_end_clean(); $image->Data = $imageVariable; $image->Checksum = crc32($imageVariable); $image->Save(); $testImage = new TestImage(); $testImage->Id = $image->Id; $testImage->TestId = $this->Id; $testImage->Role = $image->Name; $testImage->Insert(); } return true; }
function Save() { if (empty($this->Admin)) { $this->Admin = 0; } // Check if the user exists already if ($this->Exists()) { // Update the project $query = "UPDATE " . qid("user") . " SET"; $query .= " email='" . $this->Email . "'"; $query .= ",password='******'"; $query .= ",firstname='" . $this->FirstName . "'"; $query .= ",lastname='" . $this->LastName . "'"; $query .= ",institution='" . $this->Institution . "'"; $query .= ",admin='" . $this->Admin . "'"; $query .= " WHERE id='" . $this->Id . "'"; if (!pdo_query($query)) { add_last_sql_error("User Update"); return false; } } else { $id = ""; $idvalue = ""; if ($this->Id) { $id = "id,"; $idvalue = "'" . $this->Id . "',"; } $email = pdo_real_escape_string($this->Email); $passwd = pdo_real_escape_string($this->Password); $fname = pdo_real_escape_string($this->FirstName); $lname = pdo_real_escape_string($this->LastName); $institution = pdo_real_escape_string($this->Institution); $query = "INSERT INTO " . qid("user") . " (" . $id . "email,password,firstname,lastname,institution,admin)\n VALUES (" . $idvalue . "'" . $email . "','" . $passwd . "','" . $fname . "','" . $lname . "','" . $institution . "','{$this->Admin}')"; if (!pdo_query($query)) { add_last_sql_error("User Create"); return false; } if (!$this->Id) { $this->Id = pdo_insert_id("user"); } } return true; }
/** Save a site */ function Save() { // Check if the name or system already exists $query = pdo_query("SELECT id FROM client_site WHERE name='" . $this->Name . "' AND systemname='" . $this->SystemName . "'"); if (pdo_num_rows($query) == 0) { $sql = "INSERT INTO client_site (name,osid,systemname,host,basedirectory)\n VALUES ('" . $this->Name . "','" . $this->OsId . "','" . $this->SystemName . "','" . $this->Host . "','" . $this->BaseDirectory . "')"; pdo_query($sql); $this->Id = pdo_insert_id('client_site'); add_last_sql_error("clientSite::Save()"); } else { $query_array = pdo_fetch_array($query); $this->Id = $query_array['id']; $sql = "UPDATE client_site SET osid='" . $this->OsId . "',host='" . $this->Host . "',basedirectory='" . $this->BaseDirectory . "' WHERE id=" . qnum($this->Id); pdo_query($sql); add_last_sql_error("clientSite::Save()"); } }
function Save() { if ($this->Name == "" || $this->ProjectId == 0) { add_log("Name='" . $this->Name . "' or ProjectId='" . $this->ProjectId . "' not set", "SubProjectGroup::Save", LOG_WARNING); return false; } // Load the default coverage threshold for this project if one // hasn't been set for this group. if (!isset($this->CoverageThreshold)) { $row = pdo_single_row_query("SELECT coveragethreshold FROM project\n WHERE id=" . qnum($this->ProjectId)); if (empty($row)) { return false; } $this->CoverageThreshold = $row['coveragethreshold']; } // Force is_default=1 if this will be the first subproject group // for this project. $query = pdo_query("SELECT COUNT(*) FROM subprojectgroup\n WHERE projectid=" . qnum($this->ProjectId)); if (!$query) { add_last_sql_error("SubProjectGroup::Save Count"); return false; } $query_array = pdo_fetch_array($query); if ($query_array[0] == 0) { $this->IsDefault = 1; } // Check if the group already exists. if ($this->Exists()) { // Trim the name $this->Name = trim($this->Name); // Update the group $query = "UPDATE subprojectgroup SET\n name='{$this->Name}',\n projectid=" . qnum($this->ProjectId) . ",\n is_default=" . qnum($this->IsDefault) . ",\n coveragethreshold=" . qnum($this->CoverageThreshold) . "\n WHERE id=" . qnum($this->Id); if (!pdo_query($query)) { add_last_sql_error("SubProjectGroup::Save Update"); return false; } } else { $id = ""; $idvalue = ""; if ($this->Id) { $id = "id,"; $idvalue = "'" . $this->Id . "',"; } // Trim the name $this->Name = trim($this->Name); // Double check that it's not already in the database. $query = pdo_query("SELECT id FROM subprojectgroup WHERE name='{$this->Name}'\n AND projectid=" . qnum($this->ProjectId) . "\n AND endtime='1980-01-01 00:00:00'"); if (!$query) { add_last_sql_error("SubProjectGroup::Save Select"); return false; } if (pdo_num_rows($query) > 0) { $query_array = pdo_fetch_array($query); $this->Id = $query_array['id']; return true; } $starttime = gmdate(FMT_DATETIME); $endtime = "1980-01-01 00:00:00"; $query = "INSERT INTO subprojectgroup(" . $id . "name,projectid,is_default,\n coveragethreshold,starttime,endtime)\n VALUES (" . $idvalue . "'{$this->Name}'," . qnum($this->ProjectId) . "," . qnum($this->IsDefault) . "," . qnum($this->CoverageThreshold) . ",\n '{$starttime}','{$endtime}')"; if (!pdo_query($query)) { add_last_sql_error("SubProjectGroup::Save Insert"); return false; } if ($this->Id < 1) { $this->Id = pdo_insert_id("subprojectgroup"); } } // Make sure there's only one default group per project. if ($this->IsDefault) { $query = "UPDATE subprojectgroup SET is_default=0\n WHERE projectid=" . qnum($this->ProjectId) . " AND id!=" . qnum($this->Id); if (!pdo_query($query)) { add_last_sql_error("SubProjectGroup Update Default"); return false; } } return true; }
/** Save */ function Save() { // Check if the name/version already exists $query = pdo_query("SELECT id FROM client_library WHERE name='" . $this->Name . "' AND version='" . $this->Version . "'"); if (pdo_num_rows($query) == 0) { $sql = "INSERT INTO client_library (name,version)\n VALUES ('" . $this->Name . "','" . $this->Version . "')"; pdo_query($sql); $this->Id = pdo_insert_id('client_library'); add_last_sql_error("ClientLibrary::Save()"); } else { $query_array = pdo_fetch_array($query); $this->Id = $query_array['id']; $sql = "UPDATE client_library SET version='" . $this->Version . "' WHERE id=" . qnum($this->Id); pdo_query($sql); add_last_sql_error("ClientLibrary::Save()"); } // Insert into the siteid $query = pdo_query("SELECT libraryid FROM client_site2library WHERE libraryid=" . qnum($this->Id) . " AND siteid=" . qnum($this->SiteId)); if (pdo_num_rows($query) == 0) { $sql = "INSERT INTO client_site2library (siteid,libraryid,path,include)\n VALUES (" . qnum($this->SiteId) . "," . qnum($this->Id) . ",'" . $this->Path . "','" . $this->Include . "')"; pdo_query($sql); add_last_sql_error("ClientLibrary::Save()"); } else { $sql = "UPDATE client_site2library SET path='" . $this->Path . "',include='" . $this->Include . "' WHERE libraryid=" . qnum($this->Id) . " AND siteid=" . qnum($this->SiteId); pdo_query($sql); add_last_sql_error("ClientLibrary::Save()"); } }
/** Save a job schedule */ public function Save() { $cmakecache = pdo_real_escape_string($this->CMakeCache); $clientscript = pdo_real_escape_string($this->ClientScript); $description = pdo_real_escape_string($this->Description); if (!$this->Id) { $sql = "INSERT INTO client_jobschedule (userid,projectid,startdate,enddate,starttime,enable,type,\n repeattime,cmakecache,clientscript,repository,module,buildnamesuffix,\n tag,buildconfiguration,description)\n VALUES ('" . $this->UserId . "','" . $this->ProjectId . "','" . $this->StartDate . "','" . $this->EndDate . "','" . $this->StartTime . "','" . $this->Enable . "','" . $this->Type . "','" . $this->RepeatTime . "','" . $cmakecache . "','" . $clientscript . "','" . $this->Repository . "','" . $this->Module . "','" . $this->BuildNameSuffix . "','" . $this->Tag . "','" . $this->BuildConfiguration . "','" . $description . "')"; pdo_query($sql); add_last_sql_error('ClientJobSchedule::Save'); $this->Id = pdo_insert_id('client_jobschedule'); add_last_sql_error('ClientJobSchedule::Save'); } else { // update $sql = "UPDATE client_jobschedule SET\n startdate='" . $this->StartDate . "',\n enddate='" . $this->EndDate . "',\n starttime='" . $this->StartTime . "',\n repeattime='" . $this->RepeatTime . "',\n cmakecache='" . $cmakecache . "',\n clientscript='" . $clientscript . "',\n repository='" . $this->Repository . "',\n module='" . $this->Module . "',\n buildnamesuffix='" . $this->BuildNameSuffix . "',\n buildconfiguration='" . $this->BuildConfiguration . "',\n tag='" . $this->Tag . "',\n description='" . $description . "',\n enable='" . $this->Enable . "',\n type='" . $this->Type . "' WHERE id=" . qnum($this->Id); pdo_query($sql); add_last_sql_error('ClientJobSchedule::Save'); } }