Skip to content

Bad SQL in get_students function #93

@juacas

Description

@juacas

The SQL at $sql = "SELECT u.id generates duplicated keys when a user is enrolled by more than a enrolment method.

Did you remember to make the first column something unique in your call to get_records? Duplicate value '4' found in column 'id'.
line 1407 of /lib/dml/mysqli_native_moodle_database.php: call to debugging()
line 745 of /mod/certifygen/classes/certifygen.php: call to mysqli_native_moodle_database->get_records_sql()
line 326 of /mod/certifygen/classes/tables/activityteacher_table.php: call to mod_certifygen\certifygen::get_students()
line 2207 of /lib/tablelib.php: call to mod_certifygen\tables\activityteacher_table->query_db()
line 175 of /mod/certifygen/classes/output/views/activity_view.php: call to table_sql->out()
line 124 of /mod/certifygen/classes/output/views/activity_view.php: call to mod_certifygen\output\views\activity_view->get_certificates_table()
line 72 of /mod/certifygen/classes/output/renderer.php: call to mod_certifygen\output\views\activity_view->export_for_template()
line 495 of /lib/outputrenderers.php: call to mod_certifygen\output\renderer->render_activity_view()
line 70 of /mod/certifygen/view.php: call to plugin_renderer_base->render()

Steps to reproduce:

  • Create a course.
  • Enrol a user.
  • Meta-link other course with the same user.
  • go to entry page of Certifygen /mod/certifygen/view.php?id=xxxx

Nevertheless, is better to use get_enrolled_users(context $context, $withcapability = '', $groupids = 0, $userfields = 'u.*', $orderby = null,
$limitfrom = 0, $limitnum = 0, $onlyactive = false) instead of this code block. This approach may introduce future bugs.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcomplianceNecesario para cumplimiento del pliego

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions