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

The message_email does not cleanup attachment

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide
      1. Run unit tests on lib/tests/messagelib_test.php.
      2. Make sure there's no errors.

      set $CFG->tempdir to a location outside of the moodle dataroot

      Award someone a badge, login as that person and see the message was received with a badge image as an attachment.

      Show
      Run unit tests on lib/tests/messagelib_test.php. Make sure there's no errors. set $CFG->tempdir to a location outside of the moodle dataroot Award someone a badge, login as that person and see the message was received with a badge image as an attachment.
    • Affected Branches:
      MOODLE_26_STABLE
    • Fixed Branches:
      MOODLE_26_STABLE, MOODLE_27_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-44257-master

      Description

      message_output_email::send_message has this line:

      @unlink($attachment);
      

      If we remove the @ (Really shouldn't be used anyways) and then run the associated unit test, test_message_attachment_send, we get:

      PHPUnit_Framework_Error_Warning : unlink(/temp/files/tempup_XnFHaY): No such file or directory
      #0 [internal function]: PHPUnit_Util_ErrorHandler::handleError(2, 'unlink(/temp/fi...', '/moodle...', 91, Array)
      #1 /moodle//message/output/email/message_output_email.php(91): unlink('/temp/files/tem...')
      #2 /moodle//lib/messagelib.php(225): message_output_email->send_message(Object(stdClass))
      #3 /moodle//lib/tests/messagelib_test.php(184): message_send(Object(stdClass))
      #4 [internal function]: core_messagelib_testcase->test_message_attachment_send()
      #5 /moodle//vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php(983): ReflectionMethod->invokeArgs(Object(core_messagelib_testcase), Array)
      #6 /moodle//vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php(838): PHPUnit_Framework_TestCase->runTest()
      #7 /moodle//lib/phpunit/classes/advanced_testcase.php(80): PHPUnit_Framework_TestCase->runBare()
      #8 /moodle//vendor/phpunit/phpunit/PHPUnit/Framework/TestResult.php(648): advanced_testcase->runBare()
      #9 /moodle//vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php(783): PHPUnit_Framework_TestResult->run(Object(core_messagelib_testcase))
      #10 /moodle//vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php(775): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))
      #11 /moodle//vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php(745): PHPUnit_Framework_TestSuite->runTest(Object(core_messagelib_testcase), Object(PHPUnit_Framework_TestResult))
      #12 /moodle//vendor/phpunit/phpunit/PHPUnit/TextUI/TestRunner.php(349): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult), '/::test_message...', Array, Array, false)
      #13 /moodle//vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php(176): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array)
      #14 /private/var/folders/6w/_y8dc1jd0kd7n1v1lj17x4w00000gn/T/ide-phpunit.php(268): PHPUnit_TextUI_Command->run(Array, true)
      #15 /private/var/folders/6w/_y8dc1jd0kd7n1v1lj17x4w00000gn/T/ide-phpunit.php(506): IDE_Base_PHPUnit_TextUI_Command::main()
      #16 {main}
      

      Which shows us that $attachment is not an absolute path, but a relative path.

      So, suppressing any errors made phpunit pass and now we are not deleting anything or worse, deleting something we shouldn't be deleting.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

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