Browse Source

add usageupdate

andre 5 years ago
parent
commit
4811cdfc81
1 changed files with 55 additions and 0 deletions
  1. 55 0
      zimbraSingle.php

+ 55 - 0
zimbraSingle.php

@@ -446,6 +446,61 @@ function zimbraSingle_ClientArea($params)
     );
     );
 }
 }
 
 
+function zimbraSingle_UsageUpdate($params) {
+    $api = new Zm_Auth($params['serverip'], $params['serverusername'], $params['serverpassword'], "admin");
+    $login = $api->login();
+    if(is_a($login, "Exception")) {
+        logModuleCall(
+            'zimbrasingle',
+            __FUNCTION__,
+            $params,
+            "Error: cannot login to " . $params['serverip'],
+            $login->getMessage()
+        );
+        return false;
+    }
+    $apiAccountManager = new Zm_Account($api);
+    $productsObj = Capsule::table('tblhosting')
+        ->select('*')
+        ->where('server', '=', $params['serverid'])
+        ->where('domainstatus', '=', 'Active')
+        ->get();
+    foreach((array)$productsObj as $productObj) {
+        $product = get_object_vars($productObj[0]);
+        $quota = $apiAccountManager->getQuota($product['username']);
+        if(is_a($quota, "Exception")) {
+            logModuleCall(
+                'zimbrasingle',
+                __FUNCTION__,
+                $product,
+                "Error : could not find " . $product['username'],
+                $quota->getMessage()
+            );
+        }
+        $response = $apiAccountManager->getMailbox($product['username']);
+        if(is_a($response, "Exception")) {
+            logModuleCall(
+                'zimbrasingle',
+                __FUNCTION__,
+                $params,
+                "Error: could not fetch mailbox info for " . $product['username'],
+                $response->getMessage()
+            );
+        }
+        $mbox = get_object_vars($response);
+        $mboxSize = $mbox['S'];
+        Capsule::table('tblhosting')
+            ->where('id', '=', $product['id'])
+            ->update(
+                array(
+                    'diskusage' => round($mboxSize / 1048576,2),
+                    'disklimit' => round($quota / 1048576,2),
+                    'lastupdate' => Capsule::raw('now()')
+                )
+            );
+    }
+}
+
 /**
 /**
  * Change the password for a Zimbra account.
  * Change the password for a Zimbra account.
  *
  *