-
Notifications
You must be signed in to change notification settings - Fork 7
/
su_db.inc
314 lines (297 loc) · 9.39 KB
/
su_db.inc
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2019 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
// SU-specific tables.
// In addition we use some fields from BOINC tables:
//
// host.rpc_time
// last AM RPC
// host.total_credit
// -1 means host is hidden
// user.send_email
// days between status emails. zero means don't send
// user.seti_last_result_time
// when to send next status email
// user.donated
// nonzero if opted in for leaderboards
// alter table user add index user_donated(donated);
require_once("../inc/boinc_db.inc");
// values for keyword.category
//
define('SCIENCE', 0);
define('LOCATION', 1);
// values for user_keyword.type
//
define('KW_YES', 1);
define('KW_MAYBE', 0);
define('KW_NO', -1);
// values for su_account.state
//
define('ACCT_INIT', 0);
define('ACCT_SUCCESS', 1);
define('ACCT_TRANSIENT_ERROR', 3);
// values of keyword.priority
//
define('KW_MINOR', 1);
define('KW_MAJOR', 2);
// values of project.status
//
define('PROJECT_STATUS_HIDE', 0);
// don't show; deprecated
define('PROJECT_STATUS_AUTO', 2);
// normal
class SUProject {
static function insert($clause) {
$db = BoincDb::get();
$ret = $db->insert('su_project', $clause);
if (!$ret) return 0;
return $db->insert_id();
}
static function lookup_id($id) {
$db = BoincDb::get();
return $db->lookup_id($id, 'su_project', 'SUProject');
}
function update($clause) {
$db = BoincDb::get();
return $db->update($this, 'su_project', $clause);
}
function delete() {
$db = BoincDb::get();
return $db->delete($this, 'su_project');
}
static function enum($where_clause=null, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('su_project', 'SUProject', $where_clause, $order_clause);
}
static function lookup($clause) {
$db = BoincDb::get();
return $db->lookup('su_project', 'SUProject', $clause);
}
}
class SUProjectKeyword {
static function insert($clause) {
$db = BoincDb::get();
return $db->insert('su_project_keyword', $clause);
}
static function enum($where_clause=null) {
$db = BoincDb::get();
return $db->enum('su_project_keyword', 'SUProjectKeyword', $where_clause);
}
function delete() {
$db = BoincDb::get();
return $db->delete_aux('su_project_keyword',
"project_id=$this->project_id and keyword_id=$this->keyword_id"
);
}
static function delete_all() {
$db = BoincDb::get();
return $db->delete_aux('su_project_keyword', 1);
}
}
class SUUserKeyword {
static function insert($clause) {
$db = BoincDb::get();
return $db->insert('su_user_keyword', $clause);
}
static function enum($where_clause=null) {
$db = BoincDb::get();
return $db->enum('su_user_keyword', 'SUUserKeyword', $where_clause);
}
function delete() {
$db = BoincDb::get();
return $db->delete_aux('su_user_keyword',
"user_id=$this->user_id and keyword_id=$this->keyword_id"
);
}
static function delete_user($user_id) {
$db = BoincDb::get();
return $db->delete_aux('su_user_keyword', "user_id=$user_id");
}
static function update($clause) {
$db = BoincDb::get();
return $db->update_aux('su_user_keyword', $clause);
}
//static function delete_all() {
// $db = BoincDb::get();
// return $db->delete_aux('su_user_keyword', 1);
//}
}
class SUAccount {
static function insert($clause) {
$db = BoincDb::get();
return $db->insert('su_account', $clause);
}
static function enum($where_clause=null, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('su_account', 'SUAccount', $where_clause, $order_clause);
}
static function lookup($where_clause) {
$db = BoincDb::get();
return $db->lookup('su_account', 'SUAccount', $where_clause);
}
function update($clause) {
$db = BoincDb::get();
$clause .= " where user_id=$this->user_id and project_id=$this->project_id";
return $db->update_aux('su_account', $clause);
}
function delete() {
$db = BoincDb::get();
return $db->delete_aux('su_account',
"user_id=$this->user_id and project_id=$this->project_id"
);
}
static function delete_user($user_id) {
$db = BoincDb::get();
return $db->delete_aux('su_account', "user_id=$user_id");
}
static function delete_all() {
$db = BoincDb::get();
return $db->delete_aux('su_account', 1);
}
}
class SUHostProject {
static function insert($clause) {
$db = BoincDb::get();
return $db->insert('su_host_project', $clause);
}
static function lookup($where_clause) {
$db = BoincDb::get();
return $db->lookup('su_host_project', 'SUHostProject', $where_clause);
}
static function update($clause) {
$db = BoincDb::get();
return $db->update_aux('su_host_project', $clause);
}
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('su_host_project', 'SUHostProject', $where_clause, $order_clause);
}
static function delete_all() {
$db = BoincDb::get();
return $db->delete_aux('su_host_project', 1);
}
}
class SUAccounting {
static function insert($clause) {
$db = BoincDb::get();
return $db->insert('su_accounting', $clause);
}
static function enum($where_clause='', $order_clause='') {
$db = BoincDb::get();
return $db->enum('su_accounting', 'SUAccounting', $where_clause, $order_clause);
}
static function last($i=0) {
$db = BoincDb::get();
$n = $i+1;
$x = SUAccounting::enum("", "order by id desc limit $n");
if ($x && count($x) > $i) {
return $x[$i];
} else {
return null;
}
}
function update($clause) {
$db = BoincDb::get();
return $db->update($this, 'su_accounting', $clause);
}
static function delete_all() {
$db = BoincDb::get();
return $db->delete_aux('su_accounting', 1);
}
}
class SUAccountingProject {
static function insert($clause) {
$db = BoincDb::get();
return $db->insert('su_accounting_project', $clause);
}
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('su_accounting_project', 'SUAccountingProject', $where_clause, $order_clause);
}
static function last($proj_id) {
$db = BoincDb::get();
$x = SUAccountingProject::enum("project_id=$proj_id order by id desc limit 1");
if ($x) {
return $x[0];
} else {
return null;
}
}
function update($clause) {
$db = BoincDb::get();
return $db->update($this, 'su_accounting_project', $clause);
}
static function delete_all() {
$db = BoincDb::get();
return $db->delete_aux('su_accounting_project', 1);
}
}
class SUAccountingUser {
static function insert($clause) {
$db = BoincDb::get();
return $db->insert('su_accounting_user', $clause);
}
static function enum($where_clause, $order_clause=null) {
$db = BoincDb::get();
return $db->enum('su_accounting_user', 'SUAccountingUser', $where_clause, $order_clause);
}
static function last($user_id) {
$db = BoincDb::get();
$x = SUAccountingUser::enum("user_id=$user_id order by id desc limit 1");
if ($x) {
return $x[0];
} else {
return null;
}
}
function update($clause) {
$db = BoincDb::get();
return $db->update($this, 'su_accounting_user', $clause);
}
static function count($clause) {
$db = BoincDb::get();
return $db->count('su_accounting_user', $clause);
}
static function delete_user($user_id) {
$db = BoincDb::get();
return $db->delete_aux('su_accounting_user', "user_id=$user_id");
}
static function delete_all() {
$db = BoincDb::get();
return $db->delete_aux('su_accounting_user', 1);
}
}
class SUAllocate {
static function insert() {
$db = BoincDb::get();
return $db->insert('su_allocate', '(nprojects) values (0)');
}
static function lookup() {
$db = BoincDb::get();
return $db->lookup('su_allocate', 'SUAllocate', "true");
}
static function update($clause) {
$db = BoincDb::get();
return $db->update_aux('su_allocate', $clause);
}
static function get() {
static $x = null;
if ($x) return $x;
$x = SUAllocate::lookup();
return $x;
}
}