public function solution() {
        global $CFG;
        list($missingparent, $loops) = $this->find_problems();

        $solution = '<p>Consider executing the following SQL queries. These fix ' .
                'the problem by moving some categories to the top level.</p>';

        if (!empty($missingparent)) {
            $solution .= "<pre>UPDATE " . $CFG->prefix . "course_categories\n" .
                    "        SET parent = 0, depth = 1, path = CONCAT('/', id)\n" .
                    "        WHERE id IN (" . implode(',', array_keys($missingparent)) . ");</pre>\n";
        }

        if (!empty($loops)) {
            $solution .= "<pre>UPDATE " . $CFG->prefix . "course_categories\n" .
                    "        SET parent = 0, depth = 1, path = CONCAT('/', id)\n" .
                    "        WHERE id IN (" . implode(',', array_keys($loops)) . ");</pre>\n";
        }

        return $solution;
    }