1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by Gorlum 24.09.2017 17:15 |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
use DBAL\db_mysql; |
7
|
|
|
use Fleet\DbFleetStatic; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class StatUpdateLauncher |
11
|
|
|
* |
12
|
|
|
* Part of the scheduling process. Response for Stat Updater launch |
13
|
|
|
* |
14
|
|
|
*/ |
15
|
|
|
class StatUpdateLauncher { |
16
|
|
|
|
17
|
|
|
public static function unlock() { |
18
|
|
|
if ( |
19
|
|
|
SN::$config->game_disable != GAME_DISABLE_STAT || SN_TIME_NOW - strtotime(SN::$config->pass()->var_stat_update_end) <= STATS_RUN_INTERVAL_MINIMUM |
20
|
|
|
) { |
21
|
|
|
return; |
22
|
|
|
} |
23
|
|
|
$next_run = date(FMT_DATE_TIME_SQL, sys_schedule_get_prev_run(SN::$config->stats_schedule, SN::$config->var_stat_update, true)); |
24
|
|
|
SN::$config->pass()->game_disable = GAME_DISABLE_NONE; |
25
|
|
|
SN::$config->pass()->var_stat_update = SN_TIME_SQL; |
26
|
|
|
SN::$config->pass()->var_stat_update_next = $next_run; |
27
|
|
|
SN::$config->pass()->var_stat_update_end = SN_TIME_SQL; |
28
|
|
|
SN::$debug->warning('Stat worked too long - watchdog unlocked', 'Stat WARNING'); |
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
public static function scheduler_process() { |
33
|
|
|
global $user, $lang; |
34
|
|
|
|
35
|
|
|
$config = SN::$config; |
36
|
|
|
$debug = SN::$debug; |
37
|
|
|
|
38
|
|
|
$is_admin_request = false; |
39
|
|
|
|
40
|
|
|
$ts_var_stat_update = strtotime($config->pass()->var_stat_update); |
41
|
|
|
$ts_scheduled_update = sys_schedule_get_prev_run($config->pass()->stats_schedule, $config->var_stat_update); |
42
|
|
|
|
43
|
|
|
if (sys_get_param_int('admin_update')) { |
44
|
|
|
define('USER_LEVEL', isset($user['authlevel']) ? $user['authlevel'] : -1); |
45
|
|
|
if (USER_LEVEL > 0) { |
46
|
|
|
$is_admin_request = true; |
47
|
|
|
$ts_scheduled_update = SN_TIME_NOW; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
if ($ts_scheduled_update > $ts_var_stat_update) { |
52
|
|
|
lng_include('admin'); |
53
|
|
|
db_mysql::db_transaction_start(); |
54
|
|
|
$ts_var_stat_update_end = strtotime($config->pass()->var_stat_update_end); |
55
|
|
|
if (SN_TIME_NOW > $ts_var_stat_update_end) { |
56
|
|
|
$old_server_status = $config->pass()->game_disable; |
57
|
|
|
$config->pass()->game_disable = GAME_DISABLE_STAT; |
58
|
|
|
|
59
|
|
|
$statMinimalInterval = intval($config->pass()->stats_minimal_interval); |
60
|
|
|
$config->pass()->var_stat_update_end= date(FMT_DATE_TIME_SQL, SN_TIME_NOW + ($statMinimalInterval ? $statMinimalInterval : STATS_RUN_INTERVAL_MINIMUM)); |
61
|
|
|
$config->pass()->var_stat_update_msg = 'Update started'; |
62
|
|
|
db_mysql::db_transaction_commit(); |
63
|
|
|
|
64
|
|
|
$msg = $is_admin_request ? 'admin request' : 'scheduler'; |
65
|
|
|
$next_run = date(FMT_DATE_TIME_SQL, sys_schedule_get_prev_run($config->stats_schedule, $config->pass()->var_stat_update, true)); |
66
|
|
|
$msg = "Running stat updates: {$msg}. Config->var_stat_update = " . $config->var_stat_update . |
67
|
|
|
', $ts_scheduled_update = ' . date(FMT_DATE_TIME_SQL, $ts_scheduled_update) . |
68
|
|
|
', next_stat_update = ' . $next_run; |
69
|
|
|
$debug->warning($msg, 'Stat update', LOG_INFO_STAT_PROCESS); |
70
|
|
|
$total_time = microtime(true); |
71
|
|
|
|
72
|
|
|
StatCalculator::sys_stat_calculate(); |
73
|
|
|
|
74
|
|
|
DbFleetStatic::db_fleet_acs_purge(); |
75
|
|
|
|
76
|
|
|
$total_time = microtime(true) - $total_time; |
77
|
|
|
$msg = "Stat update complete in {$total_time} seconds."; |
78
|
|
|
$debug->warning($msg, 'Stat update', LOG_INFO_STAT_PROCESS); |
79
|
|
|
|
80
|
|
|
$msg = "{$lang['adm_done']}: {$total_time} {$lang['sys_sec']}."; // . date(FMT_DATE_TIME, $ts_scheduled_update) . ' ' . date(FMT_DATE_TIME, $config->var_stat_update); |
81
|
|
|
|
82
|
|
|
// TODO: Analyze maintenance result. Add record to log if error. Add record to log if OK |
83
|
|
|
$maintenance_result = sys_maintenance(); |
84
|
|
|
|
85
|
|
|
$config->pass()->var_stat_update = SN_TIME_SQL; |
86
|
|
|
$config->pass()->var_stat_update_msg = $msg; |
87
|
|
|
$config->pass()->var_stat_update_next = $next_run; |
88
|
|
|
$config->pass()->var_stat_update_admin_forced = SN_TIME_SQL; |
89
|
|
|
$config->pass()->var_stat_update_end = SN_TIME_SQL; |
90
|
|
|
|
91
|
|
|
$config->pass()->game_disable = $old_server_status; |
92
|
|
|
} elseif ($ts_scheduled_update > $ts_var_stat_update) { |
93
|
|
|
$timeout = strtotime($config->pass()->var_stat_update_end) - SN_TIME_NOW; |
94
|
|
|
$msg = $config->pass()->var_stat_update_msg; |
95
|
|
|
$msg = "{$msg} ETA {$timeout} seconds. Please wait..."; |
96
|
|
|
} |
97
|
|
|
db_mysql::db_transaction_rollback(); |
98
|
|
|
} elseif ($is_admin_request) { |
99
|
|
|
$msg = 'Stat is up to date'; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return $msg; |
|
|
|
|
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.