Browse files

database: MDL-16999 fix "Required Entries" and "Required Entries befo…

…re viewing" settings. Display a warning message during upgrade process if the fields were set previously.
  • Loading branch information...
1 parent 54d2128 commit f597bba4586e76bf4094ea4b013124744c0794e3 jerome committed Nov 21, 2008
Showing with 56 additions and 7 deletions.
  1. +2 −0 admin/environment.xml
  2. +1 −0 install/stringnames.txt
  3. +2 −0 lang/en_utf8/admin.php
  4. +2 −1 lang/en_utf8/data.php
  5. +36 −0 mod/data/lib.php
  6. +10 −3 mod/data/view.php
  7. +3 −3 version.php
View
2 admin/environment.xml
@@ -205,6 +205,8 @@
<ON_CHECK message="globalswarning" />
</FEEDBACK>
</CUSTOM_CHECK>
+ <CUSTOM_CHECK file="mod/data/lib.php" function="check_required_entries_fields" level="optional">
+ </CUSTOM_CHECK>
</CUSTOM_CHECKS>
</MOODLE>
<MOODLE version="2.0" requires="1.9">
View
1 install/stringnames.txt
@@ -136,6 +136,7 @@ qtyperqpwillberemovedanyway
remotedownloaderror
remotedownloadnotallowed
report
+requiredentrieschanged
restricted
safemode
safemodeerror
View
2 lang/en_utf8/admin.php
@@ -620,6 +620,8 @@
$string['remotelangnotavailable'] = 'Because Moodle can not connect to download.moodle.org, we are unable to do language pack installation automatically. Please download the appropriate zip file(s) from the list below, copy them to your $a directory and unzip them manually.';
$string['renameerrors'] = 'Rename errors';
$string['requiredtemplate'] = 'Required. You may use template syntax here (%%l = lastname, %%f = firstname, %%u = username). See help for details and examples.';
+$string['requiredentrieschanged'] = '<strong>IMPORTANT - PLEASE READ</strong><br/>Due to a bug fix, the behaviour of database activities using the \'Required entries\' and \'Required entries before viewing settings\' settings will change. A more detailed explaination of the changes can be read on <a href=\"http://moodle.org/mod/forum/discuss.php?d=110928\">the database module forum</a> and <a href=\"http://docs.moodle.org/en/Adding/editing_a_database#Required_entries\">Moodle Docs</a>.
+<br/><br/>This change affects the following databases in your system: (Please save this list now, and after the upgrade, check that these activities still work the way that the teacher intends.)<br/><strong style=\"color:red\">$a->text</strong><br/>';
$string['restrictbydefault'] = 'Restrict modules by default';
$string['restrictmodulesfor'] = 'Restrict modules for';
$string['reverseproxy'] = 'Reverse proxy';
View
3 lang/en_utf8/data.php
@@ -79,7 +79,8 @@
$string['emptyadd'] = 'The Add template is empty, generating a default form...';
$string['emptyaddform'] = 'You did not fill out any fields!';
$string['entries'] = 'Entries';
-$string['entrieslefttoadd'] = 'You must add $a->entriesleft more entry/entries before you can view other participants\' entries.';
+$string['entrieslefttoaddtoview'] = 'You must add $a->entrieslefttoview more entry/entries before you can view other participants\' entries.';
+$string['entrieslefttoadd'] = 'You must add $a->entriesleft more entry/entries in order to complete this activity';
$string['entry'] = 'Entry';
$string['entrysaved'] = 'Your entry has been saved';
$string['errormustbeteacher'] = 'You need to be a teacher to use this page!';
View
36 mod/data/lib.php
@@ -2101,4 +2101,40 @@ function data_get_extra_capabilities() {
return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames');
}
+/**
+ * This function is declared into environment.xml
+ * Check if both of database required entries fields have been set for a version anterior to 2007101532
+ * This check has been required by the bug MDL-16999
+ * @global <type> $CFG
+ * @param <type> $result
+ * @return object status
+ */
+function check_required_entries_fields($result) {
+ global $CFG;
+ if (!empty($CFG->version) //we are not installing a new Moodle site
+ && $CFG->version < 2007101532 //the version is anterior to the one when the fix has been applied
+ && !get_config("","data/requiredentriesfixflag")) { //do not show message when upgrading an anterior version when the patch has already been applied
+ set_config("data/requiredentriesfixflag",true); //set a flag into database in order to let know a Moodle 2.0 upgrade that the message has already been displayed
+ $databases = get_records_sql("SELECT d.*, c.fullname
+ FROM {$CFG->prefix}data d,
+ {$CFG->prefix}course c
+ WHERE d.course = c.id
+ ORDER BY c.fullname, d.name");
+ if (!empty($databases)) {
+ $a = new object();
+ foreach($databases as $database) {
+ if ($database->requiredentries != 0 || $database->requiredentriestoview != 0) {
+ $a->text .= "".$database->fullname." - " .$database->name. " (course id: ".$database->course." - database id: ".$database->id.")<br/>";
+ //set the feedback string here and not in xml file since we need something
+ //more complex than just a string picked from admin.php lang file
+ $result->setFeedbackStr(array('requiredentrieschanged', 'admin', $a));
+ $result->setStatus(false);//fail test
+ }
+ }
+ return $result;
+ }
+ }
+ return null;
+}
+
?>
View
13 mod/data/view.php
@@ -389,14 +389,21 @@
}
}
}
-
- // Check the number of entries required against the number of entries already made (doesn't apply to teachers)
- $requiredentries_allowed = true;
+
$numentries = data_numentries($data);
+ /// Check the number of entries required against the number of entries already made (doesn't apply to teachers)
if ($data->requiredentries > 0 && $numentries < $data->requiredentries && !has_capability('mod/data:manageentries', $context)) {
$data->entriesleft = $data->requiredentries - $numentries;
$strentrieslefttoadd = get_string('entrieslefttoadd', 'data', $data);
notify($strentrieslefttoadd);
+ }
+
+ /// Check the number of entries required before to view other participant's entries against the number of entries already made (doesn't apply to teachers)
+ $requiredentries_allowed = true;
+ if ($data->requiredentriestoview > 0 && $numentries < $data->requiredentriestoview && !has_capability('mod/data:manageentries', $context)) {
+ $data->entrieslefttoview = $data->requiredentriestoview - $numentries;
+ $strentrieslefttoaddtoview = get_string('entrieslefttoaddtoview', 'data', $data);
+ notify($strentrieslefttoaddtoview);
$requiredentries_allowed = false;
}
View
6 version.php
@@ -6,9 +6,9 @@
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
- $version = 2007101531; // YYYYMMDD = date of the 1.9 branch (don't change)
- // X = release number 1.9.[0,1,2,3...]
- // Y.YY = micro-increments between releases
+ $version = 2007101532; // YYYYMMDD = date of the 1.9 branch (don't change)
+ // X = release number 1.9.[0,1,2,3...]
+ // Y.YY = micro-increments between releases
$release = '1.9.3+ (Build: 20081121)'; // Human-friendly version name

0 comments on commit f597bba

Please sign in to comment.