/** * @see \wcf\system\importer\IImporter::import() */ public function import($oldID, array $data, array $additionalData = array()) { if ($data['groupType'] < 4) { $newGroupID = UserGroup::getGroupByType($data['groupType'])->groupID; } else { $action = new UserGroupAction(array(), 'create', array('data' => $data)); $returnValues = $action->executeAction(); $newGroupID = $returnValues['returnValues']->groupID; } ImportHandler::getInstance()->saveNewID('com.woltlab.wcf.user.group', $oldID, $newGroupID); return $newGroupID; }
/** * Copies a user group. */ public function copy() { // fetch user group option values if ($this->parameters['copyUserGroupOptions']) { $sql = "SELECT\toptionID, optionValue\n\t\t\t\tFROM\twcf" . WCF_N . "_user_group_option_value\n\t\t\t\tWHERE\tgroupID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->groupEditor->groupID)); } else { $sql = "SELECT\toptionID, defaultValue AS optionValue\n\t\t\t\tFROM\twcf" . WCF_N . "_user_group_option"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); } $optionValues = array(); while ($row = $statement->fetchArray()) { $optionValues[$row['optionID']] = $row['optionValue']; } $groupAction = new UserGroupAction(array(), 'create', array('data' => array('groupName' => $this->groupEditor->groupName, 'groupDescription' => $this->groupEditor->groupDescription, 'priority' => $this->groupEditor->priority, 'userOnlineMarking' => $this->groupEditor->userOnlineMarking, 'showOnTeamPage' => $this->groupEditor->showOnTeamPage), 'options' => $optionValues)); $returnValues = $groupAction->executeAction(); $group = $returnValues['returnValues']; $groupEditor = new UserGroupEditor($group); // update group name $groupName = $this->groupEditor->groupName; if (preg_match('~^wcf\\.acp\\.group\\.group\\d+$~', $this->groupEditor->groupName)) { $groupName = 'wcf.acp.group.group' . $group->groupID; // create group name language item $sql = "INSERT INTO\twcf" . WCF_N . "_language_item\n\t\t\t\t\t\t(languageID, languageItem, languageItemValue, languageItemOriginIsSystem, languageCategoryID, packageID)\n\t\t\t\tSELECT\t\tlanguageID, '" . $groupName . "', CONCAT(languageItemValue, ' (2)'), 0, languageCategoryID, packageID\n\t\t\t\tFROM\t\twcf" . WCF_N . "_language_item\n\t\t\t\tWHERE\t\tlanguageItem = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->groupEditor->groupName)); } else { $groupName .= ' (2)'; } // update group name $groupDescription = $this->groupEditor->groupName; if (preg_match('~^wcf\\.acp\\.group\\.groupDescription\\d+$~', $this->groupEditor->groupDescription)) { $groupDescription = 'wcf.acp.group.groupDescription' . $group->groupID; // create group name language item $sql = "INSERT INTO\twcf" . WCF_N . "_language_item\n\t\t\t\t\t\t(languageID, languageItem, languageItemValue, languageItemOriginIsSystem, languageCategoryID, packageID)\n\t\t\t\tSELECT\t\tlanguageID, '" . $groupDescription . "', languageItemValue, 0, languageCategoryID, packageID\n\t\t\t\tFROM\t\twcf" . WCF_N . "_language_item\n\t\t\t\tWHERE\t\tlanguageItem = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->groupEditor->groupDescription)); } $groupEditor->update(array('groupDescription' => $groupDescription, 'groupName' => $groupName)); // copy members if ($this->parameters['copyMembers']) { $sql = "INSERT INTO\twcf" . WCF_N . "_user_to_group\n\t\t\t\t\t\t(userID, groupID)\n\t\t\t\tSELECT\t\tuserID, " . $group->groupID . "\n\t\t\t\tFROM\t\twcf" . WCF_N . "_user_to_group\n\t\t\t\tWHERE\t\tgroupID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->groupEditor->groupID)); } // copy acl options if ($this->parameters['copyACLOptions']) { $sql = "INSERT INTO\twcf" . WCF_N . "_acl_option_to_group\n\t\t\t\t\t\t(optionID, objectID, groupID, optionValue)\n\t\t\t\tSELECT\t\toptionID, objectID, " . $group->groupID . ", optionValue\n\t\t\t\tFROM\t\twcf" . WCF_N . "_acl_option_to_group\n\t\t\t\tWHERE\t\tgroupID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->groupEditor->groupID)); // it is likely that applications or plugins use caches // for acl option values like for the labels which have // to be renewed after copying the acl options; because // there is no other way to delete these caches, we simply // delete all caches CacheHandler::getInstance()->flushAll(); } // reset language cache LanguageFactory::getInstance()->deleteLanguageCache(); UserGroupEditor::resetCache(); return array('redirectURL' => LinkHandler::getInstance()->getLink('UserGroupEdit', array('id' => $group->groupID))); }