How to Get User

Hi,

I have an application that log files events and gets size and time, I need to get username who made that event, I’m using the NextCloud log OCP\ILogger
I already have in the log

{"reqId":"C5MjfvVINnVLDogO4NKs","level":1,"time":"2018-01-11T07:46:26+00:00","remoteAddr":"194.165.136.114","user":"test","app":"TracerSizeFour","method":"PUT","url":"\/remote.php\/dav\/files\/test\/New%20Text%20Document%20(2).txt","message":"File created: \"\/\/New Text Document (2).txt\"","userAgent":"Mozilla\/5.0 (Windows) mirall\/2.3.3 (build 1) (Nextcloud)","version":"12.0.4.3"}

if you notice the line "user":"test" this is the user, how to get it? it doesn’t exit in the returned array from the web hook ($params)

but I don’t know how to get the user if I wanted to forward to a different URL, so the question how to get the username who made an event, keep in mind that the logging is on administrative level so need to know a user from multiple users

Thanks

I already tried this function and gave me the exception

{"reqId":"1LldjbX4NPCvGMeiPBO5","level":3,"time":"2018-01-11T08:54:44+00:00","remoteAddr":"*******","user":"test","app":"remote","method":"MOVE","url":"\/remote.php\/dav\/files\/test\/q.pdf","message":"Exception: {\"Exception\":\"Error\",\"Message\":\"Class 'OCA\\\\TracerSizeFour\\\\Actions\\\\OCP\\\\USER' not found\",\"Code\":0,\"Trace\":\"#0 \\\/var\\\/snap\\\/nextcloud\\\/4371\\\/nextcloud\\\/extra-apps\\\/tracersizefour\\\/lib\\\/Actions\\\/Files.php(90): OCA\\\\TracerSizeFour\\\\Actions\\\\Files->renameItem(Array)\\n#1 \\\/snap\\\/nextcloud\\\/4371\\\/htdocs\\\/lib\\\/private\\\/legacy\\\/hook.php(106): OCA\\\\TracerSizeFour\\\\Actions\\\\Files->rename(Array)\\n#2 \\\/snap\\\/nextcloud\\\/4371\\\/htdocs\\\/lib\\\/private\\\/Files\\\/View.php(853): OC_Hook::emit('OC_Filesystem', 'post_rename', Array)\\n#3 \\\/snap\\\/nextcloud\\\/4371\\\/htdocs\\\/apps\\\/dav\\\/lib\\\/Connector\\\/Sabre\\\/Node.php(137): OC\\\\Files\\\\View->rename('\\\/q.pdf', '\\\/i.pdf')\\n#4 \\\/snap\\\/nextcloud\\\/4371\\\/htdocs\\\/3rdparty\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/Tree.php(151): OCA\\\\DAV\\\\Connector\\\\Sabre\\\\Node->setName('i.pdf')\\n#5 \\\/snap\\\/nextcloud\\\/4371\\\/htdocs\\\/3rdparty\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/CorePlugin.php(642): Sabre\\\\DAV\\\\Tree->move('files\\\/test\\\/q...', 'files\\\/test\\\/i...')\\n#6 [internal function]: Sabre\\\\DAV\\\\CorePlugin->httpMove(Object(Sabre\\\\HTTP\\\\Request), Object(Sabre\\\\HTTP\\\\Response))\\n#7 \\\/snap\\\/nextcloud\\\/4371\\\/htdocs\\\/3rdparty\\\/sabre\\\/event\\\/lib\\\/EventEmitterTrait.php(105): call_user_func_array(Array, Array)\\n#8 \\\/snap\\\/nextcloud\\\/4371\\\/htdocs\\\/3rdparty\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/Server.php(479): Sabre\\\\Event\\\\EventEmitter->emit('method:MOVE', Array)\\n#9 \\\/snap\\\/nextcloud\\\/4371\\\/htdocs\\\/3rdparty\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/Server.php(254): Sabre\\\\DAV\\\\Server->invokeMethod(Object(Sabre\\\\HTTP\\\\Request), Object(Sabre\\\\HTTP\\\\Response))\\n#10 \\\/snap\\\/nextcloud\\\/4371\\\/htdocs\\\/apps\\\/dav\\\/lib\\\/Server.php(258): Sabre\\\\DAV\\\\Server->exec()\\n#11 \\\/snap\\\/nextcloud\\\/4371\\\/htdocs\\\/apps\\\/dav\\\/appinfo\\\/v2\\\/remote.php(33): OCA\\\\DAV\\\\Server->exec()\\n#12 \\\/snap\\\/nextcloud\\\/4371\\\/htdocs\\\/remote.php(162): require_once('\\\/snap\\\/nextcloud...')\\n#13 {main}\",\"File\":\"\\\/var\\\/snap\\\/nextcloud\\\/4371\\\/nextcloud\\\/extra-apps\\\/tracersizefour\\\/lib\\\/Actions\\\/Files.php\",\"Line\":63}","userAgent":"Mozilla\/5.0 (Windows) mirall\/2.3.3 (build 1) (Nextcloud)","version":"12.0.4.3"}

you can see that I’m missing the class \OCP\\\\USER where to find this class?

I changed the code to

<?php
$owner = \OC\Files\Filesystem::getOwner($params['path']);

and returned the username, actually it works on administrative level, meaning I have two users and it gets any of the users trigger an event (create, delete,…)

keep in mind that the variable $params['path'] works for create or delete, but for something have many paths like rename, you don’t have ‘path’ but rather $params[oldpath] or$params[newpath]