Update groups

@param array $groups
@return null
@since Moodle 3.6
769723
public static function update_groups($groups) {
        global $CFG, $DB;
        require_once("$CFG->dirroot/group/lib.php");

        $params = self::validate_parameters(self::update_groups_parameters(), array('groups' => $groups));

        $transaction = $DB->start_delegated_transaction();

        foreach ($params['groups'] as $group) {
            $group = (object)$group;

            if (trim($group->name) == '') {
                throw new invalid_parameter_exception('Invalid group name');
            }

            if (! $currentgroup = $DB->get_record('groups', array('id' => $group->id))) {
                throw new invalid_parameter_exception("Group $group->id does not exist");
            }

            // Check if the modified group name already exists in the course.
            if ($group->name != $currentgroup->name and
                    $DB->get_record('groups', array('courseid' => $currentgroup->courseid, 'name' => $group->name))) {
                throw new invalid_parameter_exception('A different group with the same name already exists in the course');
            }

            $group->courseid = $currentgroup->courseid;

            // Now security checks.
            $context = context_course::instance($group->courseid);
            try {
                self::validate_context($context);
            } catch (Exception $e) {
                $exceptionparam = new stdClass();
                $exceptionparam->message = $e->getMessage();
                $exceptionparam->courseid = $group->courseid;
                throw new moodle_exception('errorcoursecontextnotvalid', 'webservice', '', $exceptionparam);
            }
            require_capability('moodle/course:managegroups', $context);

            if (!empty($group->description)) {
                $group->descriptionformat = external_validate_format($group->descriptionformat);
            }

            groups_update_group($group);
        }

        $transaction->allow_commit();

        return null;
    }
729480
protected function updateTokens(array $tokens)
    {
        $this->roles = null;
        $this->contextHash = null;

        if ($this->request === null) {
            return;
        }

        /** @var $token TokenInterface */
        foreach ($tokens as $token) {
            $token->updateCredentials($this->request);
        }

        $sessionDataContainer = $this->objectManager->get(SessionDataContainer::class);
        $sessionDataContainer->setSecurityTokens(array_merge($this->inactiveTokens, $this->activeTokens));
    }
658916
protected function publishes(array $paths, $groups = null)
    {
        $this->ensurePublishArrayInitialized($class = static::class);

        static::$publishes[$class] = array_merge(static::$publishes[$class], $paths);

        if (! is_null($groups)) {
            foreach ((array) $groups as $group) {
                $this->addPublishGroup($group, $paths);
            }
        }
    }
858862
public function update( $tokens ) {
		foreach ( $tokens as $index => $token ) {
			$this->text[ $index ] = $this->text[ $index ]->with_value( $token->value );
		}
	}
557617
public function reverseTransform($groups)
    {
        $value = new ArrayCollection();
        if (is_array($groups) && array_key_exists('groups_collection', $groups)) {
            $groups = $groups['groups_collection'];
            foreach ($groups as $groupId => $group) {
                if (array_key_exists('group', $group) && $group['group']) {
                    $group = $this->groupRepository->find($groupId);
                    if (null !== $group && in_array($group->getSite()->getId(), $this->availableSiteIds)) {
                        $value->add($group);
                    }
                }
            }
        }

        return $value;
    }
837517
protected function syncGroups(array $groups, UserInterface $user)
    {
        $user->groups()->detach();
        $user->groups()->sync($groups);
    }
163274
protected function updateGroupStack(array $attributes = [])
    {
        if (count($this->groupStack) > 0) {
            $attributes = $this->mergeWithLastGroup($attributes);
        }

        $this->groupStack[] = $attributes;
    }
763412
public function updateGroup(array $group)
    {
        $result = $this->httpRaw(self::WECHAT_GROUP_UPDATE_PREFIX, [
            'group' => $group
        ], [
            'access_token' => $this->getAccessToken()
        ]);
        return isset($result['errmsg']) && $result['errmsg'] == 'ok';
    }
26798
public function updateGroupProduct(array $data)
    {
        $result = $this->wechat->httpRaw(self::WECHAT_GROUP_PRODUCT_UPDATE_PREFIX, $data, [
            'access_token' => $this->wechat->getAccessToken()
        ]);
        return isset($result['errmsg']) && $result['errmsg'] == 'success';
    }
520573
public function updateGroup(Group $group, array $oldRoles)
    {
        $unitOfWork = $this->om->getUnitOfWork();
        $unitOfWork->computeChangeSets();
        $changeSet = $unitOfWork->getEntityChangeSet($group);
        $newRoles = $group->getPlatformRoles();
        $oldRolesTranslationKeys = array();

        foreach ($oldRoles as $oldRole) {
            $oldRolesTranslationKeys[] = $oldRole->getTranslationKey();
        }

        $newRolesTransactionKey = array();

        foreach ($newRoles as $newRole) {
            $newRolesTransactionKeys[] = $newRole->getTranslationKey();
        }

        $changeSet['platformRole'] = array($oldRolesTranslationKeys, $newRolesTransactionKey);
        $this->eventDispatcher->dispatch('log', 'Log\LogGroupUpdate', array($group, $changeSet));

        $this->om->persist($group);
        $this->om->flush();
    }
1303930
public static function groupUpdate(Api\GroupUpdate $groupUpdate)
    {
        $fields = [];

        if (null != $groupUpdate->getName()) {
            $fields['name'] = $groupUpdate->getName() === Api\Reset::reset()
                            ? null
                            : $groupUpdate->getName();
        }

        if (!empty($groupUpdate->getMemberInsertions())) {
            $fields['add'] = $groupUpdate->getMemberInsertions();
        }

        if (!empty($groupUpdate->getMemberRemovals())) {
            $fields['remove'] = $groupUpdate->getMemberRemovals();
        }

        if (!empty($groupUpdate->getChildGroupInsertions())) {
            $fields['child_groups_add']
                = $groupUpdate->getChildGroupInsertions();
        }

        if (!empty($groupUpdate->getChildGroupRemovals())) {
            $fields['child_groups_remove']
                = $groupUpdate->getChildGroupRemovals();
        }

        if (null != $groupUpdate->getAddFromGroup()) {
            $fields['add_from_group'] = $groupUpdate->getAddFromGroup();
        }

        if (null != $groupUpdate->getRemoveFromGroup()) {
            $fields['remove_from_group'] = $groupUpdate->getRemoveFromGroup();
        }

        if (null != $groupUpdate->getAutoUpdate()) {
            if ($groupUpdate->getAutoUpdate() === Api\Reset::reset()) {
                $fields['auto_update'] = null;
            } else {
                $fields['auto_update'] = Serialize::_groupAutoUpdateHelper(
                    $groupUpdate->getAutoUpdate()
                );
            }
        }

        return empty($fields) ? '{}' : Serialize::_toJson($fields);
    }
1334682
public function setGroup($group)
    {
        $fs = FileSystem::getFileSystem();

        $fs->chgrp($this->getPath(), $group);
    }
801810
public function setGroups(array $groups)
    {
        $this->groups = [];

        foreach ($groups as $groupIdent => $group) {
            $this->addGroup($groupIdent, $group);
        }

        uasort($this->groups, [ $this, 'sortGroupsByPriority' ]);

        // Remove items that are not active.
        $this->groups = array_filter($this->groups, function($item) {
            return ($item->active());
        });

        return $this;
    }
310626
public function updateUserGroup(array $data)
    {
        $result = $this->httpRaw(self::WECHAT_MEMBER_GROUP_UPDATE_PREFIX, $data, [
            'access_token' => $this->getAccessToken()
        ]);
        return isset($result['errmsg']) && $result['errmsg'] == 'ok';
    }
562422
public function updatePermissions($permissions)
    {
        if ($this->isLink()) return;
        
        self::getDbConnection()->executeQuery('DELETE FROM users_groups_allow_cat WHERE catalog_id='.$this->id);
        if (is_array($permissions)) 
            foreach ($permissions as $pid => $groups)
                foreach($groups as $gid) if ($gid && $gid != GROUP_ADMIN)
                    self::getDbConnection()->executeQuery('INSERT INTO users_groups_allow_cat SET permission='.(int)$pid.', group_id='.(int)$gid.', catalog_id='.(int)$this->id);

    }
264485
private function setupCacheGroups(array $groups)
    {
        foreach ($groups as $group => $keys) {
            // If $keys is not an array, something is wrong
            // with the structure in the config file
            // and we'll just skip it.
            if (!is_array($keys)) {
                continue;
            }

            foreach ($keys as $key => $settings) {
                // Generate group name
                $groupName = $group.'.'.$key;

                // Make sure tag name doesn't already exists.
                // If it does, we'll keep the first one adde
                // and skip all other ones.
                if (array_key_exists($groupName, $this->cacheGroups)) {
                    continue;
                }

                // Add tag to our tags container
                $this->cacheGroups[$groupName] = $settings;
            }
        }
    }
287271
public function update(array $objects) {
        $requests = [];

        foreach ($objects as $object) {
            $requests[] = [
                'method' => 'cmdb.object.update',
                'params' => $object
            ];
        }

        $this->api->batchRequest($requests);

        return $this;
    }