-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroovesharkdb.php
executable file
·150 lines (137 loc) · 6.27 KB
/
groovesharkdb.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
require_once ('database.php');
require_once ('sessiondata.php');
class GroovesharkDatabase extends Database
{
public function getSessionData()
{
$sessionData = null;
// Get from db
$query = "SELECT * FROM cacheSessionData";
$rows = $this->select($query);
$sessionStuff = array();
foreach($rows as $key=>$val)
{
$sessionStuff[$val['name']] = $val['value'];
}
$sessionData = new SessionData(
$sessionStuff['clientRevision'],
$sessionStuff['sessionID'],
$sessionStuff['secretKey'],
$sessionStuff['token'],
$sessionStuff['uuid'],
$sessionStuff['countryID']
);
return $sessionData;
}
private function executeKeyValueInsert($name, $value)
{
$query = "INSERT INTO cacheSessionData(name, value) VALUES (:name, :value) ON DUPLICATE KEY UPDATE value=:value";
$parms = new QueryParameters();
$parms->addParameter(':name', $name);
$parms->addParameter(':value', $value);
$stmt = $this->execute($query, $parms);
//print_r($stmt);
//print_r($parms);
//printf("%d rows affected\n",$stmt->rowCount());
}
public function saveSessionData($sessionData)
{
if ($this->dbConnection != null)
{
$this->executeKeyValueInsert("clientRevision", $sessionData->ClientRevision);
$this->executeKeyValueInsert("sessionID", $sessionData->SessionID);
$this->executeKeyValueInsert("secretKey", $sessionData->SecretKey);
$this->executeKeyValueInsert("token", $sessionData->Token);
$this->executeKeyValueInsert("uuid", $sessionData->UUID);
$this->executeKeyValueInsert("countryID", $sessionData->CountryID);
}
else
{
print "break..\n";
}
}
public function saveSongHistory($play)
{
$r = array('class'=>null,'code'=>null,'details'=>null,'debug'=>null);
{ // validate the object
if ((isset($play) && is_array($play))
&& (isset($play['queueSongID']) && is_int($play['queueSongID']))
&& (isset($play['SongID']) && is_int($play['SongID']))
&& (isset($play['SongName']) && is_string($play['SongName']))
&& (isset($play['ArtistID']) && is_int($play['ArtistID']))
&& (isset($play['ArtistName']) && is_string($play['ArtistName']))
&& (isset($play['EstimateDuration']) && is_int($play['EstimateDuration']))
&& (isset($play['broadcastUpVotes']) && is_int($play['broadcastUpVotes']))
&& (isset($play['broadcastDownVotes']) && is_int($play['broadcastDownVotes']))
&& (isset($play['broadcastListens']) && is_int($play['broadcastListens']))
&& (isset($play['broadcastID']) && is_int($play['broadcastID']))
&& (isset($play['broadcastHash']) && is_string($play['broadcastHash']))
)
{
// pass, it's a valid object!
}
else
{
$r['class'] = 'fail_object';
$r['code'] = 500;
$r['detail'] = 'The provided playObject does not appear valid.';
$r['debug'] = $play;
}
}
{ // build the query
$parms = array();
$query = "INSERT INTO `grooveshark`.`songHistory` (`queueSongID`, `SongID`, `SongName`, `ArtistID`, `ArtistName`, `EstimateDuration`, `broadcastUpVotes`, `broadcastDownVotes`, `broadcastListens`, `broadcastID`, `broadcastHash`) VALUES (:queueSongID, :SongID, :SongName, :ArtistID, :ArtistName, :EstimateDuration, :broadcastUpVotes, :broadcastDownVotes, :broadcastListens, :broadcastID, :broadcastHash)
ON DUPLICATE KEY UPDATE `EstimateDuration`=:EstimateDuration, `broadcastUpVotes`=:broadcastUpVotes, `broadcastDownVotes`=:broadcastDownVotes, `broadcastListens`=:broadcastListens, `broadcastID`=:broadcastID, `broadcastHash`=:broadcastHash";
$parms[] = array(':queueSongID',$play['queueSongID']);
$parms[] = array(':SongID',$play['SongID']);
$parms[] = array(':SongName',$play['SongName']);
$parms[] = array(':ArtistID',$play['ArtistID']);
$parms[] = array(':ArtistName',$play['ArtistName']);
$parms[] = array(':EstimateDuration',$play['EstimateDuration']);
$parms[] = array(':broadcastUpVotes',$play['broadcastUpVotes']);
$parms[] = array(':broadcastDownVotes',$play['broadcastDownVotes']);
$parms[] = array(':broadcastListens',$play['broadcastListens']);
$parms[] = array(':broadcastID',$play['broadcastID']);
$parms[] = array(':broadcastHash',$play['broadcastHash']);
$stmt = $dbConnection->prepare($query);
foreach($parms as $parm) {
$stmt->bindValue($parm[0], $parm[1]);
}
}
{ // execute the insert/update
try
{
if (!$this->MaintenanceMode)
$stmt->execute();
ob_start();
echo "play :";
print_r($play);
echo "parms :";
print_r($parms);
echo "stmt :";
print_r($stmt);
$r['debug'] = ob_get_clean();
if ($stmt->rowCount() > 0)
{
$r['class'] = 'success';
$r['code'] = 201;
$r['detail'] = 'play log updated';
}
else
{
$r['class'] = 'warn_insert';
$r['code'] = 206;
$r['detail'] = 'play log already exists.';
}
}
catch (PDOException $e)
{
$r['class'] = 'fail_query';
$r['code'] = 500;
$r['detail'] = $e->getMessage();
}
}
return $r;
}
}