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.

149 lines
3.5 KiB

10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  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. if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
  96. @set_time_limit(0);
  97. }
  98. try {
  99. $migration = $this->getMigration($this->config, $this->view, $this->connection, $this->logger);
  100. $migration->reorganizeSystemFolderStructure();
  101. $migration->updateDB();
  102. foreach ($this->userManager->getBackends() as $backend) {
  103. $limit = 500;
  104. $offset = 0;
  105. do {
  106. $users = $backend->getUsers('', $limit, $offset);
  107. foreach ($users as $user) {
  108. $migration->reorganizeFolderStructureForUser($user);
  109. }
  110. $offset += $limit;
  111. } while (count($users) >= $limit);
  112. }
  113. $migration->finalCleanUp();
  114. } catch (\Exception $e) {
  115. return [
  116. 'data' => [
  117. 'message' => (string)$this->l10n->t('A problem occurred, please check your log files (Error: %s)', [$e->getMessage()]),
  118. ],
  119. 'status' => 'error',
  120. ];
  121. }
  122. return [
  123. 'data' => [
  124. 'message' => (string) $this->l10n->t('Migration Completed'),
  125. ],
  126. 'status' => 'success',
  127. ];
  128. }
  129. }