File: SpotDb.php

package info (click to toggle)
spotweb 20130826%2Bdfsg2-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,132 kB
  • ctags: 11,281
  • sloc: php: 31,367; xml: 1,009; sh: 148; makefile: 83
file content (486 lines) | stat: -rwxr-xr-x 16,974 bytes parent folder | download | duplicates (2)
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
<?php
define('SPOTDB_SCHEMA_VERSION', '0.58');

class SpotDb {
	private $_auditDao;
	private $_blackWhiteListDao;
	private $_cacheDao;
	private $_commentDao;
	private $_notificationDao;
	private $_sessionDao;
	private $_settingDao;
	private $_spotReportDao;
	private $_userFilterCountDao;
	private $_userFilterDao;
	private $_userDao;
	private $_spotDao;
	private $_spotStateListDao;
	private $_nntpDao;

	private $_dbsettings = null;
	private $_conn = null;

	/*
	 * Constants used for updating the black/whitelist
	 */
	const spotterlist_Black = 1;
	const spotterlist_White = 2;

	function __construct($db) {
		$this->_dbsettings = $db;
	} # __ctor
	

	/*
	 * Open connectie naar de database (basically factory), de 'engine' wordt uit de 
	 * settings gehaald die mee worden gegeven in de ctor.
	 */
	function connect() {
		SpotTiming::start(__FUNCTION__);

		/* 
		 * Erase username/password so it won't show up in any stacktrace
		 */

		# SQlite heeft geen username gedefinieerd
		if (isset($this->_dbsettings['user'])) {
			$tmpUser = $this->_dbsettings['user'];
			$this->_dbsettings['user'] = '*FILTERED*';
		} # if
		# en ook geen pass
		if (isset($this->_dbsettings['pass'])) {
			$tmpPass = $this->_dbsettings['pass'];
			$this->_dbsettings['pass'] = '*FILTERED*';
		} # if

		switch ($this->_dbsettings['engine']) {
			case 'mysql'	: $this->_conn = new dbeng_mysql($this->_dbsettings['host'],
												$tmpUser,
												$tmpPass,
												$this->_dbsettings['dbname']); 
							  $daoFactory = Dao_Factory::getDAOFactory("mysql");
							  break;

			case 'pdo_mysql': $this->_conn = new dbeng_pdo_mysql($this->_dbsettings['host'],
												$tmpUser,
												$tmpPass,
												$this->_dbsettings['dbname']);
							  $daoFactory = Dao_Factory::getDAOFactory("mysql");
							  break;
							  
			case 'pdo_pgsql' : $this->_conn = new dbeng_pdo_pgsql($this->_dbsettings['host'],
												$tmpUser,
												$tmpPass,
												$this->_dbsettings['dbname']);
							  $daoFactory = Dao_Factory::getDAOFactory("postgresql");
							  break;
							
			case 'pdo_sqlite': $this->_conn = new dbeng_pdo_sqlite($this->_dbsettings['path']);
							  $daoFactory = Dao_Factory::getDAOFactory("sqlite");
							   break;

			default			: throw new Exception('Unknown DB engine specified (' . $this->_dbsettings['engine'] . ', please choose pdo_pgsql, mysql or pdo_mysql');
		} # switch

		$daoFactory->setConnection($this->_conn);
		$this->_auditDao = $daoFactory->getAuditDao();
		$this->_blackWhiteListDao = $daoFactory->getBlackWhiteListDao();
		$this->_cacheDao = $daoFactory->getCacheDao();
		$this->_commentDao = $daoFactory->getCommentDao();
		$this->_notificationDao = $daoFactory->getNotificationDao();
		$this->_sessionDao = $daoFactory->getSessionDao();
		$this->_settingDao = $daoFactory->getSettingDao();
		$this->_spotReportDao = $daoFactory->getSpotReportDao();
		$this->_userFilterCountDao = $daoFactory->getUserFilterCountDao();
		$this->_userFilterDao = $daoFactory->getUserFilterDao();
		$this->_userDao = $daoFactory->getUserDao();
		$this->_spotDao = $daoFactory->getSpotdao();
		$this->_spotStateListDao = $daoFactory->getSpotStateListDao();
		$this->_nntpDao = $daoFactory->getNntpDao();

		$this->_conn->connect();
		SpotTiming::stop(__FUNCTION__);
	} # connect

	/*
	 * Geeft het database connectie object terug
	 */
	function getDbHandle() {
		return $this->_conn;
	} # getDbHandle


	function safe($x) {
		return $this->_conn->safe($x);
	}

	/* --------------------------- */
	function addAuditEntry($userid, $perm, $objectid, $allowed, $ipaddr) {
		return $this->_auditDao->addAuditEntry($userid, $perm, $objectid, $allowed, $ipaddr);
	} # addAuditEntry

	function removeOldList($listUrl,$idtype) {
		return $this->_blackWhiteListDao->removeOldList($listUrl,$idtype);
	}
	function updateExternalList($newlist,$idtype) {
		return $this->_blackWhiteListDao->updateExternalList($newlist,$idtype);
	}
	function addSpotterToList($spotterId, $ourUserId, $origin, $idType)
	{
		return $this->_blackWhiteListDao->addSpotterToList($spotterId, $ourUserId, $origin, $idType);
	}
	function removeSpotterFromList($spotterId, $ourUserId) {
		return $this->_blackWhiteListDao->removeSpotterFromList($spotterId, $ourUserId);
	}
	function getSpotterList($ourUserId) {
		return $this->_blackWhiteListDao->getSpotterList($ourUserId);
	}
	function getBlacklistForSpotterId($userId, $spotterId) {
		return $this->_blackWhiteListDao->getBlacklistForSpotterId($userId, $spotterId);
	}	
	function expireCache($expireDays) {
		return $this->_cacheDao->expireCache($expireDays);
	}
	function isCached($resourceid, $cachetype) {
		return $this->_cacheDao->isCached($resourceid, $cachetype);
	}
	function getCache($resourceid, $cachetype) {
		return $this->_cacheDao->getCache($resourceid, $cachetype);
	}
	function updateCacheStamp($resourceid, $cachetype) {
		return $this->_cacheDao->updateCacheStamp($resourceid, $cachetype);
	}
	function saveCache($resourceid, $cachetype, $metadata, $content) {
		return $this->_cacheDao->saveCache($resourceid, $cachetype, $metadata, $content);
	}
	function isCommentMessageIdUnique($messageid) {
		return $this->_commentDao->isCommentMessageIdUnique($messageid);
	}
	function removeExtraComments($messageId) {
		return $this->_commentDao->removeExtraComments($messageId);
	}
	function addPostedComment($userId, $comment) {
		return $this->_commentDao->addPostedComment($userId, $comment);
	}
	function matchCommentMessageIds($hdrList) {
		return $this->_commentDao->matchCommentMessageIds($hdrList);
	}
	function addComments($comments, $fullComments = array()) {
		return $this->_commentDao->addComments($comments, $fullComments);
	}
	function addFullComments($fullComments) {
		return $this->_commentDao->addFullComments($fullComments);
	}
	function getCommentsFull($userId, $nntpRef) {
		return $this->_commentDao->getCommentsFull($userId, $nntpRef);
	}
	function getNewCommentCountFor($nntpRefList, $ourUserId) {
		return $this->_commentDao->getNewCommentCountFor($nntpRefList, $ourUserId);
	}
	function markCommentsModerated($commentMsgIdList) {
		return $this->_commentDao->markCommentsModerated($commentMsgIdList);
	}
	function removeComments($commentMsgIdList) {
		return $this->_commentDao->removeComments($commentMsgIdList);
	}
	function expireCommentsFull($expireDays) {
		return $this->_commentDao->expireCommentsFull($expireDays);
	}
	function addNewNotification($userId, $objectId, $type, $title, $body) {
		return $this->_notificationDao->addNewNotification($userId, $objectId, $type, $title, $body);
	}
	function getUnsentNotifications($userId) {
		return $this->_notificationDao->getUnsentNotifications($userId);
	}
	function updateNotification($msg) {
		return $this->_notificationDao->updateNotification($msg);
	}
	function getSession($sessionid, $userid) {
		return $this->_sessionDao->getSession($sessionid, $userid);
	}
	function addSession($session) {
		return $this->_sessionDao->addSession($session);
	}
	function deleteSession($sessionid) {
		return $this->_sessionDao->deleteSession($sessionid);
	}
	function deleteAllUserSessions($userid) {
		return $this->_sessionDao->deleteAllUserSessions($userid);
	}
	function deleteExpiredSessions($maxLifeTime) {
		return $this->_sessionDao->deleteExpiredSessions($maxLifeTime);
	}
	function hitSession($sessionid) {
		return $this->_sessionDao->hitSession($sessionid);
	}
	public function getAllSettings() {
		return $this->_settingDao->getAllSettings();
	}
	public function removeSetting($name) {
		return $this->_settingDao->removeSetting($name);
	}
	public function updateSetting($name, $value) {
		return $this->_settingDao->updateSetting($name, $value);
	}
	public function getSchemaVer() {
		return $this->_settingDao->getSchemaVer();
	}
	function removeExtraReports($messageId) {
		return $this->_spotReportDao->removeExtraReports($messageId);
	}
	function matchReportMessageIds($hdrList) {
		return $this->_spotReportDao->matchReportMessageIds($hdrList);
	}
	function addReportRefs($reportList) {
		return $this->_spotReportDao->addReportRefs($reportList);
	}
	function setCachedFilterCount($userId, $filterHashes) {
		return $this->_userFilterCountDao->setCachedFilterCount($userId, $filterHashes);
	}
	function getNewCountForFilters($userId) {
		return $this->_userFilterCountDao->getNewCountForFilters($userId);
	}
	function createFilterCountsForEveryone() {
		return $this->_userFilterCountDao->createFilterCountsForEveryone();
	}
	function getCachedFilterCount($userId) {
		return $this->_userFilterCountDao->getCachedFilterCount($userId);
	}
	function resetFilterCountForUser($userId) {
		return $this->_userFilterCountDao->resetFilterCountForUser($userId);
	}
	function updateCurrentFilterCounts() {
		return $this->_userFilterCountDao->updateCurrentFilterCounts();
	}
	function markFilterCountAsSeen($userId) {
		return $this->_userFilterCountDao->markFilterCountAsSeen($userId);
	}
	function deleteFilter($userId, $filterId, $filterType) {
		return $this->_userFilterDao->deleteFilter($userId, $filterId, $filterType);
	}
	function addFilter($userId, $filter) {
		return $this->_userFilterDao->addFilter($userId, $filter);
	}
	function copyFilterList($srcId, $dstId) {
		return $this->_userFilterDao->copyFilterList($srcId, $dstId);
	}
	function removeAllFilters($userId) {
		return $this->_userFilterDao->removeAllFilters($userId);
	}
	function getFilter($userId, $filterId) {
		return $this->_userFilterDao->getFilter($userId, $filterId);
	}
	function getUserIndexFilter($userId) {
		return $this->_userFilterDao->getUserIndexFilter($userId);
	}
	function updateFilter($userId, $filter) {
		return $this->_userFilterDao->updateFilter($userId, $filter);
	}	
	function getPlainFilterList($userId, $filterType) {
		return $this->_userFilterDao->getPlainFilterList($userId, $filterType);
	}
	function getFilterList($userId, $filterType) {
		return $this->_userFilterDao->getFilterList($userId, $filterType);
	}
	function getUniqueFilterCombinations() {
		return $this->_userFilterDao->getUniqueFilterCombinations();
	}
	function getUsersForFilter($tree, $valuelist) {
		return $this->_userFilterDao->getUsersForFilter($tree, $valuelist);
	}
	function findUserIdForName($username) {
		return $this->_userDao->findUserIdForName($username);
	}
	function userEmailExists($mail) {
		return $this->_userDao->userEmailExists($mail);
	}
	function getUser($userid) {
		return $this->_userDao->getUser($userid);
	}
	function getUserList() {
		return $this->_userDao->getUserList();
	}
	function getUserListForDisplay() {
		return $this->_userDao->getUserListForDisplay();
	}
	function deleteUser($userid) {
		return $this->_userDao->deleteUser($userid);
	}
	function setUser($user) {
		return $this->_userDao->setUser($user);
	}
	function setUserPassword($user) {
		return $this->_userDao->setUserPassword($user);
	}
	function setUserRsaKeys($userId, $publicKey, $privateKey) {
		return $this->_userDao->setUserRsaKeys($userId, $publicKey, $privateKey);
	}
	function getUserPrivateRsaKey($userId) {
		return $this->_userDao->getUserPrivateRsaKey($userId);
	}
	function addUser($user) {
		return $this->_userDao->addUser($user);
	}
	function authUser($username, $passhash) {
		return $this->_userDao->authUser($username, $passhash);
	}
	function setUserAvatar($userId, $imageEncoded) {
		return $this->_userDao->setUserAvatar($userId, $imageEncoded);
	}
	function getGroupPerms($groupId) {
		return $this->_userDao->getGroupPerms($groupId);
	}
	function getPermissions($userId) {
		return $this->_userDao->getPermissions($userId);
	}
	function getGroupList($userId) {
		return $this->_userDao->getGroupList($userId);
	}
	function removePermFromSecGroup($groupId, $perm) {
		return $this->_userDao->removePermFromSecGroup($groupId, $perm);
	}
	function setDenyForPermFromSecGroup($groupId, $perm) {
		return $this->_userDao->setDenyForPermFromSecGroup($groupId, $perm);
	}
	function addPermToSecGroup($groupId, $perm) {
		return $this->_userDao->addPermToSecGroup($groupId, $perm);
	}
	function getSecurityGroup($groupId) {
		return $this->_userDao->getSecurityGroup($groupId);
	}
	function setSecurityGroup($group) {
		return $this->_userDao->setSecurityGroup($group);
	}
	function addSecurityGroup($group) {
		return $this->_userDao->addSecurityGroup($group);
	}
	function removeSecurityGroup($group) {
		return $this->_userDao->removeSecurityGroup($group);
	}
	function setUserGroupList($userId, $groupList) {
		return $this->_userDao->setUserGroupList($userId, $groupList);
	}
	function isReportPlaced($messageid, $userId) {
		return $this->_spotReportDao->isReportPlaced($messageid, $userId);
	}
	function isReportMessageIdUnique($messageid) {
		return $this->_spotReportDao->isReportMessageIdUnique($messageid);
	}
	function addPostedReport($userId, $report) {
		return $this->_spotReportDao->addPostedReport($userId, $report);
	}
	function getSpots($ourUserId, $pageNr, $limit, $parsedSearch) {
		return $this->_spotDao->getSpots($ourUserId, $pageNr, $limit, $parsedSearch);
	}
	function getSpotHeader($msgId) {
		return $this->_spotDao->getSpotHeader($msgId);
	}
	function getFullSpot($messageId, $ourUserId) {
		return $this->_spotDao->getFullSpot($messageId, $ourUserId);
	}
	function updateSpotRating($spotMsgIdList) {
		return $this->_spotDao->updateSpotRating($spotMsgIdList);
	}
	function updateSpotCommentCount($spotMsgIdList) {
		return $this->_spotDao->updateSpotCommentCount($spotMsgIdList);
	}
	function updateSpotReportCount($spotMsgIdList) {
		return $this->_spotDao->updateSpotReportCount($spotMsgIdList);
	}
	function removeSpots($spotMsgIdList) {
		return $this->_spotDao->removeSpots($spotMsgIdList);
	}
	function markSpotsModerated($spotMsgIdList) {
		return $this->_spotDao->markSpotsModerated($spotMsgIdList);
	}
	function deleteSpotsRetention($retention) {
		return $this->_spotDao->deleteSpotsRetention($retention);
	}
	function addSpots($spots, $fullSpots = array()) {
		return $this->_spotDao->addSpots($spots, $fullSpots);
	}
	function updateSpotInfoFromFull($fullSpot) {
		return $this->_spotDao->updateSpotInfoFromFull($fullSpot);
	}
	function addFullSpots($fullSpots) {
		return $this->_spotDao->addFullSpots($fullSpots);
	}
	function getOldestSpotTimestamp() {
		return $this->_spotDao->getOldestSpotTimestamp();
	}
	function matchSpotMessageIds($hdrList) {
		return $this->_spotDao->matchSpotMessageIds($hdrList);
	}
	function getSpotCount($sqlFilter) {
		return $this->_spotDao->getSpotCount($sqlFilter);
	}
	function getSpotCountPerHour($limit) {
		return $this->_spotDao->getSpotCountPerHour($limit);
	}
	function getSpotCountPerWeekday($limit) {
		return $this->_spotDao->getSpotCountPerWeekday($limit);
	}
	function getSpotCountPerMonth($limit) {
		return $this->_spotDao->getSpotCountPerMonth($limit);
	}
	function getSpotCountPerCategory($limit) {
		return $this->_spotDao->getSpotCountPerCategory($limit);
	}
	function removeExtraSpots($messageId) {
		return $this->_spotDao->removeExtraSpots($messageId);
	}
	function addPostedSpot($userId, $spot, $fullXml) {
		return $this->_spotDao->addPostedSpot($userId, $spot, $fullXml);
	}
	function expireSpotsFull($expireDays) {
		return $this->_spotDao->expireSpotsFull($expireDays);
	}
	function markAllAsRead($ourUserId) {
		return $this->_spotStateListDao->markAllAsRead($ourUserId);
	}
	function clearDownloadList($ourUserId) {
		return $this->_spotStateListDao->clearDownloadList($ourUserId);
	}
	function cleanSpotStateList() {
		return $this->_spotStateListDao->cleanSpotStateList();
	}
	function removeFromWatchList($messageid, $ourUserId) {
		return $this->_spotStateListDao->removeFromWatchList($messageid, $ourUserId);
	}
	function addToWatchList($messageid, $ourUserId) {
		return $this->_spotStateListDao->addToWatchList($messageid, $ourUserId);
	}
	function addToSeenList($messageid, $ourUserId) {
		return $this->_spotStateListDao->addToSeenList($messageid, $ourUserId);
	}
	function addToDownloadList($messageid, $ourUserId) {
		return $this->_spotStateListDao->addToDownloadList($messageid, $ourUserId);
	}
	function isNewSpotMessageIdUnique($messageid) {
		return $this->_spotDao->isNewSpotMessageIdUnique($messageid);
	}
	function getMaxMessageTime() {
		return $this->_spotDao->getMaxMessageTime();
	}
	function getMaxMessageId($headers) {
		return $this->_spotDao->getMaxMessageId($headers);
	}
	function setMaxArticleId($server, $maxarticleid) {
		return $this->_nntpDao->setMaxArticleId($server, $maxarticleid);
	}
	function getMaxArticleId($server) {
		return $this->_nntpDao->getMaxArticleId($server);
	}
	function isRetrieverRunning($server) {
		return $this->_nntpDao->isRetrieverRunning($server);
	}
	function setRetrieverRunning($server, $isRunning) {
		return $this->_nntpDao->setRetrieverRunning($server, $isRunning);
	}
	function setLastUpdate($server) {
		return $this->_nntpDao->setLastUpdate($server);
	}
	function getLastUpdate($server) {
		return $this->_nntpDao->getLastUpdate($server);
	}
} # class db