Skip to content

Commit dc872c2

Browse files
printminion-cobackportbot[bot]
authored andcommitted
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 3d694b8 commit dc872c2

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
@@ -649,6 +649,7 @@
649649
'OCP\\IUserManager' => $baseDir . '/lib/public/IUserManager.php',
650650
'OCP\\IUserSession' => $baseDir . '/lib/public/IUserSession.php',
651651
'OCP\\Image' => $baseDir . '/lib/public/Image.php',
652+
'OCP\\Install\\Events\\InstallationCompletedEvent' => $baseDir . '/lib/public/Install/Events/InstallationCompletedEvent.php',
652653
'OCP\\L10N\\IFactory' => $baseDir . '/lib/public/L10N/IFactory.php',
653654
'OCP\\L10N\\ILanguageIterator' => $baseDir . '/lib/public/L10N/ILanguageIterator.php',
654655
'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
@@ -690,6 +690,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
690690
'OCP\\IUserManager' => __DIR__ . '/../../..' . '/lib/public/IUserManager.php',
691691
'OCP\\IUserSession' => __DIR__ . '/../../..' . '/lib/public/IUserSession.php',
692692
'OCP\\Image' => __DIR__ . '/../../..' . '/lib/public/Image.php',
693+
'OCP\\Install\\Events\\InstallationCompletedEvent' => __DIR__ . '/../../..' . '/lib/public/Install/Events/InstallationCompletedEvent.php',
693694
'OCP\\L10N\\IFactory' => __DIR__ . '/../../..' . '/lib/public/L10N/IFactory.php',
694695
'OCP\\L10N\\ILanguageIterator' => __DIR__ . '/../../..' . '/lib/public/L10N/ILanguageIterator.php',
695696
'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
@@ -23,12 +23,14 @@
2323
use OCP\AppFramework\Utility\ITimeFactory;
2424
use OCP\BackgroundJob\IJobList;
2525
use OCP\Defaults;
26+
use OCP\EventDispatcher\IEventDispatcher;
2627
use OCP\Http\Client\IClientService;
2728
use OCP\IAppConfig;
2829
use OCP\IConfig;
2930
use OCP\IGroup;
3031
use OCP\IGroupManager;
3132
use OCP\IL10N;
33+
use OCP\Install\Events\InstallationCompletedEvent;
3234
use OCP\IRequest;
3335
use OCP\IURLGenerator;
3436
use OCP\IUserManager;
@@ -51,6 +53,7 @@ public function __construct(
5153
protected LoggerInterface $logger,
5254
protected ISecureRandom $random,
5355
protected Installer $installer,
56+
protected IEventDispatcher $eventDispatcher,
5457
) {
5558
$this->l10n = $l10nFactory->get('lib');
5659
}
@@ -495,6 +498,13 @@ public function install(array $options, ?IOutput $output = null): array {
495498
}
496499
}
497500

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

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)