|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package CleverStyle Framework |
|
4
|
|
|
* @subpackage System module |
|
5
|
|
|
* @category modules |
|
6
|
|
|
* @author Nazar Mokrynskyi <[email protected]> |
|
7
|
|
|
* @copyright Copyright (c) 2015-2016, Nazar Mokrynskyi |
|
8
|
|
|
* @license MIT License, see license.txt |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace cs\modules\System\api\Controller\admin; |
|
11
|
|
|
use |
|
12
|
|
|
cs\Cache, |
|
13
|
|
|
cs\Config, |
|
14
|
|
|
cs\Event, |
|
15
|
|
|
cs\ExitException; |
|
16
|
|
|
|
|
17
|
|
|
trait optimization { |
|
18
|
|
|
protected static $optimization_options_keys = [ |
|
19
|
|
|
'cache_compress_js_css', |
|
20
|
|
|
'frontend_load_optimization', |
|
21
|
|
|
'vulcanization', |
|
22
|
|
|
'put_js_after_body', |
|
23
|
|
|
'disable_webcomponents', |
|
24
|
|
|
'inserts_limit', |
|
25
|
|
|
'update_ratio' |
|
26
|
|
|
]; |
|
27
|
|
|
/** |
|
28
|
|
|
* Get optimization settings |
|
29
|
|
|
* |
|
30
|
|
|
* @return array |
|
31
|
|
|
*/ |
|
32
|
|
|
public static function admin_optimization_get_settings () { |
|
33
|
|
|
$Config = Config::instance(); |
|
34
|
|
|
return $Config->core(static::$optimization_options_keys) + [ |
|
35
|
|
|
'cache_state' => Cache::instance()->cache_state(), |
|
36
|
|
|
'applied' => $Config->cancel_available() |
|
37
|
|
|
]; |
|
38
|
|
|
} |
|
39
|
|
|
/** |
|
40
|
|
|
* Clean cache |
|
41
|
|
|
* |
|
42
|
|
|
* @param \cs\Request $Request |
|
43
|
|
|
* |
|
44
|
|
|
* @throws ExitException |
|
45
|
|
|
*/ |
|
46
|
|
|
public static function admin_optimization_clean_cache ($Request) { |
|
47
|
|
|
$Cache = Cache::instance(); |
|
48
|
|
|
time_limit_pause(); |
|
49
|
|
|
$path_prefix = $Request->data('path_prefix'); |
|
50
|
|
|
if ($path_prefix) { |
|
51
|
|
|
$result = $Cache->del($path_prefix); |
|
52
|
|
|
} else { |
|
53
|
|
|
$result = $Cache->clean(); |
|
54
|
|
|
__classes_clean_cache(); |
|
55
|
|
|
} |
|
56
|
|
|
time_limit_pause(false); |
|
57
|
|
|
if (!$result) { |
|
58
|
|
|
throw new ExitException(500); |
|
59
|
|
|
} |
|
60
|
|
|
$Cache->disable(); |
|
61
|
|
|
} |
|
62
|
|
|
/** |
|
63
|
|
|
* Clean public cache (CSS/JS/HTML) |
|
64
|
|
|
* |
|
65
|
|
|
* @throws ExitException |
|
66
|
|
|
*/ |
|
67
|
|
|
public static function admin_optimization_clean_public_cache () { |
|
68
|
|
|
if (!clean_public_cache()) { |
|
69
|
|
|
throw new ExitException(500); |
|
70
|
|
|
} |
|
71
|
|
|
Event::instance()->fire('admin/System/general/optimization/clean_public_cache'); |
|
72
|
|
|
} |
|
73
|
|
|
/** |
|
74
|
|
|
* Apply optimization settings |
|
75
|
|
|
* |
|
76
|
|
|
* @param \cs\Request $Request |
|
77
|
|
|
* |
|
78
|
|
|
* @throws ExitException |
|
79
|
|
|
*/ |
|
80
|
|
|
public static function admin_optimization_apply_settings ($Request) { |
|
81
|
|
|
static::admin_core_options_apply($Request, static::$optimization_options_keys); |
|
82
|
|
|
static::admin_optimization_clean_public_cache(); |
|
83
|
|
|
} |
|
84
|
|
|
/** |
|
85
|
|
|
* Save optimization settings |
|
86
|
|
|
* |
|
87
|
|
|
* @param \cs\Request $Request |
|
88
|
|
|
* |
|
89
|
|
|
* @throws ExitException |
|
90
|
|
|
*/ |
|
91
|
|
|
public static function admin_optimization_save_settings ($Request) { |
|
92
|
|
|
static::admin_core_options_save($Request, static::$optimization_options_keys); |
|
93
|
|
|
static::admin_optimization_clean_public_cache(); |
|
94
|
|
|
} |
|
95
|
|
|
/** |
|
96
|
|
|
* Cancel optimization settings |
|
97
|
|
|
* |
|
98
|
|
|
* @throws ExitException |
|
99
|
|
|
*/ |
|
100
|
|
|
public static function admin_optimization_cancel_settings () { |
|
101
|
|
|
static::admin_core_options_cancel(); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|