Skip to content

Commit b5228d3

Browse files
committed
Fix upload image issue #2919
1 parent 58beaab commit b5228d3

File tree

4 files changed

+14
-19
lines changed

4 files changed

+14
-19
lines changed

app/Domain/Files/Repositories/Files.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function addFile($values, $module): false|string
6161
return $this->db->database->lastInsertId();
6262
}
6363

64-
public function getFile($id): mixed
64+
public function getFile($id): array|false
6565
{
6666

6767
$sql = 'SELECT

app/Domain/Setting/Repositories/Setting.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(DbCore $db, SettingCache $cache)
2929
/**
3030
* @return false|mixed
3131
*/
32-
public function getSetting($type): mixed
32+
public function getSetting($type, $default = false): mixed
3333
{
3434
if ($this->checkIfInstalled() === false) {
3535
return false;
@@ -70,7 +70,7 @@ public function getSetting($type): mixed
7070
$this->cache->set($type, false);
7171

7272
// TODO: This needs to return null or throw an exception if the setting doesn't exist.
73-
return false;
73+
return $default;
7474
}
7575

7676
public function saveSetting($type, $value): bool

app/Domain/Setting/Services/Setting.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ public function saveSetting($key, $value): bool
7979
*
8080
* @api
8181
*/
82-
public function getSetting($key): mixed
82+
public function getSetting($key, $default = false): mixed
8383
{
84-
return $this->settingsRepo->getSetting($key);
84+
return $this->settingsRepo->getSetting($key, $default);
8585
}
8686

8787
/**

app/Domain/Users/Repositories/Users.php

+9-14
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class Users
3838
public function __construct(
3939
protected Environment $config,
4040
protected DbCore $db,
41-
protected Avatarcreator $avatarcreator
41+
protected Avatarcreator $avatarcreator,
42+
protected Files $files
4243
) {
4344

4445
$this->db = $db;
@@ -551,16 +552,16 @@ public function setPicture(array $_FILE, $id): void
551552
$values = $stmn->fetch();
552553
$stmn->closeCursor();
553554

554-
$files = app()->make(files::class);
555-
556555
if (isset($values['profileId']) && $values['profileId'] > 0) {
557-
$file = $files->getFile($values['profileId']);
558-
$img = 'userdata/'.$file['encName'].$file['extension'];
559556

560-
$files->deleteFile($values['profileId']);
557+
$file = $this->files->getFile($values['profileId']);
558+
if (is_array($file)) {
559+
$img = 'userdata/'.$file['encName'].$file['extension'];
560+
$this->files->deleteFile($values['profileId']);
561+
}
561562
}
562563

563-
$lastId = $files->upload($_FILE, 'user', $id, true, 200, 200);
564+
$lastId = $this->files->upload($_FILE, 'user', $id, true, 200, 200);
564565

565566
if (isset($lastId['fileId'])) {
566567
$sql = 'UPDATE
@@ -580,11 +581,6 @@ public function setPicture(array $_FILE, $id): void
580581
}
581582
}
582583

583-
/**
584-
* @return string[]|SVG
585-
*
586-
* @throws BindingResolutionException
587-
*/
588584
/**
589585
* @return string[]|SVG
590586
*
@@ -614,8 +610,7 @@ public function getProfilePicture($id): array|SVG
614610
// If user uploaded return uploaded file
615611
if (! empty($value['profileId'])) {
616612

617-
$files = app()->make(Files::class);
618-
$file = $files->getFile($value['profileId']);
613+
$file = $this->files->getFile($value['profileId']);
619614

620615
if ($file) {
621616
$filePath = $file['encName'].'.'.$file['extension'];

0 commit comments

Comments
 (0)