-
Notifications
You must be signed in to change notification settings - Fork 3
/
handle_pk3_update.php
72 lines (59 loc) · 2.79 KB
/
handle_pk3_update.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
<?php
set_time_limit(600);
require_once($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "_constants.php");
require_once($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "scripts/logger.php");
require_once($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "scripts/project_compiler.php");
$redirect = isset($_GET['redirect']) ? $_GET['redirect'] : false;
$nocache = isset($_GET['nocache']) ? $_GET['nocache'] : false;
$nozip = isset($_GET['nozip']) ? $_GET['nozip'] : false;
$lock_file_recent = file_exists(LOCK_FILE_COMPILE) && (time() - get_mtime(LOCK_FILE_COMPILE)) < 600;
$pk3_is_current = true;
if ($lock_file_recent) {
echo json_encode(['success' => false, 'error' => 'Project is already being generated! Hold on a minute then try again']);
die();
}
// Only perform PK3 check if we're not forcing a rebuild
if ($nocache) {
Logger::lg("Nocache flag was passed to PK3 updater - will rebuild");
$pk3_is_current = false;
}
// Check for changes to the catalog file
if (get_mtime(CATALOG_FILE) > get_mtime(get_project_full_path())) {
$pk3_is_current = false;
Logger::lg("Catalog file has newer data than latest snapshot - will rebuild");
}
// Check for changes to the settings file
if (get_mtime(SETTINGS_FILE) > get_mtime(get_project_full_path())) {
$pk3_is_current = false;
Logger::lg("Settings file has been changed since latest snapshot - will rebuild");
}
// Now check the fixedcontent folder... if we don't have a script, just keep the answer from before
if (!empty($GLOBALS["STATIC_CONTENT_MTIME_SCRIPT"])) {
$static_content_mtime = trim(shell_exec($GLOBALS["STATIC_CONTENT_MTIME_SCRIPT"]));
if (is_numeric($static_content_mtime) && !empty($static_content_mtime) && $static_content_mtime > get_mtime(get_project_full_path())) {
Logger::lg("Static content folder has newer data than latest snapshot - will rebuild");
$pk3_is_current = false;
}
}
// If we don't have a project file at all, we have to build
if (!file_exists(get_project_full_path())) {
Logger::lg("No snapshot exists - will rebuild");
$pk3_is_current = false;
}
// If we've reached here and the pk3_is_current flag is still true, then we've decided the existing PK3 is still OK
if ($pk3_is_current) {
Logger::lg("PK3 passed all checks - serving the existing one");
echo json_encode(['success' => true, 'newpk3' => false]);
die();
}
// Trigger a rebuild
$handler = new Project_Compiler();
if ($handler->compile_project(!$nozip)) {
if ($redirect) {
header("Location: admin/index.php");
die();
}
echo json_encode(['success' => true, 'newpk3' => true]);
die();
}
echo json_encode(['success' => false, 'error' => 'Something went wrong, the project admin should be able to see exactly what']);