You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EncryptionController.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OC\Settings\Controller;
  24. use OC\Files\View;
  25. use OCA\Encryption\Migration;
  26. use OCP\IDBConnection;
  27. use OCP\IL10N;
  28. use OCP\AppFramework\Controller;
  29. use OCP\ILogger;
  30. use OCP\IRequest;
  31. use OCP\IConfig;
  32. use OCP\IUserManager;
  33. /**
  34. * @package OC\Settings\Controller
  35. */
  36. class EncryptionController extends Controller {
  37. /** @var IL10N */
  38. private $l10n;
  39. /** @var IDBConnection */
  40. private $connection;
  41. /** @var IConfig */
  42. private $config;
  43. /** @var IUserManager */
  44. private $userManager;
  45. /** @var View */
  46. private $view;
  47. /** @var ILogger */
  48. private $logger;
  49. /**
  50. * @param string $appName
  51. * @param IRequest $request
  52. * @param IL10N $l10n
  53. * @param IConfig $config
  54. * @param IDBConnection $connection
  55. * @param IUserManager $userManager
  56. * @param View $view
  57. * @param ILogger $logger
  58. */
  59. public function __construct($appName,
  60. IRequest $request,
  61. IL10N $l10n,
  62. IConfig $config,
  63. IDBConnection $connection,
  64. IUserManager $userManager,
  65. View $view,
  66. ILogger $logger) {
  67. parent::__construct($appName, $request);
  68. $this->l10n = $l10n;
  69. $this->config = $config;
  70. $this->connection = $connection;
  71. $this->view = $view;
  72. $this->userManager = $userManager;
  73. $this->logger = $logger;
  74. }
  75. /**
  76. * @param IConfig $config
  77. * @param View $view
  78. * @param IDBConnection $connection
  79. * @param ILogger $logger
  80. * @return Migration
  81. */
  82. protected function getMigration(IConfig $config,
  83. View $view,
  84. IDBConnection $connection,
  85. ILogger $logger) {
  86. return new Migration($config, $view, $connection, $logger);
  87. }
  88. /**
  89. * start migration
  90. *
  91. * @return array
  92. */
  93. public function startMigration() {
  94. // allow as long execution on the web server as possible
  95. set_time_limit(0);
  96. try {
  97. $migration = $this->getMigration($this->config, $this->view, $this->connection, $this->logger);
  98. $migration->reorganizeSystemFolderStructure();
  99. $migration->updateDB();
  100. foreach ($this->userManager->getBackends() as $backend) {
  101. $limit = 500;
  102. $offset = 0;
  103. do {
  104. $users = $backend->getUsers('', $limit, $offset);
  105. foreach ($users as $user) {
  106. $migration->reorganizeFolderStructureForUser($user);
  107. }
  108. $offset += $limit;
  109. } while (count($users) >= $limit);
  110. }
  111. $migration->finalCleanUp();
  112. } catch (\Exception $e) {
  113. return [
  114. 'data' => [
  115. 'message' => (string)$this->l10n->t('A problem occurred, please check your log files (Error: %s)', [$e->getMessage()]),
  116. ],
  117. 'status' => 'error',
  118. ];
  119. }
  120. return [
  121. 'data' => [
  122. 'message' => (string) $this->l10n->t('Migration Completed'),
  123. ],
  124. 'status' => 'success',
  125. ];
  126. }
  127. }