Owncloud + Hooks

时间:2015-11-04 20:49:26

标签: php owncloud

我正在尝试将一些Hook添加到名为Metadata的我的OwnCloud应用程序中,我似乎无法弄清楚(钩子没有被解雇)。

我尝试关注内容https://doc.owncloud.org/server/8.2/developer_manual/app/init.htmlhttps://doc.owncloud.org/server/8.2/developer_manual/app/hooks.html(虽然看起来第二个内容已过时)。

基本上我现在要做的就是抓住pre-rename钩子并将某些内容写入文件。

我的代码是:

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');

然后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");
    }
}

什么都没有写入文件。我也试过其他方法都没有运气。谁知道我做错了什么?

1 个答案:

答案 0 :(得分:0)

我的连接错了。它应该是:

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