parent
50df5e1de0
commit
6e49aa5699
@ -0,0 +1,115 @@ |
||||
<?php |
||||
/** |
||||
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> |
||||
* |
||||
* @license GNU AGPL version 3 or any later version |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License as |
||||
* published by the Free Software Foundation, either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
* |
||||
*/ |
||||
|
||||
namespace OCA\FirstRunMigrate\Migration; |
||||
|
||||
use OCP\BackgroundJob\QueuedJob; |
||||
use OCP\AppFramework\Utility\ITimeFactory; |
||||
use OC_Util; |
||||
use OCA\FirstRunMigrate\Migration\Utils; |
||||
use OCP\IConfig; |
||||
use OCP\IUserManager; |
||||
use OCP\IUser; |
||||
use OCP\BackgroundJob\IJobList; |
||||
use OCP\Files\IRootFolder; |
||||
use Psr\Log\LoggerInterface; |
||||
|
||||
class DataJob extends QueuedJob { |
||||
protected LoggerInterface $logger; |
||||
|
||||
protected IUserManager $userManager; |
||||
|
||||
protected IJobList $jobList; |
||||
|
||||
protected IRootFolder $rootFolder; |
||||
|
||||
/** |
||||
* BackgroundJob constructor. |
||||
* |
||||
* @param INotificationManager $notificationManager |
||||
*/ |
||||
public function __construct(ITimeFactory $timeFactory, IUserManager $userManager, LoggerInterface $logger, |
||||
IJobList $jobList, IRootFolder $rootFolder) { |
||||
parent::__construct($timeFactory); |
||||
$this->logger = $logger; |
||||
$this->userManager = $userManager; |
||||
$this->jobList = $jobList; |
||||
$this->rootFolder = $rootFolder; |
||||
} |
||||
|
||||
/** |
||||
* @param array $argument |
||||
*/ |
||||
protected function run($argument) { |
||||
$this->logger->debug("Starting datas migration job {$this->getId()} with args " . json_encode($argument)); |
||||
$uid = $argument['uid']; |
||||
$user = $this->userManager->get($uid); |
||||
|
||||
Utils::setMigrationStatus('data', 'started', $user); |
||||
|
||||
if ($migrate_dir = $this->getUserMigration($user)) { |
||||
// Trigger creation of user home and /files folder |
||||
$userFolder = $this->rootFolder->getUserFolder($uid); |
||||
|
||||
$quota = $user->getQuota(); |
||||
$user->setQuota('none'); |
||||
OC_Util::copyr($migrate_dir, $userFolder); |
||||
$user->setQuota($quota); |
||||
|
||||
// update the file cache |
||||
$userFolder->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE); |
||||
} else { |
||||
$this->logger->info("{$this->getId()}: No dir to migrate"); |
||||
} |
||||
|
||||
// Schedule share migration only after migration user's datas |
||||
if (ShareJob::isMigration()) { |
||||
$this->logger->debug("Scheduling $uid share migrations"); |
||||
$this->jobList->add(ShareJob::class, ['uid' => $uid]); |
||||
Utils::setMigrationStatus('share', 'scheduled', $user); |
||||
} else { |
||||
$this->logger->info("$uid don't have share migrations"); |
||||
} |
||||
|
||||
Utils::setMigrationStatus('data', 'finished', $user); |
||||
} |
||||
|
||||
private static function getMigrationDir() : ?string { |
||||
/** @var IConfig */ |
||||
$config = \OC::$server->get(IConfig::class); |
||||
|
||||
return $config->getSystemValue('firstrunmigrate_dir', null); |
||||
} |
||||
|
||||
public static function isMigration() : bool { |
||||
return ($file = self::getMigrationDir()) && file_exists($file); |
||||
} |
||||
|
||||
private static function getUserMigration(IUser $user) : ?string { |
||||
$dir = self::getMigrationDir() . '/' . Utils::getUserId($user); |
||||
|
||||
if (file_exists($dir)) { |
||||
return $dir; |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,100 @@ |
||||
<?php |
||||
/** |
||||
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> |
||||
* |
||||
* @license GNU AGPL version 3 or any later version |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License as |
||||
* published by the Free Software Foundation, either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
* |
||||
*/ |
||||
|
||||
namespace OCA\FirstRunMigrate\Migration; |
||||
|
||||
use OCP\BackgroundJob\QueuedJob; |
||||
use OCP\AppFramework\Utility\ITimeFactory; |
||||
use OCA\FirstRunMigrate\Migration\Utils; |
||||
use OCP\IConfig; |
||||
use OCP\IGroupManager; |
||||
use OCP\IUserManager; |
||||
use OCP\IUser; |
||||
use Psr\Log\LoggerInterface; |
||||
|
||||
class GroupJob extends QueuedJob { |
||||
protected LoggerInterface $logger; |
||||
|
||||
protected IUserManager $userManager; |
||||
|
||||
protected IGroupManager $groupManager; |
||||
|
||||
/** |
||||
* BackgroundJob constructor. |
||||
* |
||||
* @param INotificationManager $notificationManager |
||||
*/ |
||||
public function __construct(ITimeFactory $timeFactory, IUserManager $userManager, |
||||
IGroupManager $groupManager, LoggerInterface $logger) { |
||||
parent::__construct($timeFactory); |
||||
$this->logger = $logger; |
||||
$this->userManager = $userManager; |
||||
$this->groupManager = $groupManager; |
||||
} |
||||
|
||||
/** |
||||
* @param array $argument |
||||
*/ |
||||
protected function run($argument) { |
||||
$this->logger->debug("Starting groups migration job {$this->getId()} with args " . json_encode($argument)); |
||||
$user = $this->userManager->get($argument['uid']); |
||||
|
||||
Utils::setMigrationStatus('group', 'started', $user); |
||||
|
||||
if ($groups = $this->getUserMigration($user)) { |
||||
foreach ($groups as $group) { |
||||
if ($this->groupManager->groupExists($group)) { |
||||
$group = $this->groupManager->get($group); |
||||
} else { |
||||
$group = $this->groupManager->createGroup($group); |
||||
} |
||||
|
||||
$group->addUser($user); |
||||
} |
||||
} else { |
||||
$this->logger->info("{$this->getId()}: No groups to migrate"); |
||||
} |
||||
|
||||
Utils::setMigrationStatus('group', 'finished', $user); |
||||
} |
||||
|
||||
private static function getMigrationFile() : ?string { |
||||
/** @var IConfig */ |
||||
$config = \OC::$server->get(IConfig::class); |
||||
|
||||
return $config->getSystemValue('firstrunmigrate_groups', null); |
||||
} |
||||
|
||||
public static function isMigration() : bool { |
||||
return ($file = self::getMigrationFile()) && file_exists($file); |
||||
} |
||||
|
||||
private static function getUserMigration(IUser $user) : ?array { |
||||
$groups = json_decode(file_get_contents(self::getMigrationFile()), true); |
||||
$id = Utils::getUserId($user); |
||||
|
||||
if (array_key_exists($id, $groups)) { |
||||
return $groups[$id]; |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,88 @@ |
||||
<?php |
||||
/** |
||||
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> |
||||
* |
||||
* @license GNU AGPL version 3 or any later version |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License as |
||||
* published by the Free Software Foundation, either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
* |
||||
*/ |
||||
|
||||
namespace OCA\FirstRunMigrate\Migration; |
||||
|
||||
use OCP\BackgroundJob\QueuedJob; |
||||
use OCP\AppFramework\Utility\ITimeFactory; |
||||
use OCA\FirstRunMigrate\Migration\Utils; |
||||
use OCP\IConfig; |
||||
use OCP\IUserManager; |
||||
use OCP\IUser; |
||||
use Psr\Log\LoggerInterface; |
||||
|
||||
class QuotaJob extends QueuedJob { |
||||
protected LoggerInterface $logger; |
||||
|
||||
protected IUserManager $userManager; |
||||
|
||||
/** |
||||
* BackgroundJob constructor. |
||||
* |
||||
* @param INotificationManager $notificationManager |
||||
*/ |
||||
public function __construct(ITimeFactory $timeFactory, IUserManager $userManager, LoggerInterface $logger) { |
||||
parent::__construct($timeFactory); |
||||
$this->logger = $logger; |
||||
$this->userManager = $userManager; |
||||
} |
||||
|
||||
/** |
||||
* @param array $argument |
||||
*/ |
||||
protected function run($argument) { |
||||
$this->logger->debug("Starting quota migration job {$this->getId()} with args " . json_encode($argument)); |
||||
$user = $this->userManager->get($argument['uid']); |
||||
|
||||
$this->logger->debug("{$this->getId()}: Migrating quota"); |
||||
Utils::setMigrationStatus('quota', 'started', $user); |
||||
|
||||
if ($quota = $this->getUserMigration($user)) { |
||||
$user->setQuota($quota); |
||||
} else { |
||||
$this->logger->info("{$this->getId()}: No quota to migrate"); |
||||
} |
||||
|
||||
Utils::setMigrationStatus('quota', 'finished', $user); |
||||
} |
||||
|
||||
private static function getMigrationFile() : ?string { |
||||
/** @var IConfig */ |
||||
$config = \OC::$server->get(IConfig::class); |
||||
|
||||
return $config->getSystemValue('firstrunmigrate_quotas', null); |
||||
} |
||||
|
||||
public static function isMigration() : bool { |
||||
return ($file = self::getMigrationFile()) && file_exists($file); |
||||
} |
||||
|
||||
private function getUserMigration(IUser $user) : ?string { |
||||
$quotas = json_decode(file_get_contents(self::getMigrationFile()), true); |
||||
$id = Utils::getUserId($user); |
||||
|
||||
if (array_key_exists($id, $quotas)) { |
||||
return $quotas[$id]; |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue