mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-44257 message: added test to make sure the stored file still exists
This commit is contained in:
parent
68e50bc80b
commit
9a2c52571e
@ -5888,7 +5888,16 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml = '',
|
||||
} else {
|
||||
require_once($CFG->libdir.'/filelib.php');
|
||||
$mimetype = mimeinfo('type', $attachname);
|
||||
$mail->addAttachment($CFG->dataroot .'/'. $attachment, $attachname, 'base64', $mimetype);
|
||||
|
||||
$attachmentpath = $attachment;
|
||||
|
||||
// If the attachment is a full path to a file in the tempdir, use it as is,
|
||||
// otherwise assume it is a relative path from the dataroot (for backwards compatibility reasons).
|
||||
if (strpos($attachmentpath, $CFG->tempdir) !== 0) {
|
||||
$attachmentpath = $CFG->dataroot . '/' . $attachmentpath;
|
||||
}
|
||||
|
||||
$mail->addAttachment($attachmentpath, $attachname, 'base64', $mimetype);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -760,6 +760,11 @@ class core_messagelib_testcase extends advanced_testcase {
|
||||
$email = reset($emails);
|
||||
$this->assertTrue(strpos($email->body, 'Content-Disposition: attachment;') !== false);
|
||||
$this->assertTrue(strpos($email->body, 'emailtest.txt') !== false);
|
||||
|
||||
// Check if the stored file still exists after remove the temporary attachment.
|
||||
$storedfileexists = $fs->file_exists($filerecord['contextid'], $filerecord['component'], $filerecord['filearea'],
|
||||
$filerecord['itemid'], $filerecord['filepath'], $filerecord['filename']);
|
||||
$this->assertTrue($storedfileexists);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,8 +77,7 @@ class message_output_email extends message_output {
|
||||
} else {
|
||||
// Copy attachment file to a temporary directory and get the file path.
|
||||
$attachment = $eventdata->attachment->copy_content_to_temp();
|
||||
// Function email_to_user() adds $CFG->dataroot to file path, so removing it here.
|
||||
$attachment = str_replace($CFG->dataroot, '', $attachment);
|
||||
|
||||
// Get attachment file name.
|
||||
$attachname = clean_filename($eventdata->attachname);
|
||||
}
|
||||
@ -88,8 +87,8 @@ class message_output_email extends message_output {
|
||||
$eventdata->fullmessagehtml, $attachment, $attachname);
|
||||
|
||||
// Remove an attachment file if any.
|
||||
if (!empty($attachment) && file_exists($CFG->dataroot.'/'.$attachment)) {
|
||||
unlink($CFG->dataroot.'/'.$attachment);
|
||||
if (!empty($attachment) && file_exists($attachment)) {
|
||||
unlink($attachment);
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
Loading…
x
Reference in New Issue
Block a user