-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.php
More file actions
70 lines (69 loc) · 2.22 KB
/
log.php
File metadata and controls
70 lines (69 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
require_once __DIR__ . '/fs.php';
class GITAUCronLog
{
/**
* 存储的时间
*/
public string $datetime;
/**
* 是否为错误日志
*/
public bool $isError;
/**
* 日志内容
*/
public string $msg;
/**
* 主题名称
*/
public string $theme_name;
/**
* 更新前的主题版本号
*/
public string $theme_version_pre;
/**
* 更新后的主题版本号
*/
public string $theme_version_post;
public function __construct(bool $isError = false, string $datetime, string $msg, string $theme_name, string $theme_version_pre, string $theme_version_post)
{
$this->datetime = $datetime;
$this->msg = $msg;
$this->theme_name = $theme_name;
$this->theme_version_pre = $theme_version_pre;
$this->theme_version_post = $theme_version_post;
$this->isError = $isError;
}
public static function serialize(GITAUCronLog $logCls)
{
$array = array(
"datetime" => $logCls->datetime,
"msg" => $logCls->msg,
"theme_name" => $logCls->theme_name,
"theme_version_pre" => $logCls->theme_version_pre,
"theme_version_post" => $logCls->theme_version_post,
"isError" => $logCls->isError
);
return json_encode($array);
}
public static function deserialize($json)
{
$array = json_decode($json);
return new GITAUCronLog($array->isError, $array->datetime, $array->msg, $array->theme_name, $array->theme_version_pre, $array->theme_version_post,);
}
}
function gitau_cron_log_err(string $msg)
{
$theme = wp_get_theme();
$log = new GITAUCronLog(true, date("Y-m-d H:i:s"), GITAU_MSG_PREFIX . ": " . $msg, $theme->get('Name'), $theme->get('Version'), $theme->get('Version'));
$logJson = GITAUCronLog::serialize($log);
gitau_write_log($logJson);
}
function gitau_cron_log_success(string $theme_version_pre, string $theme_version_post)
{
$theme = wp_get_theme();
$log = new GITAUCronLog(false, date("Y-m-d H:i:s"), "主题更新成功", $theme->get('Name'), $theme_version_pre, $theme_version_post);
$logJson = GITAUCronLog::serialize($log);
gitau_write_log($logJson);
}