Add debug/info logs

master
Florian Charlaix 1 year ago
parent 258556fdc8
commit 50ac07728c
  1. 27
      lib/AppInfo/Application.php
  2. 17
      lib/Migration/BackgroundJob.php

@ -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");
}
}
});

@ -28,11 +28,15 @@ use OCA\FirstRunMigrate\Migration\Utils;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;
class BackgroundJob extends QueuedJob {
/** @var IConfig */
protected $config;
/** @var LoggerInterface */
protected $logger;
/** @var IUserManager */
protected $userManager;
@ -44,8 +48,9 @@ class BackgroundJob extends QueuedJob {
*
* @param INotificationManager $notificationManager
*/
public function __construct(IConfig $config, IUserManager $userManager, IGroupManager $groupManager) {
public function __construct(IConfig $config, IUserManager $userManager, IGroupManager $groupManager, LoggerInterface $logger) {
$this->config = $config;
$this->logger = $logger;
$this->userManager = $userManager;
$this->groupManager = $groupManager;
}
@ -54,6 +59,7 @@ class BackgroundJob extends QueuedJob {
* @param array $argument
*/
protected function run($argument) {
$this->logger->debug("Starting job {$this->getId()} with args $argument");
$uid = $argument['uid'];
$user = $this->userManager->get($uid);
$type = $argument['type'];
@ -72,6 +78,7 @@ class BackgroundJob extends QueuedJob {
}
private function data(IUser $user) {
$this->logger->debug("{$this->getId()}: Migrating datas");
$uid = $user->getUID();
Utils::setMigrationStatus('data', 'started', $user);
@ -87,12 +94,15 @@ class BackgroundJob extends QueuedJob {
// update the file cache
$userFolder->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE);
} else {
$this->logger->info("{$this->getId()}: No dir to migrate");
}
Utils::setMigrationStatus('data', 'finished', $user);
}
private function group(IUser $user) {
$this->logger->debug("{$this->getId()}: Migrating groups");
Utils::setMigrationStatus('group', 'started', $user);
if ($groups = Utils::getUserMigrationGroups($user)) {
@ -105,16 +115,21 @@ class BackgroundJob extends QueuedJob {
$group->addUser($user);
}
} else {
$this->logger->info("{$this->getId()}: No groups to migrate");
}
Utils::setMigrationStatus('group', 'finished', $user);
}
private function quota(IUser $user) {
$this->logger->debug("{$this->getId()}: Migrating quota");
Utils::setMigrationStatus('quota', 'started', $user);
if ($quota = Utils::getUserMigrationQuota($user)) {
$user->setQuota($quota);
} else {
$this->logger->info("{$this->getId()}: No quota to migrate");
}
Utils::setMigrationStatus('quota', 'finished', $user);

Loading…
Cancel
Save