Skip to content

Commit

Permalink
mod_hotpot fix error caused by NULL intro field
Browse files Browse the repository at this point in the history
  • Loading branch information
gbateson committed Sep 15, 2022
1 parent e58dc07 commit 786e979
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Change log for mod_hotpot
========================================

2022-09-15 (48)
- fix error caused by NULL intro field

2022-09-06 (47)
- fix compatibility with PHP 8.x and Moodle 4.x (1) remove use of curly braces on strings; (2) add 'intro' and 'introformat' fields; (3) use custom version of utf8_to_entities() that does not convert strings to lowercase;

Expand Down
32 changes: 16 additions & 16 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="course"/>
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="name"/>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="course" NEXT="intro"/>
<FIELD NAME="intro" TYPE="text" NOTNULL="true" SEQUENCE="false" PREVIOUS="name" NEXT="introformat" COMMENT="Not used but required for Moodle 4.x"/>
<FIELD NAME="intro" TYPE="text" NOTNULL="false" SEQUENCE="false" PREVIOUS="name" NEXT="introformat" COMMENT="Not used but required for Moodle 4.x"/>
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="intro" NEXT="sourcefile" COMMENT="Not used but required for Moodle 4.x"/>
<FIELD NAME="sourcefile" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="introformat" NEXT="sourcetype"/>
<FIELD NAME="sourcetype" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="sourcefile" NEXT="sourcelocation"/>
Expand Down Expand Up @@ -101,11 +101,11 @@
<FIELD NAME="md5key" TYPE="char" LENGTH="32" NOTNULL="true" SEQUENCE="false" PREVIOUS="timemodified"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="hotpotid"/>
<KEY NAME="hotpotid" TYPE="foreign" FIELDS="hotpotid" REFTABLE="hotpot" REFFIELDS="id" PREVIOUS="primary"/>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="hotpcach_hot_ix"/>
<KEY NAME="hotpcach_hot_ix" TYPE="foreign" FIELDS="hotpotid" REFTABLE="hotpot" REFFIELDS="id" PREVIOUS="primary"/>
</KEYS>
<INDEXES>
<INDEX NAME="hotpotid-md5key" UNIQUE="false" FIELDS="hotpotid, md5key"/>
<INDEX NAME="hotpcach_hotmd5_ix" UNIQUE="false" FIELDS="hotpotid, md5key"/>
</INDEXES>
</TABLE>
<TABLE NAME="hotpot_attempts" COMMENT="Info about user attempts at HotPot activities" PREVIOUS="hotpot_cache" NEXT="hotpot_details">
Expand All @@ -125,11 +125,11 @@
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="clickreportid"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="hotpotid"/>
<KEY NAME="hotpotid" TYPE="foreign" FIELDS="hotpotid" REFTABLE="hotpot" REFFIELDS="id" PREVIOUS="primary"/>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="hotpatte_hot_ix"/>
<KEY NAME="hotpatte_hot_ix" TYPE="foreign" FIELDS="hotpotid" REFTABLE="hotpot" REFFIELDS="id" PREVIOUS="primary"/>
</KEYS>
<INDEXES>
<INDEX NAME="userid" UNIQUE="false" FIELDS="userid"/>
<INDEX NAME="hotpatte_use_ix" UNIQUE="false" FIELDS="userid"/>
</INDEXES>
</TABLE>
<TABLE NAME="hotpot_details" COMMENT="Raw XML data returned from HotPot attempts" PREVIOUS="hotpot_attempts" NEXT="hotpot_questions">
Expand All @@ -139,8 +139,8 @@
<FIELD NAME="details" TYPE="text" NOTNULL="true" SEQUENCE="false" PREVIOUS="attemptid"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="attemptid"/>
<KEY NAME="attemptid" TYPE="foreign" FIELDS="attemptid" REFTABLE="hotpot_attempts" REFFIELDS="id" PREVIOUS="primary"/>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="hotpdeta_att_ix"/>
<KEY NAME="hotpdeta_att_ix" TYPE="foreign" FIELDS="attemptid" REFTABLE="hotpot_attempts" REFFIELDS="id" PREVIOUS="primary"/>
</KEYS>
</TABLE>
<TABLE NAME="hotpot_questions" COMMENT="details about questions in Hot Potatoes quiz attempts" PREVIOUS="hotpot_details" NEXT="hotpot_responses">
Expand All @@ -153,11 +153,11 @@
<FIELD NAME="md5key" TYPE="char" LENGTH="32" NOTNULL="true" SEQUENCE="false" PREVIOUS="hotpotid"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="hotpotid"/>
<KEY NAME="hotpotid" TYPE="foreign" FIELDS="hotpotid" REFTABLE="hotpot" REFFIELDS="id" PREVIOUS="primary"/>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="hotpques_hot_ix"/>
<KEY NAME="hotpques_hot_ix" TYPE="foreign" FIELDS="hotpotid" REFTABLE="hotpot" REFFIELDS="id" PREVIOUS="primary"/>
</KEYS>
<INDEXES>
<INDEX NAME="md5key" UNIQUE="false" FIELDS="md5key"/>
<INDEX NAME="hotpques_md5_ix" UNIQUE="false" FIELDS="md5key"/>
</INDEXES>
</TABLE>
<TABLE NAME="hotpot_responses" COMMENT="details about responses in Hot Potatoes quiz attempts" PREVIOUS="hotpot_questions" NEXT="hotpot_strings">
Expand All @@ -175,9 +175,9 @@
<FIELD NAME="checks" TYPE="int" LENGTH="6" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="clues"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="attemptid"/>
<KEY NAME="attemptid" TYPE="foreign" FIELDS="attemptid" REFTABLE="hotpot_attempts" REFFIELDS="id" PREVIOUS="primary" NEXT="questionid"/>
<KEY NAME="questionid" TYPE="foreign" FIELDS="questionid" REFTABLE="hotpot_questions" REFFIELDS="id" PREVIOUS="attemptid"/>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="hotpresp_att_ix"/>
<KEY NAME="hotpresp_att_ix" TYPE="foreign" FIELDS="attemptid" REFTABLE="hotpot_attempts" REFFIELDS="id" PREVIOUS="primary" NEXT="hotpresp_que_ix"/>
<KEY NAME="hotpresp_que_ix" TYPE="foreign" FIELDS="questionid" REFTABLE="hotpot_questions" REFFIELDS="id" PREVIOUS="hotpresp_att_ix"/>
</KEYS>
</TABLE>
<TABLE NAME="hotpot_strings" COMMENT="strings used in Hot Potatoes questions and responses" PREVIOUS="hotpot_responses">
Expand All @@ -190,7 +190,7 @@
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
<INDEXES>
<INDEX NAME="md5key" UNIQUE="false" FIELDS="md5key"/>
<INDEX NAME="hotpstri_md5_ix" UNIQUE="false" FIELDS="md5key"/>
</INDEXES>
</TABLE>
</TABLES>
Expand Down
11 changes: 8 additions & 3 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -1030,19 +1030,24 @@ function xmldb_hotpot_upgrade($oldversion) {
upgrade_mod_savepoint(true, "$newversion", 'hotpot');
}

$newversion = 2022090647;
$newversion = 2022091548;
if ($oldversion < $newversion) {
$table = new xmldb_table('hotpot');
$fields = array(
new xmldb_field('intro', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'name'),
new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro'),
);
foreach ($fields as $field) {
if (! $dbman->field_exists($table, $field)) {
xmldb_hotpot_fix_previous_field($dbman, $table, $field);
xmldb_hotpot_fix_previous_field($dbman, $table, $field);
if ($dbman->field_exists($table, $field)) {
$dbman->change_field_type($table, $field);
} else {
$dbman->add_field($table, $field);
}
}
// Set NULL intros to empty string - just to be tidy ;-)
$DB->set_field_select('hotpot', 'intro', '', 'intro IS NULL');
upgrade_mod_savepoint(true, "$newversion", 'hotpot');
}

if ($empty_cache) {
Expand Down
8 changes: 8 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ function hotpot_process_formdata(stdclass &$data, $mform) {
global $CFG;
require_once($CFG->dirroot.'/mod/hotpot/locallib.php');

// The intro field was added in Moodle 4.0 because it is expected in
// "lib/classes/output/activity_header.php". If left unset, it may
// generate a database error, so we force it to a reasonable default.
if (! isset($data->intro)) {
$data->intro = '';
$data->introformat = 0;
}

if ($mform->is_add()) {
$data->timecreated = time();
} else {
Expand Down
8 changes: 8 additions & 0 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ function definition() {
$mform->addElement('header', 'general', get_string('general', 'form'));
//-----------------------------------------------------------------------------

// The intro field was added in Moodle 4.0 because it is
// expected in "lib/classes/output/activity_header.php".
$name = 'intro';
$mform->addElement('hidden', $name, '');
$mform->setType($name, PARAM_TEXT);
$mform->addElement('hidden', $name.'format', 0);
$mform->setType($name.'format', PARAM_INT);

// Hotpot name
$name = 'name';
$label = get_string('name');
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
$plugin->component = 'mod_hotpot';
$plugin->maturity = MATURITY_STABLE; // ALPHA=50, BETA=100, RC=150, STABLE=200
$plugin->requires = 2010112400; // Moodle 2.0
$plugin->version = 2022090647;
$plugin->release = '2022-09-06 (47)';
$plugin->version = 2022091548;
$plugin->release = '2022-09-15 (48)';

if (isset($CFG->yui3version) && version_compare($CFG->yui3version, '3.15.0') < 0) {
$module = clone($plugin); // Moodle <= 2.6
Expand Down

0 comments on commit 786e979

Please sign in to comment.