Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Set path relative to source user folder
Signed-off-by: Christopher Ng <[email protected]>
  • Loading branch information
Pytal authored and come-nc committed Apr 14, 2022
commit 8bc7abc1d0863dbe51fd0cb115c879e0096e4dca
9 changes: 7 additions & 2 deletions lib/BackgroundJob/UserImportJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OCA\UserMigration\Service\UserMigrationService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\QueuedJob;
use OCP\Files\IRootFolder;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Notification\IManager as NotificationManager;
Expand All @@ -43,14 +44,16 @@ class UserImportJob extends QueuedJob {
private LoggerInterface $logger;
private NotificationManager $notificationManager;
private UserImportMapper $mapper;
private IRootFolder $root;

public function __construct(
ITimeFactory $timeFactory,
IUserManager $userManager,
UserMigrationService $migrationService,
LoggerInterface $logger,
NotificationManager $notificationManager,
UserImportMapper $mapper
UserImportMapper $mapper,
IRootFolder $root
) {
parent::__construct($timeFactory);

Expand All @@ -59,6 +62,7 @@ public function __construct(
$this->logger = $logger;
$this->notificationManager = $notificationManager;
$this->mapper = $mapper;
$this->root = $root;
}

public function run($argument): void {
Expand All @@ -68,6 +72,7 @@ public function run($argument): void {
$sourceUser = $import->getSourceUser();
$targetUser = $import->getTargetUser();
$path = $import->getPath();
$absolutePath = $this->root->getUserFolder($sourceUser)->get($path)->getPath();

$sourceUserObject = $this->userManager->get($sourceUser);
$targetUserObject = $this->userManager->get($targetUser);
Expand All @@ -87,7 +92,7 @@ public function run($argument): void {
$import->setStatus(UserImport::STATUS_STARTED);
$this->mapper->update($import);

$this->migrationService->import($path, $targetUserObject);
$this->migrationService->import($absolutePath, $targetUserObject);
$this->successNotification($import);
} catch (\Exception $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
Expand Down
11 changes: 3 additions & 8 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCSController;
use OCP\BackgroundJob\IJobList;
use OCP\Files\IRootFolder;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\IUserSession;
Expand All @@ -57,8 +56,6 @@ class ApiController extends OCSController {

private UserImportMapper $importMapper;

private IRootFolder $root;

private IJobList $jobList;

public function __construct(
Expand All @@ -68,7 +65,6 @@ public function __construct(
UserMigrationService $migrationService,
UserExportMapper $exportMapper,
UserImportMapper $importMapper,
IRootFolder $root,
IJobList $jobList
) {
parent::__construct(Application::APP_ID, $request);
Expand All @@ -77,7 +73,6 @@ public function __construct(
$this->migrationService = $migrationService;
$this->exportMapper = $exportMapper;
$this->importMapper = $importMapper;
$this->root = $root;
$this->jobList = $jobList;
}

Expand Down Expand Up @@ -201,9 +196,8 @@ public function export(array $migrators): DataResponse {
* @NoSubAdminRequired
* @PasswordConfirmationRequired
*/
public function import(string $userPath, string $targetUserId): DataResponse {
public function import(string $path, string $targetUserId): DataResponse {
$sourceUser = $this->userSession->getUser();
$absolutePath = $this->root->getUserFolder($sourceUser->getUID())->get($userPath)->getPath();

if (empty($sourceUser)) {
throw new OCSException('No user currently logged in');
Expand Down Expand Up @@ -235,7 +229,8 @@ public function import(string $userPath, string $targetUserId): DataResponse {
$userImport = new UserImport();
$userImport->setSourceUser($sourceUser->getUID());
$userImport->setTargetUser($targetUser->getUID());
$userImport->setPath($absolutePath);
// Path is relative to the source user folder
$userImport->setPath($path);
// All available migrators are added as migrator selection for import is not allowed for now
$userImport->setMigratorsArray($availableMigrators);
$userImport->setStatus(UserImport::STATUS_WAITING);
Expand Down