Trying to implement a Hooks

Hi !
I’m working on a custom Hooks in order to manage extern hard disk power. I have a import problem on my app using namespace.
The error is Class ‘OCA\\diskM\\AppInfo\\Application’ not found . Someone knows how to fix that ?
Thank’s to help me.

More data :

I store all source file on directory /apps/diskM/appinfo and /apps/diskM/Hooks.

My routes.php

namespace OCA\diskM\AppInfo;
use OCA\diskM\AppInfo\Application;

$app = new Application();

My application.php

namespace OCA\diskM\AppInfo;

use \OCP\AppFramework\App;
use \OCA\diskM\Hooks\DiskHooks;

class Application extends App {

public function __construct(array $urlParams=array()){
    parent::__construct('DiskM', $urlParams);

    $container = $this->getContainer();

     * Controllers
    $container->registerService('DiskHooks', function($c) {
        return new DiskHooks(


Did you add your namespace to info.xml?

Yes !
You can see below my XML.

<?xml version="1.0"?>
<name>Disk Manager</name>
<description>Use a C daemon to manage disk power</description>
<author>François Gauthier-Clerc</author>
<owncloud min-version="9" />
 <owncloud max-version="11" />

I tried your code and found some wrong things. Firstly, in your info.xml, your appId should be disk_manager and you should define dependencies in one tag:

	<owncloud min-version="9" max-version="11" />

Also, why are you registering your hooks in routes.php? It should be registered in app.php. After I changed these, I successfully enabled your app without any error.
In this repo, We used hooks etc. like your app. You can take its structure as an example:

1 Like

I’m sorry to bother you again, but i still have a import error. I pushed my source code on github, if you want to see it.
Thank you.

You can find the fix in the following, Application php should be inside of AppInfo folder

1 Like

Thanks a lot, I can enable my app !!!
It’s pretty cool but the preLogin hooks don’t solve my problem. I want to execute a script when any device try to get any data. Actually, the hooks is executed only on login in, if the user has cookies, my hooks don’t works. Have you some idea to extend the prelogin Hooks ?

Use preWrite hook instead of preLogin and make your app’s type filesystem.

1 Like

I followed your instructions but my folder hooks isn"t called at all with Root folder. (I push the new source code to github). Can I use a scanFolder Hook to solve my problem ?
Thank you for all your assistance .

As far as I see, you did not point your app’s type in info.xml. You can look following app as an example: , if it would not work, I can try your code tomorrow.

1 Like

This new field does’t change anything. :’( If you try my app don’t forget to change the log file path.
Thanks you again for taking the time to help me.

I created a PR to show preWrite Hook callback function is working when you write a file.