jpahullo / moodle-tool_mergeusers

Merge users script for Moodle

Home Page:https://moodle.org/plugins/view.php?plugin=tool_mergeusers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mdl_customcert_issues duplicate value after merge

leonstr opened this issue · comments

If two merged users had been awarded a certificate by the same mod_customcert instance the warning Did you remember to make the first column something unique in your call to get_records? appears when debugging is enabled.

Tested with Moodle 3.9.18+ (build: 20221209), tool_mergeusers 2021072200, mod_customcert 2020061502.

Steps to reproduce this issue:

  1. Create a course.

  2. Add a custom certificate (mod_customcert) to the course.

  3. Add an element to the certificate (e.g. Date) because blank certificates don't get created.

  4. Create two users: user1 and user2.

  5. Enrol user1 and user2 on the course.

  6. Log in as user1 and click on certificate and click View certificate.

  7. Repeat this step as user2.

  8. Merge users removing user1 and keeping user2.

  9. Enable debugging (Debug messages: DEVELOPER and Display debug messages: Yes).

  10. Log in as user2, go to the profile page and click My certificates. The error Did you remember to make the first column something unique in your call to get_records? Duplicate value '1' found in column 'id'. appears.
    my_certificates

  11. Log in as admin, on course page click on the certificate. The error Did you remember to make the first column something unique in your call to get_records? Duplicate value '4' found in column 'id'. appears.
    recipients

Hi @leonstr!

Thanks a lot for your report. It's fantastic to know it, and how you detailed it.

As I can see from the customcert plugin, there is the table customcert_issues with the userid field.

I think that in this table must be only a record per userid. This explains the reason behind the warning.

However, there is missing the Moodle version and the plugin version.

Taking a look at customcert github repo, it seems you are at Modle 3.9 with the corresponding plugin version, and that the warnings are precisely as I explained before: several records for the same userid.

So, it is not strictly related to this plugin, but related to the data model used and managed by the customcert plugin.

Create or edit the file config/config.local.php with at least the following content (not tested, check it out with a test environment):

<?php
// config/config.local.php
defined("MOODLE_INTERNAL") || die();
return array(
    'compoundindexes' => array(
        'customcert_issues' => array(
            'userfield' => array('userid'),
            'otherfields' => array(),
        ),
    ),
];

The content of this config/config.local.php would be added or also be replacing any existing setting from config.php.

Let me know.

Jordi

Thank you for your reply. I was trying config/config.local.php just as you replied! In my tests if I have:

return array(
    'compoundindexes' => array(
        'customcert_issues' => array(
            'userfield' => array('userid'),
            'otherfields' => array('customcertid'),
        )
    )
);

then I get the desired behaviour. (This is based on special case 4 for mod/journal mentioned in the README).

Fantastic, yes. That was my fault. Reviewing the snipped finally I forgot to add the column name in otherfields.

Could you try to build a patch for adding this into the config.php core, please?

It would be very nice.

Thanks in advance.

Jordi

PR #229 added. Please let me know if there are changes required.

Closing as solved and merged thanks to #229. @leonstr, thanks!!!