|
25 | 25 |
|
26 | 26 | use OC\Files\Filesystem; |
27 | 27 | use OC\Files\View; |
| 28 | +use OC\Files\SetupManager; |
28 | 29 | use Psr\Log\LoggerInterface; |
29 | 30 |
|
30 | 31 | class HookManager { |
31 | | - /** |
32 | | - * @var Update |
33 | | - */ |
34 | | - private static $updater; |
| 32 | + private static ?Update $updater = null; |
| 33 | + private static bool $shouldTearDown = false; |
35 | 34 |
|
36 | | - public static function postShared($params) { |
| 35 | + public static function postShared($params): void { |
37 | 36 | self::getUpdate()->postShared($params); |
| 37 | + self::tearDown(); |
38 | 38 | } |
39 | | - public static function postUnshared($params) { |
| 39 | + public static function postUnshared($params): void { |
40 | 40 | self::getUpdate()->postUnshared($params); |
| 41 | + self::tearDown(); |
41 | 42 | } |
42 | 43 |
|
43 | | - public static function postRename($params) { |
| 44 | + public static function postRename($params): void { |
44 | 45 | self::getUpdate()->postRename($params); |
| 46 | + self::tearDown(); |
45 | 47 | } |
46 | 48 |
|
47 | | - public static function postRestore($params) { |
| 49 | + public static function postRestore($params): void { |
48 | 50 | self::getUpdate()->postRestore($params); |
49 | 51 | } |
50 | 52 |
|
51 | | - /** |
52 | | - * @return Update |
53 | | - */ |
54 | | - private static function getUpdate() { |
| 53 | + private static function tearDown(): void { |
| 54 | + if (!self::$shouldTearDown) { |
| 55 | + return; |
| 56 | + } |
| 57 | + |
| 58 | + $setupManager = \OC::$server->get(SetupManager::class); |
| 59 | + $setupManager->tearDownFS(); // TODO ideally we should only tear down the user fs and not the root |
| 60 | + self::shouldTearDown = false; |
| 61 | + } |
| 62 | + |
| 63 | + private static function getUpdate(): Update { |
55 | 64 | if (is_null(self::$updater)) { |
56 | 65 | $user = \OC::$server->getUserSession()->getUser(); |
| 66 | + |
57 | 67 | $uid = ''; |
58 | 68 | if ($user) { |
59 | 69 | $uid = $user->getUID(); |
60 | 70 | } |
| 71 | + |
| 72 | + $setupManager = \OC::$server->get(SetupManager::class); |
| 73 | + if (!$setupManager->isSetupComplete($user)) { |
| 74 | + self::$shouldTearDown = true; |
| 75 | + $setupManager->setupForUser($user); |
| 76 | + } |
| 77 | + |
61 | 78 | self::$updater = new Update( |
62 | 79 | new View(), |
63 | 80 | new Util( |
|
0 commit comments