|
28 | 28 | use Psr\Log\LoggerInterface; |
29 | 29 |
|
30 | 30 | class HookManager { |
31 | | - /** |
32 | | - * @var Update |
33 | | - */ |
34 | | - private static $updater; |
| 31 | + /** @var ?Updater */ |
| 32 | + private static $updater = null; |
35 | 33 |
|
36 | | - public static function postShared($params) { |
| 34 | + public static function postShared($params): void { |
37 | 35 | self::getUpdate()->postShared($params); |
38 | 36 | } |
39 | | - public static function postUnshared($params) { |
40 | | - self::getUpdate()->postUnshared($params); |
| 37 | + public static function postUnshared($params): void { |
| 38 | + // In case the unsharing happens in a background job, we don't have |
| 39 | + // a session and we load instead the user from the UserManager |
| 40 | + $path = Filesystem::getPath($params['fileSource']); |
| 41 | + $owner = Filesystem::getOwner($path); |
| 42 | + self::getUpdate($owner)->postUnshared($params); |
41 | 43 | } |
42 | 44 |
|
43 | | - public static function postRename($params) { |
| 45 | + public static function postRename($params): void { |
44 | 46 | self::getUpdate()->postRename($params); |
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 getUpdate(?string $owner = null): Update { |
55 | 54 | if (is_null(self::$updater)) { |
56 | 55 | $user = \OC::$server->getUserSession()->getUser(); |
| 56 | + if (!$user && $owner) { |
| 57 | + $user = \OC::$server->getUserManager()->get($owner); |
| 58 | + } |
| 59 | + if (!$user) { |
| 60 | + throw new \Exception("Inconsistent data, File unshared, but owner not found. Should not happen"); |
| 61 | + } |
| 62 | + |
57 | 63 | $uid = ''; |
58 | 64 | if ($user) { |
59 | 65 | $uid = $user->getUID(); |
60 | 66 | } |
| 67 | + |
| 68 | + \OC_Util::setupFS($uid); |
| 69 | + |
61 | 70 | self::$updater = new Update( |
62 | 71 | new View(), |
63 | 72 | new Util( |
|
0 commit comments