-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
[stable32] Add InstallationCompletedEvent for post-installation actions #57925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
backportbot
wants to merge
2
commits into
stable32
Choose a base branch
from
backport/57522/stable32
base: stable32
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+184
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
| namespace OCP\Install\Events; | ||
|
|
||
| use OCP\EventDispatcher\Event; | ||
|
|
||
| /** | ||
| * Emitted when the Nextcloud installation has been completed successfully. | ||
| * | ||
| * This event is dispatched after: | ||
| * - The database has been configured and migrations have run | ||
| * - The admin user has been created (if applicable) | ||
| * - Default apps have been installed | ||
| * - Background jobs have been configured | ||
| * - The system has been marked as installed | ||
| * | ||
| * Apps can listen to this event to perform additional actions after installation, | ||
| * such as: | ||
| * - Sending notification emails | ||
| * - Triggering external APIs | ||
| * - Initializing app-specific data | ||
| * - Setting up integrations | ||
| * | ||
| * @since 33.0.0 | ||
| */ | ||
| class InstallationCompletedEvent extends Event { | ||
| /** | ||
| * @since 33.0.0 | ||
| */ | ||
| public function __construct( | ||
| private string $dataDirectory, | ||
| private ?string $adminUsername = null, | ||
| private ?string $adminEmail = null, | ||
| ) { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| /** | ||
| * Get the configured data directory path | ||
| * | ||
| * @since 33.0.0 | ||
| */ | ||
| public function getDataDirectory(): string { | ||
| return $this->dataDirectory; | ||
| } | ||
|
|
||
| /** | ||
| * Get the admin username if an admin user was created | ||
| * | ||
| * @since 33.0.0 | ||
| */ | ||
| public function getAdminUsername(): ?string { | ||
| return $this->adminUsername; | ||
| } | ||
|
|
||
| /** | ||
| * Get the admin email if configured | ||
| * | ||
| * @since 33.0.0 | ||
| */ | ||
| public function getAdminEmail(): ?string { | ||
| return $this->adminEmail; | ||
| } | ||
|
|
||
| /** | ||
| * Check if an admin user was created during installation | ||
| * | ||
| * @since 33.0.0 | ||
| */ | ||
| public function hasAdminUser(): bool { | ||
| return $this->adminUsername !== null; | ||
| } | ||
| } | ||
89 changes: 89 additions & 0 deletions
89
tests/lib/Install/Events/InstallationCompletedEventTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace Test\Install\Events; | ||
|
|
||
| use OCP\Install\Events\InstallationCompletedEvent; | ||
|
|
||
| class InstallationCompletedEventTest extends \Test\TestCase { | ||
| public function testConstructorWithAllParameters(): void { | ||
| $dataDir = '/path/to/data'; | ||
| $adminUsername = 'admin'; | ||
| $adminEmail = 'admin@example.com'; | ||
|
|
||
| $event = new InstallationCompletedEvent($dataDir, $adminUsername, $adminEmail); | ||
|
|
||
| $this->assertEquals($dataDir, $event->getDataDirectory()); | ||
| $this->assertEquals($adminUsername, $event->getAdminUsername()); | ||
| $this->assertEquals($adminEmail, $event->getAdminEmail()); | ||
| $this->assertTrue($event->hasAdminUser()); | ||
| } | ||
|
|
||
| public function testConstructorWithMinimalParameters(): void { | ||
| $dataDir = '/path/to/data'; | ||
|
|
||
| $event = new InstallationCompletedEvent($dataDir); | ||
|
|
||
| $this->assertEquals($dataDir, $event->getDataDirectory()); | ||
| $this->assertNull($event->getAdminUsername()); | ||
| $this->assertNull($event->getAdminEmail()); | ||
| $this->assertFalse($event->hasAdminUser()); | ||
| } | ||
|
|
||
| public function testConstructorWithUsernameOnly(): void { | ||
| $dataDir = '/path/to/data'; | ||
| $adminUsername = 'admin'; | ||
|
|
||
| $event = new InstallationCompletedEvent($dataDir, $adminUsername); | ||
|
|
||
| $this->assertEquals($dataDir, $event->getDataDirectory()); | ||
| $this->assertEquals($adminUsername, $event->getAdminUsername()); | ||
| $this->assertNull($event->getAdminEmail()); | ||
| $this->assertTrue($event->hasAdminUser()); | ||
| } | ||
|
|
||
| public function testConstructorWithUsernameAndEmail(): void { | ||
| $dataDir = '/path/to/data'; | ||
| $adminUsername = 'admin'; | ||
| $adminEmail = 'admin@example.com'; | ||
|
|
||
| $event = new InstallationCompletedEvent($dataDir, $adminUsername, $adminEmail); | ||
|
|
||
| $this->assertEquals($dataDir, $event->getDataDirectory()); | ||
| $this->assertEquals($adminUsername, $event->getAdminUsername()); | ||
| $this->assertEquals($adminEmail, $event->getAdminEmail()); | ||
| $this->assertTrue($event->hasAdminUser()); | ||
| } | ||
|
|
||
| public function testHasAdminUserReturnsFalseWhenUsernameIsNull(): void { | ||
| $event = new InstallationCompletedEvent('/path/to/data', null, 'admin@example.com'); | ||
|
|
||
| $this->assertFalse($event->hasAdminUser()); | ||
| $this->assertNull($event->getAdminUsername()); | ||
| $this->assertEquals('admin@example.com', $event->getAdminEmail()); | ||
| } | ||
|
|
||
| public function testDataDirectoryCanBeAnyString(): void { | ||
| $customPath = '/custom/data/directory'; | ||
| $event = new InstallationCompletedEvent($customPath); | ||
|
|
||
| $this->assertEquals($customPath, $event->getDataDirectory()); | ||
| } | ||
|
|
||
| public function testEmailCanBeSetWithoutUsername(): void { | ||
| $dataDir = '/path/to/data'; | ||
| $email = 'admin@example.com'; | ||
|
|
||
| $event = new InstallationCompletedEvent($dataDir, null, $email); | ||
|
|
||
| $this->assertNull($event->getAdminUsername()); | ||
| $this->assertEquals($email, $event->getAdminEmail()); | ||
| $this->assertFalse($event->hasAdminUser()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong version.