-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add InstallationCompletedEvent for post-installation actions #57522
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
base: master
Are you sure you want to change the base?
Conversation
a4987a7 to
eaea8ed
Compare
68ec825 to
bcc3cbd
Compare
b259285 to
6cd47a7
Compare
provokateurin
left a comment
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.
While this event might be useful in server, how would a non-default app be able to use it? The app is not enabled during the installation and needs to be enabled via occ/web interface separately, but wouldn't be able to catch the event anymore.
Please explain your use-case better.
cd66d22 to
c8e03a8
Compare
|
…ner and related stubs refactor: use InstallationCompletedEvent properties instead of file parsing Remove initAdminUser() method and config file reading logic in favor of using the event's built-in getAdminUsername() method. This eliminates the need for: - Reading and parsing /vault/secrets/adminconfig - Quote stripping logic - ADMIN_CONFIG_PATH and ADMIN_USER_KEY constants Updated stub to match the real implementation from nextcloud/server#57522 including: - Constructor with dataDirectory, adminUsername, and adminEmail parameters - Getter methods: getDataDirectory(), getAdminUsername(), getAdminEmail() - hasAdminUser() helper method Benefits: - Cleaner code with no file I/O operations - No error handling needed for missing/malformed config files - Uses official Nextcloud API instead of custom parsing - Better type safety with proper event typing Signed-off-by: Misha M.-Kupriyanov <kupriyanov@strato.de>
c8e03a8 to
7e53353
Compare
…ooks Add InstallationCompletedEvent class in public API (OCP namespace) that provides installation details: data directory, admin username, and admin email. Event will be dispatched after successful installation. Include comprehensive unit tests covering all event scenarios. Signed-off-by: Misha M.-Kupriyanov <kupriyanov@strato.de>
7e53353 to
f40a561
Compare
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>
f40a561 to
ffd4c5c
Compare
Summary
This PR introduces a new event
InstallationCompletedEventthat is dispatched after a successful Nextcloud installation. This allows apps and integrations to hook into the installation process and perform additional actions once the system is fully set up.Backstory/Precondition: We are using Nextcloud in k8s. Meaning all apps are already "baked" into image. Meaning
Setup::installcallsInstaller::installShippedApps(false, $output);always and installs all apps in all apps folders.Example: InstallationCompletedEvent Sequence Diagram - Welcome Mail Focus
sequenceDiagram participant NC as Nextcloud Core participant ED as Event Dispatcher participant PIEL as PostInstallEventListener participant UM as UserManager participant IConfig as IConfig participant AppConfig as IAppConfig participant JobList as IJobList participant PSJ as PostSetupJob participant HTTP as HTTP Client participant WMH as WelcomeMailHelper Note over NC,WMH: Application Bootstrap & Post-Installation Phase NC->>ED: dispatch(InstallationCompletedEvent) ED->>PIEL: handle(Event) PIEL->>AppConfig: setValueString("example_admin_app", "post_install", "INIT") Note over PIEL: Initialize Admin User PIEL->>PIEL: initAdminUser() PIEL->>UM: get(adminUserId) UM-->>PIEL: adminUser PIEL->>IConfig: setUserValue(adminUserId, 'core', 'lang', language) rect rgb(240, 240, 240) Note over PIEL: Configure SMTP for Welcome Mail<br/>(black box) PIEL->>PIEL: setSendMailAccount() end Note over PIEL,JobList: Schedule Welcome Mail Job PIEL->>JobList: add(PostSetupJob.class, adminUserId) PIEL-->>ED: handle complete Note over NC,WMH: Background Job Execution (Every 2 seconds) loop Until job completes or times out NC->>JobList: execute scheduled jobs JobList->>PSJ: run(adminUserId) PSJ->>AppConfig: getValueString("example_admin_app", "post_install", "UNKNOWN") alt Status is "DONE" PSJ->>JobList: remove(this) Note right of PSJ: Job already completed else Status is "UNKNOWN" Note right of PSJ: Wait for initialization else Status is "INIT" Note over PSJ,WMH: Attempt to Send Welcome Mail PSJ->>PSJ: sendInitialWelcomeMail(adminUserId) Note over PSJ,HTTP: Check if Nextcloud URL is ready PSJ->>IConfig: getSystemValue("overwrite.cli.url") IConfig-->>PSJ: baseUrl PSJ->>PSJ: isUrlAvailable(client, baseUrl) PSJ->>HTTP: GET baseUrl/status.php alt URL not available (status != 2xx) HTTP-->>PSJ: error or non-2xx status Note right of PSJ: Domain not ready,<br/>retry in next cron run else URL is available HTTP-->>PSJ: status 200 OK PSJ->>UM: userExists(adminUserId) alt User doesn't exist UM-->>PSJ: false Note right of PSJ: Log warning,<br/>skip welcome mail else User exists UM-->>PSJ: true PSJ->>UM: get(adminUserId) UM-->>PSJ: adminUser rect rgb(240, 240, 240) Note over PSJ,WMH: Send Welcome Mail<br/>(black box) PSJ->>WMH: new WelcomeMailHelper() PSJ->>WMH: sendWelcomeMail(adminUser, true) WMH-->>PSJ: mail sent successfully end end Note over PSJ,AppConfig: Mark Job as Complete (always) PSJ->>AppConfig: setValueString("example_admin_app", "post_install", "DONE") PSJ->>JobList: remove(this) end end end Note over NC,WMH: Welcome Mail Delivery CompleteFlow Description - Welcome Mail Execution
1. Post-Installation Event Triggered
When Nextcloud is installed, the InstallationCompletedEvent is dispatched and handled by PostInstallEventListener.
2. Initial Setup Phase (Synchronous)
2.1 Set Job Status
example_admin_app.post_installstatus to "INIT" viaIAppConfig::setValueString()to track the setup progress2.2 Initialize Admin User
IConfig::setUserValue()2.3 Configure SMTP for Welcome Mail (Black Box)
2.4 Schedule Background Job
PostSetupJobto the job list withadminUserIdas argument3. Background Job Execution (Asynchronous)
The
PostSetupJobruns periodically via Nextcloud's cron system:3.1 Check Job Status
example_admin_app.post_installfromIAppConfig(default: "UNKNOWN")3.2 Verify Nextcloud URL Availability
overwrite.cli.urlfrom system config viaIConfig::getSystemValue()IClientService::newClient(){baseUrl}/status.php3.3 Send Welcome Mail
IUserManager::userExists()IUserManager::get()WelcomeMailHelper()instancesendWelcomeMail(adminUser, true)(Black Box)3.4 Mark Job Complete
example_admin_app.post_installstatus to "DONE" viaIAppConfig::setValueString()Status Flow
Key Components
Retry Mechanism
The job runs every 2 seconds and will retry until:
This ensures the welcome mail is sent even if the system isn't fully ready immediately after installation.
Changes
New Event Class
OCP\Install\Events\InstallationCompletedEvent- a typed event that provides:hasAdminUser()to check if an admin was createdIntegration
OC\Setupto dispatch the event after successful installation:IEventDispatcherdependencyTests
InstallationCompletedEvent(7 tests, 23 assertions)SetupTestwith integration tests (3 new tests)Use Cases
Apps can listen to this event to:
Example Usage
Breaking Changes
None. This is a new event that doesn't modify any existing behavior.
API Version
@since 33.0.0Testing
✅ All tests passing:
InstallationCompletedEventTest: 7/7 tests passed, 23 assertionsSetupTest: 21/21 tests passed, 47 assertions (including 3 new tests)Files Changed
lib/public/Install/Events/InstallationCompletedEvent.php(new, 79 lines)lib/private/Setup.php(modified, +10 lines)tests/lib/Install/Events/InstallationCompletedEventTest.php(new, 89 lines)tests/lib/SetupTest.php(modified, +88 lines)Total: 266 insertions, 1 deletion
Checklist
@sinceannotations