Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't backup or duplicate quizzes with ShortMath Questions #33

Closed
hgeorgsch opened this issue Jun 4, 2020 · 4 comments
Closed

Can't backup or duplicate quizzes with ShortMath Questions #33

hgeorgsch opened this issue Jun 4, 2020 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@hgeorgsch
Copy link
Contributor

This was posted on the Moodle site.

There is a problem with ShortMath questions. I don't know if it is a
problem that my administrator can solve or not (I already contacted) but I
post the problem here too.

I can't duplicate quizzes with a ShortMath question (dmlreadexception
error). The problem is that I also can't make a course backup with the
question bank (same error).

Does anyone know how to solve it? I want to help my administrator with
some information about it.

@hgeorgsch hgeorgsch added the bug Something isn't working label Jun 4, 2020
@andstor andstor self-assigned this Jul 24, 2020
@hgeorgsch
Copy link
Contributor Author

@nan-hk Can you test and verify this bug?

@nadavkav
Copy link

I experience the same error
SELECT * FROM mdl_qtype_shortmath WHERE questionid = ?

#19 /var/www/moodle/physics/lib/dml/moodle_database.php(486): moodle_database::query_end
#18 /var/www/moodle/physics/lib/dml/mysqli_native_moodle_database.php(1212): mysqli_native_moodle_database::get_recordset_sql
#17 /var/www/moodle/physics/lib/dml/moodle_database.php(1347): moodle_database::get_recordset_select
#16 /var/www/moodle/physics/lib/dml/moodle_database.php(1295): moodle_database::get_recordset
#15 /util/dbops/backup_structure_dbops.class.php(53): backup_structure_dbops::get_iterator
#14 /util/structure/backup_nested_element.class.php(359): backup_nested_element::get_iterator
#13 /util/structure/backup_nested_element.class.php(77): backup_nested_element::process
#12 /util/structure/backup_nested_element.class.php(107): backup_nested_element::process
#11 /util/structure/backup_optigroup.class.php(79): backup_optigroup::process
#10 /util/structure/backup_nested_element.class.php(107): backup_nested_element::process
#9 /util/structure/backup_nested_element.class.php(107): backup_nested_element::process
#8 /util/structure/backup_nested_element.class.php(107): backup_nested_element::process
#7 /util/structure/backup_nested_element.class.php(107): backup_nested_element::process
#6 /util/plan/backup_structure_step.class.php(97): backup_structure_step::execute
#5 /util/plan/base_task.class.php(181): base_task::execute
#4 /util/plan/base_plan.class.php(178): base_plan::execute
#3 /util/plan/backup_plan.class.php(145): backup_plan::execute
#2 /controller/backup_controller.class.php(410): backup_controller::execute_plan
#1 /util/ui/backup_ui.class.php(136): backup_ui::execute
#0 /backup.php(175): null

Looking at the db/install.xml and db/upgrade.php, it seemed like the backup/restore functions needs updating

Suggested fix:
diff --git a/question/type/shortmath/backup/moodle2/backup_qtype_shortmath_plugin.class.php b/question/type/shortmath/backup/moodle2/backup_qtype_shortmath_plugin.class.php
index 1e0f63ab37..e3f68e881f 100644
--- a/question/type/shortmath/backup/moodle2/backup_qtype_shortmath_plugin.class.php
+++ b/question/type/shortmath/backup/moodle2/backup_qtype_shortmath_plugin.class.php
@@ -54,7 +54,7 @@ class backup_qtype_shortmath_plugin extends backup_qtype_plugin {
// Set source to populate the data.
// JR changed table name to match new table name system in moodle 2.1 DEC 2011.
// JR changed field name question to questionid JAN 2012.

  •    $shortmath->set_source_table('qtype_shortmath', ['questionid' => backup::VAR_PARENTID]);
    
  •    $shortmath->set_source_table('qtype_shortmath_options', ['questionid' => backup::VAR_PARENTID]);
       // Don't need to annotate ids nor files.
       return $plugin;
    
    }
    diff --git a/question/type/shortmath/backup/moodle2/restore_qtype_shortmath_plugin.class.php b/question/type/shortmath/backup/moodle2/restore_qtype_shortmath_plugin.class.php
    index 22f8aacc49..bf0c8f3b62 100644
    --- a/question/type/shortmath/backup/moodle2/restore_qtype_shortmath_plugin.class.php
    +++ b/question/type/shortmath/backup/moodle2/restore_qtype_shortmath_plugin.class.php
    @@ -75,9 +75,9 @@ class restore_qtype_shortmath_plugin extends restore_qtype_plugin {
    }
    $data->answers = implode(',', $answersarr);
    // Insert record.
  •        $newitemid = $DB->insert_record('qtype_shortmath', $data);
    
  •        $newitemid = $DB->insert_record('qtype_shortmath_options', $data);
           // Create mapping.
    
  •        $this->set_mapping('qtype_shortmath', $oldid, $newitemid);
    
  •        $this->set_mapping('qtype_shortmath_options', $oldid, $newitemid);
       }
    
    }
    }

@hgeorgsch
Copy link
Contributor Author

New question about this bug today: https://moodle.org/plugins/qtype_shortmath

@nan-hk
Copy link

nan-hk commented Jan 25, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants