|
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\Model\FederatedLink; |
|
32
|
|
|
|
|
33
|
|
|
class FederatedLinksRequest extends FederatedLinksRequestBuilder { |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
public function create(FederatedLink $link) { |
|
37
|
|
|
try { |
|
38
|
|
|
$qb = $this->getLinksInsertSql(); |
|
39
|
|
|
$qb->setValue('status', $qb->createNamedParameter($link->getStatus())) |
|
40
|
|
|
->setValue('circle_id', $qb->createNamedParameter($link->getCircleId())) |
|
41
|
|
|
->setValue('remote_circle_id', $qb->createNamedParameter($link->getRemoteCircleId())) |
|
42
|
|
|
->setValue('address', $qb->createNamedParameter($link->getAddress())) |
|
43
|
|
|
->setValue('token', $qb->createNamedParameter($link->getToken())); |
|
44
|
|
|
|
|
45
|
|
|
$qb->execute(); |
|
46
|
|
|
|
|
47
|
|
|
return true; |
|
48
|
|
|
} catch (\Exception $e) { |
|
49
|
|
|
throw $e; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
public function update(FederatedLink $link) { |
|
55
|
|
|
$qb = $this->getLinksUpdateSql(); |
|
56
|
|
|
$expr = $qb->expr(); |
|
57
|
|
|
|
|
58
|
|
|
$qb->set('status', $qb->createNamedParameter($link->getStatus())); |
|
59
|
|
|
if ($link->getRemoteCircleId() > 0) { |
|
60
|
|
|
$qb->set('remote_circle_id', $qb->createNamedParameter($link->getRemoteCircleId())); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$qb->where( |
|
64
|
|
|
$expr->andX( |
|
65
|
|
|
$expr->eq('circle_id', $qb->createNamedParameter($link->getCircleId())), |
|
66
|
|
|
$expr->eq('token', $qb->createNamedParameter($link->getToken())) |
|
67
|
|
|
) |
|
68
|
|
|
); |
|
69
|
|
|
|
|
70
|
|
|
$qb->execute(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
public function delete(FederatedLink $link) { |
|
75
|
|
|
|
|
76
|
|
|
$this->miscService->log("DELETRE !! " . var_export($link, true)); |
|
77
|
|
|
if ($link === null) { |
|
78
|
|
|
return; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
$qb = $this->getLinksDeleteSql(); |
|
82
|
|
|
$expr = $qb->expr(); |
|
83
|
|
|
|
|
84
|
|
|
$qb->where( |
|
85
|
|
|
$expr->andX( |
|
86
|
|
|
$expr->eq('token', $qb->createNamedParameter($link->getToken())), |
|
87
|
|
|
$expr->eq('circle_id', $qb->createNamedParameter($link->getCircleId())) |
|
88
|
|
|
) |
|
89
|
|
|
); |
|
90
|
|
|
|
|
91
|
|
|
$qb->execute(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
} |