Rello
June 26, 2017, 10:00pm
1
Hello,
I am trying to connect to the post_delete Filesystem hook to cleanup the Audio Player library.
for some reason, the hook is not triggered when I remove a file.
any suggestion?
https://github.com/Rello/audioplayer/blob/master/appinfo/app.php#L52
Cult
June 27, 2017, 12:25am
2
Give a try to those:
File is deleted and is going to Trashbin if trashbin app is enabled:
Util::connectHook('OC_Filesystem', 'delete', '', '');
File is restored from the trashbin
Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', '', '');
File is deleted from the trashbin
Util::connectHook('\OCP\Trashbin', 'preDelete', '', '');
$this->registerFilesActivity();
}
/**
* Register the hooks for filesystem operations
*/
public function registerFilesActivity() {
// All other events from other apps have to be send via the Consumer
Util::connectHook('OC_Filesystem', 'post_create', FilesHooksStatic::class, 'fileCreate');
Util::connectHook('OC_Filesystem', 'post_update', FilesHooksStatic::class, 'fileUpdate');
Util::connectHook('OC_Filesystem', 'delete', FilesHooksStatic::class, 'fileDelete');
Util::connectHook('OC_Filesystem', 'rename', FilesHooksStatic::class, 'fileMove');
Util::connectHook('OC_Filesystem', 'post_rename', FilesHooksStatic::class, 'fileMovePost');
Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', FilesHooksStatic::class, 'fileRestore');
Util::connectHook('OCP\Share', 'post_shared', FilesHooksStatic::class, 'share');
$eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
$eventDispatcher->addListener('OCP\Share::preUnshare', [FilesHooksStatic::class, 'unShare']);
}
/**
Also works on the activity app.
Not sure what’s wrong with the post hook thou?
Cult
June 27, 2017, 5:10pm
4
I think it’s postDelete
Rello
June 27, 2017, 9:14pm
5
Cult:
preDelete
I really don´t get it.
I am trying all combinations, but my Hook is not called - no entry in log. nothing
\OCP\Util::connectHook('OC_Filesystem', 'post_delete', 'OCA\audioplayer\Hooks\FileHooks', 'deleteTrack');
\OCP\Util::connectHook('OC_Filesystem', 'postDelete', 'OCA\audioplayer\Hooks\FileHooks', 'deleteTrack');
\OCP\Util::connectHook('OC_Filesystem', 'delete', 'OCA\audioplayer\Hooks\FileHooks', 'deleteTrack');
\OCP\Util::connectHook('\OCP\Trashbin', 'preDelete', 'OCA\audioplayer\Hooks\FileHooks', 'deleteTrack');
these lines in the app.php
https://github.com/Rello/audioplayer/blob/master/appinfo/app.php
did I miss anything else?
I even restarted php to reset the caches
Cult
June 28, 2017, 11:03am
6
can’t create branch on your repo
Please check this is working, if you want to compare to your work and see what was going wrong.
Note that I moved few thing from app.php to a method in Application.php and call that method. I find it cleaner this way.
Rello
June 28, 2017, 11:30am
7
I will check.
thank you! always learning something new about app/application split…
Rello
June 28, 2017, 7:44pm
8
so,
I split all known actions into several functions for debugging
Util::connectHook('OC_Filesystem', 'post_delete', 'OCA\audioplayer\Hooks\FileHooks', 'deleteTrack1');
Util::connectHook('OC_Filesystem', 'postDelete', 'OCA\audioplayer\Hooks\FileHooks', 'deleteTrack2');
Util::connectHook('OC_Filesystem', 'delete', 'OCA\audioplayer\Hooks\FileHooks', 'deleteTrack3');
Util::connectHook('\OCP\Trashbin', 'preDelete', 'OCA\audioplayer\Hooks\FileHooks', 'deleteTrack4');
Util::connectHook('OC_Filesystem', 'delete', '\OCA\audioplayer\Hooks\FileHooks', 'deleteTrack5');
only option 4 - Trashbin preDelete works.
when disabling Trashbin, non of the functions is triggered
this does not really help me because I need the deleted-option from the files app to remove the title from my audioplayer library.
any other idea?
according to the docu, it should be "delete"
https://fossies.org/dox/nextcloud-12.0.0/classOC_1_1Files_1_1Filesystem.html#add515f395dd97c228f32c5e2ecd5c170
Cult
June 28, 2017, 8:10pm
9
My idea is that your path for the class need a \ (backslash)
try this:
Util::connectHook('OC_Filesystem', 'post_delete', '\OCA\audioplayer\Hooks\FileHooks', 'deleteTrack1');
Util::connectHook('OC_Filesystem', 'postDelete', '\OCA\audioplayer\Hooks\FileHooks', 'deleteTrack2');
Util::connectHook('OC_Filesystem', 'delete', '\OCA\audioplayer\Hooks\FileHooks', 'deleteTrack3');
Util::connectHook('\OCP\Trashbin', 'preDelete', '\OCA\audioplayer\Hooks\FileHooks', 'deleteTrack4');
Rello
June 28, 2017, 10:19pm
10
no success
it works for Trashbin without backslash
really clueless. Tried in NC12 and OC9; makes no difference
Cult
June 28, 2017, 10:21pm
11
but you tried my branch ? It looks like it is working there
Rello
June 28, 2017, 10:41pm
12
this dies not seem right in your branch
if ($user) return $user->getUID();
});
$container -> registerService('L10N', function(IContainer $c) {
return $c -> query('ServerContainer') -> getL10N($c -> query('AppName'));
});
$container->registerService('Config', function($c){
return $c->getServer()->getConfig();
});
public function registerFilesHooks() {
Util::connectHook(
'OC_Filesystem', 'delete', '\OCA\audioplayer\Hooks\FileHooks', 'deleteTrack'
);
}
}
function inside __construct.
I closed the construct with an }
but I am only getting
Object of class OCA\\audioplayer\\AppInfo\\Application could not be converted to string at \/var\/www\/nextcloud\/lib\/private\/legacy\/app.php#80
Cult
June 28, 2017, 10:55pm
13
oups, lost few lines …
I pushed a fix, and this is what I got in the log when deleting a file or a folder:
Rello
June 30, 2017, 8:04pm
14
thank you for not giving up.
I have no clue and skipping this feature.
I do not get it triggered. I even cloned your whole repo - but nothing on 2 separate test instances.
there needs to be something wrong with the file-hooks. because the user-deletion-hook is still working without issues. Don´t know if its a combination of enabled apps or something. But when I am having the issue, others could also have it.
As this does not seem to be something stable to rely on, I will not implement it.
one question: what is “version 13” in your screenshot?
Cult
June 30, 2017, 9:02pm
15
I have to admit that I am using the master from nextcloud/server (13.0.0)
Anyway, try something before giving up !
Add this to your info.xml:
<types>
<filesystem />
</types>
./occ app:disable audioplayer
./occ app:enable audioplayer
delete a file and check your log. (you might need to set the loglevel to 1 in config/config.php)
1 Like
Rello
July 2, 2017, 10:40am
16
ok, this was the usefull information!!!
the entry in info.xml is required
PLUS
app needs to be re-enabled to have effect
can you tell the background of the xml entry?
in generell the hook is called. unfortunately not via a Node object. just the path.
Now I need myself from that to the file_id…
Cult
July 2, 2017, 11:14am
17
Yes, I am not an expert, but I would try this:
$view = OC\Files\Filesystem::getView();
$fileInfo = $view->getFileInfo($path);
if it is not working, set $view this way instead:
$view = new \OC\Files\View('/' . \OC::$server->getUserSession()->getUser());
Then, you get whatever you want (\OC\Files\FileInfo):
$fileInfo->getId();
Rello
July 3, 2017, 8:11pm
18
thank you!
it works!
I flagged your post with the info.xml and the enable/disable as solution because this was the key to make it work
1 Like