mirror of
https://github.com/torrentpier/torrentpier.git
synced 2025-02-03 08:42:56 -08:00
81 lines
2.8 KiB
PHP
81 lines
2.8 KiB
PHP
<?php
|
||
/**
|
||
* TorrentPier – Bull-powered BitTorrent tracker engine
|
||
*
|
||
* @copyright Copyright (c) 2005-2025 TorrentPier (https://torrentpier.com)
|
||
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
|
||
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
|
||
*/
|
||
|
||
if (!defined('BB_ROOT')) {
|
||
die(basename(__FILE__));
|
||
}
|
||
|
||
// Synchronization
|
||
\TorrentPier\Legacy\Admin\Common::sync('topic', 'all');
|
||
\TorrentPier\Legacy\Admin\Common::sync('user_posts', 'all');
|
||
\TorrentPier\Legacy\Admin\Common::sync_all_forums();
|
||
|
||
// Cleaning bb_poll_users
|
||
if ($poll_max_days = (int)$bb_cfg['poll_max_days']) {
|
||
$per_cycle = 20000;
|
||
$row = DB()->fetch_row("SELECT MIN(topic_id) AS start_id, MAX(topic_id) AS finish_id FROM " . BB_POLL_USERS);
|
||
$start_id = (int)$row['start_id'];
|
||
$finish_id = (int)$row['finish_id'];
|
||
|
||
while (true) {
|
||
set_time_limit(600);
|
||
$end_id = $start_id + $per_cycle - 1;
|
||
|
||
DB()->query("
|
||
DELETE FROM " . BB_POLL_USERS . "
|
||
WHERE topic_id BETWEEN $start_id AND $end_id
|
||
AND vote_dt < " . (TIMENOW - 86400 * $poll_max_days) . "
|
||
");
|
||
|
||
if ($end_id > $finish_id) {
|
||
break;
|
||
}
|
||
|
||
$start_id += $per_cycle;
|
||
}
|
||
}
|
||
|
||
// Cleaning user_newpasswd
|
||
DB()->query("UPDATE " . BB_USERS . " SET user_newpasswd = '' WHERE user_lastvisit < " . (TIMENOW - 7 * 86400));
|
||
|
||
// Cleaning post cache
|
||
if ($posts_days = (int)$bb_cfg['posts_cache_days_keep']) {
|
||
DB()->query("DELETE FROM " . BB_POSTS_HTML . " WHERE post_html_time < DATE_SUB(NOW(), INTERVAL $posts_days DAY)");
|
||
}
|
||
|
||
// Autofill announcer url
|
||
if (empty($bb_cfg['bt_announce_url']) || ($bb_cfg['bt_announce_url'] === 'https://localhost/bt/announce.php')) {
|
||
bb_update_config(['bt_announce_url' => FULL_URL . 'bt/announce.php']);
|
||
}
|
||
|
||
// [Demo mode] Allow registering torrents by default for "Your first forum"
|
||
if (IN_DEMO_MODE) {
|
||
DB()->query("UPDATE " . BB_FORUMS . " SET allow_reg_tracker = 1 WHERE allow_reg_tracker = 0 AND forum_id = 1 LIMIT 1");
|
||
}
|
||
|
||
// Create unique TorrentPier instance hash
|
||
if (empty($bb_cfg['tp_instance_hash']) || ($bb_cfg['tp_instance_hash'] !== hash('xxh128', FULL_URL))) {
|
||
bb_update_config(['tp_instance_hash' => hash('xxh128', FULL_URL)]);
|
||
}
|
||
|
||
// Generate IndexNow key
|
||
if ($bb_cfg['indexnow_settings']['enabled'] && !is_file(BB_ROOT . $bb_cfg['indexnow_key'] . \TorrentPier\IndexNow::$keyFileExtension)) {
|
||
$randomIndexNowKey = empty($bb_cfg['indexnow_key']) ? make_rand_str(rand(64, 128)) : $bb_cfg['indexnow_key'];
|
||
if ($bb_cfg['indexnow_key'] !== $randomIndexNowKey) {
|
||
bb_update_config(['indexnow_key' => $randomIndexNowKey]);
|
||
}
|
||
file_write($randomIndexNowKey, (BB_ROOT . $randomIndexNowKey . \TorrentPier\IndexNow::$keyFileExtension));
|
||
}
|
||
|
||
// Check for updates
|
||
$datastore->update('check_updates');
|
||
|
||
// Integrity check
|
||
$datastore->update('files_integrity');
|