public function map_tool_to_consumer() {
        global $DB;

        if (empty($this->consumer)) {
            throw new moodle_exception('invalidtoolconsumer', 'enrol_lti');
        }

        // Map the consumer to the tool.
        $mappingparams = [
            'toolid' => $this->tool->id,
            'consumerid' => $this->consumer->getRecordId()
        ];
        $mappingexists = $DB->record_exists('enrol_lti_tool_consumer_map', $mappingparams);
        if (!$mappingexists) {
            $DB->insert_record('enrol_lti_tool_consumer_map', (object) $mappingparams);
        }
    }