From b9bcdb54da8e1a30f724bc152a97926c4dc91d3c Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Mon, 23 Apr 2012 21:48:17 +0800 Subject: [PATCH] MDL-32505 course: drop course_display table and settings --- admin/settings/appearance.php | 1 - course/format/topics/format.php | 8 +--- course/format/weeks/format.php | 8 +--- course/lib.php | 75 --------------------------------- lang/en/admin.php | 2 - lib/db/install.xml | 18 +------- lib/db/upgrade.php | 22 ++++++++++ lib/moodlelib.php | 3 +- lib/navigationlib.php | 4 +- lib/tests/phpunit_test.php | 4 ++ version.php | 2 +- 11 files changed, 34 insertions(+), 113 deletions(-) diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index c791205ca97..67d824af0f7 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -100,7 +100,6 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page $temp->add(new admin_setting_configcheckbox('navshowmycoursecategories', new lang_string('navshowmycoursecategories', 'admin'), new lang_string('navshowmycoursecategories_help', 'admin'), 0)); $temp->add(new admin_setting_configcheckbox('navshowallcourses', new lang_string('navshowallcourses', 'admin'), new lang_string('confignavshowallcourses', 'admin'), 0)); $temp->add(new admin_setting_configtext('navcourselimit',new lang_string('navcourselimit','admin'),new lang_string('confignavcourselimit', 'admin'),20,PARAM_INT)); - $temp->add(new admin_setting_configcheckbox('navlinkcoursesections', new lang_string('navlinkcoursesections', 'admin'), new lang_string('navlinkcoursesections_help', 'admin'), 0)); $temp->add(new admin_setting_configcheckbox('usesitenameforsitepages', new lang_string('usesitenameforsitepages', 'admin'), new lang_string('configusesitenameforsitepages', 'admin'), 0)); $temp->add(new admin_setting_configcheckbox('linkadmincategories', new lang_string('linkadmincategories', 'admin'), new lang_string('linkadmincategories_help', 'admin'), 0)); $temp->add(new admin_setting_configcheckbox('navshowfrontpagemods', new lang_string('navshowfrontpagemods', 'admin'), new lang_string('navshowfrontpagemods_help', 'admin'), 1)); diff --git a/course/format/topics/format.php b/course/format/topics/format.php index fc0d138da22..912671d712b 100644 --- a/course/format/topics/format.php +++ b/course/format/topics/format.php @@ -30,13 +30,7 @@ defined('MOODLE_INTERNAL') || die(); require_once($CFG->libdir.'/filelib.php'); require_once($CFG->libdir.'/completionlib.php'); -$topic = optional_param('topic', -1, PARAM_INT); - -if ($topic != -1) { - $displaysection = course_set_display($course->id, $topic); -} else { - $displaysection = course_get_display($course->id); -} +$displaysection = optional_param('topic', 0, PARAM_INT); $context = get_context_instance(CONTEXT_COURSE, $course->id); diff --git a/course/format/weeks/format.php b/course/format/weeks/format.php index ee48a432228..abc2c7def3b 100644 --- a/course/format/weeks/format.php +++ b/course/format/weeks/format.php @@ -29,13 +29,7 @@ defined('MOODLE_INTERNAL') || die(); require_once($CFG->libdir.'/filelib.php'); require_once($CFG->libdir.'/completionlib.php'); - $week = optional_param('week', -1, PARAM_INT); - - if ($week != -1) { - $displaysection = course_set_display($course->id, $week); - } else { - $displaysection = course_get_display($course->id); - } + $displaysection = optional_param('week', 0, PARAM_INT); $streditsummary = get_string('editsummary'); $stradd = get_string('add'); diff --git a/course/lib.php b/course/lib.php index 8f7d6351f3a..b5544c94326 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1276,73 +1276,6 @@ function get_all_sections($courseid) { return $coursesections[$courseid]; } -/** - * Returns the course section to display or 0 meaning show all sections. Returns 0 for guests. - * It also sets the $USER->display cache to array($courseid=>return value) - * - * @param int $courseid The course id - * @return int Course section to display, 0 means all - */ -function course_get_display($courseid) { - global $USER, $DB; - - if (!isloggedin() or isguestuser()) { - //do not get settings in db for guests - return 0; //return the implicit setting - } - - if (!isset($USER->display[$courseid])) { - if (!$display = $DB->get_field('course_display', 'display', array('userid' => $USER->id, 'course'=>$courseid))) { - $display = 0; // all sections option is not stored in DB, this makes the table much smaller - } - //use display cache for one course only - we need to keep session small - $USER->display = array($courseid => $display); - } - - return $USER->display[$courseid]; -} - -/** - * Show one section only or all sections. - * - * @param int $courseid The course id - * @param mixed $display show only this section, 0 or 'all' means show all sections - * @return int Course section to display, 0 means all - */ -function course_set_display($courseid, $display) { - global $USER, $DB; - - if ($display === 'all' or empty($display)) { - $display = 0; - } - - if (!isloggedin() or isguestuser()) { - //do not store settings in db for guests - return 0; - } - - if ($display == 0) { - //show all, do not store anything in database - $DB->delete_records('course_display', array('userid' => $USER->id, 'course' => $courseid)); - - } else { - if ($DB->record_exists('course_display', array('userid' => $USER->id, 'course' => $courseid))) { - $DB->set_field('course_display', 'display', $display, array('userid' => $USER->id, 'course' => $courseid)); - } else { - $record = new stdClass(); - $record->userid = $USER->id; - $record->course = $courseid; - $record->display = $display; - $DB->insert_record('course_display', $record); - } - } - - //use display cache for one course only - we need to keep session small - $USER->display = array($courseid => $display); - - return $display; -} - /** * Set highlighted section. Only one section can be highlighted at the time. * @@ -3020,10 +2953,6 @@ function move_section($course, $section, $move) { course_set_marker($course->id, $section); } - // if the focus is on the section that is being moved, then move the focus along - if (course_get_display($course->id) == $section) { - course_set_display($course->id, $sectiondest); - } // Fix order if needed. The database prevents duplicate sections, but it is // possible there could be a gap in the numbering. @@ -3099,10 +3028,6 @@ function move_section_to($course, $section, $destination) { course_set_marker($course, $course->marker-1); } - // if the focus is on the section that is being moved, then move the focus along - if (course_get_display($course->id) == $section) { - course_set_display($course->id, $destination); - } $transaction->allow_commit(); return true; } diff --git a/lang/en/admin.php b/lang/en/admin.php index 760b6cfa83a..6af4828d2be 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -695,8 +695,6 @@ $string['navadduserpostslinks'] = 'Add links to view user posts'; $string['navadduserpostslinks_help'] = 'If enabled two links will be added to each user in the navigation to view discussions the user has started and posts the user has made in forums throughout the site or in specific courses.'; $string['navigationupgrade'] = 'This upgrade introduces two new navigation blocks that will replace these blocks: Administration, Courses, Activities and Participants. If you had set any special permissions on those blocks you should check to make sure everything is behaving as you want it.'; $string['navcourselimit'] = 'Course limit'; -$string['navlinkcoursesections'] = 'Link course sections'; -$string['navlinkcoursesections_help'] = 'If enabled course sections will be shown as links within the navigation.'; $string['navshowfrontpagemods'] = 'Show front page activities in the navigation'; $string['navshowfrontpagemods_help'] = 'If enabled, front page activities will be shown on the navigation under site pages.'; $string['navshowallcourses'] = 'Show all courses'; diff --git a/lib/db/install.xml b/lib/db/install.xml index 76d469ec3c2..13d3f0c637f 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -206,7 +206,7 @@ - +
@@ -227,21 +227,7 @@
- - - - - - - - - - - - - -
- +
diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index c13712a668b..0bef6573dfe 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -456,5 +456,27 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2012050300.03); } + if ($oldversion < 2012050300.04) { + + // Define table course_display to be dropped + $table = new xmldb_table('course_display'); + + // Conditionally launch drop table for course_display + if ($dbman->table_exists($table)) { + $dbman->drop_table($table); + } + + // Main savepoint reached + upgrade_main_savepoint(true, 2012050300.04); + } + + if ($oldversion < 2012050300.05) { + + // Clean up removed admin setting. + unset_config('navlinkcoursesections'); + + upgrade_main_savepoint(true, 2012050300.05); + } + return true; } diff --git a/lib/moodlelib.php b/lib/moodlelib.php index d9b83eb659c..1e69ce7641a 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -4641,9 +4641,8 @@ function remove_course_contents($courseid, $showfeedback = true, array $options } $DB->update_record('course', $oldcourse); - // Delete course sections and user selections + // Delete course sections. $DB->delete_records('course_sections', array('course'=>$course->id)); - $DB->delete_records('course_display', array('course'=>$course->id)); // delete legacy, section and any other course files $fs->delete_area_files($coursecontext->id, 'course'); // files from summary and section diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 51b6efa16ed..d4e03e8a3d5 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -1762,12 +1762,12 @@ class global_navigation extends navigation_node { $viewhiddensections = has_capability('moodle/course:viewhiddensections', $this->page->context); $urlfunction = 'callback_'.$courseformat.'_get_section_url'; - if (empty($CFG->navlinkcoursesections) || !function_exists($urlfunction)) { + if ($course->coursedisplay == COURSE_DISPLAY_SINGLEPAGE || !function_exists($urlfunction)) { $urlfunction = null; } $keyfunction = 'callback_'.$courseformat.'_request_key'; - $key = course_get_display($course->id); + $key = 0; if (defined('AJAX_SCRIPT') && AJAX_SCRIPT == '0' && function_exists($keyfunction) && $this->page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)) { $key = optional_param($keyfunction(), $key, PARAM_INT); } diff --git a/lib/tests/phpunit_test.php b/lib/tests/phpunit_test.php index a9b944ec284..a9705d341cb 100644 --- a/lib/tests/phpunit_test.php +++ b/lib/tests/phpunit_test.php @@ -212,9 +212,11 @@ class core_phpunit_advanced_testcase extends advanced_testcase { $record = $DB->get_record('context_temp', array()); $this->assertEquals(5, $record->id); + /** FIXME: danp $this->assertEquals(0, $DB->count_records('course_display')); $originaldisplayid = $DB->insert_record('course_display', array('userid'=>2, 'course'=>1, 'display'=>1)); $this->assertEquals(1, $originaldisplayid); + */ $course = $this->getDataGenerator()->create_course(); $this->assertEquals(2, $course->id); @@ -232,8 +234,10 @@ class core_phpunit_advanced_testcase extends advanced_testcase { $course = $this->getDataGenerator()->create_course(); $this->assertEquals(2, $course->id); + /** FIXME: danp $displayid = $DB->insert_record('course_display', array('userid'=>2, 'course'=>1, 'display'=>1)); $this->assertEquals($originaldisplayid, $displayid); + */ $this->assertEquals(2, $DB->count_records('user')); $DB->delete_records('user', array('id'=>2)); diff --git a/version.php b/version.php index 607d106aec7..04f6b8ca8ce 100644 --- a/version.php +++ b/version.php @@ -30,7 +30,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2012050300.03; // YYYYMMDD = weekly release date of this DEV branch +$version = 2012050300.05; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes