Updates an existing category with given params

@param int $updateid
@param int $newparent
@param string $newname
@param string $newinfo
@param int $newinfoformat
@param int $idnumber
@param bool $redirect
@return int
4407
public function update_category($updateid, $newparent, $newname, $newinfo, $newinfoformat = FORMAT_HTML,
            $idnumber = null, $redirect = true) {
        global $CFG, $DB;
        if (empty($newname)) {
            print_error('categorynamecantbeblank', 'question');
        }

        // Get the record we are updating.
        $oldcat = $DB->get_record('question_categories', array('id' => $updateid));
        $lastcategoryinthiscontext = question_is_only_child_of_top_category_in_context($updateid);

        if (!empty($newparent) && !$lastcategoryinthiscontext) {
            list($parentid, $tocontextid) = explode(',', $newparent);
        } else {
            $parentid = $oldcat->parent;
            $tocontextid = $oldcat->contextid;
        }

        // Check permissions.
        $fromcontext = context::instance_by_id($oldcat->contextid);
        require_capability('moodle/question:managecategory', $fromcontext);

        // If moving to another context, check permissions some more, and confirm contextid,stamp uniqueness.
        $newstamprequired = false;
        if ($oldcat->contextid != $tocontextid) {
            $tocontext = context::instance_by_id($tocontextid);
            require_capability('moodle/question:managecategory', $tocontext);

            // Confirm stamp uniqueness in the new context. If the stamp already exists, generate a new one.
            if ($DB->record_exists('question_categories', array('contextid' => $tocontextid, 'stamp' => $oldcat->stamp))) {
                $newstamprequired = true;
            }
        }

        if ((string) $idnumber === '') {
            $idnumber = null;
        } else if (!empty($tocontextid)) {
            // While this check already exists in the form validation, this is a backstop preventing unnecessary errors.
            if ($DB->record_exists('question_categories',
                    ['idnumber' => $idnumber, 'contextid' => $tocontextid])) {
                $idnumber = null;
            }
        }

        // Update the category record.
        $cat = new stdClass();
        $cat->id = $updateid;
        $cat->name = $newname;
        $cat->info = $newinfo;
        $cat->infoformat = $newinfoformat;
        $cat->parent = $parentid;
        $cat->contextid = $tocontextid;
        if ($idnumber) {
            $cat->idnumber = $idnumber;
        }
        if ($newstamprequired) {
            $cat->stamp = make_unique_id_code();
        }
        $DB->update_record('question_categories', $cat);

        // Log the update of this category.
        $event = \core\event\question_category_updated::create_from_question_category_instance($cat);
        $event->trigger();

        // If the category name has changed, rename any random questions in that category.
        if ($oldcat->name != $cat->name) {
            $where = "qtype = 'random' AND category = ? AND " . $DB->sql_compare_text('questiontext') . " = ?";

            $randomqtype = question_bank::get_qtype('random');
            $randomqname = $randomqtype->question_name($cat, false);
            $DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '0'));

            $randomqname = $randomqtype->question_name($cat, true);
            $DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '1'));
        }

        if ($oldcat->contextid != $tocontextid) {
            // Moving to a new context. Must move files belonging to questions.
            question_move_category_to_context($cat->id, $oldcat->contextid, $tocontextid);
        }

        // Cat param depends on the context id, so update it.
        $this->pageurl->param('cat', $updateid . ',' . $tocontextid);
        if ($redirect) {
            redirect($this->pageurl); // Always redirect after successful action.
        }
    }
234503
public function updateSection($id, $name, $identifier)
    {
        try {
            return $this->innerGateway->updateSection($id, $name, $identifier);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
762614
public function update($id)
    {
        try
        {
            $credentials = Input::except('groups');
            $credentials['groups'] = Input::get('groups', array());
            $credentials['id'] = $id;


            if( $this->userForm->update($credentials) )
            {
                return Redirect::route('cpanel.users.index')
                    ->with('success', Lang::get('cpanel::users.update_success'));
            }

            return Redirect::back()
                ->withInput()
                ->withErrors($this->userForm->getErrors());
        }
        catch ( UserNotFoundException $e)
        {
            return Redirect::route('cpanel.users.index')
                    ->with('error', $e->getMessage());
        }
    }
695548
public function updatePosition($id, $newPosition = 1)
    {
        $model = $this->makeModel(false);

        if ( ! ($model = $model->find($id))) {
            return false;
        }

        $this->checkModelHasListify($model);

        /** @var ListifyInterface $model */
        $model->setListPosition( (int) $newPosition );

        return $model;
    }
1055309
public static function update_registry( $new_value, $id ) {
		$registry = self::get_registry();
		$registry[ $id ] = $new_value;

		return update_option( self::$registry_option_name, $registry );

	}
518554
public function update_moved(context $newparent) {
        global $DB;

        $frompath = $this->_path;
        $newpath  = $newparent->path . '/' . $this->_id;

        $trans = $DB->start_delegated_transaction();

        $setdepth = '';
        if (($newparent->depth +1) != $this->_depth) {
            $diff = $newparent->depth - $this->_depth + 1;
            $setdepth = ", depth = depth + $diff";
        }
        $sql = "UPDATE {context}
                   SET path = ?
                       $setdepth
                 WHERE id = ?";
        $params = array($newpath, $this->_id);
        $DB->execute($sql, $params);

        $this->_path  = $newpath;
        $this->_depth = $newparent->depth + 1;

        $sql = "UPDATE {context}
                   SET path = ".$DB->sql_concat("?", $DB->sql_substr("path", strlen($frompath)+1))."
                       $setdepth
                 WHERE path LIKE ?";
        $params = array($newpath, "{$frompath}/%");
        $DB->execute($sql, $params);

        $this->mark_dirty();

        context::reset_caches();

        $trans->allow_commit();
    }
941330
public function updateNodeAssignment($contentObjectId, $oldParent, $newParent, $opcode)
    {
        try {
            return $this->innerGateway->updateNodeAssignment($contentObjectId, $oldParent, $newParent, $opcode);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
379505
public int updateId(DatabaseConnection databaseConnection, T data, ID newId, ObjectCache objectCache)
			throws SQLException {
		if (mappedUpdateId == null) {
			mappedUpdateId = MappedUpdateId.build(dao, tableInfo);
		}
		int result = mappedUpdateId.execute(databaseConnection, data, newId, objectCache);
		if (dao != null && !localIsInBatchMode.get()) {
			dao.notifyChanges();
		}
		return result;
	}
772982
public function getUpdateRequest($id, $updateBind)
    {
        $db = $this->_getConnection();
        $table = $this->table;
        $self = $this;
        $primary = $this->_getPrimaryKetArray();

        $request = new StorageDataRequest(
            [$id, $updateBind],
            function ($id, $updateBind) use ($db, $table, $self, $primary) {
                if (!$db) {
                    $self->logError('Missing connection on getUpdateRequest on table: ' . $table);
                    return false;
                }

                $keyBind = $self->prepareKey($primary, $id);

                $whereBind = $self->prepareBind($keyBind, $db);
                $whereArray = [];
                foreach ($whereBind as $key => $value) {
                    $whereArray[] = $key . ' = ' . $value;
                }

                $keys = [];
                $values = [];

                $updateBind = $self->prepareBind($updateBind, $db);

                foreach ($updateBind as $key => $value) {
                    $keys[] = $key;
                    $values[] = $value;
                }

                $query = 'UPDATE ' . $table
                    . ' SET (' . implode(',', $keys) . ') = ROW(' . implode(',', $values) . ') '
                    . ' WHERE ' . implode(' AND ', $whereArray)
                    . ' RETURNING *';
                $stmnt = $db->query($query);

                if (!$stmnt) {
                    $this->logError('Cannot execute getUpdateRequest on table: ' . $table . ':' . implode(',', $db->errorInfo()), [
                        'code' => $db->errorCode(),
                    ]);

                    return false;
                }

                $result = $stmnt->fetch(PDO::FETCH_ASSOC);

                if (!$result && (int) $stmnt->errorCode() > 0) {
                    $this->logError('Error on execution on getUpdateRequest on table: ' . $table . ':' . implode(',',
                            $stmnt->errorInfo()), [
                        'code' => $stmnt->errorCode(),
                    ]);

                    return false;
                }

                return $result;
            });

        return $request;
    }
432419
public static function update($itemid, $newvalue) {
        global $DB, $CFG;

        require_once($CFG->libdir . '/external/externallib.php');
        // Check caps.
        // Do the thing.
        // Return one of me.
        // Validate the inputs.
        list($courseid, $userid) = explode(':', $itemid, 2);

        $courseid = clean_param($courseid, PARAM_INT);
        $userid = clean_param($userid, PARAM_INT);
        $roleids = json_decode($newvalue);
        foreach ($roleids as $index => $roleid) {
            $roleids[$index] = clean_param($roleid, PARAM_INT);
        }

        // Check user is enrolled in the course.
        $context = context_course::instance($courseid);
        core_external::validate_context($context);

        // Check permissions.
        require_capability('moodle/role:assign', $context);

        if (!is_enrolled($context, $userid)) {
            throw new coding_exception('User does not belong to the course');
        }

        // Check that all the groups belong to the course.
        $allroles = role_fix_names(get_all_roles($context), $context);
        $assignableroles = get_assignable_roles($context, ROLENAME_ALIAS, false);
        $viewableroles = get_viewable_roles($context);
        $userrolesbyid = get_user_roles($context, $userid, true, 'c.contextlevel DESC, r.sortorder ASC');
        $profileroles = get_profile_roles($context);

        // Set an array where the index is the roleid.
        $userroles = array();
        foreach ($userrolesbyid as $id => $role) {
            $userroles[$role->roleid] = $role;
        }

        $rolestoprocess = [];
        foreach ($roleids as $roleid) {
            if (!isset($assignableroles[$roleid])) {
                throw new coding_exception('Role cannot be assigned in this course.');
            }
            $rolestoprocess[$roleid] = $roleid;
        }

        // Process adds.
        foreach ($rolestoprocess as $roleid) {
            if (!isset($userroles[$roleid])) {
                // Add them.
                $id = role_assign($roleid, $userid, $context);
                // Keep this variable in sync.
                $role = new \stdClass();
                $role->id = $id;
                $role->roleid = $roleid;
                $role->contextid = $context->id;
                $userroles[$role->roleid] = $role;
            }
        }

        // Process removals.
        foreach ($assignableroles as $roleid => $rolename) {
            if (isset($userroles[$roleid]) && !isset($rolestoprocess[$roleid])) {
                // Do not remove the role if we are not in the same context.
                if ($userroles[$roleid]->contextid != $context->id) {
                    continue;
                }
                $ras = $DB->get_records('role_assignments', ['contextid' => $context->id, 'userid' => $userid,
                    'roleid' => $roleid]);
                $allremoved = true;
                foreach ($ras as $ra) {
                    if ($ra->component) {
                        if (strpos($ra->component, 'enrol_') !== 0) {
                            continue;
                        }
                        if (!$plugin = enrol_get_plugin(substr($ra->component, 6))) {
                            continue;
                        }
                        if ($plugin->roles_protected()) {
                            $allremoved = false;
                            continue;
                        }
                    }
                    role_unassign($ra->roleid, $ra->userid, $ra->contextid, $ra->component, $ra->itemid);
                }
                if ($allremoved) {
                    unset($userroles[$roleid]);
                }
            }
        }

        $course = get_course($courseid);
        $user = core_user::get_user($userid);
        return new self($course, $context, $user, $allroles, $assignableroles, $profileroles, $userroles, $viewableroles);
    }
1157539
public function update( $new_instance, $old_instance ) 
    {   
        $this->form->updater->set_new_instance( $new_instance );
        return $this->form->updater->update( $old_instance );
    }
108996
public function update(UpdateStruct $updateStruct, $tagId)
    {
        try {
            $this->innerGateway->update($updateStruct, $tagId);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
1234757
public function createOrUpdate($id, $instanceName, $content)
    {
        Redis::set($this->getKey($id, $instanceName), $content);
    }
641825
private function updateNavigationListOrder($id, $listOrder, $parentId = 0)
    {
        $row = NavigationAdmin::find($id);
        $row->list_order = $listOrder;
        $row->parent_id = $parentId;
        $row->url_parent_id = $parentId; // update the url parent id as well
        $row->updateUrl();
        $row->save();

        return $row;
    }
70378
public function updateContent($contentId, $versionNo, UpdateStruct $updateStruct)
    {
        $content = $this->load($contentId, $versionNo);
        $this->contentGateway->updateVersion($contentId, $versionNo, $updateStruct);
        $contentType = $this->contentTypeHandler->load($content->versionInfo->contentInfo->contentTypeId);
        $this->fieldHandler->updateFields($content, $updateStruct, $contentType);
        foreach ($updateStruct->name as $language => $name) {
            $this->contentGateway->setName(
                $contentId,
                $versionNo,
                $name,
                $language
            );
        }

        return $this->load($contentId, $versionNo);
    }
860924
static function updateNodeID( $oldNodeID, $newNodeID )
    {
        $db = eZDB::instance();
        $oldNodeID =(int) $oldNodeID;
        $newNodeID =(int) $newNodeID;
        $db->query( "UPDATE ezcontentbrowserecent SET node_id=$newNodeID WHERE node_id=$oldNodeID" );
    }
1370647
public static function update($itemid, $newvalue) {
        require_capability('moodle/tag:manage', context_system::instance());
        $tag = core_tag_tag::get($itemid, '*', MUST_EXIST);
        $tag->update(array('rawname' => $newvalue));
        return new self($tag);
    }