Răsfoiți Sursa

Merge branch 'usageupdate' of andre/whmcsZimbraSingle into master

andre 5 ani în urmă
părinte
comite
1f2e668284
1 a modificat fișierele cu 56 adăugiri și 1 ștergeri
  1. 56 1
      zimbraSingle.php

+ 56 - 1
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.
  *
@@ -846,7 +901,7 @@ function zimbraSingle_ConfigOptions($params)
         "Type" => "dropdown",
         "Multiple" => true,
         "Options" => implode(',', $domainNames),
-        "Description" => "select maildomains",
+        "Description" => "Info: Available Maildomains",
     );
     return $configOptions;
 }