Skip to content

Commit

Permalink
[page.system.task] Fix flush task with default cache configuration.
Browse files Browse the repository at this point in the history
Configuration options for cache directories were read from flush page with a
different (null) configuration than the one used when initializing actual
services, leading to flushing having no effect.

See: https://www.yaronet.com/topics/190254-yaronet-passe-open-source/2#post-49
  • Loading branch information
r3c committed Jan 12, 2019
1 parent b8e9247 commit bdb6c4f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
22 changes: 22 additions & 0 deletions src/engine/network/router.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace yN\Engine\Network;

defined('YARONET') or die;

class Router
{
public static function cache_directory()
{
return config('engine.network.route.cache', './storage/cache/route');
}

public static function create()
{
require './library/queros/queros.php';

$cache = self::cache_directory();

return new \Queros\Router('route.php', $cache !== null ? $cache . '/queros.php' : null);
}
}
7 changes: 6 additions & 1 deletion src/engine/text/display.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public static function _xml($name, $data)
return \yN\Engine\Text\XML::encode($name, $data);
}

public static function cache_directory()
{
return config('engine.text.display.cache', './storage/cache/template');
}

public static function default_template()
{
return config('engine.text.display.template', 'html.kyanite');
Expand Down Expand Up @@ -188,7 +193,7 @@ public function render($file, $location, $variables = array(), $external = null,
$setup = new \Deval\Setup();
$setup->style = 'deindent,collapse';

$renderer_cache = config('engine.text.display.cache', './storage/cache/template');
$renderer_cache = self::cache_directory();
$renderer = $renderer_cache !== null ? new \Deval\CacheRenderer($path, $renderer_cache, $setup) : new \Deval\FileRenderer($path, $setup);

$self = get_class();
Expand Down
7 changes: 6 additions & 1 deletion src/engine/text/internationalization.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class Internationalization
private $language;
private $locale;

public static function cache_directory()
{
return config('engine.text.i18n.cache', './storage/cache/language');
}

public static function default_language()
{
return config('engine.text.i18n.language', 'en');
Expand All @@ -37,7 +42,7 @@ public function __construct($language)
$language = self::default_language();
}

$locale_cache = config('engine.text.i18n.cache', './storage/cache/language');
$locale_cache = self::cache_directory();
$locale_source = config('engine.text.i18n.source', './resource/language');

$locale = new \Losp\Locale(mb_internal_encoding(), $language, $locale_source, $locale_cache !== null ? $locale_cache . '/' . $language . '.php' : null);
Expand Down
5 changes: 2 additions & 3 deletions src/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ function config($key, $value)
Glay\Network\HTTP::$default_timeout = config('engine.network.http.timeout', 15000);
Glay\Network\HTTP::$default_useragent = config('engine.network.http.user-agent', 'Mozilla/5.0 (compatible; yAronet; +http://www.yaronet.com/)');

require('./library/queros/queros.php');
require('./library/redmap/redmap.php');
require('./engine/diagnostic/logger.php');
require('./engine/network/router.php');
require('./engine/text/display.php');
require('./engine/text/internationalization.php');
require('./engine/text/input.php');
Expand Down Expand Up @@ -90,8 +90,7 @@ function config($key, $value)
require('./entity/account/message.php');

// Create HTTP request router
$router_cache = config('engine.network.route.cache', './storage/cache/route');
$router = new Queros\Router('route.php', $router_cache !== null ? $router_cache . '/queros.php' : null);
$router = yN\Engine\Network\Router::create();

// Resolve route
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
Expand Down
12 changes: 5 additions & 7 deletions src/page/system/task.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,13 @@ function task_flush($request, $logger, $sql, $display, $input, $user)
}

// Remove cache files
$caches = array(
'engine.network.route.cache',
'engine.text.display.cache',
'engine.text.i18n.cache'
$directories = array(
yN\Engine\Network\Router::cache_directory(),
yN\Engine\Text\Display::cache_directory(),
yN\Engine\Text\Internationalization::cache_directory()
);

foreach ($caches as $cache) {
$directory = config($cache, null);

foreach ($directories as $directory) {
if ($directory === null) {
continue;
} elseif (!is_dir($directory)) {
Expand Down

0 comments on commit bdb6c4f

Please sign in to comment.