1<?php 2/*========================================================================= 3 4 Program: CDash - Cross-Platform Dashboard System 5 Module: $Id$ 6 Language: PHP 7 Date: $Date$ 8 Version: $Revision$ 9 10 Copyright (c) 2002 Kitware, Inc. All rights reserved. 11 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details. 12 13 This software is distributed WITHOUT ANY WARRANTY; without even 14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 PURPOSE. See the above copyright notices for more information. 16 17=========================================================================*/ 18include_once('models/label.php'); 19 20/** BuildFailure */ 21class BuildFailure 22{ 23 var $BuildId; 24 var $Type; 25 var $WorkingDirectory; 26 var $Arguments; 27 var $StdOutput; 28 var $StdError; 29 var $ExitCondition; 30 var $Language; 31 var $TargetName; 32 var $SourceFile; 33 var $OutputFile; 34 var $OutputType; 35 var $Labels; 36 37 function __construct() 38 { 39 $this->Arguments = array(); 40 } 41 42 function AddLabel($label) 43 { 44 if(!isset($this->Labels)) 45 { 46 $this->Labels = array(); 47 } 48 49 $this->Labels[] = $label; 50 } 51 52 53 // Add an argument to the buildfailure 54 function AddArgument($argument) 55 { 56 $this->Arguments[] = $argument; 57 } 58 59 60 function InsertLabelAssociations($id) 61 { 62 if(empty($this->Labels)) 63 { 64 return; 65 } 66 67 if($id) 68 { 69 foreach($this->Labels as $label) 70 { 71 $label->BuildFailureId = $id; 72 $label->Insert(); 73 } 74 } 75 else 76 { 77 add_log('No BuildFailure id - cannot call $label->Insert...', 78 'BuildFailure::InsertLabelAssociations',LOG_ERR,0,$this->BuildId); 79 } 80 } 81 82 // Insert in the database (no update possible) 83 function Insert() 84 { 85 if(!$this->BuildId) 86 { 87 echo "BuildFailure::Insert(): BuildId not set<br>"; 88 return false; 89 } 90 91 $workingDirectory = pdo_real_escape_string($this->WorkingDirectory); 92 $stdOutput = pdo_real_escape_string($this->StdOutput); 93 $stdError = pdo_real_escape_string($this->StdError); 94 $exitCondition = pdo_real_escape_string($this->ExitCondition); 95 $language = pdo_real_escape_string($this->Language); 96 $targetName = pdo_real_escape_string($this->TargetName); 97 $outputFile = pdo_real_escape_string($this->OutputFile); 98 $outputType = pdo_real_escape_string($this->OutputType); 99 $sourceFile = pdo_real_escape_string($this->SourceFile); 100 101 // Compute the crc32 102 $crc32 = crc32($outputFile.$stdOutput.$stdError.$sourceFile); 103 $query = "INSERT INTO buildfailure (buildid,type,workingdirectory,stdoutput,stderror,exitcondition, 104 language,targetname,outputfile,outputtype,sourcefile,newstatus,crc32) 105 VALUES (".qnum($this->BuildId).",".qnum($this->Type).",'$workingDirectory', 106 '$stdOutput','$stdError',".qnum($exitCondition).", 107 '$language','$targetName','$outputFile','$outputType','$sourceFile',0,".qnum($crc32).")"; 108 if(!pdo_query($query)) 109 { 110 add_last_sql_error("BuildFailure Insert",0,$this->BuildId); 111 return false; 112 } 113 114 $id = pdo_insert_id("buildfailure"); 115 116 // Insert the arguments 117 $argumentids = array(); 118 119 foreach($this->Arguments as $argument) 120 { 121 // Limit the argument to 255 122 $argumentescaped = pdo_real_escape_string(substr($argument,0,255)); 123 124 // Check if the argument exists 125 $query = pdo_query("SELECT id FROM buildfailureargument WHERE argument='".$argumentescaped."'"); 126 if(!$query) 127 { 128 add_last_sql_error("BuildFailure Insert",0,$this->BuildId); 129 return false; 130 } 131 132 if(pdo_num_rows($query)>0) 133 { 134 $argumentarray = pdo_fetch_array($query); 135 $argumentids[] = $argumentarray['id']; 136 } 137 else // insert the argument 138 { 139 $query = "INSERT INTO buildfailureargument (argument) VALUES ('".$argumentescaped."')"; 140 if(!pdo_query($query)) 141 { 142 add_last_sql_error("BuildFailure Insert",0,$this->BuildId); 143 return false; 144 } 145 146 $argumentids[] = pdo_insert_id("buildfailure"); 147 } 148 } 149 150 // Insert the argument 151 $query = "INSERT INTO buildfailure2argument (buildfailureid,argumentid,place) VALUES "; 152 $i=0; 153 foreach($argumentids as $argumentid) 154 { 155 if($i>0) 156 { 157 $query .= ","; 158 } 159 $query .= "(".qnum($id).",".qnum($argumentid).",".qnum($i).")"; 160 $i++; 161 } 162 163 if(!pdo_query($query)) 164 { 165 add_last_sql_error("BuildFailure Insert",0,$this->BuildId); 166 return false; 167 } 168 169 $this->InsertLabelAssociations($id); 170 171 return true; 172 } // end insert 173} 174?> 175