Skip to content

Commit bb14273

Browse files
feat(install): dispatch InstallationCompletedEvent in Setup
Integrate event dispatching into Setup class: - Inject IEventDispatcher dependency - Dispatch InstallationCompletedEvent after successful installation - Add Setup tests for event integration - Update composer autoload for new class Signed-off-by: Misha M.-Kupriyanov <kupriyanov@strato.de> [skip ci] Signed-off-by: Misha M.-Kupriyanov <kupriyanov@strato.de>
1 parent 9bd4f41 commit bb14273

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@
607607
'OCP\\IUserManager' => $baseDir . '/lib/public/IUserManager.php',
608608
'OCP\\IUserSession' => $baseDir . '/lib/public/IUserSession.php',
609609
'OCP\\Image' => $baseDir . '/lib/public/Image.php',
610+
'OCP\\Install\\Events\\InstallationCompletedEvent' => $baseDir . '/lib/public/Install/Events/InstallationCompletedEvent.php',
610611
'OCP\\L10N\\IFactory' => $baseDir . '/lib/public/L10N/IFactory.php',
611612
'OCP\\L10N\\ILanguageIterator' => $baseDir . '/lib/public/L10N/ILanguageIterator.php',
612613
'OCP\\LDAP\\IDeletionFlagSupport' => $baseDir . '/lib/public/LDAP/IDeletionFlagSupport.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
656656
'OCP\\IUserManager' => __DIR__ . '/../../..' . '/lib/public/IUserManager.php',
657657
'OCP\\IUserSession' => __DIR__ . '/../../..' . '/lib/public/IUserSession.php',
658658
'OCP\\Image' => __DIR__ . '/../../..' . '/lib/public/Image.php',
659+
'OCP\\Install\\Events\\InstallationCompletedEvent' => __DIR__ . '/../../..' . '/lib/public/Install/Events/InstallationCompletedEvent.php',
659660
'OCP\\L10N\\IFactory' => __DIR__ . '/../../..' . '/lib/public/L10N/IFactory.php',
660661
'OCP\\L10N\\ILanguageIterator' => __DIR__ . '/../../..' . '/lib/public/L10N/ILanguageIterator.php',
661662
'OCP\\LDAP\\IDeletionFlagSupport' => __DIR__ . '/../../..' . '/lib/public/LDAP/IDeletionFlagSupport.php',

lib/private/Setup.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
use OCP\AppFramework\Utility\ITimeFactory;
2323
use OCP\BackgroundJob\IJobList;
2424
use OCP\Defaults;
25+
use OCP\EventDispatcher\IEventDispatcher;
2526
use OCP\IAppConfig;
2627
use OCP\IConfig;
2728
use OCP\IGroup;
2829
use OCP\IGroupManager;
2930
use OCP\IL10N;
31+
use OCP\Install\Events\InstallationCompletedEvent;
3032
use OCP\IRequest;
3133
use OCP\IUserManager;
3234
use OCP\IUserSession;
@@ -48,6 +50,7 @@ public function __construct(
4850
protected LoggerInterface $logger,
4951
protected ISecureRandom $random,
5052
protected Installer $installer,
53+
protected IEventDispatcher $eventDispatcher,
5154
) {
5255
$this->l10n = $l10nFactory->get('lib');
5356
}
@@ -408,6 +411,13 @@ public function install(array $options, ?IOutput $output = null): array {
408411
$user->setSystemEMailAddress($options['adminemail']);
409412
}
410413

414+
// Dispatch installation completed event
415+
$adminUsername = !empty($username) ? $username : null;
416+
$adminEmail = !empty($options['adminemail']) ? $options['adminemail'] : null;
417+
$this->eventDispatcher->dispatchTyped(
418+
new InstallationCompletedEvent($dataDir, $adminUsername, $adminEmail)
419+
);
420+
411421
return $error;
412422
}
413423

tests/lib/SetupTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OC\Setup;
1313
use OC\SystemConfig;
1414
use OCP\Defaults;
15+
use OCP\EventDispatcher\IEventDispatcher;
1516
use OCP\IL10N;
1617
use OCP\L10N\IFactory as IL10NFactory;
1718
use OCP\Security\ISecureRandom;
@@ -27,6 +28,7 @@ class SetupTest extends \Test\TestCase {
2728
protected LoggerInterface $logger;
2829
protected ISecureRandom $random;
2930
protected Installer $installer;
31+
protected IEventDispatcher $eventDispatcher;
3032

3133
protected function setUp(): void {
3234
parent::setUp();
@@ -41,9 +43,10 @@ protected function setUp(): void {
4143
$this->logger = $this->createMock(LoggerInterface::class);
4244
$this->random = $this->createMock(ISecureRandom::class);
4345
$this->installer = $this->createMock(Installer::class);
46+
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
4447
$this->setupClass = $this->getMockBuilder(Setup::class)
4548
->setMethods(['class_exists', 'is_callable', 'getAvailableDbDriversForPdo'])
46-
->setConstructorArgs([$this->config, $this->iniWrapper, $this->l10nFactory, $this->defaults, $this->logger, $this->random, $this->installer])
49+
->setConstructorArgs([$this->config, $this->iniWrapper, $this->l10nFactory, $this->defaults, $this->logger, $this->random, $this->installer, $this->eventDispatcher])
4750
->getMock();
4851
}
4952

0 commit comments

Comments
 (0)