diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-09-02 12:08:33 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-02 12:08:33 +0300 |
commit | a1d042d75603366b324a462dd7817db2b451ba94 (patch) | |
tree | 2c9ddecbfefa9c20cd0552f959d1a437d6016b37 /lib | |
parent | 04cc17e629f6cc040101d685076bedf598370191 (diff) | |
parent | 4398bb9077b0c35d47dfb33e6974bd8c83643902 (diff) |
Merge pull request #33159 from nextcloud/backport/32987/stable22
[stable22] Fix hook encryption with cron job
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Encryption/HookManager.php | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/lib/private/Encryption/HookManager.php b/lib/private/Encryption/HookManager.php index a2d6b990a88..c3a7df7fead 100644 --- a/lib/private/Encryption/HookManager.php +++ b/lib/private/Encryption/HookManager.php @@ -28,36 +28,45 @@ use OC\Files\View; use Psr\Log\LoggerInterface; class HookManager { - /** - * @var Update - */ - private static $updater; + /** @var ?Update */ + private static $updater = null; - public static function postShared($params) { + public static function postShared($params): void { self::getUpdate()->postShared($params); } - public static function postUnshared($params) { - self::getUpdate()->postUnshared($params); + public static function postUnshared($params): void { + // In case the unsharing happens in a background job, we don't have + // a session and we load instead the user from the UserManager + $path = Filesystem::getPath($params['fileSource']); + $owner = Filesystem::getOwner($path); + self::getUpdate($owner)->postUnshared($params); } - public static function postRename($params) { + public static function postRename($params): void { self::getUpdate()->postRename($params); } - public static function postRestore($params) { + public static function postRestore($params): void { self::getUpdate()->postRestore($params); } - /** - * @return Update - */ - private static function getUpdate() { + private static function getUpdate(?string $owner = null): Update { if (is_null(self::$updater)) { $user = \OC::$server->getUserSession()->getUser(); + if (!$user && $owner) { + $user = \OC::$server->getUserManager()->get($owner); + } + if (!$user) { + throw new \Exception("Inconsistent data, File unshared, but owner not found. Should not happen"); + } + $uid = ''; if ($user) { $uid = $user->getUID(); } + + \OC_Util::setupFS($uid); + self::$updater = new Update( new View(), new Util( |