Completed
Push — master ( 20a4aa...235fe7 )
by Maxence
04:53 queued 02:10
created

RemoveDeadShares::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Circles - Bring cloud-users closer together.
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2017
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\Circles\Migration;
28
29
use OCA\Circles\Db\MembersRequest;
30
use OCA\Circles\Db\SharesRequest;
31
use OCA\Circles\Model\Member;
32
use OCA\Circles\Service\ConfigService;
33
use OCP\IConfig;
34
use OCP\IDBConnection;
35
use OCP\Migration\IOutput;
36
use OCP\Migration\IRepairStep;
37
38
/**
39
 * Class ImportOwncloudCustomGroups
40
 *
41
 * @package OCA\Circles\Migration
42
 */
43
class RemoveDeadShares implements IRepairStep {
44
45
	/** @var IDBConnection */
46
	protected $connection;
47
48
	/** @var  IConfig */
49
	protected $config;
50
51
	/** @var SharesRequest */
52
	private $sharesRequest;
53
54
	/** @var MembersRequest */
55
	private $membersRequest;
56
57
	/** @var ConfigService */
58
	private $configService;
59
60
61
	/**
62
	 * RemoveDeadShares constructor.
63
	 *
64
	 * @param IDBConnection $connection
65
	 * @param IConfig $config
66
	 * @param SharesRequest $sharesRequest
67
	 * @param MembersRequest $membersRequest
68
	 * @param ConfigService $configService
69
	 */
70
	public function __construct(
71
		IDBConnection $connection, IConfig $config, SharesRequest $sharesRequest,
72
		MembersRequest $membersRequest, ConfigService $configService
73
	) {
74
		$this->connection = $connection;
75
		$this->config = $config;
76
77
		$this->sharesRequest = $sharesRequest;
78
		$this->membersRequest = $membersRequest;
79
		$this->configService = $configService;
80
	}
81
82
83
	/**
84
	 * Returns the step's name
85
	 *
86
	 * @return string
87
	 * @since 9.1.0
88
	 */
89
	public function getName() {
90
		return 'Cleaning shares database of dead shares';
91
	}
92
93
94
	/**
95
	 * @param IOutput $output
96
	 */
97
	public function run(IOutput $output) {
98
99
		$members = $this->membersRequest->forceGetAllMembers();
100
101
		foreach ($members as $member) {
102
			if ($member->getLevel() > Member::LEVEL_NONE) {
103
				continue;
104
			}
105
106
			if ($member->getType() === Member::TYPE_USER) {
107
				$this->removeSharesFromMember($member);
108
			}
109
110
			try {
111
				$this->membersRequest->removeMember($member);
112
			} catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
113
			}
114
		}
115
116
	}
117
118
119
	private function removeSharesFromMember(Member $member) {
120
		$this->sharesRequest->removeSharesFromMember($member);
121
	}
122
123
124
}
125