aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2023-07-25 13:37:51 +0200
committerGitHub <noreply@github.com>2023-07-25 13:37:51 +0200
commitf824d87fc1f3aa99ddb141b7ba19b48641d2cb84 (patch)
tree52e9690556a722051d7b71ddf7f46ce13a409f31 /apps
parent468fb5c8db2318702c9a1895271b7d9c4f579dc0 (diff)
parentab70bbd3ffbc3788035588c86984f9508db8edbe (diff)
downloadnextcloud-server-f824d87fc1f3aa99ddb141b7ba19b48641d2cb84.tar.gz
nextcloud-server-f824d87fc1f3aa99ddb141b7ba19b48641d2cb84.zip
Merge pull request #39487 from nextcloud/feat/noid/typed-events-for-db_add-missing
Feat/noid/typed events for db add missing
Diffstat (limited to 'apps')
-rw-r--r--apps/settings/lib/Controller/CheckSetupController.php57
-rw-r--r--apps/settings/tests/Controller/CheckSetupControllerTest.php11
2 files changed, 39 insertions, 29 deletions
diff --git a/apps/settings/lib/Controller/CheckSetupController.php b/apps/settings/lib/Controller/CheckSetupController.php
index 07fb627dbd8..4a1913cedfe 100644
--- a/apps/settings/lib/Controller/CheckSetupController.php
+++ b/apps/settings/lib/Controller/CheckSetupController.php
@@ -74,7 +74,9 @@ use OCP\AppFramework\Http\Attribute\IgnoreOpenAPI;
use OCP\AppFramework\Http\DataDisplayResponse;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\RedirectResponse;
+use OCP\DB\Events\AddMissingColumnsEvent;
use OCP\DB\Events\AddMissingIndicesEvent;
+use OCP\DB\Events\AddMissingPrimaryKeyEvent;
use OCP\DB\Types;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Http\Client\IClientService;
@@ -90,8 +92,6 @@ use OCP\Lock\ILockingProvider;
use OCP\Notification\IManager;
use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
#[IgnoreOpenAPI]
class CheckSetupController extends Controller {
@@ -108,8 +108,6 @@ class CheckSetupController extends Controller {
/** @var LoggerInterface */
private $logger;
/** @var IEventDispatcher */
- private $eventDispatcher;
- /** @var EventDispatcherInterface */
private $dispatcher;
/** @var Connection */
private $db;
@@ -142,8 +140,7 @@ class CheckSetupController extends Controller {
IL10N $l10n,
Checker $checker,
LoggerInterface $logger,
- IEventDispatcher $eventDispatcher,
- EventDispatcherInterface $dispatcher,
+ IEventDispatcher $dispatcher,
Connection $db,
ILockingProvider $lockingProvider,
IDateTimeFormatter $dateTimeFormatter,
@@ -163,7 +160,6 @@ class CheckSetupController extends Controller {
$this->l10n = $l10n;
$this->checker = $checker;
$this->logger = $logger;
- $this->eventDispatcher = $eventDispatcher;
$this->dispatcher = $dispatcher;
$this->db = $db;
$this->lockingProvider = $lockingProvider;
@@ -551,11 +547,8 @@ Raw output
$indexInfo = new MissingIndexInformation();
// Dispatch event so apps can also hint for pending index updates if needed
- $event = new GenericEvent($indexInfo);
- $this->dispatcher->dispatch(IDBConnection::CHECK_MISSING_INDEXES_EVENT, $event);
-
$event = new AddMissingIndicesEvent();
- $this->eventDispatcher->dispatchTyped($event);
+ $this->dispatcher->dispatchTyped($event);
$missingIndices = $event->getMissingIndices();
if ($missingIndices !== []) {
@@ -575,20 +568,46 @@ Raw output
protected function hasMissingPrimaryKeys(): array {
$info = new MissingPrimaryKeyInformation();
- // Dispatch event so apps can also hint for pending index updates if needed
- $event = new GenericEvent($info);
- $this->dispatcher->dispatch(IDBConnection::CHECK_MISSING_PRIMARY_KEYS_EVENT, $event);
+ // Dispatch event so apps can also hint for pending key updates if needed
+ $event = new AddMissingPrimaryKeyEvent();
+ $this->dispatcher->dispatchTyped($event);
+ $missingKeys = $event->getMissingPrimaryKeys();
+
+ if (!empty($missingKeys)) {
+ $schema = new SchemaWrapper(\OCP\Server::get(Connection::class));
+ foreach ($missingKeys as $missingKey) {
+ if ($schema->hasTable($missingKey['tableName'])) {
+ $table = $schema->getTable($missingKey['tableName']);
+ if (!$table->hasPrimaryKey()) {
+ $info->addHintForMissingSubject($missingKey['tableName']);
+ }
+ }
+ }
+ }
return $info->getListOfMissingPrimaryKeys();
}
protected function hasMissingColumns(): array {
- $indexInfo = new MissingColumnInformation();
- // Dispatch event so apps can also hint for pending index updates if needed
- $event = new GenericEvent($indexInfo);
- $this->dispatcher->dispatch(IDBConnection::CHECK_MISSING_COLUMNS_EVENT, $event);
+ $columnInfo = new MissingColumnInformation();
+ // Dispatch event so apps can also hint for pending column updates if needed
+ $event = new AddMissingColumnsEvent();
+ $this->dispatcher->dispatchTyped($event);
+ $missingColumns = $event->getMissingColumns();
+
+ if (!empty($missingColumns)) {
+ $schema = new SchemaWrapper(\OCP\Server::get(Connection::class));
+ foreach ($missingColumns as $missingColumn) {
+ if ($schema->hasTable($missingColumn['tableName'])) {
+ $table = $schema->getTable($missingColumn['tableName']);
+ if (!$table->hasColumn($missingColumn['columnName'])) {
+ $columnInfo->addHintForMissingColumn($missingColumn['tableName'], $missingColumn['columnName']);
+ }
+ }
+ }
+ }
- return $indexInfo->getListOfMissingColumns();
+ return $columnInfo->getListOfMissingColumns();
}
protected function isSqliteUsed() {
diff --git a/apps/settings/tests/Controller/CheckSetupControllerTest.php b/apps/settings/tests/Controller/CheckSetupControllerTest.php
index 3fc4f930321..564c1cbb62d 100644
--- a/apps/settings/tests/Controller/CheckSetupControllerTest.php
+++ b/apps/settings/tests/Controller/CheckSetupControllerTest.php
@@ -62,7 +62,6 @@ use OCP\Notification\IManager;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
/**
@@ -89,8 +88,6 @@ class CheckSetupControllerTest extends TestCase {
/** @var Checker|\PHPUnit\Framework\MockObject\MockObject */
private $checker;
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
- private $eventDispatcher;
- /** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject */
private $dispatcher;
/** @var Connection|\PHPUnit\Framework\MockObject\MockObject */
private $db;
@@ -140,9 +137,7 @@ class CheckSetupControllerTest extends TestCase {
->willReturnCallback(function ($message, array $replace) {
return vsprintf($message, $replace);
});
- $this->eventDispatcher = $this->createMock(IEventDispatcher::class);
- $this->dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)
- ->disableOriginalConstructor()->getMock();
+ $this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker')
->disableOriginalConstructor()->getMock();
$this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
@@ -171,7 +166,6 @@ class CheckSetupControllerTest extends TestCase {
$this->l10n,
$this->checker,
$this->logger,
- $this->eventDispatcher,
$this->dispatcher,
$this->db,
$this->lockingProvider,
@@ -681,7 +675,6 @@ class CheckSetupControllerTest extends TestCase {
$this->l10n,
$this->checker,
$this->logger,
- $this->eventDispatcher,
$this->dispatcher,
$this->db,
$this->lockingProvider,
@@ -1409,7 +1402,6 @@ Array
$this->l10n,
$this->checker,
$this->logger,
- $this->eventDispatcher,
$this->dispatcher,
$this->db,
$this->lockingProvider,
@@ -1464,7 +1456,6 @@ Array
$this->l10n,
$this->checker,
$this->logger,
- $this->eventDispatcher,
$this->dispatcher,
$this->db,
$this->lockingProvider,