encryptioncontroller.php 3.4 KB

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