|
|
|
@ -27,9 +27,10 @@ use OCP\AppFramework\App; |
|
|
|
|
use OCP\AppFramework\Bootstrap\IBootstrap; |
|
|
|
|
use OCP\AppFramework\Bootstrap\IBootContext; |
|
|
|
|
use OCP\AppFramework\Bootstrap\IRegistrationContext; |
|
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
|
|
|
use Symfony\Component\EventDispatcher\GenericEvent; |
|
|
|
|
use OCP\EventDispatcher\IEventDispatcher; |
|
|
|
|
use OCP\EventDispatcher\GenericEvent; |
|
|
|
|
use OCP\IUser; |
|
|
|
|
use Psr\Log\LoggerInterface; |
|
|
|
|
use OCP\BackgroundJob\IJobList; |
|
|
|
|
use OCP\Notification\IManager as INotificationManager; |
|
|
|
|
use OCA\FirstRunMigrate\Migration\Notifier; |
|
|
|
@ -52,35 +53,49 @@ class Application extends App implements IBootstrap { |
|
|
|
|
public function register(IRegistrationContext $context): void { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function registerHooks(EventDispatcherInterface $dispatcher, IJobList $jobList) { |
|
|
|
|
public function registerHooks(IEventDispatcher $dispatcher, IJobList $jobList, LoggerInterface $logger) { |
|
|
|
|
|
|
|
|
|
// first time login event setup |
|
|
|
|
$dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($jobList) { |
|
|
|
|
$dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($jobList, $logger) { |
|
|
|
|
if ($event instanceof GenericEvent) { |
|
|
|
|
$logger->debug("Trigger of::firstLogin"); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @var IUser |
|
|
|
|
*/ |
|
|
|
|
$user = $event->getSubject(); |
|
|
|
|
$uid = $user->getUID(); |
|
|
|
|
|
|
|
|
|
$logger->debug("Subject $uid set, checking migration ID"); |
|
|
|
|
// If the user dont have an ID, skip all the migrations |
|
|
|
|
if (Utils::getUserId($user) === null) { |
|
|
|
|
$logger->info("$uid don't have a migration ID"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$uid = $user->getUID(); |
|
|
|
|
|
|
|
|
|
$logger->debug("Checking $uid migrations"); |
|
|
|
|
if (Utils::isMigrationData()){ |
|
|
|
|
$logger->debug("Scheduling $uid data migrations"); |
|
|
|
|
$jobList->add('OCA\FirstRunMigrate\Migration\BackgroundJob', ['uid' => $uid, 'type' => 'data']); |
|
|
|
|
Utils::setMigrationStatus('data', 'scheduled', $user); |
|
|
|
|
} else { |
|
|
|
|
$logger->info("$uid don't have data migrations"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (Utils::isMigrationGroups()) { |
|
|
|
|
$logger->debug("Scheduling $uid groups migrations"); |
|
|
|
|
$jobList->add('OCA\FirstRunMigrate\Migration\BackgroundJob', ['uid' => $uid, 'type' => 'group']); |
|
|
|
|
Utils::setMigrationStatus('group', 'scheduled', $user); |
|
|
|
|
} else { |
|
|
|
|
$logger->info("$uid don't have groups migrations"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (Utils::isMigrationQuotas()) { |
|
|
|
|
$logger->debug("Scheduling $uid quota migrations"); |
|
|
|
|
$jobList->add('OCA\FirstRunMigrate\Migration\BackgroundJob', ['uid' => $uid, 'type' => 'quota']); |
|
|
|
|
Utils::setMigrationStatus('quota', 'scheduled', $user); |
|
|
|
|
} else { |
|
|
|
|
$logger->info("$uid don't have quota migrations"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|