@@ -466,11 +466,6 @@ public function track($doc, $users, $key, $status, $url, $token, $history, $chan
466466 $ user = $ this ->userManager ->get ($ userId );
467467 if (!empty ($ user )) {
468468 \OC_User::setUserId ($ userId );
469- \OC_Util::setupFS ($ userId );
470-
471- if ($ userId === $ hashData ->userId ) {
472- $ filePath = $ hashData ->filePath ;
473- }
474469 } else {
475470 if (empty ($ shareToken )) {
476471 $ this ->logger ->error ("Track without token: $ fileId status $ status " , ["app " => $ this ->appName ]);
@@ -480,20 +475,36 @@ public function track($doc, $users, $key, $status, $url, $token, $history, $chan
480475 $ this ->logger ->debug ("Track $ fileId by token for $ userId " , ["app " => $ this ->appName ]);
481476 }
482477
478+ // owner of file from the callback link
479+ $ ownerId = $ hashData ->ownerId ;
480+ $ owner = $ this ->userManager ->get ($ ownerId );
481+
482+ if (!empty ($ owner )) {
483+ $ userId = $ ownerId ;
484+ } else {
485+ $ callbackUserId = $ hashData ->userId ;
486+ $ callbackUser = $ this ->userManager ->get ($ callbackUserId );
487+
488+ if (!empty ($ callbackUser )) {
489+ // author of the callback link
490+ $ userId = $ callbackUserId ;
491+
492+ // path for author of the callback link
493+ $ filePath = $ hashData ->filePath ;
494+ }
495+ }
496+
497+ if (!empty ($ userId )) {
498+ \OC_Util::setupFS ($ userId );
499+ }
500+
483501 list ($ file , $ error ) = empty ($ shareToken ) ? $ this ->getFile ($ userId , $ fileId , $ filePath ) : $ this ->getFileByToken ($ fileId , $ shareToken );
484502
485503 if (isset ($ error )) {
486504 $ this ->logger ->error ("track error $ fileId " . json_encode ($ error ->getData ()), ["app " => $ this ->appName ]);
487505 return $ error ;
488506 }
489507
490- if (empty ($ user )) {
491- $ owner = $ file ->getFileInfo ()->getOwner ();
492- if ($ owner !== null ) {
493- \OC_Util::setupFS ($ owner ->getUID ());
494- }
495- }
496-
497508 $ url = $ this ->config ->ReplaceDocumentServerUrlToInternal ($ url );
498509
499510 $ prevVersion = $ file ->getFileInfo ()->getMtime ();
0 commit comments