From f7c509650faefda4e106645ccace7a65cea2c59f Mon Sep 17 00:00:00 2001 From: Holger Trampe Date: Wed, 1 Sep 2021 16:43:03 +0200 Subject: [PATCH] =?UTF-8?q?=C3=84nderung=20f=C3=BCr=20File=20Events?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- appinfo/info.xml | 3 +++ lib/AppInfo/Application.php | 40 ++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index 86e7799..ba803a2 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -19,4 +19,7 @@ app.svg --> + + + diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 18f8265..7c4787e 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -14,10 +14,11 @@ use OCP\User\Events\PostLoginEvent; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; +use OCP\Files\Events\Node\BeforeNodeDeletedEvent; + class Application extends App { protected $AppName = 'Agency'; - # TEST public function __construct() { parent::__construct($this->AppName); @@ -31,6 +32,43 @@ class Application extends App { # Checking, if a user logged in in Django and which user is logged in in Django. $dispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, LoginByNC::class); + + # Event before a File is deletet + $dispatcher->addServiceListener(BeforeNodeDeletedEvent::class, DeleteNCFileDjango::class); + } +} + +/* + A File is ready to be deleted in NC, before that happens delete the File in Django and remove it from addedfiles_nc in standards +*/ + +class DeleteNCFileDjango extends Controller { + + protected $session; + //private $nclink = 'https://test.app.digitale-agentur.com'; + private $nclink = 'http://host.docker.internal:8000'; + + public function __construct(string $AppName, IRequest $request, IUserSession $session) { + parent::__construct($AppName, $request); + $this->session = $session; + } + + public function handle(BeforeNodeDeletedEvent $event): void { + $opts = [ + "http" => array( + "method" => "GET", + "header" => "" + ), + "ssl"=> array( + "verify_peer"=>false, + "verify_peer_name"=>false, + ), + ]; + $context = stream_context_create($opts); + + + + $file = file_get_contents($this->nclink.'/api/deletefile/'.$event->getNode()->getId().'/87zuhjk87GHJ546tzgvhas76aaskbdhr45edfVHAKia87s6gbAVGFGSR3451627gBHAKJBN', false, $context); } }