|
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
|
|
|
|
|
28
|
|
|
namespace OCA\Circles\Db; |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
use OCA\Circles\Exceptions\SharingFrameDoesNotExistException; |
|
32
|
|
|
use OCA\Circles\Model\SharingFrame; |
|
33
|
|
|
|
|
34
|
|
|
class SharingFrameRequest extends SharingFrameRequestBuilder { |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param string $circleUniqueId |
|
39
|
|
|
* @param string $frameUniqueId |
|
40
|
|
|
* |
|
41
|
|
|
* @return SharingFrame |
|
42
|
|
|
* @throws SharingFrameDoesNotExistException |
|
43
|
|
|
*/ |
|
44
|
|
View Code Duplication |
public function getSharingFrame($circleUniqueId, $frameUniqueId) { |
|
|
|
|
|
|
45
|
|
|
$qb = $this->getSharesSelectSql(); |
|
46
|
|
|
$this->limitToUniqueId($qb, $frameUniqueId); |
|
47
|
|
|
$this->limitToCircleId($qb, $circleUniqueId); |
|
48
|
|
|
$this->leftJoinCircle($qb); |
|
49
|
|
|
|
|
50
|
|
|
$cursor = $qb->execute(); |
|
51
|
|
|
$data = $cursor->fetch(); |
|
52
|
|
|
$cursor->closeCursor(); |
|
53
|
|
|
|
|
54
|
|
|
if ($data === false) { |
|
55
|
|
|
throw new SharingFrameDoesNotExistException($this->l10n->t('Sharing Frame does not exist')); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return $this->parseSharesSelectSql($data); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param string $circleUniqueId |
|
64
|
|
|
* |
|
65
|
|
|
* @return SharingFrame[] |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getSharingFramesFromCircle($circleUniqueId) { |
|
68
|
|
|
$qb = $this->getSharesSelectSql(); |
|
69
|
|
|
$this->limitToCircleId($qb, $circleUniqueId); |
|
70
|
|
|
|
|
71
|
|
|
$frames = []; |
|
72
|
|
|
$cursor = $qb->execute(); |
|
73
|
|
|
while ($data = $cursor->fetch()) { |
|
74
|
|
|
$frames[] = $this->parseSharesSelectSql($data); |
|
75
|
|
|
} |
|
76
|
|
|
$cursor->closeCursor(); |
|
77
|
|
|
|
|
78
|
|
|
return $frames; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* saveFrame() |
|
84
|
|
|
* |
|
85
|
|
|
* Insert a new entry in the database to save the SharingFrame. |
|
86
|
|
|
* |
|
87
|
|
|
* @param SharingFrame $frame |
|
88
|
|
|
*/ |
|
89
|
|
View Code Duplication |
public function saveSharingFrame(SharingFrame $frame) { |
|
|
|
|
|
|
90
|
|
|
$qb = $this->getSharesInsertSql(); |
|
91
|
|
|
$circle = $frame->getCircle(); |
|
92
|
|
|
$qb->setValue('circle_id', $qb->createNamedParameter($circle->getUniqueId())) |
|
93
|
|
|
->setValue('source', $qb->createNamedParameter($frame->getSource())) |
|
94
|
|
|
->setValue('type', $qb->createNamedParameter($frame->getType())) |
|
95
|
|
|
->setValue('headers', $qb->createNamedParameter($frame->getHeaders(true))) |
|
96
|
|
|
->setValue('author', $qb->createNamedParameter($frame->getAuthor())) |
|
97
|
|
|
->setValue('cloud_id', $qb->createNamedParameter($frame->getCloudId())) |
|
98
|
|
|
->setValue('unique_id', $qb->createNamedParameter($frame->getUniqueId())) |
|
99
|
|
|
->setValue('payload', $qb->createNamedParameter($frame->getPayload(true))); |
|
100
|
|
|
|
|
101
|
|
|
$qb->execute(); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
View Code Duplication |
public function updateSharingFrame(SharingFrame $frame) { |
|
|
|
|
|
|
106
|
|
|
$qb = $this->getSharesUpdateSql($frame->getUniqueId()); |
|
107
|
|
|
$circle = $frame->getCircle(); |
|
108
|
|
|
$qb->set('circle_id', $qb->createNamedParameter($circle->getUniqueId())) |
|
109
|
|
|
->set('source', $qb->createNamedParameter($frame->getSource())) |
|
110
|
|
|
->set('type', $qb->createNamedParameter($frame->getType())) |
|
111
|
|
|
->set('headers', $qb->createNamedParameter($frame->getHeaders(true))) |
|
112
|
|
|
->set('author', $qb->createNamedParameter($frame->getAuthor())) |
|
113
|
|
|
->set('cloud_id', $qb->createNamedParameter($frame->getCloudId())) |
|
114
|
|
|
->set('unique_id', $qb->createNamedParameter($frame->getUniqueId())) |
|
115
|
|
|
->set('payload', $qb->createNamedParameter($frame->getPayload(true))); |
|
116
|
|
|
|
|
117
|
|
|
$qb->execute(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
public function updatePasswordOnShares(string $circleId, string $password) { |
|
|
|
|
|
|
124
|
|
|
$qb = $this->getSharesUpdateSql($frame->getUniqueId()); |
|
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
$this->limitToShareWith($qb, $circleId); |
|
127
|
|
|
$this->limitToShareType($qb, self::SHARE_TYPE); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
|
|
131
|
|
|
} |
|
132
|
|
|
|
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.