Skip to content

Commit 086fffd

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>
1 parent 61f69e9 commit 086fffd

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@
639639
'OCP\\IUserManager' => $baseDir . '/lib/public/IUserManager.php',
640640
'OCP\\IUserSession' => $baseDir . '/lib/public/IUserSession.php',
641641
'OCP\\Image' => $baseDir . '/lib/public/Image.php',
642+
'OCP\\Install\\Events\\InstallationCompletedEvent' => $baseDir . '/lib/public/Install/Events/InstallationCompletedEvent.php',
642643
'OCP\\L10N\\IFactory' => $baseDir . '/lib/public/L10N/IFactory.php',
643644
'OCP\\L10N\\ILanguageIterator' => $baseDir . '/lib/public/L10N/ILanguageIterator.php',
644645
'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
@@ -680,6 +680,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
680680
'OCP\\IUserManager' => __DIR__ . '/../../..' . '/lib/public/IUserManager.php',
681681
'OCP\\IUserSession' => __DIR__ . '/../../..' . '/lib/public/IUserSession.php',
682682
'OCP\\Image' => __DIR__ . '/../../..' . '/lib/public/Image.php',
683+
'OCP\\Install\\Events\\InstallationCompletedEvent' => __DIR__ . '/../../..' . '/lib/public/Install/Events/InstallationCompletedEvent.php',
683684
'OCP\\L10N\\IFactory' => __DIR__ . '/../../..' . '/lib/public/L10N/IFactory.php',
684685
'OCP\\L10N\\ILanguageIterator' => __DIR__ . '/../../..' . '/lib/public/L10N/ILanguageIterator.php',
685686
'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,12 +22,14 @@
2222
use OCP\AppFramework\Utility\ITimeFactory;
2323
use OCP\BackgroundJob\IJobList;
2424
use OCP\Defaults;
25+
use OCP\EventDispatcher\IEventDispatcher;
2526
use OCP\Http\Client\IClientService;
2627
use OCP\IAppConfig;
2728
use OCP\IConfig;
2829
use OCP\IGroup;
2930
use OCP\IGroupManager;
3031
use OCP\IL10N;
32+
use OCP\Install\Events\InstallationCompletedEvent;
3133
use OCP\IRequest;
3234
use OCP\IURLGenerator;
3335
use OCP\IUserManager;
@@ -50,6 +52,7 @@ public function __construct(
5052
protected LoggerInterface $logger,
5153
protected ISecureRandom $random,
5254
protected Installer $installer,
55+
protected IEventDispatcher $eventDispatcher,
5356
) {
5457
$this->l10n = $l10nFactory->get('lib');
5558
}
@@ -494,6 +497,13 @@ public function install(array $options, ?IOutput $output = null): array {
494497
}
495498
}
496499

500+
// Dispatch installation completed event
501+
$adminUsername = !$disableAdminUser ? ($options['adminlogin'] ?? null) : null;
502+
$adminEmail = !empty($options['adminemail']) ? $options['adminemail'] : null;
503+
$this->eventDispatcher->dispatchTyped(
504+
new InstallationCompletedEvent($dataDir, $adminUsername, $adminEmail)
505+
);
506+
497507
return $error;
498508
}
499509

lib/public/Install/Events/InstallationCompletedEvent.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
* - Initializing app-specific data
2828
* - Setting up integrations
2929
*
30-
* @since 33.0.0
30+
* @since 32.0.0
3131
*/
3232
class InstallationCompletedEvent extends Event {
3333
/**
34-
* @since 33.0.0
34+
* @since 32.0.0
3535
*/
3636
public function __construct(
3737
private string $dataDirectory,
@@ -44,7 +44,7 @@ public function __construct(
4444
/**
4545
* Get the configured data directory path
4646
*
47-
* @since 33.0.0
47+
* @since 32.0.0
4848
*/
4949
public function getDataDirectory(): string {
5050
return $this->dataDirectory;
@@ -53,7 +53,7 @@ public function getDataDirectory(): string {
5353
/**
5454
* Get the admin username if an admin user was created
5555
*
56-
* @since 33.0.0
56+
* @since 32.0.0
5757
*/
5858
public function getAdminUsername(): ?string {
5959
return $this->adminUsername;
@@ -62,7 +62,7 @@ public function getAdminUsername(): ?string {
6262
/**
6363
* Get the admin email if configured
6464
*
65-
* @since 33.0.0
65+
* @since 32.0.0
6666
*/
6767
public function getAdminEmail(): ?string {
6868
return $this->adminEmail;
@@ -71,7 +71,7 @@ public function getAdminEmail(): ?string {
7171
/**
7272
* Check if an admin user was created during installation
7373
*
74-
* @since 33.0.0
74+
* @since 32.0.0
7575
*/
7676
public function hasAdminUser(): bool {
7777
return $this->adminUsername !== null;

tests/lib/SetupTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use OC\Setup;
1414
use OC\SystemConfig;
1515
use OCP\Defaults;
16+
use OCP\EventDispatcher\IEventDispatcher;
1617
use OCP\IL10N;
1718
use OCP\L10N\IFactory as IL10NFactory;
1819
use OCP\Security\ISecureRandom;
@@ -28,6 +29,7 @@ class SetupTest extends \Test\TestCase {
2829
protected LoggerInterface $logger;
2930
protected ISecureRandom $random;
3031
protected Installer $installer;
32+
protected IEventDispatcher $eventDispatcher;
3133

3234
protected function setUp(): void {
3335
parent::setUp();
@@ -42,9 +44,10 @@ protected function setUp(): void {
4244
$this->logger = $this->createMock(LoggerInterface::class);
4345
$this->random = $this->createMock(ISecureRandom::class);
4446
$this->installer = $this->createMock(Installer::class);
47+
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
4548
$this->setupClass = $this->getMockBuilder(Setup::class)
4649
->onlyMethods(['class_exists', 'is_callable', 'getAvailableDbDriversForPdo'])
47-
->setConstructorArgs([$this->config, $this->iniWrapper, $this->l10nFactory, $this->defaults, $this->logger, $this->random, $this->installer])
50+
->setConstructorArgs([$this->config, $this->iniWrapper, $this->l10nFactory, $this->defaults, $this->logger, $this->random, $this->installer, $this->eventDispatcher])
4851
->getMock();
4952
}
5053

0 commit comments

Comments
 (0)