/** * start migration * * @return array */ public function startMigration() { // allow as long execution on the web server as possible set_time_limit(0); try { $migration = new Migration($this->config, $this->view, $this->connection); $migration->reorganizeSystemFolderStructure(); $migration->updateDB(); foreach ($this->userManager->getBackends() as $backend) { $limit = 500; $offset = 0; do { $users = $backend->getUsers('', $limit, $offset); foreach ($users as $user) { $migration->reorganizeFolderStructureForUser($user); } $offset += $limit; } while (count($users) >= $limit); } $migration->finalCleanUp(); } catch (\Exception $e) { return array('data' => array('message' => (string) $this->l10n->t('A problem occurred, please check your log files (Error: %s)', [$e->getMessage()])), 'status' => 'error'); } return array('data' => array('message' => (string) $this->l10n->t('Migration Completed')), 'status' => 'success'); }
protected function execute(InputInterface $input, OutputInterface $output) { // perform system reorganization $migration = new Migration($this->config, $this->view, $this->connection, $this->logger); $users = $input->getArgument('user_id'); if (!empty($users)) { foreach ($users as $user) { if ($this->userManager->userExists($user)) { $output->writeln("Migrating keys <info>{$user}</info>"); $migration->reorganizeFolderStructureForUser($user); } else { $output->writeln("<error>Unknown user {$user}</error>"); } } } else { $output->writeln("Reorganize system folder structure"); $migration->reorganizeSystemFolderStructure(); $migration->updateDB(); foreach ($this->userManager->getBackends() as $backend) { $name = get_class($backend); if ($backend instanceof IUserBackend) { $name = $backend->getBackendName(); } $output->writeln("Migrating keys for users on backend <info>{$name}</info>"); $limit = 500; $offset = 0; do { $users = $backend->getUsers('', $limit, $offset); foreach ($users as $user) { $output->writeln(" <info>{$user}</info>"); $migration->reorganizeFolderStructureForUser($user); } $offset += $limit; } while (count($users) >= $limit); } } $migration->finalCleanUp(); }
/** * test update db if the db already contain some existing new values */ public function testUpdateDBExistingNewConfig() { $this->prepareDB(); $config = \OC::$server->getConfig(); $config->setAppValue('encryption', 'publicShareKeyId', 'wrong_share_id'); $config->setUserValue(self::TEST_ENCRYPTION_MIGRATION_USER1, 'encryption', 'recoverKeyEnabled', '9'); $m = new Migration(\OC::$server->getConfig(), new \OC\Files\View(), \OC::$server->getDatabaseConnection(), $this->logger); $m->updateDB(); $this->verifyDB('`*PREFIX*appconfig`', 'files_encryption', 0); $this->verifyDB('`*PREFIX*preferences`', 'files_encryption', 0); $this->verifyDB('`*PREFIX*appconfig`', 'encryption', 3); $this->verifyDB('`*PREFIX*preferences`', 'encryption', 1); // check if the existing values where overwritten correctly /** @var \OC\DB\Connection $connection */ $connection = \OC::$server->getDatabaseConnection(); $query = $connection->createQueryBuilder(); $query->select('`configvalue`')->from('`*PREFIX*appconfig`')->where($query->expr()->andX($query->expr()->eq('`appid`', ':appid'), $query->expr()->eq('`configkey`', ':configkey')))->setParameter('appid', 'encryption')->setParameter('configkey', 'publicShareKeyId'); $result = $query->execute(); $value = $result->fetch(); $this->assertTrue(isset($value['configvalue'])); $this->assertSame('share_id', $value['configvalue']); $query = $connection->createQueryBuilder(); $query->select('`configvalue`')->from('`*PREFIX*preferences`')->where($query->expr()->andX($query->expr()->eq('`appid`', ':appid'), $query->expr()->eq('`configkey`', ':configkey'), $query->expr()->eq('`userid`', ':userid')))->setParameter('appid', 'encryption')->setParameter('configkey', 'recoverKeyEnabled')->setParameter('userid', self::TEST_ENCRYPTION_MIGRATION_USER1); $result = $query->execute(); $value = $result->fetch(); $this->assertTrue(isset($value['configvalue'])); $this->assertSame('1', $value['configvalue']); }
public function testUpdateDB() { $this->prepareDB(); $m = new Migration(\OC::$server->getConfig(), new \OC\Files\View(), \OC::$server->getDatabaseConnection()); $m->updateDB(); $this->verifyDB('`*PREFIX*appconfig`', 'files_encryption', 0); $this->verifyDB('`*PREFIX*preferences`', 'files_encryption', 0); $this->verifyDB('`*PREFIX*appconfig`', 'encryption', 3); $this->verifyDB('`*PREFIX*preferences`', 'encryption', 1); }