From b35f63d61e41feb2040e5bc5bd9abceecdf33fc4 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Fri, 25 Dec 2015 10:32:18 +0100 Subject: [PATCH] Add media update upon user rename --- .../files/lib/data/user/UserAction.class.php | 222 ++++++++++-------- 1 file changed, 120 insertions(+), 102 deletions(-) diff --git a/wcfsetup/install/files/lib/data/user/UserAction.class.php b/wcfsetup/install/files/lib/data/user/UserAction.class.php index aae5206188..e2c4b1e2ec 100644 --- a/wcfsetup/install/files/lib/data/user/UserAction.class.php +++ b/wcfsetup/install/files/lib/data/user/UserAction.class.php @@ -29,34 +29,34 @@ use wcf\util\UserRegistrationUtil; */ class UserAction extends AbstractDatabaseObjectAction implements IClipboardAction, ISearchAction { /** - * @see \wcf\data\AbstractDatabaseObjectAction::$className + * @inheritDoc */ - public $className = 'wcf\data\user\UserEditor'; + public $className = UserEditor::class; /** - * @see \wcf\data\AbstractDatabaseObjectAction::$allowGuestAccess + * @inheritDoc */ - protected $allowGuestAccess = array('getSearchResultList'); + protected $allowGuestAccess = ['getSearchResultList']; /** - * @see \wcf\data\AbstractDatabaseObjectAction::$permissionsCreate + * @inheritDoc */ - protected $permissionsCreate = array('admin.user.canAddUser'); + protected $permissionsCreate = ['admin.user.canAddUser']; /** - * @see \wcf\data\AbstractDatabaseObjectAction::$permissionsDelete + * @inheritDoc */ - protected $permissionsDelete = array('admin.user.canDeleteUser'); + protected $permissionsDelete = ['admin.user.canDeleteUser']; /** - * @see \wcf\data\AbstractDatabaseObjectAction::$permissionsUpdate + * @inheritDoc */ - protected $permissionsUpdate = array('admin.user.canEditUser'); + protected $permissionsUpdate = ['admin.user.canEditUser']; /** - * @see \wcf\data\AbstractDatabaseObjectAction::$requireACP + * @inheritDoc */ - protected $requireACP = array('create', 'delete', 'disable', 'enable'); + protected $requireACP = ['create', 'delete', 'disable', 'enable']; /** * Validates permissions and parameters. @@ -87,7 +87,7 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio // validate groups $conditions = new PreparedStatementConditionBuilder(); - $conditions->add("userID IN (?)", array($this->objectIDs)); + $conditions->add("userID IN (?)", [$this->objectIDs]); $sql = "SELECT DISTINCT groupID FROM wcf".WCF_N."_user_to_group @@ -95,7 +95,7 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); - $groupIDs = array(); + $groupIDs = []; while ($row = $statement->fetchArray()) { $groupIDs[] = $row['groupID']; } @@ -116,7 +116,7 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio } /** - * @see \wcf\data\IDeleteAction::delete() + * @inheritDoc */ public function delete() { if (empty($this->objects)) { @@ -124,7 +124,7 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio } // delete avatars - $avatarIDs = array(); + $avatarIDs = []; foreach ($this->objects as $user) { if ($user->avatarID) $avatarIDs[] = $user->avatarID; } @@ -191,7 +191,7 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio * Validates the unban action. */ public function validateUnban() { - WCF::getSession()->checkPermissions(array('admin.user.canBanUser')); + WCF::getSession()->checkPermissions(['admin.user.canBanUser']); $this->__validateAccessibleGroups(); } @@ -209,7 +209,7 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio } $conditionBuilder = new PreparedStatementConditionBuilder(); - $conditionBuilder->add('userID IN (?)', array($this->objectIDs)); + $conditionBuilder->add('userID IN (?)', [$this->objectIDs]); $sql = "UPDATE wcf".WCF_N."_user SET banned = ?, @@ -218,11 +218,11 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio ".$conditionBuilder; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute( - array_merge(array( + array_merge([ 1, $this->parameters['banReason'], $banExpires - ), $conditionBuilder->getParameters()) + ], $conditionBuilder->getParameters()) ); $this->unmarkItems(); @@ -233,7 +233,7 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio */ public function unban() { $conditionBuilder = new PreparedStatementConditionBuilder(); - $conditionBuilder->add('userID IN (?)', array($this->objectIDs)); + $conditionBuilder->add('userID IN (?)', [$this->objectIDs]); $sql = "UPDATE wcf".WCF_N."_user SET banned = ?, @@ -241,10 +241,10 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio ".$conditionBuilder; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute( - array_merge(array( + array_merge([ 0, 0 - ), $conditionBuilder->getParameters()) + ], $conditionBuilder->getParameters()) ); } @@ -268,13 +268,13 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio // insert user groups $addDefaultGroups = (isset($this->parameters['addDefaultGroups'])) ? $this->parameters['addDefaultGroups'] : true; - $groupIDs = (isset($this->parameters['groups'])) ? $this->parameters['groups'] : array(); + $groupIDs = (isset($this->parameters['groups'])) ? $this->parameters['groups'] : []; $userEditor->addToGroups($groupIDs, false, $addDefaultGroups); // insert visible languages if (!isset($this->parameters['languageIDs'])) { // using the 'languages' key is deprecated since WCF 2.1, please use 'languageIDs' instead - $this->parameters['languageIDs'] = (!empty($this->parameters['languages'])) ? $this->parameters['languages'] : array(); + $this->parameters['languageIDs'] = (!empty($this->parameters['languages'])) ? $this->parameters['languages'] : []; } $userEditor->addToLanguages($this->parameters['languageIDs'], false); @@ -286,15 +286,15 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio FROM wcf".WCF_N."_user_notification_event WHERE preset = ?"; $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array($user->userID, 1)); + $statement->execute([$user->userID, 1]); // update user rank if (MODULE_USER_RANK) { - $action = new UserProfileAction(array($userEditor), 'updateUserRank'); + $action = new UserProfileAction([$userEditor], 'updateUserRank'); $action->executeAction(); } // update user online marking - $action = new UserProfileAction(array($userEditor), 'updateUserOnlineMarking'); + $action = new UserProfileAction([$userEditor], 'updateUserOnlineMarking'); $action->executeAction(); } @@ -302,7 +302,7 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio } /** - * @see \wcf\data\AbstractDatabaseObjectAction::update() + * @inheritDoc */ public function update() { if (isset($this->parameters['data'])) { @@ -326,23 +326,23 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio } } - $groupIDs = (isset($this->parameters['groups'])) ? $this->parameters['groups'] : array(); - $languageIDs = (isset($this->parameters['languageIDs'])) ? $this->parameters['languageIDs'] : array(); - $removeGroups = (isset($this->parameters['removeGroups'])) ? $this->parameters['removeGroups'] : array(); - $userOptions = (isset($this->parameters['options'])) ? $this->parameters['options'] : array(); + $groupIDs = (isset($this->parameters['groups'])) ? $this->parameters['groups'] : []; + $languageIDs = (isset($this->parameters['languageIDs'])) ? $this->parameters['languageIDs'] : []; + $removeGroups = (isset($this->parameters['removeGroups'])) ? $this->parameters['removeGroups'] : []; + $userOptions = (isset($this->parameters['options'])) ? $this->parameters['options'] : []; if (!empty($groupIDs)) { - $action = new UserAction($this->objects, 'addToGroups', array( + $action = new UserAction($this->objects, 'addToGroups', [ 'groups' => $groupIDs, 'addDefaultGroups' => false - )); + ]); $action->executeAction(); } if (!empty($removeGroups)) { - $action = new UserAction($this->objects, 'removeFromGroups', array( + $action = new UserAction($this->objects, 'removeFromGroups', [ 'groups' => $removeGroups - )); + ]); $action->executeAction(); } @@ -369,20 +369,28 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio SET username = ? WHERE userID = ?"; $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array($username, $userID)); + $statement->execute([$username, $userID]); + // update comment responses $sql = "UPDATE wcf".WCF_N."_comment_response SET username = ? WHERE userID = ?"; $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array($username, $userID)); + $statement->execute([$username, $userID]); - // modification log + // update media + $sql = "UPDATE wcf".WCF_N."_media + SET username = ? + WHERE userID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute([$username, $userID]); + + // update modification log $sql = "UPDATE wcf".WCF_N."_modification_log SET username = ? WHERE userID = ?"; $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array($username, $userID)); + $statement->execute([$username, $userID]); WCF::getDB()->commitTransaction(); @@ -407,7 +415,7 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio } //reread objects - $this->objects = array(); + $this->objects = []; UserEditor::resetCache(); $this->readObjects(); @@ -439,7 +447,7 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio } //reread objects - $this->objects = array(); + $this->objects = []; UserEditor::resetCache(); $this->readObjects(); @@ -454,7 +462,7 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio } /** - * @see \wcf\data\ISearchAction::validateGetSearchResultList() + * @inheritDoc */ public function validateGetSearchResultList() { $this->readBoolean('includeUserGroups', false, 'data'); @@ -466,15 +474,15 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio } /** - * @see \wcf\data\ISearchAction::getSearchResultList() + * @inheritDoc */ public function getSearchResultList() { $searchString = $this->parameters['data']['searchString']; - $excludedSearchValues = array(); + $excludedSearchValues = []; if (isset($this->parameters['data']['excludedSearchValues'])) { $excludedSearchValues = $this->parameters['data']['excludedSearchValues']; } - $list = array(); + $list = []; if ($this->parameters['data']['includeUserGroups']) { $accessibleGroups = UserGroup::getAccessibleGroups(); @@ -483,11 +491,11 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio if (!in_array($groupName, $excludedSearchValues)) { $pos = mb_strripos($groupName, $searchString); if ($pos !== false && $pos == 0) { - $list[] = array( + $list[] = [ 'label' => $groupName, 'objectID' => $group->groupID, 'type' => 'group' - ); + ]; } } } @@ -495,34 +503,34 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio // find users $userProfileList = new UserProfileList(); - $userProfileList->getConditionBuilder()->add("username LIKE ?", array($searchString.'%')); + $userProfileList->getConditionBuilder()->add("username LIKE ?", [$searchString.'%']); if (!empty($excludedSearchValues)) { - $userProfileList->getConditionBuilder()->add("username NOT IN (?)", array($excludedSearchValues)); + $userProfileList->getConditionBuilder()->add("username NOT IN (?)", [$excludedSearchValues]); } $userProfileList->sqlLimit = 10; $userProfileList->readObjects(); foreach ($userProfileList as $userProfile) { - $list[] = array( + $list[] = [ 'icon' => $userProfile->getAvatar()->getImageTag(16), 'label' => $userProfile->username, 'objectID' => $userProfile->userID, 'type' => 'user' - ); + ]; } return $list; } /** - * @see \wcf\data\IClipboardAction::validateUnmarkAll() + * @inheritDoc */ public function validateUnmarkAll() { // does nothing } /** - * @see \wcf\data\IClipboardAction::unmarkAll() + * @inheritDoc */ public function unmarkAll() { ClipboardHandler::getInstance()->removeItems(ClipboardHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.user')); @@ -531,9 +539,9 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio /** * Unmarks users. * - * @param array $userIDs + * @param integer[] $userIDs */ - protected function unmarkItems(array $userIDs = array()) { + protected function unmarkItems(array $userIDs = []) { if (empty($userIDs)) { $userIDs = $this->objectIDs; } @@ -547,7 +555,7 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio * Validates the enable action. */ public function validateEnable() { - WCF::getSession()->checkPermissions(array('admin.user.canEnableUser')); + WCF::getSession()->checkPermissions(['admin.user.canEnableUser']); $this->__validateAccessibleGroups(); } @@ -565,26 +573,26 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio public function enable() { if (empty($this->objects)) $this->readObjects(); - $action = new UserAction($this->objects, 'update', array( - 'data' => array( + $action = new UserAction($this->objects, 'update', [ + 'data' => [ 'activationCode' => 0 - ), - 'removeGroups' => UserGroup::getGroupIDsByType(array(UserGroup::GUESTS)) - )); + ], + 'removeGroups' => UserGroup::getGroupIDsByType([UserGroup::GUESTS]) + ]); $action->executeAction(); - $action = new UserAction($this->objects, 'addToGroups', array( - 'groups' => UserGroup::getGroupIDsByType(array(UserGroup::USERS)), + $action = new UserAction($this->objects, 'addToGroups', [ + 'groups' => UserGroup::getGroupIDsByType([UserGroup::USERS]), 'deleteOldGroups' => false, 'addDefaultGroups' => false - )); + ]); $action->executeAction(); // send e-mail notification if (empty($this->parameters['skipNotification'])) { foreach ($this->objects as $user) { - $mail = new Mail(array($user->username => $user->email), $user->getLanguage()->getDynamicVariable('wcf.acp.user.activation.mail.subject'), $user->getLanguage()->getDynamicVariable('wcf.acp.user.activation.mail', array( + $mail = new Mail([$user->username => $user->email], $user->getLanguage()->getDynamicVariable('wcf.acp.user.activation.mail.subject'), $user->getLanguage()->getDynamicVariable('wcf.acp.user.activation.mail', [ 'username' => $user->username - ))); + ])); $mail->send(); } } @@ -598,25 +606,25 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio public function disable() { if (empty($this->objects)) $this->readObjects(); - $action = new UserAction($this->objects, 'update', array( - 'data' => array( + $action = new UserAction($this->objects, 'update', [ + 'data' => [ 'activationCode' => UserRegistrationUtil::getActivationCode() - ), - 'removeGroups' => UserGroup::getGroupIDsByType(array(UserGroup::USERS)), - )); + ], + 'removeGroups' => UserGroup::getGroupIDsByType([UserGroup::USERS]), + ]); $action->executeAction(); - $action = new UserAction($this->objects, 'addToGroups', array( - 'groups' => UserGroup::getGroupIDsByType(array(UserGroup::GUESTS)), + $action = new UserAction($this->objects, 'addToGroups', [ + 'groups' => UserGroup::getGroupIDsByType([UserGroup::GUESTS]), 'deleteOldGroups' => false, 'addDefaultGroups' => false - )); + ]); $action->executeAction(); $this->unmarkItems(); } /** - * @see \wcf\data\AbstractDatabaseObjectAction::readObjects() + * @inheritDoc */ protected function readObjects() { if (empty($this->objectIDs)) { @@ -624,7 +632,7 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio } // get base class - $baseClass = call_user_func(array($this->className, 'getBaseClass')); + $baseClass = call_user_func([$this->className, 'getBaseClass']); // get objects $sql = "SELECT user_option_value.*, user_table.* @@ -666,11 +674,11 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio } foreach ($this->objects as $userEditor) { - $userEditor->update(array( + $userEditor->update([ 'disableSignature' => 1, 'disableSignatureReason' => $this->parameters['disableSignatureReason'], 'disableSignatureExpires' => $disableSignatureExpires - )); + ]); } } @@ -678,7 +686,7 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio * Validates the 'enableSignature' action. */ public function validateEnableSignature() { - WCF::getSession()->checkPermissions(array('admin.user.canDisableSignature')); + WCF::getSession()->checkPermissions(['admin.user.canDisableSignature']); $this->__validateAccessibleGroups(); @@ -700,9 +708,9 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio } foreach ($this->objects as $userEditor) { - $userEditor->update(array( + $userEditor->update([ 'disableSignature' => 0 - )); + ]); } } @@ -733,11 +741,11 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio } foreach ($this->objects as $userEditor) { - $userEditor->update(array( + $userEditor->update([ 'disableAvatar' => 1, 'disableAvatarReason' => $this->parameters['disableAvatarReason'], 'disableAvatarExpires' => $disableAvatarExpires - )); + ]); } } @@ -745,7 +753,7 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio * Validates the 'enableAvatar' action. */ public function validateEnableAvatar() { - WCF::getSession()->checkPermissions(array('admin.user.canDisableAvatar')); + WCF::getSession()->checkPermissions(['admin.user.canDisableAvatar']); $this->__validateAccessibleGroups(); @@ -767,42 +775,47 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio } foreach ($this->objects as $userEditor) { - $userEditor->update(array( + $userEditor->update([ 'disableAvatar' => 0 - )); + ]); } } /** * Validates parameters to retrieve the social network privacy settings. */ - public function validateGetSocialNetworkPrivacySettings() { /* does nothing */ } + public function validateGetSocialNetworkPrivacySettings() { + // does nothing + } /** * Returns the social network privacy settings. * - * @return array + * @return string[] */ public function getSocialNetworkPrivacySettings() { $settings = @unserialize(WCF::getUser()->socialNetworkPrivacySettings); if (!is_array($settings)) { - $settings = array( + $settings = [ 'facebook' => false, 'google' => false, 'reddit' => false, 'twitter' => false - ); + ]; } - WCF::getTPL()->assign(array( + WCF::getTPL()->assign([ 'settings' => $settings - )); + ]); - return array( + return [ 'template' => WCF::getTPL()->fetch('shareButtonsPrivacySettings') - ); + ]; } + /** + * Validates the 'saveSocialNetworkPrivacySettings' action. + */ public function validateSaveSocialNetworkPrivacySettings() { $this->readBoolean('facebook', true); $this->readBoolean('google', true); @@ -810,21 +823,26 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio $this->readBoolean('twitter', true); } + /** + * Saves the social network privacy settings. + * + * @return boolean[] + */ public function saveSocialNetworkPrivacySettings() { - $settings = array( + $settings = [ 'facebook' => $this->parameters['facebook'], 'google' => $this->parameters['google'], 'reddit' => $this->parameters['reddit'], 'twitter' => $this->parameters['twitter'] - ); + ]; $userEditor = new UserEditor(WCF::getUser()); - $userEditor->update(array( + $userEditor->update([ 'socialNetworkPrivacySettings' => serialize($settings) - )); + ]); - return array( + return [ 'settings' => $settings - ); + ]; } } -- 2.20.1