public static function set_context_instance($record) {
        if ($instance = context_instance::get_record_by_contextid($record->contextid, false)) {
            // Update.
            $instance->from_record($record);

            if (empty($record->purposeid) && empty($record->categoryid)) {
                // We accept one of them to be null but we delete it if both are null.
                self::unset_context_instance($instance);
                return;
            }

        } else {
            // Add.
            $instance = new context_instance(0, $record);
        }
        $instance->save();

        return $instance;
    }
public static function set_context_instance($record) {
        if ($instance = context_instance::get_record_by_contextid($record->contextid, false)) {
            // Update.
            $instance->from_record($record);

            if (empty($record->purposeid) && empty($record->categoryid)) {
                // We accept one of them to be null but we delete it if both are null.
                self::unset_context_instance($instance);
                return;
            }

        } else {
            // Add.
            $instance = new context_instance(0, $record);
        }
        $instance->save();

        return $instance;
    }
public static function set_context_instance ( $ record ) { if ( $ instance = context_instance :: get_record_by_contextid ( $ record -> contextid , false ) ) { // Update. $ instance -> from_record ( $ record ) ; if ( empty ( $ record -> purposeid ) && empty ( $ record -> categoryid ) ) { // We accept one of them to be null but we delete it if both are null. self :: unset_context_instance ( $ instance ) ; return ; } } else { // Add. $ instance = new context_instance ( 0 , $ record ) ; } $ instance -> save ( ) ; return $ instance ; }
Sets the context instance purpose and category.

@param \stdClass $record
@return \tool_dataprivacy\context_instance
Sets the context instance purpose and category .