Commit a3d82f91 authored by Iaki Arenaza's avatar Iaki Arenaza Committed by Nigel McNie
Browse files

MAH-3317 Cannot Login to Mahara from Moodle When Picture is added to Moodle Profile

Instead of using a fixed platform-specific path for temporary image files,
create a new temporary directory inside dataroot and place temporary files

In addition to it, make sure we prefix the profile icon file names with 'mpi_'
(stands for mnet profile icon) to prevent clashes (as per Nigel's suggestion)
and check the return result from file_put_contents() for errors (but otherwise
and continue gracefully if the file can't be written, as Nigel suggested on the
bug tracker).

While in this particular case the related code takes care of the temporary
files, if we are going to have a temp directory, it might be good to have a
cronjob to clean it out (We should file a bug to remind us to do that)

[Minor whitespace fixups by Nigel]
Signed-off-by: default avatarIñaki Arenaza <>
Signed-off-by: default avatarNigel McNie <>
parent 3c44a80e
......@@ -186,6 +186,7 @@ $string['rm'] = 'RM Real Player Movie';
// Profile icons
$string['cantcreatetempprofileiconfile'] = 'Could not write temporary profile icon image in %s';
$string['profileiconsize'] = 'Profile Icon Size';
$string['profileicons'] = 'Profile Icons';
$string['Default'] = 'Default';
......@@ -271,11 +271,11 @@ class AuthXmlrpc extends Auth {
$imageobject = (object)$client->response;
$u = preg_replace('/[^A-Za-z0-9 ]/', '', $user->username);
$filename = '/tmp/'.intval($this->instanceid).'_'.$u;
$filename = get_config('dataroot') . 'temp/mpi_' . intval($this->instanceid) . '_' . $u;
if (array_key_exists('f1', $client->response)) {
$imagecontents = base64_decode($client->response['f1']);
file_put_contents($filename, $imagecontents);
if (file_put_contents($filename, $imagecontents)) {
$imageexists = false;
$icons = false;
......@@ -350,6 +350,10 @@ class AuthXmlrpc extends Auth {
else {
log_warn(get_string('cantcreatetempprofileiconfile', 'artefact.file', $filename));
......@@ -149,6 +149,7 @@ function ensure_sanity() {
!check_dir_exists(get_config('dataroot') . 'smarty/compile') ||
!check_dir_exists(get_config('dataroot') . 'smarty/cache') ||
!check_dir_exists(get_config('dataroot') . 'sessions') ||
!check_dir_exists(get_config('dataroot') . 'temp') ||
!check_dir_exists(get_config('dataroot') . 'langpacks') ||
!check_dir_exists(get_config('dataroot') . 'htmlpurifier')) {
throw new ConfigSanityException(get_string('couldnotmakedatadirectories', 'error'));
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment