Moved storage path into a constant.

This commit is contained in:
flash 2018-10-05 11:14:54 +02:00
parent c2b3becc14
commit 8ff10f9d3c
5 changed files with 15 additions and 25 deletions

View file

@ -73,6 +73,9 @@ if (!empty($errorReporter)) {
db_setup(MSZ_DATABASE_NAMES[0], config_get_default([], 'Database.' . MSZ_DATABASE_NAMES[0]));
// replace this with a better storage mechanism
define('MSZ_STORAGE', create_directory(config_get_default(MSZ_ROOT . '/store', 'Storage', 'path')));
if (PHP_SAPI === 'cli') {
if ($argv[0] === basename(__FILE__)) {
switch ($argv[1] ?? null) {
@ -237,8 +240,7 @@ MIG;
// we're running this again because ob_clean breaks gzip otherwise
ob_start();
$mszStoragePath = $app->getStoragePath();
if (!is_readable($mszStoragePath) || !is_writable($mszStoragePath)) {
if (!is_readable(MSZ_STORAGE) || !is_writable(MSZ_STORAGE)) {
echo 'Cannot access storage directory.';
exit;
}

View file

@ -16,14 +16,14 @@ switch ($mode) {
);
$user_avatar = "{$userId}.msz";
$cropped_avatar = build_path(
create_directory(build_path($app->getStoragePath(), 'avatars/200x200')),
create_directory(build_path(MSZ_STORAGE, 'avatars/200x200')),
$user_avatar
);
if (is_file($cropped_avatar)) {
$avatar_filename = $cropped_avatar;
} else {
$original_avatar = build_path($app->getStoragePath(), 'avatars/original', $user_avatar);
$original_avatar = build_path(MSZ_STORAGE, 'avatars/original', $user_avatar);
if (is_file($original_avatar)) {
try {
@ -45,7 +45,7 @@ switch ($mode) {
case 'background':
$user_background = build_path(
create_directory(build_path($app->getStoragePath(), 'backgrounds/original')),
create_directory(build_path(MSZ_STORAGE, 'backgrounds/original')),
"{$userId}.msz"
);
@ -165,7 +165,7 @@ switch ($mode) {
'is_editing' => $isEditing,
'perms' => $perms,
'profile_fields' => user_session_active() ? user_profile_fields_display($profile, !$isEditing) : [],
'has_background' => is_file(build_path($app->getStoragePath(), 'backgrounds/original', "{$profile['user_id']}.msz")),
'has_background' => is_file(build_path(MSZ_STORAGE, 'backgrounds/original', "{$profile['user_id']}.msz")),
]);
echo tpl_render('user.profile');
break;

View file

@ -367,8 +367,8 @@ switch ($settingsMode) {
$getAccountInfo->bindValue('user_id', $settingsUserId);
$accountInfo = $getAccountInfo->execute() ? $getAccountInfo->fetch(PDO::FETCH_ASSOC) : [];
$userHasAvatar = is_file(build_path($app->getStoragePath(), 'avatars/original', $avatarFileName));
$userHasBackground = is_file(build_path($app->getStoragePath(), 'backgrounds/original', $avatarFileName));
$userHasAvatar = is_file(build_path(MSZ_STORAGE, 'avatars/original', $avatarFileName));
$userHasBackground = is_file(build_path(MSZ_STORAGE, 'backgrounds/original', $avatarFileName));
tpl_vars([
'avatar' => $avatarProps,

View file

@ -23,15 +23,6 @@ final class Application
self::$instance = $this;
}
/**
* Gets a data storage path.
* @return string
*/
public function getStoragePath(): string
{
return create_directory(config_get_default(MSZ_ROOT . '/store', 'Storage', 'path'));
}
public function startGeoIP(): void
{
if (!empty($this->geoipInstance)) {

View file

@ -1,5 +1,4 @@
<?php
use Misuzu\Application;
use Misuzu\Database;
define('MSZ_PERM_USER_EDIT_PROFILE', 1);
@ -136,11 +135,10 @@ define('MSZ_USER_AVATAR_FORMAT', '%d.msz');
function user_avatar_delete(int $userId): void
{
$avatarFileName = sprintf(MSZ_USER_AVATAR_FORMAT, $userId);
$storePath = Application::getInstance()->getStoragePath();
$deleteThis = [
build_path($storePath, 'avatars/original', $avatarFileName),
build_path($storePath, 'avatars/200x200', $avatarFileName),
build_path(MSZ_STORAGE, 'avatars/original', $avatarFileName),
build_path(MSZ_STORAGE, 'avatars/200x200', $avatarFileName),
];
foreach ($deleteThis as $deleteAvatar) {
@ -217,7 +215,7 @@ function user_avatar_set_from_path(int $userId, string $path, array $options = [
$fileName = sprintf(MSZ_USER_AVATAR_FORMAT, $userId);
$avatarPath = build_path(
create_directory(build_path(Application::getInstance()->getStoragePath(), 'avatars/original')),
create_directory(build_path(MSZ_STORAGE, 'avatars/original')),
$fileName
);
@ -320,8 +318,7 @@ function user_background_set_settings(int $userId, int $settings): void
function user_background_delete(int $userId): void
{
$backgroundFileName = sprintf(MSZ_USER_BACKGROUND_FORMAT, $userId);
$storePath = Application::getInstance()->getStoragePath();
safe_delete(build_path($storePath, 'backgrounds/original', $backgroundFileName));
safe_delete(build_path(MSZ_STORAGE, 'backgrounds/original', $backgroundFileName));
}
define('MSZ_USER_BACKGROUND_TYPE_PNG', IMAGETYPE_PNG);
@ -391,7 +388,7 @@ function user_background_set_from_path(int $userId, string $path, array $options
$fileName = sprintf(MSZ_USER_BACKGROUND_FORMAT, $userId);
$backgroundPath = build_path(
create_directory(build_path(Application::getInstance()->getStoragePath(), 'backgrounds/original')),
create_directory(build_path(MSZ_STORAGE, 'backgrounds/original')),
$fileName
);