mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #57925 from nextcloud/backport/57522/stable32
[stable32] Add InstallationCompletedEvent for post-installation actions
This commit is contained in:
commit
abb135e64d
6 changed files with 184 additions and 1 deletions
|
|
@ -639,6 +639,7 @@ return array(
|
|||
'OCP\\IUserManager' => $baseDir . '/lib/public/IUserManager.php',
|
||||
'OCP\\IUserSession' => $baseDir . '/lib/public/IUserSession.php',
|
||||
'OCP\\Image' => $baseDir . '/lib/public/Image.php',
|
||||
'OCP\\Install\\Events\\InstallationCompletedEvent' => $baseDir . '/lib/public/Install/Events/InstallationCompletedEvent.php',
|
||||
'OCP\\L10N\\IFactory' => $baseDir . '/lib/public/L10N/IFactory.php',
|
||||
'OCP\\L10N\\ILanguageIterator' => $baseDir . '/lib/public/L10N/ILanguageIterator.php',
|
||||
'OCP\\LDAP\\IDeletionFlagSupport' => $baseDir . '/lib/public/LDAP/IDeletionFlagSupport.php',
|
||||
|
|
|
|||
|
|
@ -680,6 +680,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
|
|||
'OCP\\IUserManager' => __DIR__ . '/../../..' . '/lib/public/IUserManager.php',
|
||||
'OCP\\IUserSession' => __DIR__ . '/../../..' . '/lib/public/IUserSession.php',
|
||||
'OCP\\Image' => __DIR__ . '/../../..' . '/lib/public/Image.php',
|
||||
'OCP\\Install\\Events\\InstallationCompletedEvent' => __DIR__ . '/../../..' . '/lib/public/Install/Events/InstallationCompletedEvent.php',
|
||||
'OCP\\L10N\\IFactory' => __DIR__ . '/../../..' . '/lib/public/L10N/IFactory.php',
|
||||
'OCP\\L10N\\ILanguageIterator' => __DIR__ . '/../../..' . '/lib/public/L10N/ILanguageIterator.php',
|
||||
'OCP\\LDAP\\IDeletionFlagSupport' => __DIR__ . '/../../..' . '/lib/public/LDAP/IDeletionFlagSupport.php',
|
||||
|
|
|
|||
|
|
@ -22,12 +22,14 @@ use OC\User\BackgroundJobs\CleanupDeletedUsers;
|
|||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\BackgroundJob\IJobList;
|
||||
use OCP\Defaults;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Http\Client\IClientService;
|
||||
use OCP\IAppConfig;
|
||||
use OCP\IConfig;
|
||||
use OCP\IGroup;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IL10N;
|
||||
use OCP\Install\Events\InstallationCompletedEvent;
|
||||
use OCP\IRequest;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUserManager;
|
||||
|
|
@ -50,6 +52,7 @@ class Setup {
|
|||
protected LoggerInterface $logger,
|
||||
protected ISecureRandom $random,
|
||||
protected Installer $installer,
|
||||
protected IEventDispatcher $eventDispatcher,
|
||||
) {
|
||||
$this->l10n = $l10nFactory->get('lib');
|
||||
}
|
||||
|
|
@ -494,6 +497,13 @@ class Setup {
|
|||
}
|
||||
}
|
||||
|
||||
// Dispatch installation completed event
|
||||
$adminUsername = !$disableAdminUser ? ($options['adminlogin'] ?? null) : null;
|
||||
$adminEmail = !empty($options['adminemail']) ? $options['adminemail'] : null;
|
||||
$this->eventDispatcher->dispatchTyped(
|
||||
new InstallationCompletedEvent($dataDir, $adminUsername, $adminEmail)
|
||||
);
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
|
|
|
|||
79
lib/public/Install/Events/InstallationCompletedEvent.php
Normal file
79
lib/public/Install/Events/InstallationCompletedEvent.php
Normal file
|
|
@ -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 32.0.6
|
||||
*/
|
||||
class InstallationCompletedEvent extends Event {
|
||||
/**
|
||||
* @since 32.0.6
|
||||
*/
|
||||
public function __construct(
|
||||
private string $dataDirectory,
|
||||
private ?string $adminUsername = null,
|
||||
private ?string $adminEmail = null,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configured data directory path
|
||||
*
|
||||
* @since 32.0.6
|
||||
*/
|
||||
public function getDataDirectory(): string {
|
||||
return $this->dataDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the admin username if an admin user was created
|
||||
*
|
||||
* @since 32.0.6
|
||||
*/
|
||||
public function getAdminUsername(): ?string {
|
||||
return $this->adminUsername;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the admin email if configured
|
||||
*
|
||||
* @since 32.0.6
|
||||
*/
|
||||
public function getAdminEmail(): ?string {
|
||||
return $this->adminEmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an admin user was created during installation
|
||||
*
|
||||
* @since 32.0.6
|
||||
*/
|
||||
public function hasAdminUser(): bool {
|
||||
return $this->adminUsername !== null;
|
||||
}
|
||||
}
|
||||
89
tests/lib/Install/Events/InstallationCompletedEventTest.php
Normal file
89
tests/lib/Install/Events/InstallationCompletedEventTest.php
Normal file
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@ use OC\Installer;
|
|||
use OC\Setup;
|
||||
use OC\SystemConfig;
|
||||
use OCP\Defaults;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\IL10N;
|
||||
use OCP\L10N\IFactory as IL10NFactory;
|
||||
use OCP\Security\ISecureRandom;
|
||||
|
|
@ -28,6 +29,7 @@ class SetupTest extends \Test\TestCase {
|
|||
protected LoggerInterface $logger;
|
||||
protected ISecureRandom $random;
|
||||
protected Installer $installer;
|
||||
protected IEventDispatcher $eventDispatcher;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -42,9 +44,10 @@ class SetupTest extends \Test\TestCase {
|
|||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->random = $this->createMock(ISecureRandom::class);
|
||||
$this->installer = $this->createMock(Installer::class);
|
||||
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
||||
$this->setupClass = $this->getMockBuilder(Setup::class)
|
||||
->onlyMethods(['class_exists', 'is_callable', 'getAvailableDbDriversForPdo'])
|
||||
->setConstructorArgs([$this->config, $this->iniWrapper, $this->l10nFactory, $this->defaults, $this->logger, $this->random, $this->installer])
|
||||
->setConstructorArgs([$this->config, $this->iniWrapper, $this->l10nFactory, $this->defaults, $this->logger, $this->random, $this->installer, $this->eventDispatcher])
|
||||
->getMock();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue