Add basic check for folder permissions for quicker troubleshooting
This commit is contained in:
parent
b3474ddff2
commit
ff97cc1cb2
1
.gitignore
vendored
1
.gitignore
vendored
@ -30,3 +30,4 @@ public/images/anime/**
|
||||
public/images/avatars/**
|
||||
public/images/manga/**
|
||||
public/images/characters/**
|
||||
public/images/people/**
|
@ -24,6 +24,7 @@
|
||||
<script defer="defer" src="<?= $urlGenerator->assetUrl('js.php/g/base') ?>"></script>
|
||||
</head>
|
||||
<body class="<?= $escape->attr($url_type) ?> list">
|
||||
<?php include 'setup-check.php' ?>
|
||||
<header>
|
||||
<?php
|
||||
include 'main-menu.php';
|
||||
|
27
app/views/setup-check.php
Normal file
27
app/views/setup-check.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
$setupErrors = \Aviat\AnimeClient\checkFolderPermissions($container->get('config'));
|
||||
?>
|
||||
|
||||
<?php if ( ! empty($setupErrors)): ?>
|
||||
<aside class="message error">
|
||||
<h1>Issues with server setup:</h1>
|
||||
|
||||
<?php if (array_key_exists('missing', $setupErrors)): ?>
|
||||
<h3>The following folders need to be created, and writable.</h3>
|
||||
<ul>
|
||||
<?php foreach ($setupErrors['missing'] as $error): ?>
|
||||
<li><?= $error ?></li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if (array_key_exists('writable', $setupErrors)): ?>
|
||||
<h3>The following folders are not writable by the server.</h3>
|
||||
<ul>
|
||||
<?php foreach($setupErrors['writable'] as $error): ?>
|
||||
<li><?= $error ?></li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
</aside>
|
||||
<?php endif ?>
|
0
public/images/people/.gitkeep
Normal file
0
public/images/people/.gitkeep
Normal file
@ -16,26 +16,24 @@
|
||||
|
||||
namespace Aviat\AnimeClient;
|
||||
|
||||
use Aviat\Ion\ConfigInterface;
|
||||
use Yosymfony\Toml\Toml;
|
||||
|
||||
if ( ! \function_exists('Aviat\AnimeClient\loadToml'))
|
||||
{
|
||||
/**
|
||||
/**
|
||||
* Load configuration options from .toml files
|
||||
*
|
||||
* @param string $path - Path to load config
|
||||
* @return array
|
||||
*/
|
||||
function loadToml(string $path): array
|
||||
{
|
||||
function loadToml(string $path): array
|
||||
{
|
||||
$output = [];
|
||||
$files = glob("{$path}/*.toml");
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$key = str_replace('.toml', '', basename($file));
|
||||
$toml = file_get_contents($file);
|
||||
$config = Toml::parse($toml);
|
||||
$config = Toml::parseFile($file);
|
||||
|
||||
if ($key === 'config')
|
||||
{
|
||||
@ -51,5 +49,45 @@ if ( ! \function_exists('Aviat\AnimeClient\loadToml'))
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that folder permissions are correct for proper operation
|
||||
*
|
||||
* @param ConfigInterface $config
|
||||
* @return array
|
||||
*/
|
||||
function checkFolderPermissions(ConfigInterface $config): array
|
||||
{
|
||||
$errors = [];
|
||||
$publicDir = $config->get('asset_dir');
|
||||
|
||||
$pathMap = [
|
||||
'app/logs' => realpath(__DIR__ . '/../app/logs'),
|
||||
'public/js/cache' => "{$publicDir}/js/cache",
|
||||
'public/images/avatars' => "{$publicDir}/images/avatars",
|
||||
'public/images/anime' => "{$publicDir}/images/anime",
|
||||
'public/images/characters' => "{$publicDir}/images/characters",
|
||||
'public/images/manga' => "{$publicDir}/images/manga",
|
||||
'public/images/people' => "{$publicDir}/images/people",
|
||||
];
|
||||
|
||||
foreach ($pathMap as $pretty => $actual)
|
||||
{
|
||||
// Make sure the folder exists first
|
||||
if ( ! is_dir($actual))
|
||||
{
|
||||
$errors['missing'][] = $pretty;
|
||||
continue;
|
||||
}
|
||||
|
||||
$writable = is_writable($actual) && is_executable($actual);
|
||||
|
||||
if ( ! $writable)
|
||||
{
|
||||
$errors['writable'][] = $pretty;
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
Loading…
Reference in New Issue
Block a user