From ff97cc1cb2e49e66d1c633f48742150cbc79ae76 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Thu, 16 Aug 2018 12:10:24 -0400 Subject: [PATCH] Add basic check for folder permissions for quicker troubleshooting --- .gitignore | 3 +- app/views/header.php | 1 + app/views/setup-check.php | 27 +++++++++++ public/images/people/.gitkeep | 0 src/AnimeClient.php | 86 +++++++++++++++++++++++++---------- 5 files changed, 92 insertions(+), 25 deletions(-) create mode 100644 app/views/setup-check.php create mode 100644 public/images/people/.gitkeep diff --git a/.gitignore b/.gitignore index 9a13d5e9..9cff69ac 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,5 @@ build/humbuglog.txt public/images/anime/** public/images/avatars/** public/images/manga/** -public/images/characters/** \ No newline at end of file +public/images/characters/** +public/images/people/** \ No newline at end of file diff --git a/app/views/header.php b/app/views/header.php index 4a7de884..7f94c721 100644 --- a/app/views/header.php +++ b/app/views/header.php @@ -24,6 +24,7 @@ +
get('config')); +?> + + + + \ No newline at end of file diff --git a/public/images/people/.gitkeep b/public/images/people/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/src/AnimeClient.php b/src/AnimeClient.php index 5383dabb..8b94f169 100644 --- a/src/AnimeClient.php +++ b/src/AnimeClient.php @@ -16,40 +16,78 @@ 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 { - /** - * Load configuration options from .toml files - * - * @param string $path - Path to load config - * @return array - */ - function loadToml(string $path): array + $output = []; + $files = glob("{$path}/*.toml"); + + foreach ($files as $file) { - $output = []; - $files = glob("{$path}/*.toml"); + $key = str_replace('.toml', '', basename($file)); + $config = Toml::parseFile($file); - foreach ($files as $file) + if ($key === 'config') { - $key = str_replace('.toml', '', basename($file)); - $toml = file_get_contents($file); - $config = Toml::parse($toml); - - if ($key === 'config') + foreach($config as $name => $value) { - foreach($config as $name => $value) - { - $output[$name] = $value; - } - - continue; + $output[$name] = $value; } - $output[$key] = $config; + continue; } - return $output; + $output[$key] = $config; } + + 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; +} \ No newline at end of file