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.

122 lines
2.9 KiB

  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\IRequest;
  27. use OCP\IConfig;
  28. use OC\DB\Connection;
  29. use OCP\IUserManager;
  30. /**
  31. * @package OC\Settings\Controller
  32. */
  33. class EncryptionController extends Controller {
  34. /** @var \OCP\IL10N */
  35. private $l10n;
  36. /** @var Connection */
  37. private $connection;
  38. /** @var IConfig */
  39. private $config;
  40. /** @var IUserManager */
  41. private $userManager;
  42. /** @var View */
  43. private $view;
  44. /**
  45. * @param string $appName
  46. * @param IRequest $request
  47. * @param \OCP\IL10N $l10n
  48. * @param \OCP\IConfig $config
  49. * @param \OC\DB\Connection $connection
  50. * @param IUserManager $userManager
  51. * @param View $view
  52. */
  53. public function __construct($appName,
  54. IRequest $request,
  55. IL10N $l10n,
  56. IConfig $config,
  57. Connection $connection,
  58. IUserManager $userManager,
  59. View $view) {
  60. parent::__construct($appName, $request);
  61. $this->l10n = $l10n;
  62. $this->config = $config;
  63. $this->connection = $connection;
  64. $this->view = $view;
  65. $this->userManager = $userManager;
  66. }
  67. /**
  68. * start migration
  69. *
  70. * @return array
  71. */
  72. public function startMigration() {
  73. // allow as long execution on the web server as possible
  74. set_time_limit(0);
  75. $migration = new Migration($this->config, $this->view, $this->connection);
  76. $migration->reorganizeSystemFolderStructure();
  77. $migration->updateDB();
  78. try {
  79. foreach ($this->userManager->getBackends() as $backend) {
  80. $limit = 500;
  81. $offset = 0;
  82. do {
  83. $users = $backend->getUsers('', $limit, $offset);
  84. foreach ($users as $user) {
  85. $migration->reorganizeFolderStructureForUser($user);
  86. }
  87. $offset += $limit;
  88. } while (count($users) >= $limit);
  89. }
  90. } catch (\Exception $e) {
  91. return array(
  92. 'data' => array(
  93. 'message' => (string)$this->l10n->t('A problem occurred, please check your log files (Error: %s)', [$e->getMessage()]),
  94. ),
  95. 'status' => 'error',
  96. );
  97. }
  98. return array('data' =>
  99. array('message' =>
  100. (string) $this->l10n->t('Migration Completed')
  101. ),
  102. 'status' => 'success'
  103. );
  104. }
  105. }