forked from econpy/torque
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Torque sometimes crashes, leading to fragmented sessions. These can now be merged. Unnecessary sessions can be deleted. TODO: Find an elegant way to clean up those <60 data points sessions.
- Loading branch information
Showing
3 changed files
with
110 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
require_once("./creds.php"); | ||
|
||
session_start(); | ||
|
||
if (isset($_POST["deletesession"])) { | ||
$deletesession = preg_replace('/\D/', '', $_POST['deletesession']); | ||
} | ||
elseif (isset($_GET["deletesession"])) { | ||
$deletesession = preg_replace('/\D/', '', $_GET['deletesession']); | ||
} | ||
|
||
if (isset($deletesession) && !empty($deletesession)) { | ||
// Connect to Database | ||
$con = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error()); | ||
mysql_select_db($db_name, $con) or die(mysql_error()); | ||
|
||
$delresult = mysql_query("DELETE FROM $db_table | ||
WHERE session=$deletesession;", $con) or die(mysql_error()); | ||
|
||
mysql_free_result($delresult); | ||
mysql_close($con); | ||
} | ||
|
||
?> |
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,44 @@ | ||
<?php | ||
require_once("./creds.php"); | ||
require_once("./get_sessions.php"); | ||
|
||
session_start(); | ||
|
||
if (isset($_POST["mergesession"])) { | ||
$mergesession = preg_replace('/\D/', '', $_POST['mergesession']); | ||
} | ||
elseif (isset($_GET["mergesession"])) { | ||
$mergesession = preg_replace('/\D/', '', $_GET['mergesession']); | ||
} | ||
|
||
if (isset($_POST["mergesessionwith"])) { | ||
$mergesessionwith = preg_replace('/\D/', '', $_POST['mergesessionwith']); | ||
} | ||
elseif (isset($_GET["mergesessionwith"])) { | ||
$mergesessionwith = preg_replace('/\D/', '', $_GET['mergesessionwith']); | ||
} | ||
|
||
if (isset($mergesession) && !empty($mergesession) && isset($mergesessionwith) && !empty($mergesessionwith) ) { | ||
//Sessions to be merged must be direct neighbors. 'With' must be younger, thus have a lower array index in $sids | ||
$idx1 = array_search( $mergesession, $sids); | ||
$idx2 = array_search( $mergesessionwith, $sids); | ||
if($idx1 != ($idx2+1)) { | ||
die("Invalid sessions to be merged. Aborted."); | ||
} | ||
|
||
// Connect to Database | ||
$con = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error()); | ||
mysql_select_db($db_name, $con) or die(mysql_error()); | ||
|
||
$mergeresult = mysql_query("UPDATE $db_table | ||
SET session=$mergesession | ||
WHERE session=$mergesessionwith;", $con) or die(mysql_error()); | ||
|
||
mysql_free_result($mergeresult); | ||
mysql_close($con); | ||
|
||
//Show merged session | ||
$session_id = $mergesession; | ||
} | ||
|
||
?> |
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