Fix initial setup bugs.

This commit is contained in:
Greg Sarjeant 2025-06-17 21:25:53 -04:00
parent a15cfc5876
commit 61eaa42373
4 changed files with 31 additions and 10 deletions

View File

@ -41,16 +41,19 @@ function handle_setup_exception(SetupException $e){
// Show error message and exit
http_response_code(500);
echo "<h1>Configuration Error</h1>";
echo "<p>" . Util::escape_html($setupError['message']) . "</p>";
echo "<p>" . Util::escape_html($e->getSetupIssue) . '-' . Util::escape_html($e->getMessage()) . "</p>";
exit;
case 'table_contents':
// Recoverable error.
// Redirect to setup if we aren't already headed there.
$config = ConfigModel::load();
// NOTE: Just read directly from init.php instead of
// trying to use the config object. This is the initial
// setup. It shouldn't assume anything can be loaded.
$init = require APP_ROOT . '/config/init.php';
$currentPath = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
if (strpos($currentPath, 'setup') === false) {
header('Location: ' . $config->basePath . 'setup');
header('Location: ' . $init['base_path'] . 'setup');
exit;
}
}
@ -92,7 +95,7 @@ function validate_storage_subdirs(): void {
foreach($storageSubdirs as $storageSubdir){
if (!is_dir($storageSubdir)) {
if (!mkdir($dir, 0770, true)) {
if (!mkdir($storageSubdir, 0770, true)) {
throw new SetupException(
"Failed to create required directory: $dir",
'directory_creation'

View File

@ -37,7 +37,16 @@ server {
# I've excluded /css/custom so that requests for uploaded css can be handled by the PHP app.
# That lets me store uploaded content outside of the document root,
# so it isn't served directly.
location ~* ^/(?!css/custom/).+\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
# CSS files - 1 hour cache
location ~* ^/(?!css/custom/).+\.css$ {
expires 1h;
add_header Cache-Control "public";
try_files $uri =404;
}
# Other static assets - 1 year cache
location ~* ^/.+\.(js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
try_files $uri =404;

View File

@ -42,7 +42,16 @@ server {
# I've excluded /css/custom so that requests for uploaded css can be handled by the PHP app.
# That lets me store uploaded content outside of the document root,
# so it isn't served directly.
location ~* ^/tkr/(?!css/custom/).+\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
# CSS files - 1 hour cache
location ~* ^/tkr/(?!css/custom/).+\.css$ {
expires 1h;
add_header Cache-Control "public";
try_files $uri =404;
}
# Other static assets - 1 year cache
location ~* ^/tkr/.+\.(js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
try_files $uri =404;

View File

@ -15,10 +15,6 @@ if (preg_match('/\.php$/', $path)) {
include_once(dirname(dirname(__FILE__)) . "/config/bootstrap.php");
load_classes();
// initialize the database
global $db;
$db = get_db();
// Make sure the initial setup is complete
// unless we're already heading to setup
if (!(preg_match('/setup$/', $path))) {
@ -30,6 +26,10 @@ if (!(preg_match('/setup$/', $path))) {
}
}
// initialize the database
global $db;
$db = get_db();
// Everything's loaded and setup is confirmed.
// Let's start ticking.