UnknownUsers::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 4
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Julius Härtl <[email protected]>
4
 *
5
 * @author Julius Härtl <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program. If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
25
namespace OCA\Deck\Migration;
26
27
use OCA\Deck\Db\Acl;
28
use OCA\Deck\Db\AclMapper;
29
use OCA\Deck\Db\Board;
30
use OCA\Deck\Db\BoardMapper;
31
use OCP\IGroupManager;
32
use OCP\IUserManager;
33
use OCP\Migration\IRepairStep;
34
use OCP\Migration\IOutput;
35
36
class UnknownUsers implements IRepairStep {
37
38
	private $userManager;
39
	private $groupManager;
40
	private $aclMapper;
41
	private $boardMapper;
42
43
	public function __construct(IUserManager $userManager, IGroupManager $groupManager, AclMapper $aclMapper, BoardMapper $boardMapper) {
44
		$this->userManager = $userManager;
45
		$this->groupManager = $groupManager;
46
		$this->aclMapper = $aclMapper;
47
		$this->boardMapper = $boardMapper;
48
	}
49
50
	/*
51
	 * @inheritdoc
52
	 */
53
	public function getName() {
54
		return 'Delete orphaned ACL rules';
55
	}
56
57
	/**
58
	 * @inheritdoc
59
	 */
60
	public function run(IOutput $output) {
61
		$boards = $this->boardMapper->findAll();
62
		/** @var Board $board */
63
		foreach ($boards as $board) {
64
			$acls = $this->aclMapper->findAll($board->getId());
65
			/** @var Acl $acl */
66
			foreach ($acls as $acl) {
67 View Code Duplication
				if ($acl->getType() === Acl::PERMISSION_TYPE_USER) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
					$user = $this->userManager->get($acl->getParticipant());
69
					if ($user === null) {
70
						$this->aclMapper->delete($acl);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::delete() has been deprecated with message: 14.0.0 Move over to QBMapper

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
71
					}
72
				}
73 View Code Duplication
				if ($acl->getType() === Acl::PERMISSION_TYPE_GROUP) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74
					$group = $this->groupManager->get($acl->getParticipant());
75
					if ($group === null) {
76
						$this->aclMapper->delete($acl);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::delete() has been deprecated with message: 14.0.0 Move over to QBMapper

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
77
					}
78
				}
79
80
			}
81
		}
82
	}
83
}
84