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

"add_moduleinfo" can change value of db field "intro" after a plugin has set it

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.9.8, 3.0.6, 3.1, 3.2
    • Fix Version/s: 3.1.4, 3.2.1
    • Component/s: Course
    • Labels:
    • Testing Instructions:
      Hide

      Test 1
      test that you can create and edit modules with the descriptions and without, use different formats for descriptions (disable atto editor in your preferences)

      Test 2

      To test this I added the following code to the function book_add_instance in mod/book/lib.php line 87.
      $data->intro = '<p>Everything is awesome!</p>';

      Followed by:
      1. Log into moodle as an admin.
      2. Navigating to a course.
      3. Turn editing on.
      4. Click '+ Add an activity or a resource'.
      5. From the Resources group select Book then click Add.
      6. When the form to edit the book loads provide a name.
      7. Add a description then click Save and return to course.
      8. Find the new Book resource and click Edit then click Edit settings.
      9. Verify that the value Everything is awesome! appears in the description.

      To test the value of intro when a mod is updated add the following code to the function book_update_instance function in mod/book/lib.php line 107.
      $data->intro = "<p>Everything is cool when you're part of a team!</p>";

      Followed by:
      1. Navigating to the course where an existing book resource exists.
      2. Turn editing on.
      3. For the book mod in the course click on Edit then Edit settings.
      4. Add some random text to the description field i.e. This will not save!
      5. Click Save and return to course.
      6. Find the book mod that was recently updated.
      7. Click on Edit then Edit settings.
      8. Verify that the text 'Everything is cool when you're part of team!' appears.

      (see https://moodle.org/mod/forum/discuss.php?d=341003#p1374406)

      Show
      Test 1 test that you can create and edit modules with the descriptions and without, use different formats for descriptions (disable atto editor in your preferences) Test 2 To test this I added the following code to the function book_add_instance in mod/book/lib.php line 87. $data->intro = '<p>Everything is awesome!</p>'; Followed by: 1. Log into moodle as an admin. 2. Navigating to a course. 3. Turn editing on. 4. Click '+ Add an activity or a resource'. 5. From the Resources group select Book then click Add. 6. When the form to edit the book loads provide a name. 7. Add a description then click Save and return to course. 8. Find the new Book resource and click Edit then click Edit settings. 9. Verify that the value Everything is awesome! appears in the description. To test the value of intro when a mod is updated add the following code to the function book_update_instance function in mod/book/lib.php line 107. $data->intro = "<p>Everything is cool when you're part of a team!</p>"; Followed by: 1. Navigating to the course where an existing book resource exists. 2. Turn editing on. 3. For the book mod in the course click on Edit then Edit settings. 4. Add some random text to the description field i.e. This will not save! 5. Click Save and return to course. 6. Find the book mod that was recently updated. 7. Click on Edit then Edit settings. 8. Verify that the text 'Everything is cool when you're part of team!' appears. (see https://moodle.org/mod/forum/discuss.php?d=341003#p1374406 )
    • Workaround:
      Hide

      At the moment, if you want to change what is in the "intro" field in your "add_instance" function, you will either have to:

      1. Write your own intro form functions so that the core ones are not used in add_moduleinfo(), or.
      2. create an event to trigger after the module creation and change the intro field there.
      Show
      At the moment, if you want to change what is in the "intro" field in your "add_instance" function, you will either have to: Write your own intro form functions so that the core ones are not used in add_moduleinfo(), or. create an event to trigger after the module creation and change the intro field there.
    • Affected Branches:
      MOODLE_29_STABLE, MOODLE_30_STABLE, MOODLE_31_STABLE, MOODLE_32_STABLE
    • Fixed Branches:
      MOODLE_31_STABLE, MOODLE_32_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-56301-master

      Description

      See discussion https://moodle.org/mod/forum/discuss.php?d=341003

      Essentially, when a plugin's "add_instance" function is called, it might decide to change the value of the "intro" field before creating the database record. When it does, after the "add_instance" function completes, the core "add_moduleinfo" may change it back to whatever was originally supplied in the form.

      This happens around lines 145 - 152, where the embedded links and files are saved. At that point, this function also rewrites the "intro" field with the modified intro text. The problem is that it relies on what was provided from the form, which may have been modified by the plugin's "add_instance" function. I believe it must be necessary to reload the module data with the saved record, to ensure that the plugin's data is respected.

        Attachments

          Activity

            People

            • Votes:
              1 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                9/Jan/17