From 4dcee993cc3b686c8218f6ba734cc731bdd7d082 Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Mon, 11 Nov 2024 01:17:35 +0700 Subject: [PATCH] Minor improvements (#1676) * Minor improvements * Update functions.php * Update common.php * Update init_bb.php * Updated * Update build_files_integrity.php * Updated * Update CHANGELOG.md * Update legacy-changes.txt * Update legacy-changes.txt * Update legacy-changes.txt * Update .gitignore * Update legacy-changes.txt --- .gitignore | 1 + CHANGELOG.md | 2 +- common.php | 24 +++++++ install/upgrade/legacy-changes.txt | 70 ++----------------- library/config.php | 7 +- .../datastore/build_check_updates.php | 22 ++++-- .../datastore/build_files_integrity.php | 3 +- library/includes/functions.php | 6 +- library/includes/init_bb.php | 14 ---- 9 files changed, 55 insertions(+), 94 deletions(-) diff --git a/.gitignore b/.gitignore index 5474b0b43..bb9052f4d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *.log *.integrity install.php_* +composer-setup.php .env .php_cs.cache data/avatars diff --git a/CHANGELOG.md b/CHANGELOG.md index 592977705..ccfc439f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ - Fixed `md5()` deprecated in PHP 8.4 [\#1561](https://github.com/torrentpier/torrentpier/pull/1561) ([belomaxorka](https://github.com/belomaxorka)) - Increased `USEREMAIL_MAX_LENGTH` [\#1566](https://github.com/torrentpier/torrentpier/pull/1566) ([belomaxorka](https://github.com/belomaxorka)) - Disabled resizing for textarea tag [\#1638](https://github.com/torrentpier/torrentpier/pull/1638) ([belomaxorka](https://github.com/belomaxorka)) -- Minor improvements [\#1570](https://github.com/torrentpier/torrentpier/pull/1570), [\#1571](https://github.com/torrentpier/torrentpier/pull/1571), [\#1575](https://github.com/torrentpier/torrentpier/pull/1575), [\#1589](https://github.com/torrentpier/torrentpier/pull/1589), [\#1592](https://github.com/torrentpier/torrentpier/pull/1592), [\#1605](https://github.com/torrentpier/torrentpier/pull/1605), [\#1611](https://github.com/torrentpier/torrentpier/pull/1611), [\#1612](https://github.com/torrentpier/torrentpier/pull/1612), [\#1615](https://github.com/torrentpier/torrentpier/pull/1615), [\#1627](https://github.com/torrentpier/torrentpier/pull/1627), [\#1633](https://github.com/torrentpier/torrentpier/pull/1633), [\#1641](https://github.com/torrentpier/torrentpier/pull/1641), [\#1651](https://github.com/torrentpier/torrentpier/pull/1651), [\#1658](https://github.com/torrentpier/torrentpier/pull/1658), [\#1674](https://github.com/torrentpier/torrentpier/pull/1674), [\#1675](https://github.com/torrentpier/torrentpier/pull/1675) ([belomaxorka](https://github.com/belomaxorka)) +- Minor improvements [\#1570](https://github.com/torrentpier/torrentpier/pull/1570), [\#1571](https://github.com/torrentpier/torrentpier/pull/1571), [\#1575](https://github.com/torrentpier/torrentpier/pull/1575), [\#1589](https://github.com/torrentpier/torrentpier/pull/1589), [\#1592](https://github.com/torrentpier/torrentpier/pull/1592), [\#1605](https://github.com/torrentpier/torrentpier/pull/1605), [\#1611](https://github.com/torrentpier/torrentpier/pull/1611), [\#1612](https://github.com/torrentpier/torrentpier/pull/1612), [\#1615](https://github.com/torrentpier/torrentpier/pull/1615), [\#1627](https://github.com/torrentpier/torrentpier/pull/1627), [\#1633](https://github.com/torrentpier/torrentpier/pull/1633), [\#1641](https://github.com/torrentpier/torrentpier/pull/1641), [\#1651](https://github.com/torrentpier/torrentpier/pull/1651), [\#1658](https://github.com/torrentpier/torrentpier/pull/1658), [\#1674](https://github.com/torrentpier/torrentpier/pull/1674), [\#1675](https://github.com/torrentpier/torrentpier/pull/1675), [\#1676](https://github.com/torrentpier/torrentpier/pull/1676) ([belomaxorka](https://github.com/belomaxorka)) - Updated `modern-normalize` to `v3.0.1` [\#1669](https://github.com/torrentpier/torrentpier/pull/1669) ([belomaxorka](https://github.com/belomaxorka)) - Updated deps [\#1563](https://github.com/torrentpier/torrentpier/pull/1563), [\#1564](https://github.com/torrentpier/torrentpier/pull/1564), [\#1608](https://github.com/torrentpier/torrentpier/pull/1608), [\#1609](https://github.com/torrentpier/torrentpier/pull/1609), [\#1610](https://github.com/torrentpier/torrentpier/pull/1610), [\#1637](https://github.com/torrentpier/torrentpier/pull/1637), [\#1646](https://github.com/torrentpier/torrentpier/pull/1646), [\#1647](https://github.com/torrentpier/torrentpier/pull/1647), [\#1650](https://github.com/torrentpier/torrentpier/pull/1650), [\#1656](https://github.com/torrentpier/torrentpier/pull/1656) ([belomaxorka](https://github.com/belomaxorka)) - New Crowdin updates [\#1569](https://github.com/torrentpier/torrentpier/pull/1569), [\#1572](https://github.com/torrentpier/torrentpier/pull/1572), [\#1573](https://github.com/torrentpier/torrentpier/pull/1573), [\#1574](https://github.com/torrentpier/torrentpier/pull/1574), [\#1588](https://github.com/torrentpier/torrentpier/pull/1588), [\#1590](https://github.com/torrentpier/torrentpier/pull/1590), [\#1600](https://github.com/torrentpier/torrentpier/pull/1600), [\#1601](https://github.com/torrentpier/torrentpier/pull/1601), [\#1606](https://github.com/torrentpier/torrentpier/pull/1606), [\#1607](https://github.com/torrentpier/torrentpier/pull/1607), [\#1625](https://github.com/torrentpier/torrentpier/pull/1625), [\#1626](https://github.com/torrentpier/torrentpier/pull/1626), [\#1629](https://github.com/torrentpier/torrentpier/pull/1629), [\#1630](https://github.com/torrentpier/torrentpier/pull/1630), [\#1631](https://github.com/torrentpier/torrentpier/pull/1631), [\#1632](https://github.com/torrentpier/torrentpier/pull/1632), [\#1639](https://github.com/torrentpier/torrentpier/pull/1639), [\#1640](https://github.com/torrentpier/torrentpier/pull/1640), [\#1654](https://github.com/torrentpier/torrentpier/pull/1654), [\#1655](https://github.com/torrentpier/torrentpier/pull/1655) ([Exileum](https://github.com/Exileum)) diff --git a/common.php b/common.php index 9c619ba1a..15db02974 100644 --- a/common.php +++ b/common.php @@ -324,6 +324,12 @@ function hide_bb_path(string $path): string return ltrim(str_replace(BB_PATH, '', $path), '/\\'); } +/** + * Returns memory usage statistic + * + * @param string $param + * @return int|void + */ function sys(string $param) { switch ($param) { @@ -336,9 +342,27 @@ function sys(string $param) } } +/** + * Returns version code + * + * @param string $version + * @return int + */ +function version_code(string $version): int +{ + return (int)trim(str_replace(['.', 'v'], '', $version)); +} + /** * Some shared defines */ +// Initialize demo mode +define('IN_DEMO_MODE', env('APP_DEMO_MODE', false)); + +// Version code +define('VERSION_CODE', version_code($bb_cfg['tp_version'])); + +// Ratio status define('RATIO_ENABLED', TR_RATING_LIMITS && MIN_DL_FOR_RATIO > 0); // Initialization diff --git a/install/upgrade/legacy-changes.txt b/install/upgrade/legacy-changes.txt index ca87a8462..89aad9de9 100644 --- a/install/upgrade/legacy-changes.txt +++ b/install/upgrade/legacy-changes.txt @@ -104,10 +104,8 @@ CREATE TABLE IF NOT EXISTS `bb_thx` DEFAULT CHARSET = utf8mb4; // 2.4.0 -INSERT INTO `bb_attachments_config` -VALUES ('upload_dir', 'data/uploads'); -INSERT INTO `bb_attachments_config` -VALUES ('img_min_thumb_filesize', '12000'); +UPDATE `bb_attachments_config` SET `config_value` = 'data/uploads' WHERE `config_name` = 'upload_dir'; +UPDATE `bb_attachments_config` SET `config_value` = '12000' WHERE `config_name` = 'img_min_thumb_filesize'; DELETE FROM `bb_attachments_config` WHERE config_name = 'attach_version'; DELETE FROM `bb_attachments_config` WHERE config_name = 'img_min_thumb_filesize'; DELETE FROM `bb_attachments_config` WHERE config_name = 'img_imagick'; @@ -129,8 +127,7 @@ CREATE TABLE IF NOT EXISTS `bb_banlist` DEFAULT CHARSET = utf8mb4; // 2.4.1 -INSERT INTO `bb_config` -VALUES ('bt_announce_url', ''); +UPDATE `bb_config` SET `config_value` = '' WHERE `config_name` = 'bt_announce_url'; // 2.4.2 INSERT INTO `bb_cron` (`cron_active`, `cron_title`, `cron_script`, `schedule`, `run_day`, `run_time`, `run_order`, @@ -138,67 +135,10 @@ INSERT INTO `bb_cron` (`cron_active`, `cron_title`, `cron_script`, `schedule`, ` `disable_board`, `run_counter`) VALUES ('1', 'Demo mode', 'demo_mode.php', 'daily', '', '05:00:00', '255', '', '', '', '1', 'demo_mode_cron', '1', '1', '0'); // 2.4.3 -INSERT INTO `bb_config` -VALUES ('bt_announce_url', 'https://localhost/bt/announce.php'); +UPDATE `bb_config` SET `config_value` = 'https://localhost/bt/announce.php' WHERE `config_name` = 'bt_announce_url'; // 2.4.4 -ALTER TABLE `bb_attachments` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_attachments_config` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_attachments_desc` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_attach_quota` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_auth_access` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_auth_access_snap` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_banlist` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_bt_dlstatus` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_bt_dlstatus_snap` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_bt_last_torstat` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_bt_last_userstat` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_bt_torhelp` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_bt_torrents` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_bt_torstat` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_bt_tor_dl_stat` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_bt_tracker` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_bt_tracker_snap` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_bt_users` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_bt_user_settings` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_categories` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_config` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_cron` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_disallow` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_extensions` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_extension_groups` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_forums` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_groups` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_log` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_poll_users` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_poll_votes` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_posts` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_posts_html` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_posts_search` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_posts_text` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_privmsgs` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_privmsgs_text` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_quota_limits` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_ranks` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_search_rebuild` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_search_results` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_sessions` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_smilies` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_topics` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_topics_watch` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_topic_tpl` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_users` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_user_group` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_words` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `buf_last_seeder` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_thx` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `buf_topic_view` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `bb_config` CHANGE `config_name` `config_name` VARCHAR(155) NOT NULL DEFAULT ''; -ALTER TABLE `bb_attachments_config` CHANGE `config_name` `config_name` VARCHAR(155) NOT NULL DEFAULT ''; ALTER TABLE `bb_poll_users` CHANGE `user_id` `user_id` MEDIUMINT(8) NOT NULL; ALTER TABLE `bb_bt_users` ADD COLUMN `ratio_nulled` TINYINT(1) NOT NULL DEFAULT '0'; DELETE FROM `bb_cron` WHERE `cron_script` = 'cache_gc.php'; -DELETE FROM `bb_cron` WHERE `cron_script` = 'tr_seed_bonus.php'; -INSERT INTO `bb_cron` (`cron_active`, `cron_title`, `cron_script`, `schedule`, `run_day`, `run_time`, `run_order`, - `last_run`, `next_run`, `run_interval`, `log_enabled`, `log_file`, `log_sql_queries`, - `disable_board`, `run_counter`) VALUES ('1', 'Accrual seedbonus', 'tr_seed_bonus.php', 'interval', '', '', '25', '', '', '00:10:00', '0', '', '0', '0', '0'); +UPDATE `bb_cron` SET `run_interval` = '00:10:00' WHERE `cron_script` = 'tr_seed_bonus.php'; diff --git a/library/config.php b/library/config.php index 6c2e55f0b..395139ba1 100644 --- a/library/config.php +++ b/library/config.php @@ -17,14 +17,15 @@ $reserved_port = 80; $bb_cfg = []; -// Increase number after changing js or css -$bb_cfg['js_ver'] = $bb_cfg['css_ver'] = 1; - // Version info $bb_cfg['tp_version'] = 'v2.4.5-dev'; $bb_cfg['tp_release_date'] = 'XX-XX-2024'; $bb_cfg['tp_release_codename'] = 'Cattle'; +// Increase version number after changing JS or CSS +// Note: by default used same as TorrentPier version +$bb_cfg['js_ver'] = $bb_cfg['css_ver'] = $bb_cfg['tp_version']; + // Database // Settings for database ['db']['srv_name'] => (array) srv_cfg; $bb_cfg['db'] = [ diff --git a/library/includes/datastore/build_check_updates.php b/library/includes/datastore/build_check_updates.php index 3233d2da5..1f7b11e00 100644 --- a/library/includes/datastore/build_check_updates.php +++ b/library/includes/datastore/build_check_updates.php @@ -19,17 +19,29 @@ $updaterDownloader = new \TorrentPier\Updater(); $updaterDownloader = $updaterDownloader->getLastVersion(); $getVersion = $updaterDownloader['tag_name']; -$versionCodeActual = (int)trim(str_replace(['.', 'v'], '', $getVersion)); +$versionCodeActual = version_code($getVersion); // Has update! if (VERSION_CODE < $versionCodeActual) { $latestBuildFileLink = $updaterDownloader['assets'][0]['browser_download_url']; + // Check updater file + $updater_file = readUpdaterFile(); + $updater_need_replaced = !empty($updater_file) && ($updater_file['latest_version']['short_code'] < $versionCodeActual); + // Save current version & latest available - file_write(json_encode([ - 'previous_version' => VERSION_CODE, - 'latest_version' => $versionCodeActual - ]), UPDATER_FILE, replace_content: true); + if (!is_file(UPDATER_FILE) || $updater_need_replaced) { + file_write(json_encode([ + 'previous_version' => [ + 'short_code' => VERSION_CODE, + 'version' => $bb_cfg['tp_version'] + ], + 'latest_version' => [ + 'short_code' => $versionCodeActual, + 'version' => $getVersion + ] + ]), UPDATER_FILE, replace_content: true); + } // Get MD5 checksum $buildFileChecksum = ''; diff --git a/library/includes/datastore/build_files_integrity.php b/library/includes/datastore/build_files_integrity.php index 420762ace..71d8d552e 100644 --- a/library/includes/datastore/build_files_integrity.php +++ b/library/includes/datastore/build_files_integrity.php @@ -13,7 +13,8 @@ if (!defined('BB_ROOT')) { global $bb_cfg; -if (!$bb_cfg['integrity_check'] || is_dir(BB_ROOT . '.git')) { +// TODO: if (!local environment) { ... } +if (!$bb_cfg['integrity_check']) { return; } diff --git a/library/includes/functions.php b/library/includes/functions.php index c0ecde3c0..383334b32 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -2154,11 +2154,7 @@ function readUpdaterFile(): array|bool return false; } - $decodedFile = json_decode(file_get_contents(UPDATER_FILE), true); - return [ - 'previous_version' => $decodedFile['previous_version'], - 'latest_version' => $decodedFile['latest_version'] - ]; + return json_decode(file_get_contents(UPDATER_FILE), true); } /** diff --git a/library/includes/init_bb.php b/library/includes/init_bb.php index b8cd9cd15..5046afdc2 100644 --- a/library/includes/init_bb.php +++ b/library/includes/init_bb.php @@ -24,12 +24,6 @@ $user_ip = \TorrentPier\Helpers\IPHelper::ip2long($client_ip); define('CLIENT_IP', $client_ip); define('USER_IP', $user_ip); -// Initialize demo mode -define('IN_DEMO_MODE', env('APP_DEMO_MODE', false)); - -// Version code -define('VERSION_CODE', (int)trim(str_replace(['.', 'v'], '', $bb_cfg['tp_version']))); - /** * @param $contents * @return string @@ -400,14 +394,6 @@ $user = new TorrentPier\Legacy\Common\User(); $userdata =& $user->data; -/** - * Check for updates - */ -$updaterFile = readUpdaterFile(); -if ($updaterFile && ($updaterFile['previous_version'] < VERSION_CODE)) { - define('IN_UPDATER', true); -} - /** * Cron */