From e4b6a919097c899abbf5499ef1fbd8262ee7c97f Mon Sep 17 00:00:00 2001 From: Yury Pikhtarev Date: Fri, 17 Mar 2023 19:26:07 +0700 Subject: [PATCH] New cron initialization and minor edits (#619) * New cron initialization and minor edits Updated the mechanism to check if cron needs to run and made minor improvements to the first run * Adding a warning in the control panel --- .env.example | 1 + README.md | 2 +- admin/admin_cron.php | 4 ++-- install/sql/mysql.sql | 1 - install/upgrade/changes.txt | 5 ++++- library/config.php | 4 ++-- library/includes/functions.php | 5 ++++- library/includes/init_bb.php | 7 ++++++- library/language/source/main.php | 1 + src/Helpers/CronHelper.php | 10 ++++++++++ styles/templates/admin/admin_cron.tpl | 8 ++++++-- 11 files changed, 37 insertions(+), 11 deletions(-) diff --git a/.env.example b/.env.example index dd55a2a6e..75e2d842d 100644 --- a/.env.example +++ b/.env.example @@ -2,6 +2,7 @@ APP_NAME=TorrentPier APP_ENV=local APP_DEBUG=false +APP_CRON_ENABLED=true # Database credentials DB_CONNECTION=mysql diff --git a/README.md b/README.md index 42ed47649..d27ec746f 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ and go from there. The documentation will be translated into english in the near * Apache / nginx * MySQL 5.5.3 or above / MariaDB 10.0 or above / Percona -* PHP: 7.1 / 7.2 / 7.3 +* PHP: 7.1 / 7.2 / 7.3 / 7.4 * PHP Extensions: bcmath, intl, tidy (optional), xml, xmlwriter ## Installation diff --git a/admin/admin_cron.php b/admin/admin_cron.php index cee94cd44..cb1330e9e 100644 --- a/admin/admin_cron.php +++ b/admin/admin_cron.php @@ -33,7 +33,7 @@ if (!IS_SUPER_ADMIN) { bb_die($lang['NOT_ADMIN']); } -$sql = DB()->fetch_rowset('SELECT * FROM ' . BB_CONFIG . " WHERE config_name = 'cron_enabled' OR config_name = 'cron_check_interval'"); +$sql = DB()->fetch_rowset('SELECT * FROM ' . BB_CONFIG . " WHERE config_name = 'cron_check_interval'"); foreach ($sql as $row) { $config_name = $row['config_name']; @@ -48,7 +48,7 @@ foreach ($sql as $row) { } $template->assign_vars(array( - 'CRON_ENABLED' => $new['cron_enabled'] ? true : false, + 'CRON_ENABLED' => TorrentPier\Helpers\CronHelper::isEnabled(), 'CRON_CHECK_INTERVAL' => $new['cron_check_interval'], )); diff --git a/install/sql/mysql.sql b/install/sql/mysql.sql index bd5e25aa7..463d793a8 100644 --- a/install/sql/mysql.sql +++ b/install/sql/mysql.sql @@ -560,7 +560,6 @@ VALUES ('allow_autologin', '1'), ('static_sitemap', ''), ('topics_per_page', '50'), ('xs_use_cache', '1'), - ('cron_enabled', '1'), ('cron_check_interval', '180'), ('magnet_links_enabled', '1'), ('gender', '1'), diff --git a/install/upgrade/changes.txt b/install/upgrade/changes.txt index db905b432..fd0fab693 100644 --- a/install/upgrade/changes.txt +++ b/install/upgrade/changes.txt @@ -45,6 +45,9 @@ ALTER TABLE `bb_groups` CHANGE `group_signature` `group_signature` TEXT NOT NULL ALTER TABLE `bb_groups` CHANGE `group_description` `group_description` TEXT NOT NULL DEFAULT ''; UPDATE `bb_smilies` SET `code` = ':cd:', `smile_url` = 'cd.gif', `emoticon` = 'cd' WHERE `code` = ':сd:' AND `smile_url` = 'сd.gif' AND `emoticon` = 'сd'; -2.3.1-rc2 +// 2.3.1-rc2 ALTER TABLE `bb_search_results` CHANGE `search_id` `search_id` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT ''; ALTER TABLE `bb_users` CHANGE `autologin_id` `autologin_id` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT ''; + +// 2.3.1-rc3 +DELETE FROM `bb_config` WHERE `config_name` = 'cron_enabled'; diff --git a/library/config.php b/library/config.php index 1e113d474..a2561ccfc 100644 --- a/library/config.php +++ b/library/config.php @@ -21,7 +21,7 @@ $bb_cfg = []; $bb_cfg['js_ver'] = $bb_cfg['css_ver'] = 1; // Version info -$bb_cfg['tp_version'] = '2.3.1-rc1'; +$bb_cfg['tp_version'] = '2.3.1-rc2'; $bb_cfg['tp_release_date'] = '10-03-2023'; $bb_cfg['tp_release_codename'] = 'Bison'; @@ -33,7 +33,7 @@ $bb_cfg['db'] = [ env('DB_HOST', 'localhost'), env('DB_DATABASE', 'torrentpier'), env('DB_USERNAME', 'root'), - env('DB_PASSWORD', 'pass'), + env('DB_PASSWORD'), 'utf8', false ], diff --git a/library/includes/functions.php b/library/includes/functions.php index 19a3e6461..7e9f65e82 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -834,7 +834,10 @@ function show_bt_userdata($user_id) { global $lang, $template; - $btu = get_bt_userdata($user_id); + if (!$btu = get_bt_userdata($user_id)) { + \TorrentPier\Legacy\Torrent::generate_passkey($user_id, true); + $btu = get_bt_userdata($user_id); + } $template->assign_vars(array( 'SHOW_BT_USERDATA' => true, diff --git a/library/includes/init_bb.php b/library/includes/init_bb.php index b8ea9ef9c..f98b576c2 100644 --- a/library/includes/init_bb.php +++ b/library/includes/init_bb.php @@ -405,7 +405,12 @@ $userdata =& $user->data; /** * Cron */ -if ((empty($_POST) && !defined('IN_ADMIN') && !defined('IN_AJAX') && !file_exists(CRON_RUNNING) && ($bb_cfg['cron_enabled'] || defined('START_CRON'))) || defined('FORCE_CRON')) { +if ( + empty($_POST) && + !defined('IN_ADMIN') && !defined('IN_AJAX') && + !file_exists(CRON_RUNNING) && + (TorrentPier\Helpers\CronHelper::isEnabled() || defined('START_CRON')) +) { if (TIMENOW - $bb_cfg['cron_last_check'] > $bb_cfg['cron_check_interval']) { /** Update cron_last_check */ diff --git a/library/language/source/main.php b/library/language/source/main.php index 5fbc52d08..f946a749b 100644 --- a/library/language/source/main.php +++ b/library/language/source/main.php @@ -2386,6 +2386,7 @@ $lang['CRON_NEXT_RUN'] = 'Next Run'; $lang['CRON_RUN_COUNT'] = 'Runs'; $lang['CRON_MANAGE'] = 'Manage'; $lang['CRON_OPTIONS'] = 'Cron options'; +$lang['CRON_DISABLED_WARNING'] = 'Warning! Running cron scripts is disabled. To enable it, set the APP_CRON_ENABLED variable.'; $lang['CRON_ENABLED'] = 'Cron enabled'; $lang['CRON_CHECK_INTERVAL'] = 'Cron check interval (sec)'; diff --git a/src/Helpers/CronHelper.php b/src/Helpers/CronHelper.php index 2eaa25dfb..1928da08a 100644 --- a/src/Helpers/CronHelper.php +++ b/src/Helpers/CronHelper.php @@ -15,6 +15,16 @@ namespace TorrentPier\Helpers; */ class CronHelper { + /** + * Checking whether cron scripts execution is enabled + * + * @return bool + */ + public static function isEnabled(): bool + { + return env('APP_CRON_ENABLED', true); + } + /** * Снятие блокировки крона (по времени) * diff --git a/styles/templates/admin/admin_cron.tpl b/styles/templates/admin/admin_cron.tpl index e4f08177c..191ca6991 100644 --- a/styles/templates/admin/admin_cron.tpl +++ b/styles/templates/admin/admin_cron.tpl @@ -35,8 +35,7 @@ tr.hl-tr:hover td { background-color: #CFC !important; } {L_CRON_ENABLED} -    - + {L_YES}{L_NO} {L_CRON_CHECK_INTERVAL} @@ -62,6 +61,11 @@ tr.hl-tr:hover td { background-color: #CFC !important; }
+ + + + +
{L_CRON_DISABLED_WARNING}
{L_CRON_LIST}