Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 38 additions & 19 deletions apps/settings/lib/Controller/CheckSetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@
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;
Expand All @@ -90,8 +92,6 @@
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 {
Expand All @@ -108,8 +108,6 @@ class CheckSetupController extends Controller {
/** @var LoggerInterface */
private $logger;
/** @var IEventDispatcher */
private $eventDispatcher;
/** @var EventDispatcherInterface */
private $dispatcher;
/** @var Connection */
private $db;
Expand Down Expand Up @@ -142,8 +140,7 @@ public function __construct($AppName,
IL10N $l10n,
Checker $checker,
LoggerInterface $logger,
IEventDispatcher $eventDispatcher,
EventDispatcherInterface $dispatcher,
IEventDispatcher $dispatcher,
Connection $db,
ILockingProvider $lockingProvider,
IDateTimeFormatter $dateTimeFormatter,
Expand All @@ -163,7 +160,6 @@ public function __construct($AppName,
$this->l10n = $l10n;
$this->checker = $checker;
$this->logger = $logger;
$this->eventDispatcher = $eventDispatcher;
$this->dispatcher = $dispatcher;
$this->db = $db;
$this->lockingProvider = $lockingProvider;
Expand Down Expand Up @@ -551,11 +547,8 @@ protected function hasMissingIndexes(): array {
$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 !== []) {
Expand All @@ -575,20 +568,46 @@ protected function hasMissingIndexes(): array {

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() {
Expand Down
11 changes: 1 addition & 10 deletions apps/settings/tests/Controller/CheckSetupControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;

/**
Expand All @@ -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;
Expand Down Expand Up @@ -140,9 +137,7 @@ protected function setUp(): void {
->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();
Expand Down Expand Up @@ -171,7 +166,6 @@ protected function setUp(): void {
$this->l10n,
$this->checker,
$this->logger,
$this->eventDispatcher,
$this->dispatcher,
$this->db,
$this->lockingProvider,
Expand Down Expand Up @@ -681,7 +675,6 @@ public function testGetCurlVersion() {
$this->l10n,
$this->checker,
$this->logger,
$this->eventDispatcher,
$this->dispatcher,
$this->db,
$this->lockingProvider,
Expand Down Expand Up @@ -1409,7 +1402,6 @@ public function testIsMysqlUsedWithoutUTF8MB4(string $db, bool $useUTF8MB4, bool
$this->l10n,
$this->checker,
$this->logger,
$this->eventDispatcher,
$this->dispatcher,
$this->db,
$this->lockingProvider,
Expand Down Expand Up @@ -1464,7 +1456,6 @@ public function testIsEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(string $m
$this->l10n,
$this->checker,
$this->logger,
$this->eventDispatcher,
$this->dispatcher,
$this->db,
$this->lockingProvider,
Expand Down
Loading