2015-11-04 61 views
2

我想一些鉤子添加到我的OwnCloud應用程序稱爲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"); 
    } 
} 

從來都沒有被寫入文件。我也試過其他方法都沒有運氣。任何人都知道我在做什麼錯?

回答

0

我connecthook是錯誤的。它應該是:

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