Skip to content

Commit 8f9b2af

Browse files
committed
Fix hook encryption with cron job
Make sure the setup fs is set before using the Update service Fix #29674 Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent cf4c77e commit 8f9b2af

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

lib/private/Encryption/HookManager.php

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,39 +25,56 @@
2525

2626
use OC\Files\Filesystem;
2727
use OC\Files\View;
28+
use OC\Files\SetupManager;
2829
use Psr\Log\LoggerInterface;
2930

3031
class HookManager {
31-
/**
32-
* @var Update
33-
*/
34-
private static $updater;
32+
private static ?Update $updater = null;
33+
private static bool $shouldTearDown = false;
3534

36-
public static function postShared($params) {
35+
public static function postShared($params): void {
3736
self::getUpdate()->postShared($params);
37+
self::tearDown();
3838
}
39-
public static function postUnshared($params) {
39+
public static function postUnshared($params): void {
4040
self::getUpdate()->postUnshared($params);
41+
self::tearDown();
4142
}
4243

43-
public static function postRename($params) {
44+
public static function postRename($params): void {
4445
self::getUpdate()->postRename($params);
46+
self::tearDown();
4547
}
4648

47-
public static function postRestore($params) {
49+
public static function postRestore($params): void {
4850
self::getUpdate()->postRestore($params);
4951
}
5052

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 {
5564
if (is_null(self::$updater)) {
5665
$user = \OC::$server->getUserSession()->getUser();
66+
5767
$uid = '';
5868
if ($user) {
5969
$uid = $user->getUID();
6070
}
71+
72+
$setupManager = \OC::$server->get(SetupManager::class);
73+
if (!$setupManager->isSetupComplete($user)) {
74+
self::$shouldTearDown = true;
75+
$setupManager->setupForUser($user);
76+
}
77+
6178
self::$updater = new Update(
6279
new View(),
6380
new Util(

0 commit comments

Comments
 (0)