Просмотр исходного кода

suspendAccount - disable users

andre 2 лет назад
Родитель
Сommit
363e3791a0
2 измененных файлов с 34 добавлено и 11 удалено
  1. 20 4
      api/KerioWhmcs.php
  2. 14 7
      app/Http/Actions/SuspendAccount.php

+ 20 - 4
api/KerioWhmcs.php

@@ -181,7 +181,7 @@ class KerioWhmcs extends KerioConnectApi {
 				'fields' => $fields,
 				'orderBy' => array(array(
 					'columnName' => 'name',
-					'direction' => $this->constants['kerio_web_Asc']
+					'direction' => 'Asc'
 				))
 			),
 			'domainId' => $domainId
@@ -246,7 +246,7 @@ class KerioWhmcs extends KerioConnectApi {
 				'fields' => $fields,
 				'orderBy' => array(array(
 					'columnName' => 'name',
-					'direction' => $this->constants['kerio_web_Asc']
+					'direction' => 'Asc'
 				))
 			),
 			'domainId' => $domainId
@@ -301,7 +301,7 @@ class KerioWhmcs extends KerioConnectApi {
 				'fields' => $fields,
 				'orderBy' => array(array(
 					'columnName' => 'name',
-					'direction' => $this->constants['kerio_web_Asc']
+					'direction' => 'Asc'
 				))
 			),
 			'domainId' => $domainId
@@ -333,7 +333,7 @@ class KerioWhmcs extends KerioConnectApi {
 					'fields' => $fields,
 					'orderBy' => array(array(
 							'columnName' => 'name',
-							'direction' => $this->constants['kerio_web_Asc']
+							'direction' => 'Asc'
 					)),
 					'combining' => 'Or'
 			),
@@ -438,6 +438,22 @@ class KerioWhmcs extends KerioConnectApi {
 		return $result;
 	}
 
+	/**
+	 * Modify user.
+	 *
+	 * @param	string	User ID
+	 * @param	array	Attributes
+	 * @return	array	Result
+	 */
+	function modifyUser($userId, $attr) {
+		$params = array(
+			'userIds' => $userId,
+			'pattern' => $attr
+		);
+		$result = $this->sendRequest('Users.set', $params);
+		return $result;
+	}
+
 	/**
 	 * Create domain.
 	 *

+ 14 - 7
app/Http/Actions/SuspendAccount.php

@@ -82,13 +82,20 @@ class SuspendAccount extends AddonController
             return ['error' => $error->getMessage()];
         }             
 
-        logModuleCall(
-            'kerioEmail',
-            __FUNCTION__,
-            $domainID,
-            'Debug SuspendAccount',
-            $users
-        );
+        foreach($users as $user) {
+            try {
+                $api->modifyUser($user, ['isEnabled' => FALSE]);
+            } catch (KerioApiException $error) {
+                logModuleCall(
+                    'kerioEmail',
+                    __FUNCTION__,
+                    $error,
+                    'Debug Error',
+                    $error->getMessage()
+                );
+                return ['error' => $error->getMessage()];
+            }             
+        }
 
         /**
          * return success response