mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-21 13:54:02 -07:00
Minor improvements (#1480)
* Some enhancements for updates checker * Updated * Update updater.php * Update init_bb.php * Update CHANGELOG.md * Update globals.css * Updated * Update functions.php * Update init_bb.php * Updated * Updated * Updated * Update update_geolite_db.php * Update update_geolite_db.php * Update update_geolite_db.php * Updated * Update .gitignore * Update init_bb.php * Updated * Update CHANGELOG.md
This commit is contained in:
parent
784b608691
commit
9ada2c63b9
10 changed files with 48 additions and 38 deletions
|
@ -45,7 +45,7 @@ foreach ($cron_jobs as $job) {
|
|||
|
||||
if (is_file($job_script)) {
|
||||
$cron_start_time = utime();
|
||||
$cron_runtime_log = '';
|
||||
$cron_runtime_log = [];
|
||||
$cron_write_log = (CRON_LOG_ENABLED && (CRON_FORCE_LOG || $job['log_enabled'] >= 1));
|
||||
$cron_sql_log_file = CRON_LOG_DIR . '/SQL-' . basename($job['cron_script']);
|
||||
|
||||
|
@ -83,9 +83,10 @@ foreach ($cron_jobs as $job) {
|
|||
$msg .= LOG_LF . '------=-------=----------=------=-------=----------';
|
||||
bb_log($msg . LOG_LF, CRON_LOG_DIR . '/' . CRON_LOG_FILE);
|
||||
|
||||
if ($cron_runtime_log) {
|
||||
if (is_countable($cron_runtime_log)) {
|
||||
$runtime_log_file = ($job['log_file']) ?: $job['cron_script'];
|
||||
bb_log($cron_runtime_log . LOG_LF, CRON_LOG_DIR . '/' . basename($runtime_log_file));
|
||||
$cron_runtime_log[] = '';
|
||||
bb_log($cron_runtime_log, CRON_LOG_DIR . '/' . basename($runtime_log_file));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,6 @@ global $cron_runtime_log;
|
|||
foreach ($bb_cfg['cache']['engines'] as $cache_name => $cache_val) {
|
||||
if (method_exists(CACHE($cache_name), 'gc')) {
|
||||
$changes = CACHE($cache_name)->gc();
|
||||
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- " . str_pad("$cache_name ", 25, '-', STR_PAD_RIGHT) . " del: $changes\n";
|
||||
$cron_runtime_log[] = date('Y-m-d H:i:s') . " -- " . str_pad("$cache_name ", 25, '-', STR_PAD_RIGHT) . " del: $changes";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ foreach (file($dump_path) as $line) {
|
|||
$temp_line .= $line;
|
||||
if (str_ends_with(trim($line), ';')) {
|
||||
if (!DB()->query($temp_line)) {
|
||||
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Error performing query: " . $temp_line . " | " . DB()->sql_error()['message'] . "\n";
|
||||
$cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Error performing query: " . $temp_line . " | " . DB()->sql_error()['message'];
|
||||
}
|
||||
$temp_line = '';
|
||||
}
|
||||
|
|
|
@ -20,17 +20,17 @@ $old_file_path = INT_DATA_DIR . '/GeoLite2-City.mmdb.old';
|
|||
$repo_link = 'https://api.github.com/repos/P3TERX/GeoLite.mmdb/releases/latest';
|
||||
|
||||
if (is_file($old_file_path) && unlink($old_file_path)) {
|
||||
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Old GeoLite file successfully removed (First step)\n";
|
||||
$cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Old GeoLite file successfully removed (First step)";
|
||||
}
|
||||
|
||||
if (is_file($save_path)) {
|
||||
if (rename($save_path, $old_file_path)) {
|
||||
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Successfully created old GeoLite file\n";
|
||||
$cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Successfully created old GeoLite file";
|
||||
} else {
|
||||
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Cannot create old GeoLite file\n";
|
||||
$cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Cannot create old GeoLite file";
|
||||
}
|
||||
} else {
|
||||
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Cannot find GeoLite file (It's okay)\n";
|
||||
$cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Cannot find GeoLite file (It's okay)";
|
||||
}
|
||||
|
||||
$context = stream_context_create(['http' => ['header' => 'User-Agent: ' . APP_NAME]]);
|
||||
|
@ -39,43 +39,44 @@ $repo_content = file_get_contents($repo_link, context: $context);
|
|||
$json_response = false;
|
||||
if ($repo_content !== false) {
|
||||
$json_response = json_decode(utf8_encode($repo_content), true);
|
||||
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Successfully connected to: " . $repo_link . "\n";
|
||||
$cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Successfully connected to: " . $repo_link;
|
||||
} else {
|
||||
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Cannot access to: " . $repo_link . "\n";
|
||||
$cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Cannot access to: " . $repo_link;
|
||||
}
|
||||
|
||||
if (is_array($json_response) && !empty($json_response)) {
|
||||
$download_link = $json_response['assets'][1]['browser_download_url'];
|
||||
$file_date = $json_response['name'] ?? '';
|
||||
if (!empty($download_link)) {
|
||||
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Link to download is valid: " . $download_link . "\n";
|
||||
$cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Link to download is valid: " . $download_link;
|
||||
$get_file = file_get_contents($download_link);
|
||||
$get_file_md5 = md5_file($download_link);
|
||||
if ($get_file !== false) {
|
||||
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- GeoLite file obtained\n";
|
||||
$cron_runtime_log[] = date('Y-m-d H:i:s') . " -- GeoLite file obtained. MD5: $get_file_md5";
|
||||
file_put_contents($save_path, $get_file); // Save new GeoLite file!
|
||||
if (is_file($save_path)) {
|
||||
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- GeoLite file successfully saved ($file_date)\n";
|
||||
if (is_file($save_path) && ($get_file_md5 === md5_file($save_path))) {
|
||||
$cron_runtime_log[] = date('Y-m-d H:i:s') . " -- GeoLite file successfully saved ($file_date). MD5 hashes are identical";
|
||||
if (is_file($old_file_path) && unlink($old_file_path)) {
|
||||
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Old GeoLite file successfully removed (Second step)\n";
|
||||
$cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Old GeoLite file successfully removed (Second step)";
|
||||
}
|
||||
} else {
|
||||
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Reverting all changes...\n";
|
||||
$cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Reverting all changes...";
|
||||
if (is_file($old_file_path)) {
|
||||
if (rename($old_file_path, $save_path)) {
|
||||
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Successfully reverted\n";
|
||||
$cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Successfully reverted";
|
||||
} else {
|
||||
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Cannot revert changes, because cannot rename old file\n";
|
||||
$cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Cannot revert changes, because cannot rename old file";
|
||||
}
|
||||
} else {
|
||||
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Cannot revert changes, old file not found\n";
|
||||
$cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Cannot revert changes, old file not found";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- GeoLite file not obtained\n";
|
||||
$cron_runtime_log[] = date('Y-m-d H:i:s') . " -- GeoLite file not obtained";
|
||||
}
|
||||
} else {
|
||||
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Cannot find link to download\n";
|
||||
$cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Cannot find link to download";
|
||||
}
|
||||
} else {
|
||||
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Invalid response from server: " . $json_response . "\n";
|
||||
$cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Invalid response from server: " . $json_response;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue