Pārlūkot izejas kodu

cleanup, exeption handling DB updates

andre 5 gadi atpakaļ
vecāks
revīzija
4ce5b79e7b
1 mainītis faili ar 38 papildinājumiem un 17 dzēšanām
  1. 38 17
      zimbraSingle.php

+ 38 - 17
zimbraSingle.php

@@ -228,15 +228,25 @@ function zimbraSingle_UsageUpdate($params) {
         }
         $mboxVars = get_object_vars($mboxObj);
         $mboxSize = $mboxVars['S'];
-        Capsule::table('tblhosting')
-            ->where('id', '=', $product['id'])
-            ->update(
-                array(
-                    'diskusage' => round($mboxSize / 1048576,2),
-                    'disklimit' => round($accountQuota / 1048576,2),
-                    'lastupdate' => Capsule::raw('now()')
-                )
+        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()
             );
+        }
     }
 }
 
@@ -371,15 +381,26 @@ function zimbraSingle_CreateAccount($params)
         );
         return "Error: could not create account " . $params['username'];
     }
-    Capsule::table('tblhosting')
-    ->where('id', '=', $params['serviceid'])
-    ->update(
-        array(
-            'username' => $params['username'],
-            'password' => $params['customfields']['password'],
-        )
-    );
-return 'success';
+    try {
+        Capsule::table('tblhosting')
+            ->where('id', '=', $params['serviceid'])
+            ->update(
+                array(
+                    'username' => $params['username'],
+                    'password' => $params['customfields']['password'],
+                )
+            );
+    } catch (\Exception $e) {
+        logModuleCall(
+            'zimbrasingle',
+            __FUNCTION__,
+            $params,
+            "Error: could save username & password in database",
+            $e->getMessage()
+        );
+        return "Error: could save username & password in database";
+    }
+    return 'success';
 }
 
 /**