Owncloud postCreate/post_create hooks not executing for other users on shared folders

162 views Asked by At

We are developing an OwnCloud app where we are trying to track the user who upload the file to specific folder. the hooks is working for the admin but the hook is not executing when another user upload to a shared folder. is this a permission issue ?

our hook register code. we try both hook system, but same result.

public function register() {

        \OCP\Util::connectHook('OC_Filesystem', 'post_create', 'OCA\FileActivities\Controller\UserHooks', 'onFileCreate');
                
        $reference = $this;

        $callback = function (Node $node) use($reference) {
            $reference->onPostCreate($node);
        };

       
        $this->fileManager->listen('\OC\Files', 'postCreate', $callback);

    }
1

There are 1 answers

0
mmdush On BEST ANSWER

Ok to anyone searching the answer for the same, I got this figured out. as follow.

in your app.php

namespace OCA\xxxxxxxxxx\AppInfo;

$app = new Application();
$app->registerFilesActivity();

and in your lib/AppInfo/

namespace OCA\XXXXXXXXXXXX\AppInfo;

use \OCP\AppFramework\App;
use \OCA\XXXXXXXXXXXX\Controller\UserHooks;
use OCP\IContainer;
use OCP\Util;

class Application extends App {
    public function __construct(array $urlParams=array()){
        parent::__construct('viewfinance', $urlParams);

        $container = $this->getContainer();                
        $container->registerService('UserHooks', function($c) {
                     
            return new UserHooks(
                $c->query('AppName'),
                $c->query('Request'),
                $c->query('UserSession'),
                $c->query('ServerContainer')->getRootFolder()
            );
        });

        $container->registerService('UserSession', function($c) {
            return $c->query('ServerContainer')->getUserSession();
        });
    }

    /**
     * Register the hooks for filesystem operations
     */
    public function registerFilesActivity() {
        
        Util::connectHook('OC_Filesystem', 'post_create', 'OCA\FileActivities\Controller\UserHooks', 'onFileCreate');
        
    }
}

The documentation is not very clear on this, after checking a few other apps with similar functions, I figured this out.