From 9330ccd3ef8a552afd990b11936b3cf6ad31ddf5 Mon Sep 17 00:00:00 2001 From: Robert Lyon Date: Tue, 24 Dec 2019 07:42:59 +1300 Subject: [PATCH] Bug 1857366: Allow save_file() to make profileicon rather than image If we specify the artefacttype = 'profileicon' behatnotneeded Change-Id: I20aaa0c5176427abab3564fdf7c267617e6e81b7 Signed-off-by: Robert Lyon --- htdocs/artefact/file/lib.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/htdocs/artefact/file/lib.php b/htdocs/artefact/file/lib.php index f5e6e1d84e..290df2ddc0 100644 --- a/htdocs/artefact/file/lib.php +++ b/htdocs/artefact/file/lib.php @@ -1143,6 +1143,10 @@ class ArtefactTypeFile extends ArtefactTypeFileBase { return "artefact/file/originals/" . ($id % 256); } + public static function get_profileicon_file_directory($id) { + return "artefact/file/profileicons/originals/" . ($id % 256); + } + public function get_path($data=array()) { if (!empty($this->externalfilesystem)) { return $this->externalfilesystem->get_path($this); @@ -1174,6 +1178,9 @@ class ArtefactTypeFile extends ArtefactTypeFileBase { $data->filetype = $imageinfo['mime']; $data->width = $imageinfo[0]; $data->height = $imageinfo[1]; + if (isset($data->artefacttype) && $data->artefacttype == 'profileicon') { + return new ArtefactTypeProfileicon(0, $data); + } return new ArtefactTypeImage(0, $data); } @@ -1227,7 +1234,12 @@ class ArtefactTypeFile extends ArtefactTypeFileBase { $f->commit(); $id = $f->get('id'); - $newdir = $dataroot . self::get_file_directory($id); + if (isset($data->artefacttype) && $data->artefacttype == 'profileicon') { + $newdir = $dataroot . self::get_profileicon_file_directory($id); + } + else { + $newdir = $dataroot . self::get_file_directory($id); + } check_dir_exists($newdir); $newname = $newdir . '/' . $id; if (!rename($pathname, $newname)) { -- GitLab