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

email_to_user() adds $CFG->dataroot redundantly

XMLWordPrintable

    • MOODLE_35_STABLE, MOODLE_36_STABLE, MOODLE_37_STABLE, MOODLE_38_STABLE, MOODLE_39_STABLE
    • MOODLE_37_STABLE, MOODLE_38_STABLE
    • Hide
      1. Use testemailattachment.php and add this line in the code after $message = 'Test attachment path';
        .
      2. $user->email = "<your_email_address>";
      3. Copy the file in the moodle directory.
      4. Change directory into the moodle directory.
      5. Execute command,
      6. $ php testemailattachement.php
      7. File will be attached with email recieved with the patched code.
      Show
      Use testemailattachment.php and add this line in the code after $message = 'Test attachment path'; . $user->email = "<your_email_address>"; Copy the file in the moodle directory. Change directory into the moodle directory. Execute command, $ php testemailattachement.php File will be attached with email recieved with the patched code.

      When plugins using localcache directory to store a file for attchment, $CFG->dataroot is unconditionally added to the path with email_to_user() in lib/moodlelib.php by which the path becoming non-existent one.

      Possible case is some plugin creating temporary directory with 'make_request_directory()' which creates directory in localcache which means the path inclued $CFG->dataroot.

      'email_to_user()' function in lib/moodlelib.php only checks if $attachmentpath inclues $CFG->temppath and does not consider the situation which includes $CFG->dataroot.

      I will add a patch which safely checks $attachmentpath already inclueds $CFG-dataroot and if so, does not add $CFG-dataroot.

      Added 2nd May 2020

      During the process of making a patch, experts adviced me to add more allowed paths, so I added them.

      Testing instructions

      Use testemailattachment.php and set like this in the code.

      $user->email = "<your_email_address>";

      Copy the file in the moodle directory.
      Change directory into the moodle directory.
      Execute command,

      $ php testemailattachement.php

      File will not be attached with email recieved with the original code.
      File will be attached with email recieved with the patched code.

            intrajp Shintaro Fujiwara
            intrajp Shintaro Fujiwara
            Paul Holden Paul Holden
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Anna Carissa Sadia Anna Carissa Sadia
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 6 hours, 10 minutes
                6h 10m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.