Moodle
  1. Moodle
  2. MDL-27432

php fatal error in database activity if php GD extension isnt installed

    Details

    • Database:
      Any
    • Testing Instructions:
      Hide

      Check that your debug message level is set to "Developer". Also check the environment page and check that you do NOT have the GD extension installed.

      As a teacher create a new database activity. It will complain you have no fields defined. Elect to use a preset collection of fields. Select image gallery.
      As a student upload an image through the activity (add entry -> upload an image -> "save and view")

      A debug message saying

      Unknown exception related to local files (imagecreatefromstring() doesnt exist. The PHP extension "GD" must be installed for image conversion.)
      

      and providing a stack trace should be displayed. The continue link should take you to your entry.

      Note that although the fatal error has been avoided the absence of the GD php extension means that thumbnails cannot be created. If you go to "view list" youll see one or more broken images. This is expected behaviour.

      Show
      Check that your debug message level is set to "Developer". Also check the environment page and check that you do NOT have the GD extension installed. As a teacher create a new database activity. It will complain you have no fields defined. Elect to use a preset collection of fields. Select image gallery. As a student upload an image through the activity (add entry -> upload an image -> "save and view") A debug message saying Unknown exception related to local files (imagecreatefromstring() doesnt exist. The PHP extension "GD" must be installed for image conversion.) and providing a stack trace should be displayed. The continue link should take you to your entry. Note that although the fatal error has been avoided the absence of the GD php extension means that thumbnails cannot be created. If you go to "view list" youll see one or more broken images. This is expected behaviour.
    • Affected Branches:
      MOODLE_20_STABLE, MOODLE_21_STABLE, MOODLE_22_STABLE, MOODLE_23_STABLE
    • Fixed Branches:
      MOODLE_21_STABLE, MOODLE_22_STABLE
    • Pull Master Branch:
      MDL-27432_gd_error
    • Rank:
      17109

      Description

      to reproduce create a new database activity. It will complain you have no fields defined. Elect to use a preset collection of fields. Select image gallery. As a student upload an image through the activity.

      I get the following php error Fatal error: Call to undefined function imagecreatefromstring() in /var/www/moodle/lib/filestorage/file_storage.php on line 994

      Oddly the teacher seems to be able to see the uploaded image but the student cant.

      Anyhow, we either need to make GD a firm requirement of Moodle (preventing install unless its present) or the database activity needs to avoid the error should GD not be present. Currently the environment does suggest the GD extension but suggesting it then throwing errors is pretty crappy.

        Activity

        Hide
        Andrew Davis added a comment -

        Added master branch and updated testing instructions. Ill add other branches after peer review.

        Show
        Andrew Davis added a comment - Added master branch and updated testing instructions. Ill add other branches after peer review.
        Hide
        Martin Dougiamas added a comment -

        isn't GD2 standard in PHP?

        Show
        Martin Dougiamas added a comment - isn't GD2 standard in PHP?
        Hide
        Andrew Davis added a comment -

        It appears not. Running stock standard Ubuntu I've run into this problem the last 2 times we've run QA.

        The actual error isn't super serious. The database activity just can't generate thumbnails. However, if a fatal error is allowed to be generated the user gets a blank page (or an error message if they have debug set to "developer") when they try to add a database entry. It's just a bit crappy as the only preset set of fields we provide is image gallery so we could be creating a situation where a new user exploring Moodle is channeled into encountering this problem.

        Show
        Andrew Davis added a comment - It appears not. Running stock standard Ubuntu I've run into this problem the last 2 times we've run QA. The actual error isn't super serious. The database activity just can't generate thumbnails. However, if a fatal error is allowed to be generated the user gets a blank page (or an error message if they have debug set to "developer") when they try to add a database entry. It's just a bit crappy as the only preset set of fields we provide is image gallery so we could be creating a situation where a new user exploring Moodle is channeled into encountering this problem.
        Hide
        Andrew Davis added a comment -

        Adding 2.1 and 2.0 branches for if we go ahead with this change.

        Show
        Andrew Davis added a comment - Adding 2.1 and 2.0 branches for if we go ahead with this change.
        Hide
        Sam Hemelryk added a comment -

        Hi Andrew,

        The changes look good and this gets my +1.

        Just noting that the GD library has been bundled with PHP since 4.3 however in some distributions the default configuration may not have it enabled.
        Also worth noting is that it is already being checked in server environment checks so for any sites lacking the GD extension it would be highlighted during installation and upgrade hopefully.

        Cheers
        Sam

        Show
        Sam Hemelryk added a comment - Hi Andrew, The changes look good and this gets my +1. Just noting that the GD library has been bundled with PHP since 4.3 however in some distributions the default configuration may not have it enabled. Also worth noting is that it is already being checked in server environment checks so for any sites lacking the GD extension it would be highlighted during installation and upgrade hopefully. Cheers Sam
        Hide
        Andrew Davis added a comment -

        Adding a 2.2 branch.

        During installation and upgrade you do get a warning about the GD extension not being installed/enabled. Sadly that installation screen is likely to be a distant memory by the time you reach the database activity.

        Show
        Andrew Davis added a comment - Adding a 2.2 branch. During installation and upgrade you do get a warning about the GD extension not being installed/enabled. Sadly that installation screen is likely to be a distant memory by the time you reach the database activity.
        Hide
        Aparup Banerjee added a comment -

        Thanks for the fix Andrew.

        I've integrated that into 2.1.x, 2.2.x and master. I've left it out of 2.0.x (security support phase) as its a non-security issue and is minor.

        Show
        Aparup Banerjee added a comment - Thanks for the fix Andrew. I've integrated that into 2.1.x, 2.2.x and master. I've left it out of 2.0.x (security support phase) as its a non-security issue and is minor.
        Hide
        Rajesh Taneja added a comment -

        Works Great
        Thanks for fixing this, Andrew.

        Show
        Rajesh Taneja added a comment - Works Great Thanks for fixing this, Andrew.
        Hide
        Eloy Lafuente (stronk7) added a comment -

        Yes, you did it!

        Now your code is part of the best weeklies released ever, many thanks!

        Closing, ciao

        Show
        Eloy Lafuente (stronk7) added a comment - Yes, you did it! Now your code is part of the best weeklies released ever, many thanks! Closing, ciao

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: