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

Conditional availability: empty availability should be saved as null

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.7.2
    • Fix Version/s: 2.7.3
    • Component/s: Conditional activities
    • Labels:
    • Testing Instructions:
      Hide

      NOTE: In order to do this test you will need access to query the database.

      0. Ensure availability is enabled.

      1. On a test course, create a new Label. Enter some text and save changes.

      2. Run the following SQL query, replacing prefix with your database prefix, and '999' with the cmid of your label (you can find that out by hovering over 'Edit settings' link):

      SELECT * FROM prefix_course_modules WHERE id=999 AND availability IS NULL
      

      EXPECTED: This should show the course_modules row for the label you just added.
      BEFORE FIX: Prior to this fix, the query returned nothing because the availability value was set to:

      {"op":"&","c":[],"showc":[]}
      

      3. Edit settings for the label. Expand 'Restrict access' and set a date restriction. Save changes.
      EXPECTED: The date restriction should be correctly displayed by the label.

      4. Edit settings again. Expand 'Restrict access' and delete the date restriction. Save changes.
      EXPECTED: No restrictions indicated.

      5. Run the SQL query again from step 2.
      EXPECTED: This should also return the row (i.e. availability is null again after the update).

      Show
      NOTE: In order to do this test you will need access to query the database. 0. Ensure availability is enabled. 1. On a test course, create a new Label. Enter some text and save changes. 2. Run the following SQL query, replacing prefix with your database prefix, and '999' with the cmid of your label (you can find that out by hovering over 'Edit settings' link): SELECT * FROM prefix_course_modules WHERE id=999 AND availability IS NULL EXPECTED: This should show the course_modules row for the label you just added. BEFORE FIX: Prior to this fix, the query returned nothing because the availability value was set to: {"op":"&","c":[],"showc":[]} 3. Edit settings for the label. Expand 'Restrict access' and set a date restriction. Save changes. EXPECTED: The date restriction should be correctly displayed by the label. 4. Edit settings again. Expand 'Restrict access' and delete the date restriction. Save changes. EXPECTED: No restrictions indicated. 5. Run the SQL query again from step 2. EXPECTED: This should also return the row (i.e. availability is null again after the update).
    • Affected Branches:
      MOODLE_27_STABLE
    • Fixed Branches:
      MOODLE_27_STABLE
    • Pull Master Branch:
      MDL-47322-master

      Description

      When you turn on the availability system, every time you save changes to an activity, it saves a JSON structure for the availability value for that activity - even if you haven't added any availability conditions.

      While this doesn't break anything, it wastes database space and CPU time when processing availability (as there are shortcuts for when it's null).

      The solution is quite simple, it should check if the structure is 'empty' before saving it.

      I think this should probably be fixed in 2.7 as it is a bug, although that does mean I'll have to write the unit tests slightly differently (there were enhancements in 2.8 to the way you can write availability unit tests).

      It would also be quite easy to make a database update to fix existing instances but as this doesn't cause any real harm and will go away gradually as people edit things, probably not worth the hassle.

        Attachments

          Activity

            People

            • Assignee:
              quen Sam Marshall
              Reporter:
              quen Sam Marshall
              Peer reviewer:
              Sam Hemelryk
              Integrator:
              Dan Poltawski
              Tester:
              Ankit Agarwal
              Participants:
              Component watchers:
              Sam Marshall, Jake Dallimore, Jun Pataleta, Ryan Wyllie
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                10/Nov/14