We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit f805c058 authored by clint's avatar clint

use adodb exceptions in gnukebox instead of PEAR stuff

parent ad96e644
......@@ -31,10 +31,11 @@ function usernameFromSID($session_id)
// Delete any expired session ids
$adodb->Execute("DELETE FROM Scrobble_Sessions WHERE expires < " . time());
$res = $adodb->GetOne("SELECT username FROM Scrobble_Sessions WHERE sessionid = " . $adodb->qstr($session_id)); // get the username from the table
if(PEAR::isError($res)) {
die("FAILED ufs " . $res->getMessage() . "\n");
try {
$res = $adodb->GetOne("SELECT username FROM Scrobble_Sessions WHERE sessionid = " . $adodb->qstr($session_id)); // get the username from the table
}
catch (exception $e) {
die("FAILED ufs " . $e->getMessage() . "\n");
// die is there is an error, printing the error
}
......@@ -54,16 +55,20 @@ function createArtistIfNew($artist) {
$artist = NoSpamTracks($artist);
$res = $adodb->Execute("SELECT name FROM Artist WHERE name = " . ($artist));
if(PEAR::isError($res)) {
die("FAILED art " . $res->getMessage() . "\n");
try {
$res = $adodb->Execute("SELECT name FROM Artist WHERE name = " . ($artist));
}
catch (exception $e) {
die("FAILED art " . $e->getMessage() . "\n");
}
if(!$res) {
// Artist doesn't exist, so we create them
$res = $adodb->Execute("INSERT INTO Artist (name) VALUES (" . ($artist) . ")");
if(PEAR::isError($res)) {
die("FAILED artc " . $res->getMessage() . "\n");
try {
$res = $adodb->Execute("INSERT INTO Artist (name) VALUES (" . ($artist) . ")");
}
catch (exception $e) {
die("FAILED artc " . $e->getMessage() . "\n");
}
}
}
......@@ -71,15 +76,19 @@ function createArtistIfNew($artist) {
function createAlbumIfNew($artist, $album) {
global $adodb;
try {
$res = $adodb->Execute("SELECT name FROM Album WHERE name = " . ($album) . " AND artist_name = " . ($artist));
if(PEAR::isError($res)) {
die("FAILED alb " . $res->getMessage() . "\n");
}
catch (exception $e) {
die("FAILED alb " . $e->getMessage() . "\n");
}
if(!$res) {
// Album doesn't exist, so create it
$art = $adodb->qstr(getAlbumArt($artist, $album));
try {
if ($art !="") {
$license = $adodb->qstr("amazon");
......@@ -90,10 +99,10 @@ function createAlbumIfNew($artist, $album) {
$res = $adodb->Execute("INSERT INTO Album (name, artist_name) VALUES (" . ($album) . ", " . ($artist) . ")");
}
if(PEAR::isError($res)) {
die("FAILED albc " . $res->getMessage() . "\n");
}
}
catch (exception $e) {
die("FAILED albc " . $e->getMessage() . "\n");
}
}
}
......@@ -103,24 +112,28 @@ function getTrackCreateIfNew($artist, $album, $track, $mbid) {
$track = NoSpamTracks($track);
$artist = NoSpamTracks($artist);
try {
if($album != 'NULL') {
$res = $adodb->GetOne("SELECT id FROM Track WHERE lower(name) = lower(" . ($track) . ") AND lower(artist_name) = lower(" . ($artist) . ") AND lower(album_name) = lower(" . ($album) . ")");
} else {
$res = $adodb->GetOne("SELECT id FROM Track WHERE lower(name) = lower(" . ($track) . ") AND lower(artist_name) = lower(" . ($artist) . ") AND album_name IS NULL");
}
if(PEAR::isError($res)) {
die("FAILED trk " . $res->getMessage() . "\n");
}
catch (exception $e) {
die("FAILED trk " . $e->getMessage() . "\n");
}
if(!$res) {
// Create new track
try {
$res = $adodb->Execute("INSERT INTO Track (name, artist_name, album_name, mbid) VALUES ("
. ($track) . ", "
. ($artist) . ", "
. ($album) . ", "
. ($mbid) . ")");
if(PEAR::isError($res)) {
die("FAILED trkc " . $res->getMessage() . "\n");
}
catch (exception $e) {
die("FAILED trkc " . $e->getMessage() . "\n");
}
return getTrackCreateIfNew($artist, $album, $track, $mbid);
} else {
......@@ -131,12 +144,14 @@ function getTrackCreateIfNew($artist, $album, $track, $mbid) {
function getScrobbleTrackCreateIfNew($artist, $album, $track, $mbid, $tid) {
global $adodb;
try {
$res = $adodb->GetOne("SELECT id FROM Scrobble_Track WHERE name = lower("
. ($track) . ") AND artist = lower(" . ($artist) . ") AND album "
. (($album == 'NULL') ? "IS NULL" : ("= lower(" . ($album) . ")")) . " AND mbid "
. (($mbid == 'NULL') ? "IS NULL" : ("= lower(" . ($mbid) . ")")));
if(PEAR::isError($res)) {
die("FAILED st " . $res->getMessage() . "\n");
}
catch (exception $e) {
die("FAILED st " . $e->getMessage() . "\n");
}
if(!$res) {
......@@ -146,9 +161,11 @@ function getScrobbleTrackCreateIfNew($artist, $album, $track, $mbid, $tid) {
. (($album == 'NULL') ? "NULL" : "lower(" . ($album) . ")") . ", "
. (($mbid == 'NULL') ? "NULL" : "lower(" . ($mbid) . ")") . ", "
. ($tid) . ")";
$res = $adodb->Execute($sql);
if(PEAR::isError($res)) {
$msg = $res->getMessage() . " - " . $res->getUserInfo();
try {
$res = $adodb->Execute($sql);
}
catch (exception $e) {
$msg = $e->getMessage() . " - " . $e->getUserInfo();
reportError($msg, $sql);
die("FAILED stc " . $res->getMessage() . "\n");
......@@ -162,9 +179,11 @@ function getScrobbleTrackCreateIfNew($artist, $album, $track, $mbid, $tid) {
function scrobbleExists($username, $artist, $track, $time) {
global $adodb;
try {
$res = $adodb->GetOne("SELECT time FROM Scrobbles WHERE username = " . ($username) . " AND artist = " . ($artist) . " AND track = " . ($track) . " AND time = " . ($time));
if(PEAR::isError($res)) {
die("FAILED se " . $res->getMessage() . "\n");
}
catch (exception $e) {
die("FAILED se " . $e->getMessage() . "\n");
}
if(!$res) {
......
......@@ -42,23 +42,26 @@ if(!in_array($protocol, $supported_protocols)) {
$timestamp = time();
$res = $adodb->GetOne("SELECT password FROM Users WHERE username = ". $adodb->qstr($username));
if(PEAR::isError($res)) {
die("FAILED " . $res->getMessage() . "\n");
try {
$res = $adodb->GetOne("SELECT password FROM Users WHERE username = ". $adodb->qstr($username));
}
catch (exception $e) {
die("FAILED " . $e->getMessage() . "\n");
}
if(!$res->numRows()) {
die("BADUSER\n");
}
$password = $res;
$session_id = md5($password . $timestamp);
try {
$res = $adodb->Execute("INSERT INTO Scrobble_Sessions(username, sessionid, client, expires) VALUES ("
. $adodb->qstr($username, "text") . ","
. $adodb->qstr($session_id, "text") . ","
. $adodb->qstr($client, "text") . ","
. $adodb->qstr(time() + 86400) . ")");
if(PEAR::isError($res)) {
die("FAILED " . $res->getMessage() . "\n");
}
catch (exception $e) {
die("FAILED " . $e->getMessage() . "\n");
}
echo "UPTODATE\n";
......
......@@ -61,10 +61,11 @@ $sql = "INSERT INTO Scrobble_Sessions(username, sessionid, client, expires) VALU
. $adodb->qstr($client) . ","
. (time() + 86400) . ")";
try {
$res = $adodb->Execute($sql);
if(PEAR::isError($res)) {
$msg = $res->getMessage();
}
catch (exception $e) {
$msg = $e->getMessage();
reportError($msg, $sql);
die("FAILED " . $msg . "\n");
}
......
......@@ -146,9 +146,11 @@ for($i = 0; $i < count($_POST['a']); $i++) {
// Scrobble!
$sql = "INSERT INTO Scrobbles (username, artist, album, track, time, mbid, source, rating, length, stid) VALUES " . $rowvalues[$j];
try {
$res =& $adodb->Execute($sql);
if(PEAR::isError($res)) {
$msg = $res->getMessage() . " - " . $res->getUserInfo();
}
catch (exception $e) {
$msg = $e->getMessage() . " - " . $e->getUserInfo();
$adodb->FailTrans();
$adodb->CompleteTrans();
reportError($msg, $sql);
......@@ -157,14 +159,13 @@ for($i = 0; $i < count($_POST['a']); $i++) {
}
$adodb->CompleteTrans();
if(PEAR::isError($res)) {
$msg = $res->getMessage() . " - " . $res->getUserInfo();
$adodb->FailTrans();
$adodb->CompleteTrans();
reportError($msg, $sql);
die("FAILED " . $msg . "\nError has been reported to site administrators.\n");
try {
$adodb->CompleteTrans();
}
catch (exception $e) {
die("FAILED " . $e->getMessage() . "\n";
}
}
// Destroy now_playing since it is almost certainly obsolescent
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment