Small optimization
authorMarcel Werk <burntime@woltlab.com>
Wed, 8 May 2013 23:11:13 +0000 (01:11 +0200)
committerMarcel Werk <burntime@woltlab.com>
Wed, 8 May 2013 23:11:13 +0000 (01:11 +0200)
wcfsetup/install/files/lib/acp/form/UserAssignToGroupForm.class.php
wcfsetup/install/files/lib/data/user/UserAction.class.php

index ec3c10b2e671c5a9970dd633f13b325dceabae49..a906a6aea3dd06dd99b27ba19eae808c4264785f 100755 (executable)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\acp\form;
 use wcf\data\user\group\UserGroup;
+use wcf\data\user\UserAction;
 use wcf\data\user\UserEditor;
 use wcf\form\AbstractForm;
 use wcf\system\clipboard\ClipboardHandler;
@@ -140,8 +141,11 @@ class UserAssignToGroupForm extends AbstractForm {
                        $groupsIDs = array_merge($groups[$user->userID], $this->groupIDs);
                        $groupsIDs = array_unique($groupsIDs);
                        
-                       $userEditor = new UserEditor($user);
-                       $userEditor->addToGroups($groupsIDs, true, false);
+                       $action = new UserAction(array(new UserEditor($user)), 'addToGroups', array(
+                               'groups' => $groupsIDs,
+                               'addDefaultGroups' => false             
+                       ));
+                       $action->executeAction();
                }
                
                ClipboardHandler::getInstance()->removeItems($this->objectTypeID);
index 4ca3e19ed96263bf92b3a8b1ab487da5bdcbfa8c..0a80ca626d75359c980904f36451f80fac48642d 100644 (file)
@@ -236,11 +236,12 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio
                $removeGroups = (isset($this->parameters['removeGroups'])) ? $this->parameters['removeGroups'] : array();
                $userOptions = (isset($this->parameters['options'])) ? $this->parameters['options'] : array();
                
+               if (!empty($groupIDs)) {
+                       $action = new UserAction($this->objects, 'addToGroups', array('groups' => $groupIDs));
+                       $action->executeAction();
+               }
+               
                foreach ($this->objects as $userEditor) {
-                       if (!empty($groupIDs)) {
-                               $userEditor->addToGroups($groupIDs);
-                       }
-                       
                        if (!empty($removeGroups)) {
                                $userEditor->removeFromGroups($removeGroups);
                        }
@@ -255,6 +256,22 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio
                }
        }
        
+       
+       public function addToGroups() {
+               if (empty($this->objects)) {
+                       $this->readObjects();
+               }
+               
+               $groupIDs = $this->parameters['groups'];
+               $deleteOldGroups = $addDefaultGroups = true;
+               if (isset($this->parameters['deleteOldGroups'])) $deleteOldGroups = $this->parameters['deleteOldGroups'];
+               if (isset($this->parameters['addDefaultGroups'])) $addDefaultGroups = $this->parameters['addDefaultGroups'];
+               
+               foreach ($this->objects as $userEditor) {
+                       $userEditor->addToGroups($groupIDs, $deleteOldGroups, $addDefaultGroups);
+               }
+       }
+       
        /**
         * @see wcf\data\ISearchAction::validateGetSearchResultList()
         */