|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (c) 2016 Joas Schilling <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* @author Joas Schilling <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* @license GNU AGPL version 3 or any later version |
|
9
|
|
|
* |
|
10
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
11
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
12
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
13
|
|
|
* License, or (at your option) any later version. |
|
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 |
|
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
22
|
|
|
* |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
namespace OCA\AnnouncementCenter\Migration; |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
use OCP\IDBConnection; |
|
30
|
|
|
use OCP\Migration\IOutput; |
|
31
|
|
|
use OCP\Migration\IRepairStep; |
|
32
|
|
|
|
|
33
|
|
|
class AnnouncementsGroupsLinks implements IRepairStep { |
|
34
|
|
|
|
|
35
|
|
|
/** @var IDBConnection */ |
|
36
|
|
|
protected $connection; |
|
37
|
|
|
|
|
38
|
1 |
|
public function __construct(IDBConnection $connection) { |
|
39
|
1 |
|
$this->connection = $connection; |
|
40
|
1 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Returns the step's name |
|
44
|
|
|
* |
|
45
|
|
|
* @return string |
|
46
|
|
|
* @since 9.1.0 |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getName(): string { |
|
49
|
|
|
return 'Add read permissions for existing announcements'; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Run repair step. |
|
54
|
|
|
* Must throw exception on error. |
|
55
|
|
|
* |
|
56
|
|
|
* @since 9.1.0 |
|
57
|
|
|
* @param IOutput $output |
|
58
|
|
|
* @throws \Exception in case of failure |
|
59
|
|
|
*/ |
|
60
|
|
|
public function run(IOutput $output) { |
|
61
|
|
|
$queryInsert = $this->connection->getQueryBuilder(); |
|
62
|
|
|
$queryInsert->insert('announcements_groups') |
|
63
|
|
|
->values([ |
|
64
|
|
|
'announcement_id' => $queryInsert->createParameter('aid'), |
|
65
|
|
|
'gid' => $queryInsert->createNamedParameter('everyone'), |
|
66
|
|
|
]); |
|
67
|
|
|
|
|
68
|
|
|
$query = $this->connection->getQueryBuilder(); |
|
69
|
|
|
$query->select(['a.announcement_id', 'a.announcement_subject']) |
|
70
|
|
|
->from('announcements', 'a') |
|
71
|
|
|
->leftJoin('a', 'announcements_groups', 'ag', $query->expr()->eq( |
|
72
|
|
|
'a.announcement_id', 'ag.announcement_id' |
|
73
|
|
|
)) |
|
74
|
|
|
->where($query->expr()->isNull('ag.gid')); |
|
75
|
|
|
$result = $query->execute(); |
|
76
|
|
|
|
|
77
|
|
|
$output->startProgress(); |
|
78
|
|
|
while ($row = $result->fetch()) { |
|
79
|
|
|
$output->advance(1, $row['announcement_subject']); |
|
80
|
|
|
$queryInsert->setParameter('aid', (int) $row['announcement_id']) |
|
81
|
|
|
->execute(); |
|
82
|
|
|
} |
|
83
|
|
|
$output->finishProgress(); |
|
84
|
|
|
|
|
85
|
|
|
$result->closeCursor(); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|