BoincThread::delete()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
// This file is part of BOINC.
3
// http://boinc.berkeley.edu
4
// Copyright (C) 2008 University of California
5
//
6
// BOINC is free software; you can redistribute it and/or modify it
7
// under the terms of the GNU Lesser General Public License
8
// as published by the Free Software Foundation,
9
// either version 3 of the License, or (at your option) any later version.
10
//
11
// BOINC is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
// See the GNU Lesser General Public License for more details.
15
//
16
// You should have received a copy of the GNU Lesser General Public License
17
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
18
19
require_once("../inc/boinc_db.inc");
20
21
#[AllowDynamicProperties]
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
22
class BoincCategory {
23
    static function lookup_id($id) {
24
        $db = BoincDb::get();
25
        return $db->lookup_id($id, 'category', 'BoincCategory');
26
    }
27
    static function lookup($clause) {
28
        $db = BoincDb::get();
29
        return $db->lookup('category', 'BoincCategory', $clause);
30
    }
31
    static function enum($clause=null) {
32
        $db = BoincDb::get();
33
        return $db->enum('category', 'BoincCategory', $clause);
34
    }
35
}
36
37
#[AllowDynamicProperties]
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
38
class BoincForum {
39
    static function insert($clause) {
40
        $db = BoincDb::get();
41
        $ret = $db->insert('forum', $clause);
42
        if (!$ret) return null;
43
        return $db->insert_id();
44
    }
45
    static function lookup_id($id) {
46
        $db = BoincDb::get();
47
        return $db->lookup_id($id, 'forum', 'BoincForum');
48
    }
49
    static function lookup($clause) {
50
        $db = BoincDb::get();
51
        return $db->lookup('forum', 'BoincForum', $clause);
52
    }
53
    static function enum($clause) {
54
        $db = BoincDb::get();
55
        return $db->enum('forum', 'BoincForum', $clause);
56
    }
57
    function update($clause) {
58
        $db = BoincDb::get();
59
        return $db->update($this, 'forum', $clause);
60
    }
61
    function delete() {
62
        $db = BoincDb::get();
63
        return $db->delete($this, 'forum');
64
    }
65
}
66
67
#[AllowDynamicProperties]
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
68
class BoincThread {
69
    static function insert($clause) {
70
        $db = BoincDb::get();
71
        $ret = $db->insert('thread', $clause);
72
        if (!$ret) return null;
73
        return $db->insert_id();
74
75
    }
76
    static function lookup_id($id) {
77
        $db = BoincDb::get();
78
        return $db->lookup_id($id, 'thread', 'BoincThread');
79
    }
80
    function update($clause) {
81
        $db = BoincDb::get();
82
        return $db->update($this, 'thread', $clause);
83
    }
84
    static function enum($clause="") {
85
        $db = BoincDb::get();
86
        return $db->enum('thread', 'BoincThread', $clause);
87
    }
88
89
    function rating() {
90
        return $this->score*$this->votes;
0 ignored issues
show
Bug Best Practice introduced by
The property score does not exist on BoincThread. Did you maybe forget to declare it?
Loading history...
Bug Best Practice introduced by
The property votes does not exist on BoincThread. Did you maybe forget to declare it?
Loading history...
91
    }
92
    function delete() {
93
        $db = BoincDb::get();
94
        return $db->delete($this, 'thread');
95
    }
96
}
97
98
#[AllowDynamicProperties]
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
99
class BoincPost {
100
    static function insert($clause) {
101
        $db = BoincDb::get();
102
        $ret = $db->insert('post', $clause);
103
        if (!$ret) return null;
104
        return $db->insert_id();
105
    }
106
    static function lookup_id($id) {
107
        $db = BoincDb::get();
108
        return $db->lookup_id($id, 'post', 'BoincPost');
109
    }
110
    static function count($clause) {
111
        $db = BoincDb::get();
112
        return $db->count('post', $clause);
113
    }
114
    function update($clause) {
115
        $db = BoincDb::get();
116
        return $db->update($this, 'post', $clause);
117
    }
118
    static function enum($clause) {
119
        $db = BoincDb::get();
120
        return $db->enum('post', 'BoincPost', $clause);
121
    }
122
    static function enum_general($query) {
123
        $db = BoincDb::get();
124
        return $db->enum_general('BoincPost', $query);
125
    }
126
    function rating() {
127
        return $this->score*$this->votes;
0 ignored issues
show
Bug Best Practice introduced by
The property votes does not exist on BoincPost. Did you maybe forget to declare it?
Loading history...
Bug Best Practice introduced by
The property score does not exist on BoincPost. Did you maybe forget to declare it?
Loading history...
128
    }
129
    function delete() {
130
        $db = BoincDb::get();
131
        return $db->delete($this, 'post');
132
    }
133
    static function delete_aux($clause) {
134
        $db = BoincDb::get();
135
        return $db->delete_aux('post', $clause);
136
    }
137
}
138
139
#[AllowDynamicProperties]
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
140
class BoincForumPrefs {
141
    static $cache;
142
    static function lookup_userid($id) {
143
        $db = BoincDb::get();
144
        return $db->lookup('forum_preferences', 'BoincForumPrefs', "userid=$id");
145
    }
146
    static function insert($clause) {
147
        $db = BoincDb::get();
148
        $ret = $db->insert('forum_preferences', $clause);
149
    }
150
    static function lookup(&$user, $nocache=false) {
151
        if (!$user) return;
152
        if (isset($user->prefs)) return;
153
        if (!$nocache && isset(self::$cache[$user->id])) {
154
            $prefs = self::$cache[$user->id];
155
        } else {
156
            $prefs = self::lookup_userid($user->id);
157
            if (!$prefs) {
158
                $db = BoincDb::get();
159
                // is DB readonly? (shouldn't ever happen)
160
                if ($db->dbnum) {
161
                    return;
162
                }
163
                self::insert("(userid, last_post, forum_sorting, thread_sorting, rated_posts, ignorelist, pm_notification) values ($user->id, 0, 0, 8, '', '', 0)");
164
                $prefs = self::lookup_userid($user->id);
165
                $prefs->userid = $user->id;
166
                $prefs->thread_sorting = 6;
167
            }
168
            self::$cache[$user->id] = $prefs;
169
        }
170
        $user->prefs = $prefs;
171
    }
172
    function privilege($specialbit) {
173
         return (substr($this->special_user, $specialbit,1)==1);
0 ignored issues
show
Bug Best Practice introduced by
The property special_user does not exist on BoincForumPrefs. Did you maybe forget to declare it?
Loading history...
174
    }
175
    function update($clause) {
176
        $db = BoincDb::get();
177
        $clause = "$clause where userid=$this->userid";
178
        return $db->update_aux('forum_preferences', $clause);
179
    }
180
    function delete() {
181
        $db = BoincDb::get();
182
        return $db->delete_aux('forum_preferences', "userid=$this->userid");
183
    }
184
    static function enum($clause=null) {
185
        $db = BoincDb::get();
186
        return $db->enum('forum_preferences', 'BoincForumPrefs', $clause);
187
    }
188
}
189
190
#[AllowDynamicProperties]
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
191
class BoincForumLogging {
192
    static $cache;
193
    static function replace($userid, $threadid, $timestamp) {
194
        $db = BoincDb::get();
195
        return $db->replace('forum_logging', "userid=$userid, threadid=$threadid, timestamp=$timestamp");
196
    }
197
    static function lookup($userid, $threadid) {
198
        $db = BoincDb::get();
199
        return $db->lookup('forum_logging', 'BoincForumLogging', "userid=$userid and threadid=$threadid");
200
    }
201
    static function lookup_cached($userid, $threadid) {
202
        if (isset(self::$cache[$threadid])) {
203
            return self::$cache[$threadid];
204
        }
205
        $x = self::lookup($userid, $threadid);
206
        if (!$x) {
207
            $x = new BoincForumLogging();
208
            $x->timestamp = 0;
209
        }
210
        self::$cache[$threadid] = $x;
211
    }
212
    static function delete_aux($clause) {
213
        $db = BoincDb::get();
214
        return $db->delete_aux('forum_logging', $clause);
215
    }
216
    static function cleanup() {
217
        // Every 28 days, delete records older than 28 days.
218
        // Keep track of the last time we did this in a special record
219
        // with userid = threadid = 0.
220
        // This gets called from forum_index.php
221
        // (i.e. each time the forum main page is loaded).
222
        //
223
        $fl = BoincForumLogging::lookup(0, 0);
224
        if ($fl) {
225
            if ($fl->timestamp<time()-MAX_FORUM_LOGGING_TIME){
226
                BoincForumLogging::delete_aux("timestamp<'".(time()-MAX_FORUM_LOGGING_TIME)."' and userid != 0");
227
                BoincForumLogging::replace(0, 0, time());
228
            }
229
        } else {
230
            // No cleanup timestamp found, make one
231
            //
232
            BoincForumLogging::replace(0, 0, 0);
233
        }
234
    }
235
}
236
237
#[AllowDynamicProperties]
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
238
class BoincSubscription {
239
    static function lookup($userid, $threadid) {
240
        $db = BoincDb::get();
241
        return $db->lookup('subscriptions', 'BoincSubscription', "userid=$userid and threadid=$threadid");
242
    }
243
    static function delete($userid, $threadid) {
244
        $db = BoincDb::get();
245
        return $db->delete_aux('subscriptions', "userid=$userid and threadid=$threadid");
246
    }
247
    static function enum($clause) {
248
        $db = BoincDb::get();
249
        return $db->enum('subscriptions', 'BoincSubscription', $clause);
250
    }
251
    static function replace($userid, $threadid) {
252
        $db = BoincDb::get();
253
        return $db->replace('subscriptions', "userid=$userid, threadid=$threadid");
254
    }
255
}
256
257
#[AllowDynamicProperties]
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
258
class BoincPostRating {
259
    static function lookup($userid, $postid) {
260
        $db = BoincDb::get();
261
        return $db->lookup('post_ratings', 'BoincPostRating', "user=$userid and post=$postid");
262
    }
263
    static function replace($userid, $postid, $rating) {
264
        $db = BoincDb::get();
265
        return $db->replace('post_ratings', "user=$userid, post=$postid, rating=$rating");
266
    }
267
}
268
269
#[AllowDynamicProperties]
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
270
class BoincFriend {
271
    static function insert($clause) {
272
        $db = BoincDb::get();
273
        return $db->insert('friend', $clause);
274
    }
275
    static function lookup($uid1, $uid2) {
276
        $db = BoincDb::get();
277
        return $db->lookup('friend', 'BoincFriend', "user_src=$uid1 and user_dest=$uid2");
278
    }
279
    function update($clause) {
280
        $db = BoincDb::get();
281
        return $db->update_aux('friend', "$clause where user_src=$this->user_src and user_dest=$this->user_dest");
0 ignored issues
show
Bug Best Practice introduced by
The property user_dest does not exist on BoincFriend. Did you maybe forget to declare it?
Loading history...
Bug Best Practice introduced by
The property user_src does not exist on BoincFriend. Did you maybe forget to declare it?
Loading history...
282
    }
283
    static function enum($clause) {
284
        $db = BoincDb::get();
285
        return $db->enum('friend', 'BoincFriend', $clause);
286
    }
287
    static function delete_aux($clause) {
288
        $db = BoincDb::get();
289
        return $db->delete_aux('friend', $clause);
290
    }
291
    static function delete($id1, $id2) {
292
        $db = BoincDb::get();
293
        $db->delete_aux('friend', "user_src=$id1 and user_dest=$id2");
294
        $db->delete_aux('friend', "user_src=$id2 and user_dest=$id1");
295
    }
296
    static function replace($clause) {
297
        $db = BoincDb::get();
298
        return $db->replace('friend', $clause);
299
    }
300
}
301
302
#[AllowDynamicProperties]
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
303
class BoincNotify {
304
    static function insert($clause) {
305
        $db = BoincDb::get();
306
        $ret = $db->insert('notify', $clause);
307
        if (!$ret) return null;
308
        return $db->insert_id();
309
    }
310
    static function replace($clause) {
311
        $db = BoincDb::get();
312
        return $db->replace('notify', $clause);
313
    }
314
    static function enum($clause) {
315
        $db = BoincDb::get();
316
        return $db->enum('notify', 'BoincNotify', $clause);
317
    }
318
    static function lookup($userid, $type, $opaque) {
319
        $db = BoincDb::get();
320
        return $db->lookup('notify', 'BoincNotify', "userid=$userid and type=$type and opaque=$opaque");
321
    }
322
    function delete() {
323
        $db = BoincDb::get();
324
        return $db->delete($this, 'notify');
325
    }
326
    static function delete_aux($clause) {
327
        $db = BoincDb::get();
328
        $db->delete_aux('notify', $clause);
329
    }
330
    static function enum_general($query) {
331
        $db = BoincDb::get();
332
        return $db->enum_general('BoincNotify', $query);
333
    }
334
    function update($clause) {
335
        $db = BoincDb::get();
336
        return $db->update($this, 'notify', $clause);
337
    }
338
}
339
340
define ('NOTIFY_FRIEND_REQ', 1);
341
define ('NOTIFY_FRIEND_ACCEPT', 2);
342
define ('NOTIFY_PM', 3);
343
define ('NOTIFY_SUBSCRIBED_THREAD', 4);
344
define ('NOTIFY_SUBSCRIBED_FORUM', 5);
345
346
?>
347