Hooks::deleteUserStream()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * @author Joas Schilling <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2016, ownCloud, Inc.
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace OCA\Activity;
23
24
use OCA\Activity\AppInfo\Application;
25
use OCP\IDBConnection;
26
27
/**
28
 * Handles the stream and mail queue of a user when he is being deleted
29
 */
30
class Hooks {
31
	/**
32
	 * Delete remaining activities and emails when a user is deleted
33
	 *
34
	 * @param array $params The hook params
35
	 */
36 1
	public static function deleteUser($params) {
37 1
		$connection = \OC::$server->getDatabaseConnection();
38 1
		self::deleteUserStream($params['uid']);
39 1
		self::deleteUserMailQueue($connection, $params['uid']);
40 1
	}
41
42
	/**
43
	 * Delete all items of the stream
44
	 *
45
	 * @param string $user
46
	 */
47 1
	protected static function deleteUserStream($user) {
48
		// Delete activity entries
49 1
		$app = new Application();
50
		/** @var Data $activityData */
51 1
		$activityData = $app->getContainer()->query('ActivityData');
52 1
		$activityData->deleteActivities(['affecteduser' => $user]);
53 1
	}
54
55
	/**
56
	 * Delete all mail queue entries
57
	 *
58
	 * @param IDBConnection $connection
59
	 * @param string $user
60
	 */
61 1
	protected static function deleteUserMailQueue(IDBConnection $connection, $user) {
62
		// Delete entries from mail queue
63 1
		$queryBuilder = $connection->getQueryBuilder();
64
65 1
		$queryBuilder->delete('activity_mq')
66 1
			->where($queryBuilder->expr()->eq('amq_affecteduser', $queryBuilder->createParameter('user')))
67 1
			->setParameter('user', $user);
68 1
		$queryBuilder->execute();
69 1
	}
70
}
71