diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index feece2e75328697116a435c64e8ef8e8c6535090..ec46b18189ae7f4f20334a57cf1e2c3f3453c86c 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -23,8 +23,10 @@ namespace OCA\EcloudDropAccount\AppInfo; -use OCA\EcloudDropAccount\Hooks\UserHooks; +use OCA\EcloudDropAccount\Event\BeforeUserDeletedEvent; +use OCA\EcloudDropAccount\Listener\PrepareEDeletion; use OCP\AppFramework\App; +use OCP\EventDispatcher\IEventDispatcher; use OCP\ILogger; use OCP\IContainer; use OCP\ServerContainer; @@ -32,26 +34,12 @@ use OCP\IUserManager; use OCP\IConfig; -class Application extends App { - - const APP_NAME = 'ecloud_drop_account'; - - public function __construct () - { - parent::__construct(self::APP_NAME); - - $container = $this->getContainer(); - - - $container->registerService('UserHooks', function($c) { - return new UserHooks( - $c->query('ServerContainer')->getUserManager(), - $c->query('ServerContainer')->getLogger(), - $c->query('ServerContainer')->getConfig() - ); - }); - - } - +class Application extends App { + public function __construct() { + parent::__construct('EcloudDropAccount'); + /* @var IEventDispatcher $eventDispatcher */ + $dispatcher = $this->getContainer()->query(IEventDispatcher::class); + $dispatcher->addListener(BeforeUserDeletedEvent::class, PrepareEDeletion::class); + } } diff --git a/lib/Event/BeforeUserDeletedEvent.php b/lib/Event/BeforeUserDeletedEvent.php new file mode 100644 index 0000000000000000000000000000000000000000..7137481544f48f28c1aca16ae606b4a5a36c0bda --- /dev/null +++ b/lib/Event/BeforeUserDeletedEvent.php @@ -0,0 +1,27 @@ +user = $user; + } + + public function getUser(): IUser { + return $this->user; + } + +} \ No newline at end of file diff --git a/lib/Hooks/curl.class.php b/lib/Hooks/curl.class.php deleted file mode 100644 index c188d269fc3381b6db6179ca447b40142a5ef2b9..0000000000000000000000000000000000000000 --- a/lib/Hooks/curl.class.php +++ /dev/null @@ -1,87 +0,0 @@ -request('GET',$url,$params,$headers,$userOptions); - } - - /** - * POST alis for request method - * - * @param $url - * @param array $params - * @param array $headers - * @param array $userOptions - * @return mixed - */ - public function post($url, $params = array(), $headers = array(), $userOptions = array()) { - return $this->request('POST',$url,$params,$headers,$userOptions); - } - - - /** - * Curl run request - * - * @param $method - * @param string $url - * @param array $params - * @param array $headers - * @param array $userOptions - * @return mixed - * @throws Exception - */ - private function request($method, $url, $params = array(), $headers = array(), $userOptions = array()) { - $ch = curl_init(); - $method = strtoupper($method); - $options = array( - CURLOPT_RETURNTRANSFER => true, - CURLOPT_HEADER => $headers - ); - array_merge($options,$userOptions); - switch ($method) { - case 'GET': - if($params) { - $url = $url.'?'.http_build_query($params); - } - break; - case 'POST': - $options[CURLOPT_POST] = true; - $options[CURLOPT_POSTFIELDS] = $params; - break; - default: - throw new Exception('Unsuported method.'); - break; - } - $options[CURLOPT_URL] = $url; - - curl_setopt_array($ch, $options); - - $response = curl_exec($ch); - - if($errno = curl_errno($ch)) { - var_dump($errno); - $errorMessage = curl_strerror($errno); - throw new Exception("Curl error $errno - $errorMessage"); - } - - curl_close($ch); - - return $response; - - } -} \ No newline at end of file diff --git a/lib/Hooks/UserHooks.php b/lib/Listener/PrepareEDeletion.php similarity index 65% rename from lib/Hooks/UserHooks.php rename to lib/Listener/PrepareEDeletion.php index 8ceb765ebb9fe1cbbc6d8b14109a384cf5dbe6d8..eb0cc1d696ac275878eb740e9028d452297b859c 100644 --- a/lib/Hooks/UserHooks.php +++ b/lib/Listener/PrepareEDeletion.php @@ -1,47 +1,29 @@ ecloudDelete($event->GetUser()->getUID()); -class UserHooks { + } - private $userManager; - private $logger; - public function __construct(IUserManager $userManager, ILogger $logger, IConfig $config){ - $this->userManager = $userManager; - $this->logger = $logger; - $this->config = $config; - } - public function register() { - - - - /** - * when auto delete action is done by user, fire postDelete hook - * to send postDelete actions to be done for /e/ specific setup - * - * username in ecloud-selfhost setup IS in the form user@$DOMAIN - * - */ - - $callback = function(IUser $user) { - - $externalDelete = $this->ecloudDelete($user->getUID()); - - }; - $this->userManager->listen('\OC\User', 'postDelete', $callback); - } - - /** + /** * Once NC deleted account datas * do specific ecloud selfhosting actions * post delete action is delegated welcome container @@ -94,5 +76,4 @@ class UserHooks { } } - } \ No newline at end of file