Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-68683

Competency cleanup upgrade step causes DML exception when loading user context

XMLWordPrintable

    • MOODLE_38_STABLE
    • MOODLE_38_STABLE, MOODLE_39_STABLE
    • MDL-68683-master
    • Hide

      Test 1 (Delete stale evidence files)

      For this test we will need to do a before/after upgrade, or alternatively checkout the following commits:

      • 310: 1222c2125ee6be2dd828ae61e76926814027e4c2
      • 39: 2cd36e8ea0df01832cc3778f6cf35a6f69bb2b07
      • 38: 45d06fe9b6b92ad49427acf5145ae0e195954393
      1. Before upgrade: Download setup_env.php and put it in your root folder.
      2. Open the browser, run that script and make note of the context id of each user.
      3. Now, upgrade moodle (or apply the version commit)
        1. If you checked out the commit then run the following command : git checkout MOODLE_310_STABLE Change the 310 to 39 for 3.9 and 38 for 3.8 branches.
        2. Upgrade

          php admin/cli/upgrade.php

      4. Open your database and run the following query replacing the context id number

        select * from mdl_files WHERE component = 'core_competency' AND filearea = 'userevidence' and contextid = {USER1_CONTEXTID_HERE} 
        

      5. Make sure the query above does not return any records
      6. Replace the context id number to the user 2 context id and run that query again
      7. Make sure it returns the records for the user 2 evidence files.

      Test 2 (DML error)

      This test can be done after upgrading, you'll need to tweak version numbers again

      1. Run setup_env.php
      2. Open version.php and bump the version number (increment (+1) to whatever the last number is)
      3. Copy that whole version number.
      4. Open lib/db/upgrade.php and find the previous upgrade step (line 2172) and replace the version number check by the new ones:

        if ($oldversion < VERSIONNUMBERYOUCOPIEDHERE) {
        

      5. Also update the savepoint (line 2216):

         
                upgrade_main_savepoint(true, NEWVERSIONNUMBERHERE);
        

      6. In your moodle, run the upgrade on the web interface.
      7. Make sure you don't see any DML related error.
      Show
      Test 1 (Delete stale evidence files) For this test we will need to do a before/after upgrade, or alternatively checkout the following commits: 310 : 1222c2125ee6be2dd828ae61e76926814027e4c2 39 : 2cd36e8ea0df01832cc3778f6cf35a6f69bb2b07 38 : 45d06fe9b6b92ad49427acf5145ae0e195954393 Before upgrade : Download setup_env.php and put it in your root folder. Open the browser, run that script and make note of the context id of each user. Now, upgrade moodle (or apply the version commit) If you checked out the commit then run the following command : git checkout MOODLE_310_STABLE Change the 310 to 39 for 3.9 and 38 for 3.8 branches. Upgrade php admin/cli/upgrade.php Open your database and run the following query replacing the context id number select * from mdl_files WHERE component = 'core_competency' AND filearea = 'userevidence' and contextid = {USER1_CONTEXTID_HERE} Make sure the query above does not return any records Replace the context id number to the user 2 context id and run that query again Make sure it returns the records for the user 2 evidence files. Test 2 (DML error) This test can be done after upgrading, you'll need to tweak version numbers again Run setup_env.php Open version.php and bump the version number (increment (+1) to whatever the last number is) Copy that whole version number. Open lib/db/upgrade.php and find the previous upgrade step (line 2172) and replace the version number check by the new ones: if ($oldversion < VERSIONNUMBERYOUCOPIEDHERE) { Also update the savepoint (line 2216): upgrade_main_savepoint(true, NEWVERSIONNUMBERHERE); In your moodle, run the upgrade on the web interface. Make sure you don't see any DML related error.
    • 0
    • International 4.0 - Sprint 3, International 4.0 - Sprint 4

      MDL-60126 added an upgrade step:

      $sql = "SELECT cue.id, cue.userid
                    FROM {competency_userevidence} cue
               LEFT JOIN {user} u ON cue.userid = u.id
                   WHERE u.deleted = 1";
      $userevidences = $DB->get_records_sql($sql);
      foreach ($userevidences as $userevidence) {
          ...
          $context = context_user::instance($userevidence->userid);    
          ...
      }
      

      context_user::instance requires that the user not be flagged as deleted in the DB and thus the upgrade fails.

            lameze Simey Lameze
            cameron1729 cameron1729
            Peter Dias Peter Dias
            Adrian Greeve Adrian Greeve
            Glyn (Mathew) May Glyn (Mathew) May
            Votes:
            1 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 4 days, 26 minutes
                4d 26m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.