public function start_conversion(stored_file $file, $format, $forcerefresh = false) {
        $conversions = conversion::get_conversions_for_file($file, $format);

        if ($forcerefresh || count($conversions) > 1) {
            while ($conversion = array_shift($conversions)) {
                if ($conversion->get('id')) {
                    $conversion->delete();
                }
            }
        }

        if (empty($conversions)) {
            $conversion = new conversion(0, (object) [
                'sourcefileid' => $file->get_id(),
                'targetformat' => $format,
            ]);
            $conversion->create();
        } else {
            $conversion = array_shift($conversions);
        }

        if ($conversion->get('status') !== conversion::STATUS_COMPLETE) {
            $this->poll_conversion($conversion);
        }

        return $conversion;
    }