mirror of
https://github.com/slawkens/myaac.git
synced 2025-11-03 17:26:23 +01:00
Ensure some cache folders & index.html exists
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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.');
|
||||
|
||||
@@ -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, '<?php $var = ' . $var . ';', LOCK_EX);
|
||||
|
||||
@@ -513,6 +513,9 @@ class Plugins {
|
||||
return false;
|
||||
}
|
||||
|
||||
ensureFolderExists($cachePlugins = CACHE . 'plugins');
|
||||
ensureIndexExists($cachePlugins);
|
||||
|
||||
self::$error = 'There was a problem with extracting zip archive.';
|
||||
$file_name = $plugin_temp_dir . $json_file;
|
||||
if(!file_exists($file_name)) {
|
||||
|
||||
@@ -53,6 +53,9 @@
|
||||
exit;
|
||||
}
|
||||
|
||||
ensureFolderExists(SIGNATURES_CACHE);
|
||||
ensureIndexExists(SIGNATURES_CACHE);
|
||||
|
||||
$cached = SIGNATURES_CACHE.$player->getId() . '.png';
|
||||
if(file_exists($cached) && (time() < (filemtime($cached) + (60 * setting('core.signature_cache_time')))))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user