git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

Commit db8e29eb authored by Jonas Haraldsson's avatar Jonas Haraldsson

install.php: Scrobble_Sessions api_key field

parent 2fbbe993
......@@ -198,6 +198,7 @@ if (isset($_POST['install'])) {
userid INTEGER REFERENCES Users(uniqueid),
sessionid VARCHAR(32) PRIMARY KEY,
client CHAR(3),
api_key VARCHAR(32),
expires INTEGER)',
'CREATE TABLE Now_Playing(
......
......@@ -93,7 +93,7 @@ function getOrCreateAlbum($artist, $album) {
* @param string track Track name.
* @param string mbid Track's musicbrainz ID.
* @param int duration Track length in seconds.
* @return int Album ID.
* @return int Track ID.
*
* @todo Rename the function?
*/
......@@ -130,7 +130,13 @@ function getOrCreateTrack($artist, $album, $track, $mbid, $duration) {
/**
* Add track to Scrobble_Track db table
*
* @todo docs
* @param string artist Artist name.
* @param string album Album name.
* @param string track Track name.
* @param string mbid Track musicbrainz ID.
* @param int duration Track length in seconds.
* @param int track_id Track ID in Track database table
* @return int Scrobble_Track ID.
*/
function getOrCreateScrobbleTrack($artist, $album, $track, $mbid, $duration, $track_id) {
global $adodb;
......@@ -155,7 +161,6 @@ function getOrCreateScrobbleTrack($artist, $album, $track, $mbid, $duration, $tr
$scrobbletrack_id = $adodb->GetOne($query, $params);
if (!$scrobbletrack_id) {
// TODO we are sometimes running lower() on some null values here, i hope that's ok
$query = 'INSERT INTO Scrobble_Track (name, artist, album, mbid, track) VALUES (lower(?), lower(?), lower(?), lower(?), ?)';
$params = array($track, $artist, $album, $mbid, $track_id);
$res = $adodb->Execute($query, $params);
......@@ -188,7 +193,6 @@ function getOrCreateScrobbleSession($userid, $api_key = null) {
$query = 'SELECT sessionid FROM Scrobble_Sessions WHERE userid = ? AND expires > ?';
$params = array($userid, time());
//TODO not yet in install.php, alter table Scrobble_Sessions add column api_key varchar(32)
if (strlen($api_key) == 32) {
$query .= ' AND api_key=?';
$params[] = $api_key;
......@@ -203,8 +207,7 @@ function getOrCreateScrobbleSession($userid, $api_key = null) {
try {
$adodb->Execute($query, $params);
} catch (Exception $e) {
// TODO possible exception if inserting wrong length api_key, or sessionid=null
return false;
return null;
}
}
return $sessionid;
......
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