diff --git a/system/functions.php b/system/functions.php index 582f9c30..88c02102 100644 --- a/system/functions.php +++ b/system/functions.php @@ -1177,7 +1177,8 @@ function getTopPlayers($limit = 5, $skill = 'level') { }); } -function deleteDirectory($dir, $ignore = array(), $contentOnly = false) { +function deleteDirectory($dir, $ignore = array(), $contentOnly = false): bool +{ if(!file_exists($dir)) { return true; } @@ -1203,6 +1204,21 @@ function deleteDirectory($dir, $ignore = array(), $contentOnly = false) { return rmdir($dir); } +function ensureFolderExists($dir): void +{ + if (!file_exists($dir)) { + mkdir($dir, 0777, true); + } +} + +function ensureIndexExists($dir): void +{ + $dir = rtrim($dir, '/'); + if (!file_exists($file = $dir . '/index.html')) { + touch($file); + } +} + function config($key) { global $config; if (is_array($key)) { diff --git a/system/init.php b/system/init.php index 57c299ba..862b5370 100644 --- a/system/init.php +++ b/system/init.php @@ -18,6 +18,9 @@ use MyAAC\Settings; defined('MYAAC') or die('Direct access not allowed!'); +ensureIndexExists(CACHE); +ensureIndexExists(CACHE . 'twig/'); + global $config; if(!isset($config['installed']) || !$config['installed']) { throw new RuntimeException('MyAAC has not been installed yet or there was error during installation. Please install again.'); diff --git a/system/src/Cache/PHP.php b/system/src/Cache/PHP.php index e42bd928..0b13db07 100644 --- a/system/src/Cache/PHP.php +++ b/system/src/Cache/PHP.php @@ -27,6 +27,9 @@ class PHP { $var = var_export($var, true); + ensureFolderExists($this->dir); + ensureIndexExists($this->dir); + // Write to temp file first to ensure atomicity $tmp = $this->dir . "tmp_$key." . uniqid('', true) . '.tmp'; file_put_contents($tmp, 'getId() . '.png'; if(file_exists($cached) && (time() < (filemtime($cached) + (60 * setting('core.signature_cache_time'))))) {