Hook don´t fire

development
9.1.x

#1

Hey @everybody,

I am a newcomer and have a litte problem with my own app. I want to fire a hook, that add a LDAP user to his LDAP shared group folder. This is what I want at the end. For the first testing I only want that the hook create a log-file when I create an user in the backend. But it didn´t work and I didn´t get any errors. I created the hook as desribet in the development manual:

https://doc.owncloud.org/server/latest/developer_manual/app/hooks.html

And this is the code that I had created:
AppInfo/app.php
<?php
namespace OCA\LdapFolder\AppInfo;

$app = new Application();
$app->getContainer()->query('LdapHooks')->register();

//\OCP\Util::connectHook('OC_User', 'post_createUser', 'OCA\LdapFolder\Hooks\LdapHooks', 'LdapHooks');

lib/AppInfo/Application.php
<?php
namespace OCA\LdapFolder\AppInfo;

use \OCP\AppFramework\App;

use \OCA\LdapFolder\Hooks\LdapHooks;


class Application extends App {

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

		$container = $this->getContainer();

		/**
		 * Controllers
		 */
		$container->registerService('LdapHooks', function($c) {
			return new LdapHooks(
				$c->query('ServerContainer')->getUserManager()
			);
		});
	}
}

lib/Hooks/LdapHooks.php
<?php
namespace OCA\LdapFolder\Hooks;

class LdapHooks {

	private $userManager;

	public function __construct($userManager){
		$this->userManager = $userManager;
	}

	public function register() {
		$callback = function($user) {
			$file=fopen("test.txt", "a");
			fwrite($file, 'it is working' . $user);
			fclose($file);
		};
		$this->userManager->listen('\OC\User', 'postCreateUser', $callback);
	}

}

I hope that I made only a little mistake, or that I understand something wronge.

Thank you for your help

Best Regards


#2

Hey there,

I have a similar problem, using ownCloud 10.

Anyone any idea on how to do it right?


#3

For reference: Topic „Filesystem hooks don't fire