Skip to content

Commit

Permalink
MDL-22547 course->legacyfiles switch implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed May 22, 2010
1 parent 1285531 commit bf34822
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 10 deletions.
6 changes: 6 additions & 0 deletions course/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ function definition() {
$mform->addHelpButton('maxbytes', 'maximumupload');
$mform->setDefault('maxbytes', $courseconfig->maxbytes);

if (!empty($course->legacyfiles)) {
$choices = array('1'=>get_string('no'), '2'=>get_string('yes'));
$mform->addElement('select', 'legacyfiles', get_string('courselegacyfiles'), $choices);
$mform->addHelpButton('legacyfiles', 'courselegacyfiles');
}

if (!empty($CFG->allowcoursethemes)) {
$themeobjects = get_list_of_themes();
$themes=array();
Expand Down
10 changes: 7 additions & 3 deletions file.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* This script fetches legacy files from the course files in dataroot directory
* This script fetches legacy course files in dataroot directory, it is enabled
* only if course->legacyfiles == 2.
*
* You should use the get_file_url() function, available in lib/filelib.php, to link to file.php.
* This ensures proper formatting and offers useful options.
Expand Down Expand Up @@ -64,8 +65,11 @@
$relativepath = '/'.implode('/', $args);

// security: limit access to existing course subdirectories
if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
print_error('invalidcourseid');
$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);

if ($course->legacyfiles != 2) {
// course files disabled
send_file_not_found();
}

if ($course->id != SITEID) {
Expand Down
2 changes: 2 additions & 0 deletions lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@
$string['courseinfo'] = 'Course info';
$string['coursemessage'] = 'Message course users';
$string['coursenotaccessible'] = 'This course does not allow public access';
$string['courselegacyfiles'] = 'Legacy course files';
$string['courselegacyfiles_help'] = 'Files are now stored in separate areas for each activity or specific purposes, the old course files area is not available any more in new courses. This was necessary for real access control implementation, reliable backup/restore, etc.';
$string['courseoverview'] = 'Course overview';
$string['courseoverviewgraph'] = 'Course overview graph';
$string['courseprofiles'] = 'Course profiles';
Expand Down
7 changes: 4 additions & 3 deletions lib/db/install.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20100516" COMMENT="XMLDB file for core Moodle tables"
<XMLDB PATH="lib/db" VERSION="20100522" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
Expand Down Expand Up @@ -86,8 +86,9 @@
<FIELD NAME="enrolperiod" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="startdate" NEXT="numsections"/>
<FIELD NAME="numsections" TYPE="int" LENGTH="5" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="enrolperiod" NEXT="marker"/>
<FIELD NAME="marker" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="numsections" NEXT="maxbytes"/>
<FIELD NAME="maxbytes" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="marker" NEXT="showreports"/>
<FIELD NAME="showreports" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="maxbytes" NEXT="visible"/>
<FIELD NAME="maxbytes" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="marker" NEXT="legacyfiles"/>
<FIELD NAME="legacyfiles" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="course files are not necessary any more: 0 no legacy files, 1 legacy files disabled, 2 legacy files enabled" PREVIOUS="maxbytes" NEXT="showreports"/>
<FIELD NAME="showreports" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="legacyfiles" NEXT="visible"/>
<FIELD NAME="visible" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="showreports" NEXT="hiddensections"/>
<FIELD NAME="hiddensections" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="visible" NEXT="groupmode"/>
<FIELD NAME="groupmode" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="hiddensections" NEXT="groupmodeforce"/>
Expand Down
30 changes: 30 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,20 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint($result, 2008073111);
}

if ($result && $oldversion < 2008073112) {
// Define field legacyfiles to be added to course
$table = new xmldb_table('course');
$field = new xmldb_field('legacyfiles', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'maxbytes');

// Launch add field legacyfiles
$dbman->add_field($table, $field);
// enable legacy files in all courses
$DB->execute("UPDATE {course} SET legacyfiles = 2");

// Main savepoint reached
upgrade_main_savepoint($result, 2008073112);
}

if ($result && $oldversion < 2008073113) {
/// move all course, backup and other files to new filepool based storage
upgrade_migrate_files_courses();
Expand Down Expand Up @@ -4083,6 +4097,22 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint($result, 2010052100);
}

if ($result && $oldversion < 2010052200) {
// Define field legacyfiles to be added to course - just in case we are upgrading from PR1
$table = new xmldb_table('course');
$field = new xmldb_field('legacyfiles', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'maxbytes');

// Conditionally launch add field legacyfiles
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
// enable legacy files in all courses
$DB->execute("UPDATE {course} SET legacyfiles = 2");
}

// Main savepoint reached
upgrade_main_savepoint($result, 2010052200);
}


return $result;
}
Expand Down
5 changes: 5 additions & 0 deletions lib/file/file_browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ private function get_file_info_course($context, $filearea=null, $itemid=null, $f
$filearea = null;
}

if ($filearea === 'course_content' and $course->legacyfiles != 2) {
// bad luck, legacy course files not used any more
return null;
}

$filepath = is_null($filepath) ? '/' : $filepath;
$filename = is_null($filename) ? '.' : $filename;

Expand Down
6 changes: 4 additions & 2 deletions lib/file/file_info_course.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ public function get_children() {
$children[] = $child;
}

if ($child = $this->browser->get_file_info($this->context, 'course_content', 0)) {
$children[] = $child;
if ($this->course->legacyfiles == 2) {
if ($child = $this->browser->get_file_info($this->context, 'course_content', 0)) {
$children[] = $child;
}
}

$modinfo = get_fast_modinfo($this->course);
Expand Down
2 changes: 1 addition & 1 deletion lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2772,7 +2772,7 @@ protected function load_course_settings($forceopen = false) {
}

// Manage files
if (has_capability('moodle/course:managefiles', $coursecontext)) {
if ($course->legacyfiles == 2 and has_capability('moodle/course:managefiles', $coursecontext)) {
$url = new moodle_url('/files/index.php', array('contextid'=>$coursecontext->id, 'itemid'=>0, 'filearea'=>'course_content'));
$coursenode->add(get_string('files'), $url, self::TYPE_SETTING, null, 'coursefiles', new pix_icon('i/files', ''));
}
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)

$version = 2010052100; // YYYYMMDD = date of the last version bump
$version = 2010052200; // YYYYMMDD = date of the last version bump
// XX = daily increments

$release = '2.0 Preview 2 (Build: 20100522)'; // Human-friendly version name
Expand Down

0 comments on commit bf34822

Please sign in to comment.