Changeset 1929
- Timestamp:
- 4/16/2010 2:16:44 PM (3 years ago)
- File:
-
- 1 edited
-
trunk/website/scripts/blackbox/upload.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/website/scripts/blackbox/upload.php
r1672 r1929 4 4 5 5 ob_start(); 6 require('../ database.php');6 require('../Database.php'); 7 7 8 8 function GetFunctionNameFromStackTrace($line) … … 23 23 //Check that a similar stack trace hasn't been uploaded. 24 24 $status = 'exists'; 25 $pdo = new Database(); 25 26 foreach ($stackTrace as $exceptionDepth => $exception) 26 27 { … … 36 37 37 38 $stackFrames .= sprintf('(StackFrameIndex=%d AND Function=\'%s\') OR ', 38 $stackIndex, mysql_real_escape_string(GetFunctionNameFromStackTrace($stackFrame)));39 $stackIndex, $pdo->quote(GetFunctionNameFromStackTrace($stackFrame))); 39 40 } 40 41 … … 43 44 44 45 //Query for the list of exceptions containing the given functions 45 $ query = mysql_query(sprintf('SELECT DISTINCT(BlackBox_Exceptions.ID) FROM BlackBox_StackFrames46 $statement = $pdo->query(sprintf('SELECT DISTINCT(BlackBox_Exceptions.ID) FROM BlackBox_StackFrames 46 47 INNER JOIN BlackBox_Exceptions ON BlackBox_StackFrames.ExceptionID=BlackBox_Exceptions.ID 47 WHERE (%s) AND ExceptionDepth=%d AND ExceptionType=\'%s\'', 48 substr($stackFrames, 0, strlen($stackFrames) - 4), $exceptionDepth, 49 mysql_real_escape_string($exception['exception']))); 50 51 if (mysql_num_rows($query) == 0) 48 WHERE (%s) AND ExceptionDepth=? AND ExceptionType=?', 49 substr($stackFrames, 0, strlen($stackFrames) - 4))); 50 $statement->bindParam(1, $exceptionDepth); 51 $statement->bindParam(2, $exception['exception']); 52 $statement->execute(); 53 54 if ($statement->rowCount() == 0) 52 55 $status = 'new'; 53 56 } … … 60 63 function Upload($stackTrace, $crashReport) 61 64 { 62 mysql_query('BEGIN TRANSACTION'); 63 mysql_query(sprintf('INSERT INTO BlackBox_Reports SET IPAddress=%u', ip2long($_SERVER['REMOTE_ADDR']))); 64 if (mysql_affected_rows() != 1) 65 throw new Exception('Could not insert crash report into Reports table: ' . mysql_error()); 65 $pdo = new Database(); 66 $pdo->beginTransaction(); 66 67 67 $reportId = mysql_insert_id(); 68 $statement = $pdo->prepare('INSERT INTO BlackBox_Reports SET IPAddress=?'); 69 $statement->bindParam(1, sprintf('%u', ip2long($_SERVER['REMOTE_ADDR']))); 70 try 71 { 72 $statement->execute(); 73 } 74 catch (PDOException $e) 75 { 76 throw new Exception('Could not insert crash report into Reports table', null, $e); 77 } 78 79 $reportId = $pdo->lastInsertId(); 80 $exceptionInsert = $pdo->prepare('INSERT INTO BlackBox_Exceptions 81 SET ReportID=?, ExceptionType=?, ExceptionDepth=?'); 82 $exceptionInsert->bindParam(1, $reportId); 83 $stackFrameInsert = $pdo->prepare('INSERT INTO BlackBox_StackFrames SET 84 ExceptionID=?, StackFrameIndex=?, Function=?, File=?, Line=?'); 68 85 foreach ($stackTrace as $exceptionDepth => $exception) 69 86 { 70 mysql_query(sprintf('INSERT INTO BlackBox_Exceptions SET ReportID=%d, ExceptionType=\'%s\', ExceptionDepth=%d', 71 $reportId, mysql_real_escape_string($exception['exception']), $exceptionDepth)); 72 if (mysql_affected_rows() != 1) 73 throw new Exception('Could not insert exception into Exceptions table: ' . mysql_error()); 74 75 $exceptionId = mysql_insert_id(); 87 $exceptionInsert->bindParam(2, $exception['exception']); 88 $exceptionInsert->bindParam(3, $exceptionDepth); 89 try 90 { 91 $exceptionInsert->execute(); 92 } 93 catch (PDOException $e) 94 { 95 throw new Exception('Could not insert exception into Exceptions table', null, $e); 96 } 97 98 $exceptionId = $pdo->lastInsertId(); 76 99 foreach ($exception as $stackIndex => $stackFrame) 77 100 { … … 93 116 $function = $matches[2]; 94 117 } 95 96 mysql_query(sprintf('INSERT INTO BlackBox_StackFrames SET 97 ExceptionID=%d, StackFrameIndex=%d, Function=\'%s\', File=%s, Line=%s', 98 $exceptionId, $stackIndex, mysql_real_escape_string($function), 99 empty($file) ? 'null' : sprintf('\'%s\'', mysql_real_escape_string($file)), 100 $line == null ? 'null' : intval($line))); 101 102 if (mysql_affected_rows() != 1) 103 throw new Exception('Could not insert stack frame into Stack Frames table: ' . mysql_error()); 118 119 $stackFrameInsert->bindParam(1, $exceptionId); 120 $stackFrameInsert->bindParam(2, $stackIndex); 121 $stackFrameInsert->bindParam(3, $function); 122 $stackFrameInsert->bindParam(4, $file); 123 $stackFrameInsert->bindParam(5, $line); 124 try 125 { 126 $stackFrameInsert->execute(); 127 } 128 catch (PDOException $e) 129 { 130 throw new Exception('Could not insert stack frame into Stack Frames table', null, $e); 131 } 104 132 } 105 133 } 106 134 107 mysql_query('COMMIT');108 135 $pdo->commit(); 136 109 137 //Move the temporary file to out dumps folder for later inspection 110 138 if (!move_uploaded_file($crashReport['tmp_name'], 'dumps/' . $reportId . '.tbz'))
Note: See TracChangeset
for help on using the changeset viewer.
