-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for custom errorMsg in Action::setError + minor changes
- Adding support in Action to set a custom error info message. Also moving array creation from getError to setError. - More mysql_queryf to Database class converting - Remove "signup" specific error code "account-already-exists", using "invalid-input" instead with a custom error message - Remove 'password' column from the SELECT query in the "duplicate username" check of SignupAction, is not needed or used. - Resolve issue #118 Remove normalization calls in LoginAction and other places. Implement pattern requirement in SignupAction. - Using $db->getRow instead of $row assignment inside `if` statements. - Replace `/>` with `>` in HTML Replace ` >` with `>` in HTML - Fix bug in actions/wiperun.php where it redirects to job/"" $jobID isn't always set. - JobPage: Remove bogus $request->getSessionData PHP Notice: Undefined property: WebRequest::$getSessionData in /Users/krinkle/Sites/github/jquery-testswarm/inc/pages/JobPage.php on line 65 - UserPage: Put username in subtitle and set title to "User" - RunresultsPage: Add additional if statement to termine that the query returned a row, and provide a fallback. Else it would output the gzip header without echoing gezipped content resulting in a browser failure: Error 330 (net::ERR_CONTENT_DECODING_FAILED): Unknown error. Also moved override down to Page::execute instead of Page::output so that the try catch is still preserved so that a nice 500 page can be generated if things go wrong also added a basic title and html output in case row doesn't exist (anymore). - ScoresPage: Branch logic off into ScoresAction
- Loading branch information
Showing
14 changed files
with
296 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* "Scores" action. | ||
* | ||
* @since 0.1.0 | ||
* @package TestSwarm | ||
*/ | ||
|
||
class ScoresAction extends Action { | ||
|
||
public function doAction() { | ||
$db = $this->getContext()->getDB(); | ||
|
||
$rows = $db->getRows( | ||
"SELECT | ||
users.name as user_name, | ||
SUM(total) as score | ||
FROM | ||
clients, run_client, users | ||
WHERE clients.id = run_client.client_id | ||
AND clients.user_id = users.id | ||
GROUP BY user_id | ||
HAVING score > 0 | ||
ORDER by score DESC;" | ||
); | ||
|
||
$scores = array(); | ||
foreach ( $rows as $pos => $row ) { | ||
$scores[] = array( | ||
"position" => intval( $pos + 1 ), // Array is 0 based | ||
"userName" => $row->user_name, | ||
"score" => intval( $row->score ) | ||
); | ||
} | ||
|
||
$this->setData( $scores ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,80 @@ | ||
<?php | ||
$run_id = preg_replace("/[^0-9]/", "", $_POST["run_id"]); | ||
$client_id = preg_replace("/[^0-9]/", "", $_POST["client_id"]); | ||
$request = $swarmContext->getRequest(); | ||
|
||
$wipedRun = false; | ||
$jobID = false; | ||
|
||
if ( $request->wasPosted() ) { | ||
|
||
$run_id = $request->getInt( "run_id" ); | ||
$client_id = $request->getInt( "client_id" ); | ||
|
||
if ( $run_id && $client_id && $request->getSessionData( "username" ) && $request->getSessionData( "auth" ) === "yes" ) { | ||
|
||
$results = mysql_queryf( | ||
"SELECT | ||
jobs.id as job_id | ||
FROM | ||
users, jobs, runs | ||
WHERE users.name=%s | ||
AND jobs.user_id=users.id | ||
AND runs.id=%u | ||
AND runs.job_id=jobs.id;", | ||
$request->getSessionData( "username" ), | ||
$run_id | ||
); | ||
$row = mysql_fetch_row($results); | ||
|
||
if ( $run_id && $client_id && $_SESSION["username"] && $_SESSION["auth"] == "yes" ) { | ||
|
||
$results = mysql_queryf( | ||
"SELECT | ||
jobs.id | ||
FROM | ||
users, jobs, runs | ||
WHERE users.name=%s | ||
AND jobs.user_id=users.id | ||
AND runs.id=%u | ||
AND runs.job_id=jobs.id;", | ||
$_SESSION["username"], | ||
$run_id | ||
); | ||
|
||
if ( $row = mysql_fetch_row($results) ) { | ||
$job_id = $row[0]; | ||
|
||
$results = mysql_queryf( "SELECT useragent_id FROM clients WHERE id=%u;", $client_id ); | ||
|
||
if ( $row = mysql_fetch_row($results) ) { | ||
$useragent_id = $row[0]; | ||
|
||
mysql_queryf( | ||
"DELETE run_client FROM run_client,clients WHERE run_id=%u AND clients.id=client_id AND clients.useragent_id=%u;", | ||
$run_id, | ||
$useragent_id | ||
); | ||
mysql_queryf( | ||
"UPDATE run_useragent SET status=0, runs=0, completed=0, updated=%s WHERE run_id=%u AND useragent_id=%u;", | ||
swarmdb_dateformat( SWARM_NOW ), | ||
$run_id, | ||
$useragent_id | ||
); | ||
mysql_queryf( | ||
"UPDATE runs SET status=1, updated=%s WHERE id=%u;", | ||
swarmdb_dateformat( SWARM_NOW ), | ||
$run_id | ||
); | ||
|
||
$wipedRun = true; | ||
if ( $row ) { | ||
$jobID = $row["job_id"]; | ||
|
||
$results = mysql_queryf( "SELECT useragent_id FROM clients WHERE id=%u;", $client_id ); | ||
$row = mysql_fetch_row( $results ); | ||
|
||
if ( $row ) { | ||
$useragent_id = $row["useragent_id"]; | ||
|
||
mysql_queryf( | ||
"DELETE run_client FROM run_client, clients | ||
WHERE run_id = %u | ||
AND clients.id = client_id | ||
AND clients.useragent_id = %u;", | ||
$run_id, | ||
$useragent_id | ||
); | ||
mysql_queryf( | ||
"UPDATE run_useragent | ||
SET status = 0, runs = 0, completed = 0, updated = %s | ||
WHERE run_id = %u | ||
AND useragent_id = %u;", | ||
swarmdb_dateformat( SWARM_NOW ), | ||
$run_id, | ||
$useragent_id | ||
); | ||
mysql_queryf( | ||
"UPDATE runs | ||
SET status = 1, updated = %s | ||
WHERE id = %u;", | ||
swarmdb_dateformat( SWARM_NOW ), | ||
$run_id | ||
); | ||
|
||
$wipedRun = true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
if ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) | ||
&& strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest' | ||
) { | ||
echo json_encode( $wipedRun ? "ok" : "error" ); | ||
echo json_encode( $wipedRun && $jobID ? "ok" : "error" ); | ||
|
||
} elseif ( $wipedRun && $jobID ) { | ||
header("Location: " . swarmpath( "job/{$jobID}" ) ); | ||
|
||
} else { | ||
header("Location: " . swarmpath( "job/{$job_id}/" ) ); | ||
header("Location: " . swarmpath( "" ) ); | ||
} | ||
|
||
exit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.