2
votes

I am trying to add some Hooks to my OwnCloud app called Metadata, and i can't seem to figure it out (the hook is not being fired).

I tried following the content https://doc.owncloud.org/server/8.2/developer_manual/app/init.html and https://doc.owncloud.org/server/8.2/developer_manual/app/hooks.html (although it seems like the second one is outdated).

Basically all i am trying to do for now is the catch the pre-rename hook and write something to a file.

My code is :

myapp/appinfo/app.php

namespace OCA\Metadata\AppInfo;

use OCP\AppFramework\App;

$app = new App('metadata');
$container = $app->getContainer();

$container->query('OCP\INavigationManager')->add(function () use ($container) {
    $urlGenerator = $container->query('OCP\IURLGenerator');
    $l10n = $container->query('OCP\IL10N');
    return [
        // the string under which your app will be referenced in owncloud
        'id' => 'metadata',

        // sorting weight for the navigation. The higher the number, the higher
        // will it be listed in the navigation
        'order' => 10,

        // the route that will be shown on startup
        'href' => $urlGenerator->linkToRoute('metadata.page.index'),

        // the icon that will be shown in the navigation
        // this file needs to exist in img/
        'icon' => $urlGenerator->imagePath('metadata', 'app.svg'),

        // the title of your application. This will be used in the
        // navigation or on the settings page of your app
        'name' => $l10n->t('Metadata'),
    ];
});

\OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OC\Metadata\Hooks', 'postRename');

and then myapp/hooks.php

<?php
namespace OCA\Metadata;

use OC\Files\Filesystem;
use OC\Files\View;

class Hooks {

    // private $userManager;

    public static function postRename($params) {
       file_put_contents("/var/www/data/owncloud_print2.log", "post_rename");
    }
}

nothing ever gets written to the file. i have also tried other approaches all with no luck. anyone knows what i am doing wrong??

1

1 Answers

0
votes

my connecthook was wrong. it should be:

\OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OCA\Metadata\Hooks', 'postRename');