Merge pull request #1712 from joshuaruesweg/patch-18
authorAlexander Ebert <ebert@woltlab.com>
Mon, 21 Jul 2014 21:14:43 +0000 (23:14 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 21 Jul 2014 21:14:43 +0000 (23:14 +0200)
add method "removeFromGroups()"

1  2 
wcfsetup/install/files/lib/data/user/UserAction.class.php

index c4fc29578bc776ea83a04ff97816ee6cbb1d7d65,378f07c9378e58bf409e9372454218ad2eabd078..2c3e8d42adce4296a7b27fb726e43f29a58b7d02
@@@ -360,43 -330,37 +363,72 @@@ class UserAction extends AbstractDataba
                                $userEditor->addToLanguages($languageIDs);
                        }
                }
 +              
 +              // handle user rename
 +              if (count($this->objects) == 1 && !empty($this->parameters['data']['username'])) {
 +                      if ($this->objects[0]->username != $this->parameters['data']['username']) {
 +                              $userID = $this->objects[0]->userID;
 +                              $username = $this->parameters['data']['username'];
 +                              
 +                              WCF::getDB()->beginTransaction();
 +                              
 +                              // update comments
 +                              $sql = "UPDATE  wcf".WCF_N."_comment
 +                                      SET     username = ?
 +                                      WHERE   userID = ?";
 +                              $statement = WCF::getDB()->prepareStatement($sql);
 +                              $statement->execute(array($username, $userID));
 +                              
 +                              $sql = "UPDATE  wcf".WCF_N."_comment_response
 +                                      SET     username = ?
 +                                      WHERE   userID = ?";
 +                              $statement = WCF::getDB()->prepareStatement($sql);
 +                              $statement->execute(array($username, $userID));
 +                              
 +                              // modification log
 +                              $sql = "UPDATE  wcf".WCF_N."_modification_log
 +                                      SET     username = ?
 +                                      WHERE   userID = ?";
 +                              $statement = WCF::getDB()->prepareStatement($sql);
 +                              $statement->execute(array($username, $userID));
 +                              
 +                              WCF::getDB()->commitTransaction();
 +                              
 +                              // fire event to handle other database tables
 +                              EventHandler::getInstance()->fireAction($this, 'rename');
 +                      }
 +              }
        }
        
+       /**
+        * Remove users from given groups.
+        */
+       public function removeFromGroups() {
+               if (empty($this->objects)) {
+                       $this->readObjects();
+               }
+               
+               $groupIDs = $this->parameters['groups'];
+               
+               foreach ($this->objects as $userEditor) {
+                       $userEditor->removeFromGroups($groupIDs);
+               }
+               
+               //reread objects
+               $this->objects = array();
+               UserEditor::resetCache();
+               $this->readObjects();
+               
+               if (MODULE_USER_RANK) {
+                       $action = new UserProfileAction($this->objects, 'updateUserRank');
+                       $action->executeAction();
+               }
+               if (MODULE_USERS_ONLINE) {
+                       $action = new UserProfileAction($this->objects, 'updateUserOnlineMarking');
+                       $action->executeAction();
+               }
+       }
+       
        /**
         * Add users to given groups.
         */