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

Fatal error if cohort_role_sync task is run when an assigned role no longer exists

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      Test 1: Deleting the cohort role assignment without syncing first

      As admin:

      1. Clone new site (mdk create -v BRANCH)
      2. Checkout last week's weekly:
        • Master: git checkout 8cf4c97217230e74
        • 38: git checkout 773b1f738fa
        • 37: git checkout fcc93935bea
      3. Install the site
      4. Create a cohort and add some users to it, including user t1 (or any user, just remember their username)
      5. Create a new role 'cohortmanager', based on manager (Admin -> Users -> Define roles) and make sure to check the "User" box next to the "Context types where this role may be assigned" option.
      6. Now, via the cohorts role assign page (Admin -> Users -> Assign user roles to cohort), assign the cohortmanager role to the t1 user for that cohort.
      7. Now, go back to define roles via system admin
      8. Delete the 'cohort manager' role
      9. Now, run the sync task:

        php admin/tool/task/cli/schedule_task.php --execute=\\tool_cohortroles\\task\\cohort_role_sync
        

        Verify you see a bunch of errors

      10. Now, checkout HEAD (git checkout master or git checkout MOODLE_38_STABLE, etc)
      11. Run the upgrade
      12. Verify the upgrade runs without any errors
      13. Now, run the following query (change table prefix as needed):

        select t.*, r.id from mdl_tool_cohortroles t left join mdl_role r on t.roleid = r.id where r.id is null;
        

        Verify there are 0 results;

      14. Now, run the following query (change table prefix as needed):

        select ra.*, r.id from mdl_role_assignments ra left join mdl_role r on ra.roleid = r.id where r.id is null;

        Verify there are 0 results;

      15. Now, run the sync task:

        php admin/tool/task/cli/schedule_task.php --execute=\\tool_cohortroles\\task\\cohort_role_sync
        

        Verify the task completes without any errors

      Test 2: Deleting the cohort role assignment after syncing

      1. Clone new site (mdk create -v BRANCH)
      2. Checkout last week's weekly:
        • Master: git checkout 8cf4c97217230e74
        • 38: git checkout 773b1f738fa
        • 37: git checkout fcc93935bea
      3. Install the site
      4. Create a cohort and add some users to it, including user t1 (or any user, just remember their username)
      5. Create a new role 'cohortmanager', based on manager (Admin -> Users -> Define roles) and make sure to check the "User" box next to the "Context types where this role may be assigned" option.
      6. Now, via the cohorts role assign page (Admin -> Users -> Assign user roles to cohort), assign the cohortmanager role to the t1 user for that cohort.
      7. Now, run the sync task:

        php admin/tool/task/cli/schedule_task.php --execute=\\tool_cohortroles\\task\\cohort_role_sync
        

      8. Delete the 'cohort manager' role
      9. Now, run the sync task:

        php admin/tool/task/cli/schedule_task.php --execute=\\tool_cohortroles\\task\\cohort_role_sync
        

        You may see some errors. If so, that's ok.

      10. Now, checkout HEAD (git checkout master or git checkout MOODLE_38_STABLE, etc)
      11. Run the upgrade
      12. Verify the upgrade runs without any errors
      13. Now, run the following query (change table prefix as needed):

        select t.*, r.id from mdl_tool_cohortroles t left join mdl_role r on t.roleid = r.id where r.id is null;
        

        Verify there are 0 results;

      14. Now, run the following query (change table prefix as needed):

        select ra.*, r.id from mdl_role_assignments ra left join mdl_role r on ra.roleid = r.id where r.id is null;

        Verify there are 0 results;

      15. Now, run the sync task:

        php admin/tool/task/cli/schedule_task.php --execute=\\tool_cohortroles\\task\\cohort_role_sync
        

        Verify the task completes without any errors

      Show
      Test 1: Deleting the cohort role assignment without syncing first As admin: Clone new site (mdk create -v BRANCH) Checkout last week's weekly: Master: git checkout 8cf4c97217230e74 38: git checkout 773b1f738fa 37: git checkout fcc93935bea Install the site Create a cohort and add some users to it, including user t1 (or any user, just remember their username) Create a new role 'cohortmanager', based on manager (Admin -> Users -> Define roles) and make sure to check the "User" box next to the "Context types where this role may be assigned" option. Now, via the cohorts role assign page (Admin -> Users -> Assign user roles to cohort), assign the cohortmanager role to the t1 user for that cohort. Now, go back to define roles via system admin Delete the 'cohort manager' role Now, run the sync task: php admin/tool/task/cli/schedule_task.php --execute=\\tool_cohortroles\\task\\cohort_role_sync Verify you see a bunch of errors Now, checkout HEAD (git checkout master or git checkout MOODLE_38_STABLE, etc) Run the upgrade Verify the upgrade runs without any errors Now, run the following query (change table prefix as needed): select t.*, r.id from mdl_tool_cohortroles t left join mdl_role r on t.roleid = r.id where r.id is null; Verify there are 0 results; Now, run the following query (change table prefix as needed): select ra.*, r.id from mdl_role_assignments ra left join mdl_role r on ra.roleid = r.id where r.id is null; Verify there are 0 results; Now, run the sync task: php admin/tool/task/cli/schedule_task.php --execute=\\tool_cohortroles\\task\\cohort_role_sync Verify the task completes without any errors Test 2: Deleting the cohort role assignment after syncing Clone new site (mdk create -v BRANCH) Checkout last week's weekly: Master: git checkout 8cf4c97217230e74 38: git checkout 773b1f738fa 37: git checkout fcc93935bea Install the site Create a cohort and add some users to it, including user t1 (or any user, just remember their username) Create a new role 'cohortmanager', based on manager (Admin -> Users -> Define roles) and make sure to check the "User" box next to the "Context types where this role may be assigned" option. Now, via the cohorts role assign page (Admin -> Users -> Assign user roles to cohort), assign the cohortmanager role to the t1 user for that cohort. Now, run the sync task: php admin/tool/task/cli/schedule_task.php --execute=\\tool_cohortroles\\task\\cohort_role_sync Delete the 'cohort manager' role Now, run the sync task: php admin/tool/task/cli/schedule_task.php --execute=\\tool_cohortroles\\task\\cohort_role_sync You may see some errors. If so, that's ok. Now, checkout HEAD (git checkout master or git checkout MOODLE_38_STABLE, etc) Run the upgrade Verify the upgrade runs without any errors Now, run the following query (change table prefix as needed): select t.*, r.id from mdl_tool_cohortroles t left join mdl_role r on t.roleid = r.id where r.id is null; Verify there are 0 results; Now, run the following query (change table prefix as needed): select ra.*, r.id from mdl_role_assignments ra left join mdl_role r on ra.roleid = r.id where r.id is null; Verify there are 0 results; Now, run the sync task: php admin/tool/task/cli/schedule_task.php --execute=\\tool_cohortroles\\task\\cohort_role_sync Verify the task completes without any errors
    • Affected Branches:
      MOODLE_38_STABLE
    • Fixed Branches:
      MOODLE_37_STABLE, MOODLE_38_STABLE
    • Pull from Repository:
    • Pull 3.8 Branch:
    • Pull Master Branch:
      MDL-67458-master

      Description

      1. Create a new role that can be assigned in the user context
      2. Create a cohort and add some users to it
      3. Assign the role from step 1 to users in the cohort
      4. Delete the role from step 1
      5. Run the cohort_role_sync task
        • php admin/tool/task/cli/schedule_task.php --execute=\\tool_cohortroles\\task
          cohort_role_sync
      6. Boom

        Attachments

          Activity

            People

            Assignee:
            jaked Jake Dallimore
            Reporter:
            cameron1729 cameron1729
            Peer reviewer:
            cameron1729
            Integrator:
            Andrew Nicols
            Tester:
            Gladys Basiana
            Participants:
            Component watchers:
            Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona)
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              13/Jan/20

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 7 hours
                7h