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

Commit aaf2dd2b authored by Jonas Haraldsson's avatar Jonas Haraldsson

Clean up ban/unban

Bind sql parameters in Track->isLoved function
Added Track->isBanned function.
Moved sql from api/TrackXML.php functions into data/Track.php
functions.
ban/unban calls now only return True if a row is added/deleted
from Banned_Tracks table, False in any other case.
parent 8638a301
......@@ -149,18 +149,18 @@ class TrackXML {
}
public static function ban($artist, $name, $userid) {
global $adodb;
try {
$res = $adodb->Execute('INSERT INTO Banned_Tracks VALUES ('
. $userid . ', '
. $adodb->qstr($name) . ', '
. $adodb->qstr($artist) . ', '
. time() . ')');
} catch (Exception $e) {}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
$track = new Track($name, $artist);
$res = $track->ban($userid);
} catch (Exception $e) {
return XML::error('failed', '7', 'Invalid resource specified');
}
if(!$res) {
$xml = XML::error('failed', '7', 'Invalid resource specified');
} else {
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
}
return $xml;
}
......@@ -181,14 +181,18 @@ class TrackXML {
}
public static function unban($artist, $name, $userid) {
global $adodb;
try {
$res = $adodb->Execute('DELETE FROM Banned_Tracks WHERE userid=' . $userid . ' AND track=' . $adodb->qstr($name) . ' AND artist=' . $adodb->qstr($artist));
} catch (Exception $e) {}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
$track = new Track($name, $artist);
$res = $track->unban($userid);
} catch (Exception $e) {
return XML::error('failed', '7', 'Invalid resource specified');
}
if(!$res) {
$xml = XML::error('failed', '7', 'Invalid resource specified');
} else {
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
}
return $xml;
}
......
......@@ -402,12 +402,14 @@ class Track {
function isLoved($userid) {
global $adodb;
$query = 'SELECT * FROM Loved_Tracks WHERE userid=? AND track=? AND artist=?';
$params = array((int) $userid, $this->name, $this->artist_name);
try {
$res = $adodb->GetRow('SELECT * FROM Loved_Tracks WHERE userid='
. $userid . ' AND track='
. $adodb->qstr($this->name) . ' AND artist='
. $adodb->qstr($this->artist_name));
} catch (Exception $e) {}
$res = $adodb->GetRow($query, $params);
} catch (Exception $e) {
reportError($e->GetMessage(), $e->GetTraceAsString());
return False;
}
if($res) {
return True;
......@@ -415,6 +417,77 @@ class Track {
return False;
}
/**
* Ban a track
*
* @param int $userid The user banning this track.
* @return bool True on success, False on fail.
*
*/
function ban($userid) {
global $adodb;
$query = 'INSERT INTO Banned_Tracks (userid, track, artist, time) VALUES(?,?,?,?)';
$params = array((int) $userid, $this->name, $this->artist_name, time());
try {
$adodb->Execute($query, $params);
$res = $adodb->Affected_Rows();
} catch (Exception $e) {
reportError($e->GetMessage(), $e->GetTraceAsString());
return False;
}
return (bool) $res;
}
/**
* Unban a track
*
* @param int $userid The user unbanning this track.
* @return bool True on success, False on fail.
*/
function unban($userid) {
global $adodb;
$query = 'DELETE FROM Banned_Tracks WHERE userid=? AND track=? AND artist=?';
$params = array((int) $userid, $this->name, $this->artist_name);
try {
$adodb->Execute($query, $params);
$res = $adodb->Affected_Rows();
} catch (Exception $e) {
reportError($e->GetMessage(), $e->GetTraceAsString());
return False;
}
return (bool) $res;
}
/**
* Check if track has been banned by user
*
* @param int $userid The user we are looking for
* @return bool True if track has been banned by user
*/
function isBanned($userid) {
global $adodb;
$query = 'SELECT * FROM Banned_Tracks WHERE userid=? AND track=? AND artist=?';
$params = array((int) $userid, $this->name, $this->artist_name);
try {
$res = $adodb->GetRow($query, $params);
} catch (Exception $e) {
reportError($e->GetMessage(), $e->GetTraceAsString());
return False;
}
if($res) {
return True;
}
return False;
}
/*
* Remove a tag from a track
*
......
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