Procházet zdrojové kódy

do usage update after package change

andre před 5 roky
rodič
revize
a38ea7d290
1 změnil soubory, kde provedl 46 přidání a 41 odebrání
  1. 46 41
      zimbraSingle.php

+ 46 - 41
zimbraSingle.php

@@ -48,6 +48,50 @@ function recursiveFindAll($haystack, $needle)
     return $values;
 }
 
+function zimbraSingleUpdateUsage ($api, $service) {
+    $accountQuota = $api->getQuota($service['username']);
+    if(is_a($accountQuota, 'Exception')) {
+        logModuleCall(
+            'zimbrasingle',
+            __FUNCTION__,
+            $service,
+            'Error : could not find quota for ' . $service['username'],
+            $accountQuota->getMessage()
+        );
+    }
+    $mboxObj = $api->getMailbox($service['username']);
+    if(is_a($mboxObj, 'Exception')) {
+        logModuleCall(
+            'zimbrasingle',
+            __FUNCTION__,
+            $service,
+            'Error: could not fetch mailbox info for ' . $service['username'],
+            $mboxObj->getMessage()
+        );
+    }
+    $mboxVars = get_object_vars($mboxObj);
+    $mboxSize = $mboxVars['S'];
+    try {
+        Capsule::table('tblhosting')
+            ->where('id', '=', $service['id'])
+            ->update(
+                array(
+                    'diskusage' => round($mboxSize / 1048576,2),
+                    'disklimit' => round($accountQuota / 1048576,2),
+                    'lastupdate' => Capsule::raw('now()')
+                )
+            );
+    } catch (\Exception $e) {
+        logModuleCall(
+            'zimbrasingle',
+            __FUNCTION__,
+            $service,
+            'Error: could update usage information for ' . $service['username'],
+            $e->getMessage()
+        );
+    }
+}
+
 /**
  * Define module related meta data.
  *
@@ -203,47 +247,7 @@ function zimbraSingle_UsageUpdate($params) {
         ->get();
     foreach((array)$productsObj as $productObj) {
         $product = get_object_vars($productObj[0]);
-        $accountQuota = $apiAccountManager->getQuota($product['username']);
-        if(is_a($accountQuota, 'Exception')) {
-            logModuleCall(
-                'zimbrasingle',
-                __FUNCTION__,
-                $params,
-                'Error : could not find quota for ' . $product['username'],
-                $accountQuota->getMessage()
-            );
-        }
-        $mboxObj = $apiAccountManager->getMailbox($product['username']);
-        if(is_a($mboxObj, 'Exception')) {
-            logModuleCall(
-                'zimbrasingle',
-                __FUNCTION__,
-                $params,
-                'Error: could not fetch mailbox info for ' . $product['username'],
-                $mboxObj->getMessage()
-            );
-        }
-        $mboxVars = get_object_vars($mboxObj);
-        $mboxSize = $mboxVars['S'];
-        try {
-            Capsule::table('tblhosting')
-                ->where('id', '=', $product['id'])
-                ->update(
-                    array(
-                        'diskusage' => round($mboxSize / 1048576,2),
-                        'disklimit' => round($accountQuota / 1048576,2),
-                        'lastupdate' => Capsule::raw('now()')
-                    )
-                );
-        } catch (\Exception $e) {
-            logModuleCall(
-                'zimbrasingle',
-                __FUNCTION__,
-                $params,
-                'Error: could update usage information for ' . $product['username'],
-                $e->getMessage()
-            );
-        }
+        zimbraSingleUpdateUsage($apiAccountManager, $product);
     }
 }
 
@@ -575,6 +579,7 @@ function zimbraSingle_ChangePackage($params) {
         );
         return 'Error: could not set class of service for '. $params['username'];
     }
+    zimbraSingleUpdateUsage($apiAccountManager, $params);
     return 'success';
 }