-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck.php
180 lines (163 loc) · 6.25 KB
/
check.php
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
require __DIR__ . '/common.php';
// Get all of the software to check
$classes = array();
$dir = new DirectoryIterator('software');
foreach ($dir as $fileinfo)
{
if (!$fileinfo->isDot() && $fileinfo->getExtension() == 'php')
{
include_once('software' . DIRECTORY_SEPARATOR . $fileinfo->getFilename());
$classes[] = strtolower($fileinfo->getBasename('.php'));
}
}
// Check for updates
foreach ($classes as $class)
{
if (!class_exists($class, false))
continue;
$software = new $class();
if (!is_subclass_of($software, 'SoftwareCheck', false))
continue;
if (!$class::$enabled)
{
//echo 'Skipping disabled class: ' . $class . "\n";
continue;
}
$versions = array();
try {
$data = $software->get_data();
$versions = $software->get_versions($data);
} catch (Exception $e)
{
echo "Exception while getting version data for $class: $e";
continue;
}
/*
Array (
[3.0] => Array (
[version] => 3.0.14
[announcement] => https://www.phpbb.com/community/viewtopic.php?f=14&t=2313941
[estimated] => 1
[release_date] => 2020-06-28 22:23:08
),
...
*/
$updates = array();
$sql = 'SELECT id, version FROM ' . VERSION_TABLE . ' WHERE software = :software AND branch = :branch';
$sth = $db->prepare($sql);
foreach ($versions as $branch => $version_info)
{
$sth->execute(array(':software' => $class, ':branch' => $branch));
$row = $sth->fetch();
$id = 0;
if ($row !== false && count($row) > 0)
{
$id = (int)$row['id'];
}
if ($id > 0)
{
if ($row['version'] != $version_info['version'])
{
//echo 'Updating ' . $class . ' from ' . $row['version'] . ' to ' . $version_info['version'] . ': ' . $id . "\n";
$sql = 'UPDATE ' . VERSION_TABLE . ' SET
version = :version,
announcement = :announcement,
release_date = :release_date,
last_check = :last_check,
estimated = :estimated
WHERE id = :id';
$uph = $db->prepare($sql);
$ret = $uph->execute(array(
':id' => (int) $id,
':version' => $version_info['version'],
':announcement' => array_key_exists('announcement', $version_info) ? $version_info['announcement'] : '',
':release_date' => $version_info['release_date'],
':last_check' => date("Y-m-d H:i:s"),
':estimated' => array_key_exists('estimated', $version_info) ? (int)$version_info['estimated'] : 0,
));
if (!$ret)
{
echo 'Error while updating version information' . "\n";
print_r($uph->errorInfo());
print_r($uph->debugDumpParams());
//exit;
continue;
}
$updates[$class][$branch] = $version_info['version'];
}
else
{
//echo 'Updating ' . $class . ' ' . $row['version'] . ' checked time: ' . $id . "\n";
$sql = 'UPDATE ' . VERSION_TABLE . ' SET
last_check = :last_check
WHERE id = :id';
$uph = $db->prepare($sql);
$ret = $uph->execute(array(
':id' => (int) $id,
':last_check' => date("Y-m-d H:i:s"),
));
if (!$ret)
{
echo 'Error while updating check time' . "\n";
print_r($uph->errorInfo());
print_r($uph->debugDumpParams());
//exit;
continue;
}
}
}
else
{
//echo 'Inserting new software branch: ' . $class . ' - ' . $branch . ' - ' . $version_info['version'] . "\n";
$sql = 'INSERT INTO ' . VERSION_TABLE . ' (software, branch, version, announcement, release_date, last_check, estimated) VALUES (
:software, :branch, :version, :announcement, :release_date, :last_check, :estimated
)';
$uph = $db->prepare($sql);
$ret = $uph->execute(array(
':software' => $class,
':branch' => $branch,
':version' => $version_info['version'],
':announcement' => array_key_exists('announcement', $version_info) ? $version_info['announcement'] : '',
':release_date' => $version_info['release_date'],
':last_check' => date("Y-m-d H:i:s"),
':estimated' => array_key_exists('estimated', $version_info) ? (int)$version_info['estimated'] : 0,
));
if (!$ret)
{
echo 'Error while adding new version information' . "\n";
print_r($uph->errorInfo());
print_r($uph->debugDumpParams());
//exit;
continue;
}
$updates[$class][$branch] = $version_info['version'];
}
//echo $software::$name . "\n";
//echo $branch ."\n";
//print_r($version_info);
}
// Log the updates so we can send notifications
// This assumes all pending updates were already sent
$sql = 'INSERT INTO ' . NOTIFICATIONS_TABLE . ' (software, branch, version) VALUES (:software, :branch, :version)';
$sth = $db->prepare($sql);
foreach ($updates as $software => $data)
{
foreach ($data as $branch => $version)
{
$ret = $sth->execute(array(
':software' => $software,
':branch' => $branch,
':version' => $version,
));
if (!$ret)
{
echo 'Error while adding notification information' . "\n";
print_r($sth->errorInfo());
print_r($sth->debugDumpParams());
//exit;
continue;
}
}
}
}