Browse Source

mass status ressources

andre 2 năm trước cách đây
mục cha
commit
ee5cde6b40
2 tập tin đã thay đổi với 42 bổ sung16 xóa
  1. 17 0
      api/KerioWhmcs.php
  2. 25 16
      app/UI/Client/Ressource/Providers/RessourceDataProvider.php

+ 17 - 0
api/KerioWhmcs.php

@@ -462,6 +462,23 @@ class KerioWhmcs extends KerioConnectApi {
 		return $result;
 	}
 
+	/**
+	 * Update resource.
+	 *
+	 * @param	array	Resource attributes
+	 * @param	string	Resource ID
+	 * @return	array	Result
+	 */
+	function updateResouce($attr, $resource) {
+		$params = array(
+			'resourceIds' => array($resource),
+			'pattern' => $attr 
+		);
+	
+		$result = $this->sendRequest('Resources.set', $params);
+		return $result;
+	}
+
 	/**
 	 * Get list of aliases from a domain
 	 * 

+ 25 - 16
app/UI/Client/Ressource/Providers/RessourceDataProvider.php

@@ -145,16 +145,20 @@ class RessourceDataProvider extends BaseDataProvider
 
     public function update()
     {
-        /**
-         * hosting id
-         */
-        $hid = $this->request->get('id');
-
-        /**
-         * product manager allow to check product settings
-         */
-        $productManager = new ProductManager();
-        $productManager->loadByHostingId($hid);
+        $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
+        try {
+            $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
+            $domainID = $api->getDomainId($this->getWhmcsParamByKey('domain'));
+        } catch (KerioApiException $error) {
+            logModuleCall(
+                'kerioEmail',
+                __FUNCTION__,
+                $error,
+                'Debug Error',
+                $error->getMessage()
+            );
+            return ['error' => $error->getMessage()];
+        }
 
         logModuleCall(
             'kerioEmail',
@@ -163,12 +167,17 @@ class RessourceDataProvider extends BaseDataProvider
             'Debug Error',
             $this->formData
         );
-        /**
-         * run service for each id
-         */
-        foreach($this->request->get('massActions') as $id)
-        {
-
+        try {
+            $result = $api->updateResouce(['isEnabled' => false], $this->request->get('massActions'));
+        } catch (KerioApiException $error) {
+            logModuleCall(
+                'kerioEmail',
+                __FUNCTION__,
+                $error,
+                'Debug Error',
+                $error->getMessage()
+            );
+            return ['error' => $error->getMessage()];
         }
 
         /**