Skip to content

Commit 770103c

Browse files
committed
Fix hook encryption with cron job
Make sure the setup fs is set before using the Update service Backport of #29674 Signed-off-by: Carl Schwan <[email protected]>
1 parent 63fb2e0 commit 770103c

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

apps/files_sharing/lib/ExpireSharesJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function run($argument) {
8585
)
8686
);
8787

88-
$shares = $qb->execute();
88+
$shares = $qb->executeQuery();
8989
while ($share = $shares->fetch()) {
9090
if ((int)$share['share_type'] === IShare::TYPE_LINK) {
9191
$id = 'ocinternal';

lib/private/Encryption/HookManager.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,45 @@
2828
use Psr\Log\LoggerInterface;
2929

3030
class HookManager {
31-
/**
32-
* @var Update
33-
*/
34-
private static $updater;
31+
/** @var ?Updater */
32+
private static $updater = null;
3533

36-
public static function postShared($params) {
34+
public static function postShared($params): void {
3735
self::getUpdate()->postShared($params);
3836
}
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);
4143
}
4244

43-
public static function postRename($params) {
45+
public static function postRename($params): void {
4446
self::getUpdate()->postRename($params);
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 getUpdate(?string $owner = null): Update {
5554
if (is_null(self::$updater)) {
5655
$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+
5763
$uid = '';
5864
if ($user) {
5965
$uid = $user->getUID();
6066
}
67+
68+
\OC_Util::setupFS($uid);
69+
6170
self::$updater = new Update(
6271
new View(),
6372
new Util(

0 commit comments

Comments
 (0)