]> source.dussan.org Git - nextcloud-server.git/commitdiff
cleanup the trash bin tables in the database after a user was deleted
authorBjörn Schießle <schiessle@owncloud.com>
Thu, 11 Apr 2013 10:37:52 +0000 (12:37 +0200)
committerBjörn Schießle <schiessle@owncloud.com>
Thu, 11 Apr 2013 10:37:52 +0000 (12:37 +0200)
apps/files_trashbin/appinfo/app.php
apps/files_trashbin/lib/hooks.php
apps/files_trashbin/lib/trash.php

index a6a99db034c9f19deb1fa1d1e9b47e1e9254fe39..e83d3b8fbbd766ccadf600b766452bec191e3a16 100644 (file)
@@ -3,5 +3,7 @@
 OC::$CLASSPATH['OCA\Files_Trashbin\Hooks'] = 'files_trashbin/lib/hooks.php';
 OC::$CLASSPATH['OCA\Files_Trashbin\Trashbin'] = 'files_trashbin/lib/trash.php';
 
-
+//Listen to delete file signal
 OCP\Util::connectHook('OC_Filesystem', 'delete', "OCA\Files_Trashbin\Hooks", "remove_hook");
+//Listen to delete user signal
+OCP\Util::connectHook('OC_User', 'pre_deleteUser', "OCA\Files_Trashbin\Hooks", "deleteUser_hook");
\ No newline at end of file
index 9081706a2c56defdf26eb609a4f89ff8d2606b0b..f1df1d7ec77f9106e7b7ed4c1a2542d44b81118b 100644 (file)
@@ -42,4 +42,18 @@ class Hooks {
                        Trashbin::move2trash($path);
                }
        }
+
+       /**
+        * @brief clean up user specific settings if user gets deleted
+        * @param array with uid
+        *
+        * This function is connected to the pre_deleteUser signal of OC_Users
+        * to remove the used space for the trash bin stored in the database
+        */
+       public static function deleteUser_hook($params) {
+               if( \OCP\App::isEnabled('files_trashbin') ) {
+                       $uid = $params['uid'];
+                       Trashbin::deleteUser($uid);
+                       }
+       }
 }
index 35a2e1a8a1e8480e508372095a8a4904764b5401..9efb041bb9d037710f1ab47a4babde4b699e0344 100644 (file)
@@ -336,6 +336,22 @@ class Trashbin {
                return $view->file_exists($target);
        }
 
+       /**
+        * @brief deletes used space for trash bin in db if user was deleted
+        *
+        * @param type $uid id of deleted user
+        * @return result of db delete operation
+        */
+       public static function deleteUser($uid) {
+               $query = \OC_DB::prepare('DELETE FROM `*PREFIX*files_trash` WHERE `user`=?');
+               $result = $query->execute(array($uid));
+               if ($result) {
+                       $query = \OC_DB::prepare('DELETE FROM `*PREFIX*files_trashsize` WHERE `user`=?');
+                       return $query->execute(array($uid));
+               }
+               return false;
+       }
+
        /**
         * clean up the trash bin
         * @param max. available disk space for trashbin