Skip to content

Commit 93c6db1

Browse files
authored
Merge pull request #235 from aula-app/dev
Release dev -> staging
2 parents 10e23a9 + 536f835 commit 93c6db1

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

classes/models/Media.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,22 +309,23 @@ public function addMedia($name, $path, $type, $system_type, $filename, $status =
309309
$status = intval($status);
310310
$type = intval($type);
311311
$system_type = intval($system_type);
312+
$result = [];
312313

313314
// if it is an avatar
314315
if ($system_type == 0) {
315316
$stmt = $this->db->query('SELECT filename FROM ' . $this->db->au_media . ' WHERE updater_id = :updater_id');
316317
$this->db->bind(':updater_id', $updater_id); // id of the user doing the update (i.e. admin)
317318

318319
try {
319-
$action = $this->db->execute(); // do the query
320-
$has_avatar = count($this->db->resultSet()) > 0;
321-
$old_avatar = $this->db->resultSet()[0];
320+
$result = $this->db->resultSet(); // do the query
321+
$has_avatar = !empty($result);
322322
} catch (Exception $e) {
323323
$err = true;
324324
}
325325
}
326326

327327
if ($has_avatar) {
328+
$old_avatar = $result[0];
328329
unlink($this->files_dir . '/' . $old_avatar["filename"]);
329330
$stmt = $this->db->query('DELETE FROM ' . $this->db->au_media . ' WHERE updater_id = :updater_id');
330331
$this->db->bind(':updater_id', $updater_id); // id of the user doing the update (i.e. admin)

controllers/upload.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
throw new RuntimeException('Invalid instance code');
1515
}
1616

17-
$db = new Database($headers['aula-instance-code']);
17+
$db = new Database($code);
1818
$crypt = new Crypt($cryptFile);
1919
$syslog = new Systemlog($db);
2020
$jwt = new JWT($instances[$code]['jwt_key'], $db, $crypt, $syslog);
21-
$media = new Media($db, $crypt, $syslog, $filesDir);
21+
$media = new Media($db, $crypt, $syslog, $filesDir . '/' . $code);
2222

2323
$check_jwt = $jwt->check_jwt();
2424

@@ -74,6 +74,10 @@
7474
throw new RuntimeException('Invalid file format.');
7575
}
7676

77+
if (!file_exists($filesDir . '/' . $code)) {
78+
mkdir($filesDir . '/' . $code);
79+
}
80+
7781
$random_part = bin2hex(random_bytes(8)) . number_format(microtime(true), 0, '', '');
7882
$file_name = sha1_file($_FILES['file']['tmp_name']) . $random_part . "." . $ext;
7983
$file_path = sprintf($filesDir . '/' . $code . '/%s', $file_name);

0 commit comments

Comments
 (0)