|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
/** |
|
5
|
|
|
* @copyright Copyright (c) 2019 Arthur Schiwon <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @author Arthur Schiwon <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* @license GNU AGPL version 3 or any later version |
|
10
|
|
|
* |
|
11
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
13
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
14
|
|
|
* License, or (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* This program is distributed in the hope that it will be useful, |
|
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19
|
|
|
* GNU Affero General Public License for more details. |
|
20
|
|
|
* |
|
21
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
23
|
|
|
* |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
namespace OCA\WorkflowEngine\Migration; |
|
27
|
|
|
|
|
28
|
|
|
use Doctrine\DBAL\Driver\Statement; |
|
29
|
|
|
use OCP\IDBConnection; |
|
30
|
|
|
use OCP\Migration\IOutput; |
|
31
|
|
|
use OCP\Migration\IRepairStep; |
|
32
|
|
|
use OCP\WorkflowEngine\IManager; |
|
33
|
|
|
|
|
34
|
|
|
class PopulateNewlyIntroducedDatabaseFields implements IRepairStep { |
|
35
|
|
|
|
|
36
|
|
|
/** @var IDBConnection */ |
|
37
|
|
|
private $dbc; |
|
38
|
|
|
|
|
39
|
|
|
public function __construct(IDBConnection $dbc) { |
|
40
|
|
|
$this->dbc = $dbc; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function getName() { |
|
44
|
|
|
return 'Populating added database structures for workflows'; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function run(IOutput $output) { |
|
48
|
|
|
$result = $this->getIdsWithoutScope(); |
|
49
|
|
|
|
|
50
|
|
|
$this->populateScopeTable($result); |
|
51
|
|
|
|
|
52
|
|
|
$result->closeCursor(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
protected function populateScopeTable(Statement $ids): void { |
|
56
|
|
|
$qb = $this->dbc->getQueryBuilder(); |
|
57
|
|
|
|
|
58
|
|
|
$insertQuery = $qb->insert('flow_operations_scope'); |
|
59
|
|
|
while ($id = $ids->fetchColumn(0)) { |
|
60
|
|
|
$insertQuery->values(['operation_id' => $qb->createNamedParameter($id), 'type' => IManager::SCOPE_ADMIN]); |
|
61
|
|
|
$insertQuery->execute(); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
protected function getIdsWithoutScope(): Statement { |
|
66
|
|
|
$qb = $this->dbc->getQueryBuilder(); |
|
67
|
|
|
$selectQuery = $qb->select('o.id') |
|
68
|
|
|
->from('flow_operations', 'o') |
|
69
|
|
|
->leftJoin('o', 'flow_operations_scope', 's', $qb->expr()->eq('o.id', 's.operation_id')) |
|
70
|
|
|
->where($qb->expr()->isNull('s.operation_id')); |
|
71
|
|
|
// The left join operation is not necessary, usually, but it's a safe-guard |
|
72
|
|
|
// in case the repair step is executed multiple times for whatever reason. |
|
73
|
|
|
|
|
74
|
|
|
return $selectQuery->execute(); |
|
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|