Browse Source

Clear quota usage immediately when data is deleted, triggering a recalc.

Moonchild 3 years ago
parent
commit
5f1f5f914b
2 changed files with 21 additions and 1 deletions
  1. 3 0
      index.php
  2. 18 1
      weave_storage.php

+ 3 - 0
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
 			{ 

+ 18 - 1
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);