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

PHP notice and warning when editing a course with course tags disabled.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.8, 3.8.1
    • Fix Version/s: 3.8.4
    • Component/s: Course, Tags
    • Labels:
    • Testing Instructions:
      Hide
      1. Make sure debugging is turned on. (Site administration > Development > Debugging)
      2. Navigate to Site Administration -> Advanced features
      3. Make sure tags functionality is enabled
      4. Navigate to Site Administration -> Appearance -> Manage tags
      5. In the tags area disable the Courses row by pressing the eyeball icon.
      6. Create a course
      7. Navigate to your course 
      8. Click on edit settings 
      9. Save and display
      10. Confirm that there is no debug message
      Show
      Make sure debugging is turned on. (Site administration > Development > Debugging) Navigate to Site Administration -> Advanced features Make sure tags functionality is enabled Navigate to Site Administration -> Appearance -> Manage tags In the tags area disable  the Courses row by pressing the eyeball icon. Create a course Navigate to your course  Click on edit settings  Save and display Confirm that there is no debug message
    • Affected Branches:
      MOODLE_38_STABLE
    • Fixed Branches:
      MOODLE_38_STABLE
    • Pull from Repository:
    • Pull 3.8 Branch:
    • Pull Master Branch:
      MDL-67773-master

      Description

      If tags are enabled site wide (site administration -> advanced features), but are disabled for courses (site administration -> appearance -> manage tags), and course settings are saved, you get a warning and notice because $data ->tags is undefined. 

       

      Steps to reproduce: 

      1. Turn on debugging
      2. Go to Site administration -> Advanced features 
      3. Make sure tags functionality is enabled
      4. Go to Site administration -> Appearance -> Manage tags 
      5. In the tags area, find the Courses row and disable it
      6. Create a course and go to it
      7. Edit setting
      8. Save and display

      Output: 

       

      Notice: Undefined property: stdClass::$tags in /var/www/html/course/lib.php on line 2570
       
      Warning: array_values() expects parameter 1 to be array, null given in /var/www/html/course/lib.php on line 2570
       
      Notice: Undefined property: stdClass::$tags in /var/www/html/course/lib.php on line 2571

       

       

      Expected: 

      Not see a notice or warning when saving a course. 

       

      Related issue: 

      https://tracker.moodle.org/browse/MDL-66446

      Looks like this was reported and partially fixed before. That fix added a check to the if statement in the code on line 2568 in course/lib.php for the site wide tags setting, but we are still missing a solution for the other way to disable course tags (setting under site administration -> appearance -> manage tags). 

       

      Potential solution: 

      Replace the check for tags being enabled on line 2568 of course/lib.php  

      } else if ($field == 'tags' && !empty($CFG->usetags)) {

      with

      } else if ($field == 'tags' && isset($data->tags)) {

      or potentially add this check to the current line if the other part is still needed for something. Or maybe add something else so that it includes a check for the manage tags setting. 

      The reasoning behind this suggestion though is that further below in the same function (update_course), the part that actually updates the tags in the course is wrapped in a check for isset($data->tags). So it would make sense that the code checking if it should add tags to $updatedfields would also use the same criteria as the part that actually updates them. 

       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              radzisze Anthony Radziszewski
              Reporter:
              radzisze Anthony Radziszewski
              Peer reviewer:
              Amaia Anabitarte
              Integrator:
              Adrian Greeve
              Tester:
              Janelle Barcega
              Participants:
              Component watchers:
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona)
              Votes:
              5 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

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

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 hour, 30 minutes
                  1h 30m