public static function reset_tour_sortorder() {
        global $DB;
        $tours = $DB->get_records('tool_usertours_tours', null, 'sortorder ASC, pathmatch DESC', 'id, sortorder');

        $index = 0;
        foreach ($tours as $tour) {
            if ($tour->sortorder != $index) {
                $DB->set_field('tool_usertours_tours', 'sortorder', $index, array('id' => $tour->id));
            }
            $index++;
        }

        // Notify the cache that a tour has changed.
        // Tours are only stored in the cache if there are steps.
        // If there step count has changed for some reason, this will change the potential cache results.
        cache::notify_tour_change();
    }