// Listen to delete and rename signals
OCP\Util::connectHook('OC_Filesystem', 'post_delete', "OCA\Files_Versions\Hooks", "remove_hook");
OCP\Util::connectHook('OC_Filesystem', 'rename', "OCA\Files_Versions\Hooks", "rename_hook");
+//Listen to delete user signal
+OCP\Util::connectHook('OC_User', 'pre_deleteUser', "OCA\Files_Versions\Hooks", "deleteUser_hook");
}
}
+ /**
+ * @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 versions stored in the database
+ */
+ public static function deleteUser_hook($params) {
+ if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
+ $uid = $params['uid'];
+ Storage::deleteUser($uid);
+ }
+ }
+
}
}
+
+ /**
+ * @brief deletes used space for files versions 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_versions` WHERE `user`=?');
+ return $query->execute(array($uid));
+ }
+
/**
* @brief get the size of all stored versions from a given user
* @param $uid id from the user