From 5f1f5f914b790086b9b9634117657dc9a84db734 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Thu, 11 Feb 2021 04:16:14 +0100 Subject: [PATCH] Clear quota usage immediately when data is deleted, triggering a recalc. --- index.php | 3 +++ weave_storage.php | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index 0530074..3868491 100644 --- a/index.php +++ b/index.php @@ -280,6 +280,7 @@ if ($id) { $db->delete_object($collection, $id); + $db->clear_quota_usage($username); } else if ($collection) { @@ -293,12 +294,14 @@ $params['ids'], $params['index_above'], $params['index_below'] ); + $db->clear_quota_usage($username); } else if($function == 'storage') // ich vermute mal storage reinigen { if (!array_key_exists('HTTP_X_CONFIRM_DELETE', $_SERVER)) report_problem(WEAVE_ERROR_NO_OVERWRITE, 412); $db->delete_storage($username); + $db->clear_quota_usage($username); } else { diff --git a/weave_storage.php b/weave_storage.php index d9daf05..7eb7426 100644 --- a/weave_storage.php +++ b/weave_storage.php @@ -794,8 +794,25 @@ class WeaveStorage return 0; } return 1; - } + } + function clear_quota_usage($username) + { + try + { + $update_statement = "update users set quota_usage = 0 where username = :username"; + $sth = $this->_dbh->prepare($update_statement); + $sth->bindParam(':username', $username); + $sth->execute(); + } + catch( PDOException $exception ) + { + log_error("clear quota usage:" . $exception->getMessage()); + return 0; + } + return 1; + } + function create_user($username, $password) { log_error("Create User - Username: ".$username."|".$password);