1
0

HookManager.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Julius Härtl <jus@bitgrid.net>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OC\Encryption;
  25. use OC\Files\Filesystem;
  26. use OC\Files\SetupManager;
  27. use OC\Files\View;
  28. use Psr\Log\LoggerInterface;
  29. class HookManager {
  30. private static ?Update $updater = null;
  31. public static function postShared($params): void {
  32. self::getUpdate()->postShared($params);
  33. }
  34. public static function postUnshared($params): void {
  35. // In case the unsharing happens in a background job, we don't have
  36. // a session and we load instead the user from the UserManager
  37. $path = Filesystem::getPath($params['fileSource']);
  38. $owner = Filesystem::getOwner($path);
  39. self::getUpdate($owner)->postUnshared($params);
  40. }
  41. public static function postRename($params): void {
  42. self::getUpdate()->postRename($params);
  43. }
  44. public static function postRestore($params): void {
  45. self::getUpdate()->postRestore($params);
  46. }
  47. private static function getUpdate(?string $owner = null): Update {
  48. if (is_null(self::$updater)) {
  49. $user = \OC::$server->getUserSession()->getUser();
  50. if (!$user && $owner) {
  51. $user = \OC::$server->getUserManager()->get($owner);
  52. }
  53. if (!$user) {
  54. throw new \Exception("Inconsistent data, File unshared, but owner not found. Should not happen");
  55. }
  56. $uid = '';
  57. if ($user) {
  58. $uid = $user->getUID();
  59. }
  60. $setupManager = \OC::$server->get(SetupManager::class);
  61. if (!$setupManager->isSetupComplete($user)) {
  62. $setupManager->setupForUser($user);
  63. }
  64. self::$updater = new Update(
  65. new View(),
  66. new Util(
  67. new View(),
  68. \OC::$server->getUserManager(),
  69. \OC::$server->getGroupManager(),
  70. \OC::$server->getConfig()),
  71. Filesystem::getMountManager(),
  72. \OC::$server->getEncryptionManager(),
  73. \OC::$server->getEncryptionFilesHelper(),
  74. \OC::$server->get(LoggerInterface::class),
  75. $uid
  76. );
  77. }
  78. return self::$updater;
  79. }
  80. }