Trying to implement a Hooks

apps

#1

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();
$app->getContainer()->query(‘DiskHooks’)->register();

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(
            $c->query('ServerContainer')->getUserSession()
        );
    });
}

}


#2

Did you add your namespace to info.xml?


#3

Yes !
You can see below my XML.

<?xml version="1.0"?>
<info>
<id>diskM</id>
<name>Disk Manager</name>
<description>Use a C daemon to manage disk power</description>
<licence>AGPL</licence>
<author>François Gauthier-Clerc</author>
 <version>0.0.1</version>
<namespace>diskM</namespace>
<category>DiskManager</category>
 <dependencies>
<owncloud min-version="9" />
 <owncloud max-version="11" />
</dependencies>
</info>

#4

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:

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

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: https://github.com/owncloud/brute_force_protection


#5

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. https://github.com/Enderdead/disk_manager_OwncloudApp/tree/master
Thank you.


#6

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


#7

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 ?


#8

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


#9

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 .


#10

As far as I see, you did not point your app’s type in info.xml. You can look following app as an example:https://github.com/karakayasemi/filesystem_quota/blob/master/appinfo/info.xml#L13 , if it would not work, I can try your code tomorrow.


#11

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.


#12


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