Completed
Push — master ( 65a2de...91e3d3 )
by mw
11:17
created

TableUpdater::updateGroupIdsForUser()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 8.8571
c 0
b 0
f 0
ccs 16
cts 16
cp 1
cc 2
eloc 15
nc 2
nop 2
crap 2
1
<?php
2
3
namespace SWL;
4
5
use DatabaseBase;
6
7
/**
8
 * @ingroup semantic-watchlist
9
 *
10
 * @license GNU GPL v2+
11
 * @since 1.0
12
 *
13
 * @author Jeroen De Dauw < [email protected] >
14
 * @author mwjames
15
 */
16
class TableUpdater {
17
18
	/**
19
	 * @var LazyDBConnectionProvider
20
	 */
21
	private $connectionProvider;
22
23
	/**
24
	 * @since 1.0
25
	 *
26
	 * @param LazyDBConnectionProvider $connectionProvider
27
	 */
28 3
	public function __construct( LazyDBConnectionProvider $connectionProvider ) {
29 3
		$this->connectionProvider = $connectionProvider;
30 3
	}
31
32
	/**
33
	 * @since 1.0
34
	 *
35
	 * @param $userId
36
	 * @param array $groupIds
37
	 */
38 2
	public function updateGroupIdsForUser( $userId, array $groupIds ) {
39
40 2
		$connection = $this->connectionProvider->getConnection();
41 2
		$connection->startAtomic( __METHOD__ );
42
43 2
		$connection->delete(
44 2
			'swl_users_per_group',
45
			array(
46
				'upg_user_id' => $userId
47 2
			)
48 2
		);
49
50 2
		foreach ( $groupIds as $groupId ) {
51 1
			$connection->insert(
52 1
				'swl_users_per_group',
53
				array(
54 1
					'upg_user_id'  => $userId,
55
					'upg_group_id' => $groupId
56 1
				)
57 1
			);
58 2
		}
59
60 2
		$connection->endAtomic( __METHOD__ );
61
62 2
		return true;
63
	}
64
65
}
66