33 * PROJECT: ReactOS Testman
44 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
55 * PURPOSE: Class for submitting WineTest results
6- * COPYRIGHT: Copyright 2008-2017 Colin Finck (colin@reactos.org)
6+ * COPYRIGHT: Copyright 2008-2025 Colin Finck (colin@reactos.org)
77 * Copyright 2012-2013 Kamil Hornicek (kamil.hornicek@reactos.org)
88 */
99
@@ -22,27 +22,27 @@ public function __construct($source_id, $password)
2222
2323 // Check the login credentials
2424 $ stmt = $ this ->_dbh ->prepare ("SELECT COUNT(*) FROM sources WHERE id = :sourceid AND password = MD5(:password) " );
25- $ stmt ->bindParam (":sourceid " , $ source_id );
25+ $ stmt ->bindValue (":sourceid " , ( int ) $ source_id, PDO :: PARAM_INT );
2626 $ stmt ->bindParam (":password " , $ password );
2727 $ stmt ->execute ();
2828 if (!$ stmt ->fetchColumn ())
2929 throw new ErrorMessageException ("Invalid Login credentials! " );
3030
3131 // Store the source_id for later.
32- $ this ->_source_id = $ source_id ;
32+ $ this ->_source_id = ( int ) $ source_id ;
3333 }
3434
3535 public function getTestId ($ revision , $ platform , $ comment )
3636 {
3737 // Add a new Test ID with the given information.
3838 $ stmt = $ this ->_dbh ->prepare ("INSERT INTO winetest_runs (source_id, revision, platform, comment) VALUES (:sourceid, :revision, :platform, :comment) " );
39- $ stmt ->bindParam (":sourceid " , $ this ->_source_id );
39+ $ stmt ->bindValue (":sourceid " , ( int ) $ this ->_source_id , PDO :: PARAM_INT );
4040 $ stmt ->bindParam (":revision " , $ revision );
4141 $ stmt ->bindParam (":platform " , $ platform );
4242 $ stmt ->bindParam (":comment " , $ comment );
4343 $ stmt ->execute ();
4444
45- return $ this ->_dbh ->lastInsertId ();
45+ return ( int ) $ this ->_dbh ->lastInsertId ();
4646 }
4747
4848 public function getSuiteId ($ module , $ test )
@@ -54,38 +54,71 @@ public function getSuiteId($module, $test)
5454 $ stmt ->execute ();
5555 $ id = $ stmt ->fetchColumn ();
5656 if ($ id )
57- return $ id ;
57+ return ( int ) $ id ;
5858
5959 // Add this combination to the table and return the ID for it.
6060 $ stmt = $ this ->_dbh ->prepare ("INSERT INTO winetest_suites (module, test) VALUES (:module, :test) " );
6161 $ stmt ->bindParam (":module " , $ module );
6262 $ stmt ->bindParam (":test " , $ test );
6363 $ stmt ->execute ();
6464
65- return $ this ->_dbh ->lastInsertId ();
65+ return (int )$ this ->_dbh ->lastInsertId ();
66+ }
67+
68+ public function getModuleAndTestForSuiteId ($ suite_id , &$ module , &$ test )
69+ {
70+ $ stmt = $ this ->_dbh ->prepare ("SELECT module, test FROM winetest_suites WHERE id = :id " );
71+ $ stmt ->bindValue (":id " , (int )$ suite_id , PDO ::PARAM_INT );
72+ $ stmt ->execute ();
73+
74+ if ($ row = $ stmt ->fetch (PDO ::FETCH_ASSOC ))
75+ {
76+ $ module = $ row ["module " ];
77+ $ test = $ row ["test " ];
78+ return true ;
79+ }
80+ else
81+ {
82+ return false ;
83+ }
6684 }
6785
6886 public function submit ($ test_id , $ suite_id , $ log )
6987 {
7088 // Make sure that we may add information to the test with this Test ID
7189 $ stmt = $ this ->_dbh ->prepare ("SELECT COUNT(*) FROM winetest_runs WHERE id = :testid AND finished = 0 AND source_id = :sourceid " );
72- $ stmt ->bindParam (":testid " , $ test_id );
73- $ stmt ->bindParam (":sourceid " , $ this ->_source_id );
90+ $ stmt ->bindValue (":testid " , ( int ) $ test_id, PDO :: PARAM_INT );
91+ $ stmt ->bindValue (":sourceid " , ( int ) $ this ->_source_id , PDO :: PARAM_INT );
7492 $ stmt ->execute ();
7593 if (!$ stmt ->fetchColumn ())
76- throw new RuntimeException ("No such test or no permissions! " );
94+ {
95+ throw new RuntimeException ("Test ID {$ test_id } for Source ID {$ this ->_source_id } could not be found or accessed in the database! " );
96+ }
7797
7898 // Make sure that this test run does not yet have a result for this test suite
7999 $ stmt = $ this ->_dbh ->prepare ("SELECT COUNT(*) FROM winetest_results WHERE test_id = :testid AND suite_id = :suiteid " );
80- $ stmt ->bindParam (":testid " , $ test_id );
81- $ stmt ->bindParam (":suiteid " , $ suite_id );
100+ $ stmt ->bindValue (":testid " , ( int ) $ test_id, PDO :: PARAM_INT );
101+ $ stmt ->bindValue (":suiteid " , ( int ) $ suite_id, PDO :: PARAM_INT );
82102 $ stmt ->execute ();
83- if ($ stmt ->fetchColumn ())
84- throw new RuntimeException ("We already have a result for this test suite in this test run! " );
103+
104+ if ($ stmt ->fetchColumn () > 0 )
105+ {
106+ $ module = "" ;
107+ $ test = "" ;
108+
109+ if ($ this ->getModuleAndTestForSuiteId ($ suite_id , $ module , $ test ))
110+ {
111+ throw new RuntimeException ("Duplicate result for test suite {$ module }: {$ test } in this test run! " );
112+ }
113+ else
114+ {
115+ throw new RuntimeException ("Duplicate result for this test suite in this test run, and couldn't fetch the test suite! " );
116+ }
117+ }
85118
86119 // Get the test name
87120 $ stmt = $ this ->_dbh ->prepare ("SELECT test FROM winetest_suites WHERE id = :id " );
88- $ stmt ->bindParam (":id " , $ suite_id );
121+ $ stmt ->bindValue (":id " , ( int ) $ suite_id, PDO :: PARAM_INT );
89122 $ stmt ->execute ();
90123 $ test = $ stmt ->fetchColumn ();
91124
@@ -137,18 +170,18 @@ public function submit($test_id, $suite_id, $log)
137170
138171 // Add the information into the DB.
139172 $ stmt = $ this ->_dbh ->prepare ("INSERT INTO winetest_results (test_id, suite_id, status, count, failures, skipped, todo, time) VALUES (:testid, :suiteid, :status, :count, :failures, :skipped, :todo, :time) " );
140- $ stmt ->bindValue (":testid " , (int )$ test_id );
141- $ stmt ->bindValue (":suiteid " , (int )$ suite_id );
173+ $ stmt ->bindValue (":testid " , (int )$ test_id, PDO :: PARAM_INT );
174+ $ stmt ->bindValue (":suiteid " , (int )$ suite_id, PDO :: PARAM_INT );
142175 $ stmt ->bindParam (":status " , $ status );
143- $ stmt ->bindParam (":count " , $ count );
144- $ stmt ->bindParam (":failures " , $ failures );
145- $ stmt ->bindParam (":skipped " , $ skipped );
146- $ stmt ->bindParam (":todo " , $ todo );
176+ $ stmt ->bindValue (":count " , ( int ) $ count, PDO :: PARAM_INT );
177+ $ stmt ->bindValue (":failures " , ( int ) $ failures, PDO :: PARAM_INT );
178+ $ stmt ->bindValue (":skipped " , ( int ) $ skipped, PDO :: PARAM_INT );
179+ $ stmt ->bindValue (":todo " , ( int ) $ todo, PDO :: PARAM_INT );
147180 $ stmt ->bindParam (":time " , $ time );
148181 $ stmt ->execute ();
149182
150183 $ stmt = $ this ->_dbh ->prepare ("INSERT INTO winetest_logs (id, log) VALUES (:id, COMPRESS(:log)) " );
151- $ stmt ->bindValue (":id " , (int )$ this ->_dbh ->lastInsertId ());
184+ $ stmt ->bindValue (":id " , (int )$ this ->_dbh ->lastInsertId (), PDO :: PARAM_INT );
152185 $ stmt ->bindParam (":log " , $ log );
153186 $ stmt ->execute ();
154187 }
@@ -170,13 +203,13 @@ public function finish($test_id, $performance)
170203 time = :time
171204 WHERE id = :testid AND source_id = :sourceid "
172205 );
173- $ stmt ->bindParam (":sourceid " , $ this ->_source_id );
174- $ stmt ->bindParam (":testid " , $ test_id );
175- $ stmt ->bindParam (":boot_cycles " , $ performance ["boot_cycles " ]);
176- $ stmt ->bindParam (":context_switches " , $ performance ["context_switches " ]);
177- $ stmt ->bindParam (":interrupts " , $ performance ["interrupts " ]);
178- $ stmt ->bindParam (":reboots " , $ performance ["reboots " ]);
179- $ stmt ->bindParam (":system_calls " , $ performance ["system_calls " ]);
206+ $ stmt ->bindValue (":sourceid " , ( int ) $ this ->_source_id , PDO :: PARAM_INT );
207+ $ stmt ->bindValue (":testid " , ( int ) $ test_id, PDO :: PARAM_INT );
208+ $ stmt ->bindValue (":boot_cycles " , ( int ) $ performance ["boot_cycles " ], PDO :: PARAM_INT );
209+ $ stmt ->bindValue (":context_switches " , ( int ) $ performance ["context_switches " ], PDO :: PARAM_INT );
210+ $ stmt ->bindValue (":interrupts " , ( int ) $ performance ["interrupts " ], PDO :: PARAM_INT );
211+ $ stmt ->bindValue (":reboots " , ( int ) $ performance ["reboots " ], PDO :: PARAM_INT );
212+ $ stmt ->bindValue (":system_calls " , ( int ) $ performance ["system_calls " ], PDO :: PARAM_INT );
180213 $ stmt ->bindParam (":time " , $ performance ["time " ]);
181214 $ stmt ->execute ();
182215 if (!$ stmt ->rowCount ())
0 commit comments