2019-08-16 11:17:38 -04:00
|
|
|
<?php
|
2020-04-09 05:50:14 -04:00
|
|
|
|
2019-08-16 11:17:38 -04:00
|
|
|
declare(strict_types=1);
|
2021-06-04 15:52:51 -04:00
|
|
|
|
2019-08-16 11:17:38 -04:00
|
|
|
/**
|
2024-05-30 14:13:41 -04:00
|
|
|
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2019-08-16 11:17:38 -04:00
|
|
|
*/
|
|
|
|
|
namespace OCA\WorkflowEngine\Migration;
|
|
|
|
|
|
2021-01-03 09:28:31 -05:00
|
|
|
use OCP\DB\IResult;
|
2019-08-16 11:17:38 -04:00
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
use OCP\Migration\IOutput;
|
|
|
|
|
use OCP\Migration\IRepairStep;
|
|
|
|
|
use OCP\WorkflowEngine\IManager;
|
|
|
|
|
|
|
|
|
|
class PopulateNewlyIntroducedDatabaseFields implements IRepairStep {
|
|
|
|
|
|
2024-10-16 04:41:21 -04:00
|
|
|
public function __construct(
|
|
|
|
|
private IDBConnection $dbc,
|
|
|
|
|
) {
|
2019-08-16 11:17:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getName() {
|
|
|
|
|
return 'Populating added database structures for workflows';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function run(IOutput $output) {
|
|
|
|
|
$result = $this->getIdsWithoutScope();
|
|
|
|
|
|
|
|
|
|
$this->populateScopeTable($result);
|
|
|
|
|
|
|
|
|
|
$result->closeCursor();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-03 09:28:31 -05:00
|
|
|
protected function populateScopeTable(IResult $ids): void {
|
2019-08-16 11:17:38 -04:00
|
|
|
$qb = $this->dbc->getQueryBuilder();
|
|
|
|
|
|
|
|
|
|
$insertQuery = $qb->insert('flow_operations_scope');
|
2022-03-08 06:10:52 -05:00
|
|
|
while (($id = $ids->fetchOne()) !== false) {
|
2019-08-16 11:17:38 -04:00
|
|
|
$insertQuery->values(['operation_id' => $qb->createNamedParameter($id), 'type' => IManager::SCOPE_ADMIN]);
|
2024-10-16 04:41:21 -04:00
|
|
|
$insertQuery->executeStatement();
|
2019-08-16 11:17:38 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-03 09:28:31 -05:00
|
|
|
protected function getIdsWithoutScope(): IResult {
|
2019-08-16 11:17:38 -04:00
|
|
|
$qb = $this->dbc->getQueryBuilder();
|
|
|
|
|
$selectQuery = $qb->select('o.id')
|
|
|
|
|
->from('flow_operations', 'o')
|
|
|
|
|
->leftJoin('o', 'flow_operations_scope', 's', $qb->expr()->eq('o.id', 's.operation_id'))
|
|
|
|
|
->where($qb->expr()->isNull('s.operation_id'));
|
|
|
|
|
// The left join operation is not necessary, usually, but it's a safe-guard
|
|
|
|
|
// in case the repair step is executed multiple times for whatever reason.
|
|
|
|
|
|
2021-01-03 09:28:31 -05:00
|
|
|
/** @var IResult $result */
|
2024-10-16 04:41:21 -04:00
|
|
|
$result = $selectQuery->executeQuery();
|
2021-01-03 09:28:31 -05:00
|
|
|
return $result;
|
2019-08-16 11:17:38 -04:00
|
|
|
}
|
|
|
|
|
}
|