Completed
Push — master ( ddbb9b...8e16e7 )
by Joas
12:36
created

Hooks::post_addToGroup()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 15
rs 9.4285
cc 3
eloc 9
nc 3
nop 1
1
<?php
2
/**
3
 * @author Björn Schießle <[email protected]>
4
 * @author Morris Jobke <[email protected]>
5
 * @author Robin McCorkell <[email protected]>
6
 * @author Roeland Jago Douma <[email protected]>
7
 *
8
 * @copyright Copyright (c) 2016, ownCloud, Inc.
9
 * @license AGPL-3.0
10
 *
11
 * This code is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License, version 3,
13
 * as published by the Free Software Foundation.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License, version 3,
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
22
 *
23
 */
24
25
namespace OC\Share;
26
27
class Hooks extends \OC\Share\Constants {
28
	/**
29
	 * Function that is called after a user is removed from a group. Shares are cleaned up.
30
	 * @param array $arguments
31
	 */
32
	public static function post_removeFromGroup($arguments) {
33
		$sql = 'SELECT `id`, `share_type` FROM `*PREFIX*share`'
34
			.' WHERE (`share_type` = ? AND `share_with` = ?) OR (`share_type` = ? AND `share_with` = ?)';
35
		$result = \OC_DB::executeAudited($sql, array(self::SHARE_TYPE_GROUP, $arguments['gid'],
36
			self::$shareTypeGroupUserUnique, $arguments['uid']));
37
		while ($item = $result->fetchRow()) {
38
			if ($item['share_type'] == self::SHARE_TYPE_GROUP) {
39
				// Delete all reshares by this user of the group share
40
				Helper::delete($item['id'], true, $arguments['uid']);
41
			} else {
42
				Helper::delete($item['id']);
43
			}
44
		}
45
	}
46
47
	/**
48
	 * Function that is called after a group is removed. Cleans up the shares to that group.
49
	 * @param array $arguments
50
	 */
51
	public static function post_deleteGroup($arguments) {
52
		$sql = 'SELECT `id` FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?';
53
		$result = \OC_DB::executeAudited($sql, array(self::SHARE_TYPE_GROUP, $arguments['gid']));
54
		while ($item = $result->fetchRow()) {
55
			Helper::delete($item['id']);
56
		}
57
	}
58
59
}
60