{"action":"created","issue":{"url":"https://api.github.com/repos/owncloud/core/issues/26778","repository_url":"https://api.github.com/repos/owncloud/core","labels_url":"https://api.github.com/repos/owncloud/core/issues/26778/labels{/name}","comments_url":"https://api.github.com/repos/owncloud/core/issues/26778/comments","events_url":"https://api.github.com/repos/owncloud/core/issues/26778/events","html_url":"https://github.com/owncloud/core/issues/26778","id":193812272,"number":26778,"title":"Hook doesn't work with getRootFolder()","user":{"login":"Kitounet","id":7276217,"avatar_url":"https://avatars.githubusercontent.com/u/7276217?v=3","gravatar_id":"","url":"https://api.github.com/users/Kitounet","html_url":"https://github.com/Kitounet","followers_url":"https://api.github.com/users/Kitounet/followers","following_url":"https://api.github.com/users/Kitounet/following{/other_user}","gists_url":"https://api.github.com/users/Kitounet/gists{/gist_id}","starred_url":"https://api.github.com/users/Kitounet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kitounet/subscriptions","organizations_url":"https://api.github.com/users/Kitounet/orgs","repos_url":"https://api.github.com/users/Kitounet/repos","events_url":"https://api.github.com/users/Kitounet/events{/privacy}","received_events_url":"https://api.github.com/users/Kitounet/received_events","type":"User","site_admin":false},"labels":[{"id":12470597,"url":"https://api.github.com/repos/owncloud/core/labels/needs%20info","name":"needs info","color":"0b02e1","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-12-06T16:06:33Z","updated_at":"2016-12-07T08:29:09Z","closed_at":null,"body":"Hello everyone,\r\n\r\nI'm a beginner in developing owncloud apps and I actually have a problem for implementing the hooks.\r\nI followed this documentation https://doc.owncloud.org/server/9.2/developer_manual/app/hooks.html and tested with the getUserManager() function and it worked. (I saw with the logger if it worked or not)\r\nBut I'm applying the same code's logic with getRootFolder() and nothing happens.\r\n\r\nIt is a knew issues ? or am I doing something bad ?\r\n\r\nThanks to you.\r\n\r\n### Steps to reproduce\r\n1.preWrite\r\n2.preCreate\r\n3.postWrite\r\n4.postCreate\r\n\r\n### Expected behaviour\r\nHook should be called.\r\n\r\n### Actual behaviour\r\nNothing , no error, no debug messages.\r\n\r\n### Server configuration\r\n**Operating system**:\r\nUbuntu 16.04\r\n**Web server:**\r\nApache/2.4.18\r\n**Database:**\r\nSQL Lite\r\n**PHP version:**\r\nPHP 5.6.28\r\n**ownCloud version:** (see ownCloud admin page)\r\n9.2.0\r\n**Updated from an older ownCloud or fresh install:**\r\nfresh install\r\n**Where did you install ownCloud from:**\r\nGit\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/owncloud/core/issues/comments/265386449","html_url":"https://github.com/owncloud/core/issues/26778#issuecomment-265386449","issue_url":"https://api.github.com/repos/owncloud/core/issues/26778","id":265386449,"user":{"login":"Kitounet","id":7276217,"avatar_url":"https://avatars.githubusercontent.com/u/7276217?v=3","gravatar_id":"","url":"https://api.github.com/users/Kitounet","html_url":"https://github.com/Kitounet","followers_url":"https://api.github.com/users/Kitounet/followers","following_url":"https://api.github.com/users/Kitounet/following{/other_user}","gists_url":"https://api.github.com/users/Kitounet/gists{/gist_id}","starred_url":"https://api.github.com/users/Kitounet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kitounet/subscriptions","organizations_url":"https://api.github.com/users/Kitounet/orgs","repos_url":"https://api.github.com/users/Kitounet/repos","events_url":"https://api.github.com/users/Kitounet/events{/privacy}","received_events_url":"https://api.github.com/users/Kitounet/received_events","type":"User","site_admin":false},"created_at":"2016-12-07T08:29:09Z","updated_at":"2016-12-07T08:29:09Z","body":"Hi,\r\n\r\nYes sure here is the code.\r\n```\r\n<?php\r\n//app.php\r\nnamespace OCA\\FilesQuota\\AppInfo;\r\n\r\nuse OCP\\AppFramework\\App;\r\n\r\nrequire_once __DIR__ . '/autoload.php';\r\n\r\n$appli = new Application();\r\n$appli->getContainer()->query('RootHooks')->register();\r\n\r\n$app = new App('filesquota');\r\n$container = $app->getContainer();\r\n\r\n$container->query('OCP\\INavigationManager')->add(function () use ($container) {\r\n\t$urlGenerator = $container->query('OCP\\IURLGenerator');\r\n\t$l10n = $container->query('OCP\\IL10N');\r\n\treturn [\r\n\t\t// the string under which your app will be referenced in owncloud\r\n\t\t'id' => 'filesquota',\r\n\r\n\t\t// sorting weight for the navigation. The higher the number, the higher\r\n\t\t// will it be listed in the navigation\r\n\t\t'order' => 10,\r\n\r\n\t\t// the route that will be shown on startup\r\n\t\t'href' => $urlGenerator->linkToRoute('filesquota.page.index'),\r\n\r\n\t\t// the icon that will be shown in the navigation\r\n\t\t// this file needs to exist in img/\r\n\t\t'icon' => $urlGenerator->imagePath('filesquota', 'app.svg'),\r\n\r\n\t\t// the title of your application. This will be used in the\r\n\t\t// navigation or on the settings page of your app\r\n\t\t'name' => $l10n->t('Files Quota'),\r\n\t];\r\n});\r\n```\r\n```\r\n<?php\r\n//application.php\r\nnamespace OCA\\FilesQuota\\AppInfo;\r\n\r\nuse \\OCP\\AppFramework\\App;\r\n\r\nuse \\OCA\\FilesQuota\\Hooks\\RootHooks;\r\nuse OCP\\IContainer;\r\n\r\n\r\nclass Application extends App {\r\n\r\n\tpublic function __construct(array $urlParams=array()){\r\n\t\tparent::__construct('filesquota', $urlParams);\r\n\r\n\t\t$container = $this->getContainer();\r\n\r\n\t\t/**\r\n\t\t * Controllers\r\n\t\t */\r\n\t\t$container->registerService('RootHooks', function($c) {\r\n\t\t\treturn new RootHooks(\r\n\t\t\t\t$c->query('ServerContainer')->getRootFolder(),\r\n\t\t\t\t$c->query('Logger'),\r\n\t\t\t\t$c->query('AppName')\r\n\t\t\t);\r\n\t\t});\r\n\r\n\t\t$container->registerService('Logger', function($c) {\r\n\t\t\treturn $c->query('ServerContainer')->getLogger();\r\n\t\t});\r\n\t}\r\n}\r\n```\r\n```\r\n<?php\r\n//roothooks.php\r\nnamespace OCA\\FilesQuota\\Hooks;\r\n\r\nuse OCP\\ILogger;\r\n\r\n\r\nclass RootHooks {\r\n\r\n\tprivate $rootFolder;\r\n\tprivate\t$logger;\r\n\tprivate\t$appName;\r\n\r\n\tpublic function __construct($rootFolder, ILogger $logger, $appName){\r\n\t\t$this->rootFolder = $rootFolder;\r\n\t\t$this->logger = $logger;\r\n\t\t$this->appName = $appName;\r\n\t}\r\n\r\n\tpublic function register() {\r\n\t\t$callback = function(\\OCP\\Files\\Node $node) {\r\n\t\t\t// your code that executes before $node is writed\r\n\t\t\t$this->log(\"LOGTEST\");\r\n\t\t};\r\n\t\t$this->rootFolder->listen('\\OC\\Files', 'preWrite', $callback);\r\n\t}\r\n\r\n\r\n\tpublic function log($message) {\r\n\t\t$this->logger->error($message, array('app' => $this->appName));\r\n\t}\r\n\r\n}\r\n```\r\nI tried to upload a file or create a folder, I saw in the core that when a folder or a file is created it will emit the \"preWrite\" and \"preCreate\".\r\nI'm not sure if I really get your last question. I'm using the administrator account.\r\nMy hooks is not supposed to listen every users actions ?\r\n\r\nThanks for your help.\r\n"}}
{"actor":{"display_login":"Kitounet"}}