mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-14 10:37:30 -07:00
Перенос файлов движка в корень
This commit is contained in:
parent
584f692288
commit
f94c0dd2ee
585 changed files with 14 additions and 14 deletions
2
library/includes/cron/.htaccess
Normal file
2
library/includes/cron/.htaccess
Normal file
|
@ -0,0 +1,2 @@
|
|||
order allow,deny
|
||||
deny from all
|
38
library/includes/cron/cron_check.php
Normal file
38
library/includes/cron/cron_check.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
bb_log(date('H:i:s - ') . getmypid() .' --x- SELECT jobs'. LOG_LF, CRON_LOG_DIR .'cron_check');
|
||||
|
||||
// Get cron jobs
|
||||
$cron_jobs = DB()->fetch_rowset("
|
||||
SELECT * FROM ". BB_CRON ."
|
||||
WHERE cron_active = 1
|
||||
AND next_run <= NOW()
|
||||
ORDER BY run_order
|
||||
");
|
||||
|
||||
// Run cron jobs
|
||||
if ($cron_jobs)
|
||||
{
|
||||
bb_log(date('H:i:s - ') . getmypid() .' --x- RUN jobs'. LOG_LF, CRON_LOG_DIR .'cron_check');
|
||||
|
||||
foreach ($cron_jobs as $job)
|
||||
{
|
||||
if ($job['disable_board'])
|
||||
{
|
||||
cron_disable_board();
|
||||
sleep(10);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
require(CRON_DIR .'cron_run.php');
|
||||
|
||||
// Update cron_last_check
|
||||
bb_update_config(array('cron_last_check' => (TIMENOW + 10)));
|
||||
}
|
||||
else
|
||||
{
|
||||
bb_log(date('H:i:s - ') . getmypid() .' --x- no active jobs found ----------------------------------------------'. LOG_LF, CRON_LOG_DIR .'cron_check');
|
||||
}
|
67
library/includes/cron/cron_init.php
Normal file
67
library/includes/cron/cron_init.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
//
|
||||
// Functions
|
||||
//
|
||||
function cron_get_file_lock ()
|
||||
{
|
||||
$lock_obtained = false;
|
||||
|
||||
if (file_exists(CRON_ALLOWED))
|
||||
{
|
||||
# bb_log(date('H:i:s - ') . getmypid() .' -x-- FILE-LOCK try'. LOG_LF, CRON_LOG_DIR .'cron_check');
|
||||
|
||||
$lock_obtained = @rename(CRON_ALLOWED, CRON_RUNNING);
|
||||
}
|
||||
elseif (file_exists(CRON_RUNNING))
|
||||
{
|
||||
cron_release_deadlock();
|
||||
}
|
||||
elseif (!file_exists(CRON_ALLOWED) && !file_exists(CRON_RUNNING))
|
||||
{
|
||||
file_write('', CRON_ALLOWED);
|
||||
$lock_obtained = @rename(CRON_ALLOWED, CRON_RUNNING);
|
||||
}
|
||||
|
||||
return $lock_obtained;
|
||||
}
|
||||
|
||||
function cron_track_running ($mode)
|
||||
{
|
||||
@define('CRON_STARTMARK', TRIGGERS_DIR .'cron_started_at_'. date('Y-m-d_H-i-s') .'_by_pid_'. getmypid());
|
||||
|
||||
if ($mode == 'start')
|
||||
{
|
||||
cron_touch_lock_file(CRON_RUNNING);
|
||||
file_write('', CRON_STARTMARK);
|
||||
}
|
||||
elseif ($mode == 'end')
|
||||
{
|
||||
@unlink(CRON_STARTMARK);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Run cron
|
||||
//
|
||||
if (cron_get_file_lock())
|
||||
{
|
||||
ignore_user_abort(true);
|
||||
register_shutdown_function('cron_release_file_lock');
|
||||
register_shutdown_function('cron_enable_board');
|
||||
|
||||
# bb_log(date('H:i:s - ') . getmypid() .' --x- FILE-LOCK OBTAINED ###############'. LOG_LF, CRON_LOG_DIR .'cron_check');
|
||||
|
||||
cron_track_running('start');
|
||||
|
||||
require(CRON_DIR .'cron_check.php');
|
||||
|
||||
cron_track_running('end');
|
||||
}
|
||||
|
||||
if (defined('IN_CRON'))
|
||||
{
|
||||
bb_log(date('H:i:s - ') . getmypid() .' --x- ALL jobs FINISHED *************************************************'. LOG_LF, CRON_LOG_DIR .'cron_check');
|
||||
}
|
129
library/includes/cron/cron_run.php
Normal file
129
library/includes/cron/cron_run.php
Normal file
|
@ -0,0 +1,129 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
define('IN_CRON', true);
|
||||
|
||||
// Set SESSION vars
|
||||
DB()->query("
|
||||
SET SESSION
|
||||
myisam_sort_buffer_size = 16*1024*1024
|
||||
, bulk_insert_buffer_size = 8*1024*1024
|
||||
, join_buffer_size = 4*1024*1024
|
||||
, read_buffer_size = 4*1024*1024
|
||||
, read_rnd_buffer_size = 8*1024*1024
|
||||
, sort_buffer_size = 4*1024*1024
|
||||
, tmp_table_size = 80*1024*1024
|
||||
, group_concat_max_len = 1*1024*1024
|
||||
");
|
||||
|
||||
// Restore vars at shutdown
|
||||
DB()->add_shutdown_query("
|
||||
SET SESSION
|
||||
myisam_sort_buffer_size = DEFAULT
|
||||
, bulk_insert_buffer_size = DEFAULT
|
||||
, join_buffer_size = DEFAULT
|
||||
, read_buffer_size = DEFAULT
|
||||
, read_rnd_buffer_size = DEFAULT
|
||||
, sort_buffer_size = DEFAULT
|
||||
, tmp_table_size = DEFAULT
|
||||
, group_concat_max_len = DEFAULT
|
||||
");
|
||||
|
||||
// $cron_jobs obtained in cron_check.php
|
||||
foreach ($cron_jobs as $job)
|
||||
{
|
||||
$job_script = CRON_JOB_DIR . basename($job['cron_script']);
|
||||
|
||||
if (file_exists($job_script))
|
||||
{
|
||||
$cron_start_time = utime();
|
||||
$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']);
|
||||
|
||||
if ($cron_write_log)
|
||||
{
|
||||
$msg = array();
|
||||
$msg[] = 'start';
|
||||
$msg[] = date('m-d');
|
||||
$msg[] = date('H:i:s');
|
||||
$msg[] = sprintf('%-4s', round(sys('la'), 1));
|
||||
$msg[] = sprintf('%05d', getmypid());
|
||||
$msg[] = $job['cron_title'];
|
||||
$msg = join(LOG_SEPR, $msg);
|
||||
bb_log($msg . LOG_LF, CRON_LOG_DIR . CRON_LOG_FILE);
|
||||
}
|
||||
|
||||
if ($job['log_sql_queries'])
|
||||
{
|
||||
DB()->log_next_query(100000, $cron_sql_log_file);
|
||||
}
|
||||
|
||||
set_time_limit(600);
|
||||
require($job_script);
|
||||
|
||||
if ($job['log_sql_queries'])
|
||||
{
|
||||
DB()->log_next_query(0);
|
||||
bb_log(LOG_LF, $cron_sql_log_file);
|
||||
}
|
||||
|
||||
if ($cron_write_log)
|
||||
{
|
||||
$msg = array();
|
||||
$msg[] = ' end';
|
||||
$msg[] = date('m-d');
|
||||
$msg[] = date('H:i:s');
|
||||
$msg[] = sprintf('%-4s', round(sys('la'), 1));
|
||||
$msg[] = sprintf('%05d', getmypid());
|
||||
$msg[] = round(utime() - $cron_start_time) .'/'. round(utime() - TIMESTART) . ' sec';
|
||||
$msg = join(LOG_SEPR, $msg);
|
||||
$msg .= LOG_LF .'------=-------=----------=------=-------=----------';
|
||||
bb_log($msg . LOG_LF, CRON_LOG_DIR . CRON_LOG_FILE);
|
||||
|
||||
if ($cron_runtime_log)
|
||||
{
|
||||
$runtime_log_file = ($job['log_file']) ? $job['log_file'] : $job['cron_script'];
|
||||
bb_log($cron_runtime_log . LOG_LF, CRON_LOG_DIR . basename($runtime_log_file));
|
||||
}
|
||||
}
|
||||
|
||||
DB()->query("
|
||||
UPDATE ". BB_CRON ." SET
|
||||
last_run = NOW(),
|
||||
run_counter = run_counter + 1,
|
||||
next_run =
|
||||
CASE
|
||||
WHEN schedule = 'hourly' THEN
|
||||
DATE_ADD(NOW(), INTERVAL 1 HOUR)
|
||||
WHEN schedule = 'daily' THEN
|
||||
DATE_ADD(DATE_ADD(CURDATE(), INTERVAL 1 DAY), INTERVAL TIME_TO_SEC(run_time) SECOND)
|
||||
WHEN schedule = 'weekly' THEN
|
||||
DATE_ADD(
|
||||
DATE_ADD(DATE_SUB(CURDATE(), INTERVAL WEEKDAY(NOW()) DAY), INTERVAL 7 DAY),
|
||||
INTERVAL CONCAT(ROUND(run_day-1), ' ', run_time) DAY_SECOND)
|
||||
WHEN schedule = 'monthly' THEN
|
||||
DATE_ADD(
|
||||
DATE_ADD(DATE_SUB(CURDATE(), INTERVAL DAYOFMONTH(NOW())-1 DAY), INTERVAL 1 MONTH),
|
||||
INTERVAL CONCAT(ROUND(run_day-1), ' ', run_time) DAY_SECOND)
|
||||
ELSE
|
||||
DATE_ADD(NOW(), INTERVAL TIME_TO_SEC(run_interval) SECOND)
|
||||
END
|
||||
WHERE cron_id = {$job['cron_id']}
|
||||
LIMIT 1
|
||||
");
|
||||
|
||||
sleep(1);
|
||||
|
||||
if (utime() - TIMESTART > 600)
|
||||
{
|
||||
return; // чтобы daily скрипты не блокировали надолго interval'ные
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$cron_err_msg = "Can not run \"{$job['cron_title']}\" : file \"$job_script\" not found". LOG_LF;
|
||||
bb_log($cron_err_msg, 'cron_error');
|
||||
}
|
||||
}
|
2
library/includes/cron/jobs/.htaccess
Normal file
2
library/includes/cron/jobs/.htaccess
Normal file
|
@ -0,0 +1,2 @@
|
|||
order allow,deny
|
||||
deny from all
|
224
library/includes/cron/jobs/attach_maintenance.php
Normal file
224
library/includes/cron/jobs/attach_maintenance.php
Normal file
|
@ -0,0 +1,224 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
DB()->expect_slow_query(600);
|
||||
|
||||
$fix_errors = true;
|
||||
$debug_mode = false;
|
||||
|
||||
$tmp_attach_tbl = 'tmp_attachments';
|
||||
$db_max_packet = 800000;
|
||||
$sql_limit = 3000;
|
||||
|
||||
$check_attachments = false;
|
||||
$orphan_files = $orphan_db_attach = $orphan_tor = array();
|
||||
$posts_without_attach = $topics_without_attach = array();
|
||||
|
||||
DB()->query("
|
||||
CREATE TEMPORARY TABLE $tmp_attach_tbl (
|
||||
physical_filename VARCHAR(255) NOT NULL default '',
|
||||
KEY physical_filename (physical_filename(20))
|
||||
) ENGINE = MyISAM DEFAULT CHARSET = utf8
|
||||
");
|
||||
DB()->add_shutdown_query("DROP TEMPORARY TABLE IF EXISTS $tmp_attach_tbl");
|
||||
|
||||
// Get attach_mod config
|
||||
$attach_dir = get_attachments_dir();
|
||||
|
||||
// Get all names of existed attachments and insert them into $tmp_attach_tbl
|
||||
if ($dir = @opendir($attach_dir))
|
||||
{
|
||||
$check_attachments = true;
|
||||
$files = array();
|
||||
$f_len = 0;
|
||||
|
||||
while (false !== ($f = readdir($dir)))
|
||||
{
|
||||
if ($f == 'index.php' || $f == '.htaccess' || is_dir("$attach_dir/$f") || is_link("$attach_dir/$f"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$f = DB()->escape($f);
|
||||
$files[] = "('$f')";
|
||||
$f_len += strlen($f) + 5;
|
||||
|
||||
if ($f_len > $db_max_packet)
|
||||
{
|
||||
$files = join(',', $files);
|
||||
DB()->query("INSERT INTO $tmp_attach_tbl VALUES $files");
|
||||
$files = array();
|
||||
$f_len = 0;
|
||||
}
|
||||
}
|
||||
if ($files = join(',', $files))
|
||||
{
|
||||
DB()->query("INSERT INTO $tmp_attach_tbl VALUES $files");
|
||||
}
|
||||
closedir($dir);
|
||||
}
|
||||
|
||||
if ($check_attachments)
|
||||
{
|
||||
// Delete bad records
|
||||
DB()->query("
|
||||
DELETE a, d
|
||||
FROM ". BB_ATTACHMENTS_DESC ." d
|
||||
LEFT JOIN ". BB_ATTACHMENTS ." a USING(attach_id)
|
||||
WHERE (
|
||||
d.physical_filename = ''
|
||||
OR d.real_filename = ''
|
||||
OR d.extension = ''
|
||||
OR d.mimetype = ''
|
||||
OR d.filesize = 0
|
||||
OR d.filetime = 0
|
||||
OR a.post_id = 0
|
||||
)
|
||||
");
|
||||
|
||||
// Delete attachments that exist in file system but not exist in DB
|
||||
$sql = "SELECT f.physical_filename
|
||||
FROM $tmp_attach_tbl f
|
||||
LEFT JOIN ". BB_ATTACHMENTS_DESC ." d USING(physical_filename)
|
||||
WHERE d.physical_filename IS NULL
|
||||
LIMIT $sql_limit";
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row)
|
||||
{
|
||||
if ($filename = basename($row['physical_filename']))
|
||||
{
|
||||
if ($fix_errors)
|
||||
{
|
||||
@unlink("$attach_dir/$filename");
|
||||
@unlink("$attach_dir/". THUMB_DIR .'/t_'. $filename);
|
||||
}
|
||||
if ($debug_mode)
|
||||
{
|
||||
$orphan_files[] = "$attach_dir/$filename";
|
||||
}
|
||||
}
|
||||
}
|
||||
// Find DB records for attachments that exist in DB but not exist in file system
|
||||
$sql = "SELECT d.attach_id
|
||||
FROM ". BB_ATTACHMENTS_DESC ." d
|
||||
LEFT JOIN $tmp_attach_tbl f USING(physical_filename)
|
||||
WHERE f.physical_filename IS NULL
|
||||
LIMIT $sql_limit";
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row)
|
||||
{
|
||||
$orphan_db_attach[] = $row['attach_id'];
|
||||
}
|
||||
// Attachment exist in DESC_TABLE but not exist in ATTACH_TABLE
|
||||
$sql = "SELECT d.attach_id
|
||||
FROM ". BB_ATTACHMENTS_DESC ." d
|
||||
LEFT JOIN ". BB_ATTACHMENTS ." a USING(attach_id)
|
||||
WHERE a.attach_id IS NULL
|
||||
LIMIT $sql_limit";
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row)
|
||||
{
|
||||
$orphan_db_attach[] = $row['attach_id'];
|
||||
}
|
||||
// Attachment exist in ATTACH_TABLE but not exist in DESC_TABLE
|
||||
$sql = "SELECT a.attach_id
|
||||
FROM ". BB_ATTACHMENTS ." a
|
||||
LEFT JOIN ". BB_ATTACHMENTS_DESC ." d USING(attach_id)
|
||||
WHERE d.attach_id IS NULL
|
||||
LIMIT $sql_limit";
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row)
|
||||
{
|
||||
$orphan_db_attach[] = $row['attach_id'];
|
||||
}
|
||||
// Attachments without post
|
||||
$sql = "SELECT a.attach_id
|
||||
FROM ". BB_ATTACHMENTS ." a
|
||||
LEFT JOIN ". BB_POSTS ." p USING(post_id)
|
||||
WHERE p.post_id IS NULL
|
||||
LIMIT $sql_limit";
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row)
|
||||
{
|
||||
$orphan_db_attach[] = $row['attach_id'];
|
||||
}
|
||||
// Delete all orphan attachments
|
||||
if ($orphans_sql = join(',', $orphan_db_attach))
|
||||
{
|
||||
if ($fix_errors)
|
||||
{
|
||||
DB()->query("DELETE FROM ". BB_ATTACHMENTS_DESC ." WHERE attach_id IN($orphans_sql)");
|
||||
DB()->query("DELETE FROM ". BB_ATTACHMENTS ." WHERE attach_id IN($orphans_sql)");
|
||||
}
|
||||
}
|
||||
|
||||
// Torrents without attachments
|
||||
$sql = "SELECT tor.topic_id
|
||||
FROM ". BB_BT_TORRENTS ." tor
|
||||
LEFT JOIN ". BB_ATTACHMENTS_DESC ." d USING(attach_id)
|
||||
WHERE d.attach_id IS NULL
|
||||
LIMIT $sql_limit";
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row)
|
||||
{
|
||||
$orphan_tor[] = $row['topic_id'];
|
||||
}
|
||||
// Delete all orphan torrents
|
||||
if ($orphans_sql = join(',', $orphan_tor))
|
||||
{
|
||||
if ($fix_errors)
|
||||
{
|
||||
DB()->query("DELETE FROM ". BB_BT_TORRENTS ." WHERE topic_id IN($orphans_sql)");
|
||||
}
|
||||
}
|
||||
|
||||
// Check post_attachment markers
|
||||
$sql = "SELECT p.post_id
|
||||
FROM ". BB_POSTS ." p
|
||||
LEFT JOIN ". BB_ATTACHMENTS ." a USING(post_id)
|
||||
WHERE p.post_attachment = 1
|
||||
AND a.post_id IS NULL";
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row)
|
||||
{
|
||||
$posts_without_attach[] = $row['post_id'];
|
||||
}
|
||||
if ($posts_sql = join(',', $posts_without_attach))
|
||||
{
|
||||
if ($fix_errors)
|
||||
{
|
||||
DB()->query("UPDATE ". BB_POSTS ." SET post_attachment = 0 WHERE post_id IN($posts_sql)");
|
||||
}
|
||||
}
|
||||
// Check topic_attachment markers
|
||||
$sql = "SELECT t.topic_id
|
||||
FROM ". BB_POSTS ." p, ". BB_TOPICS ." t
|
||||
WHERE t.topic_id = p.topic_id
|
||||
AND t.topic_attachment = 1
|
||||
GROUP BY p.topic_id
|
||||
HAVING SUM(p.post_attachment) = 0";
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row)
|
||||
{
|
||||
$topics_without_attach[] = $row['topic_id'];
|
||||
}
|
||||
if ($topics_sql = join(',', $topics_without_attach))
|
||||
{
|
||||
if ($fix_errors)
|
||||
{
|
||||
DB()->query("UPDATE ". BB_TOPICS ." SET topic_attachment = 0 WHERE topic_id IN($topics_sql)");
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($debug_mode)
|
||||
{
|
||||
prn_r($orphan_files, '$orphan_files');
|
||||
prn_r($orphan_db_attach, '$orphan_db_attach');
|
||||
prn_r($orphan_tor, '$orphan_tor');
|
||||
prn_r($posts_without_attach, '$posts_without_attach');
|
||||
prn_r($topics_without_attach, '$topics_without_attach');
|
||||
}
|
||||
|
||||
DB()->query("DROP TEMPORARY TABLE $tmp_attach_tbl");
|
||||
|
||||
unset($fix_errors, $debug_mode);
|
49
library/includes/cron/jobs/board_maintenance.php
Normal file
49
library/includes/cron/jobs/board_maintenance.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
require_once(INC_DIR .'functions_admin.php');
|
||||
|
||||
// Синхронизация
|
||||
sync('topic', 'all');
|
||||
sync('user_posts', 'all');
|
||||
sync_all_forums();
|
||||
|
||||
// Чистка 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 < DATE_SUB(NOW(), INTERVAL $poll_max_days DAY)
|
||||
");
|
||||
if ($end_id > $finish_id)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (!($start_id % ($per_cycle*10)))
|
||||
{
|
||||
sleep(1);
|
||||
}
|
||||
$start_id += $per_cycle;
|
||||
}
|
||||
}
|
||||
|
||||
// Чистка user_newpasswd
|
||||
DB()->query("UPDATE ". BB_USERS ." SET user_newpasswd = '' WHERE user_lastvisit < ". (TIMENOW - 7*86400));
|
||||
|
||||
// Чистка кеша постов
|
||||
if ($posts_days = intval($bb_cfg['posts_cache_days_keep']))
|
||||
{
|
||||
DB()->query("DELETE FROM ". BB_POSTS_HTML ." WHERE post_html_time < DATE_SUB(NOW(), INTERVAL $posts_days DAY)");
|
||||
}
|
14
library/includes/cron/jobs/cache_gc.php
Normal file
14
library/includes/cron/jobs/cache_gc.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
61
library/includes/cron/jobs/captcha_gen_gc.php
Normal file
61
library/includes/cron/jobs/captcha_gen_gc.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
//
|
||||
// Создание новых картинок
|
||||
//
|
||||
$cap_img_total = CAPTCHA()->cap_img_total; // сколько должно быть всего активных (cap_id > 0)
|
||||
$new_per_minute = CAPTCHA()->new_per_minute; // сколько добавлять новых
|
||||
$cap_expire_time = TIMENOW + CAPTCHA()->key_ttl*2;
|
||||
|
||||
$gen_new_img_count = $new_per_minute; // сколько реально нужно сгенерить новых
|
||||
$expire_img_count = $new_per_minute; // сколько пометить для удаления
|
||||
|
||||
$row = DB('cap')->fetch_row("SELECT COUNT(*) AS cnt, MAX(cap_id) AS max_id FROM ". BB_CAPTCHA ." WHERE cap_id > 0");
|
||||
|
||||
$cur_total_count = (int) $row['cnt'];
|
||||
$cur_max_id = (int) $row['max_id'];
|
||||
|
||||
if ($cur_total_count < $cap_img_total)
|
||||
{
|
||||
$gen_new_img_count += ($cap_img_total - $cur_total_count);
|
||||
}
|
||||
|
||||
$start_id = $cur_max_id + 1;
|
||||
$cur_id = $start_id;
|
||||
$finish_id = $start_id + $gen_new_img_count - 1;
|
||||
|
||||
while ($cur_id <= $finish_id)
|
||||
{
|
||||
$code = CAPTCHA()->gen_img($cur_id);
|
||||
DB('cap')->query("INSERT INTO ". BB_CAPTCHA ." (cap_id, cap_code) VALUES ($cur_id, '$code')");
|
||||
$cur_id++;
|
||||
}
|
||||
|
||||
//
|
||||
// Метка о неактивности и об истечении срока
|
||||
//
|
||||
DB('cap')->query("
|
||||
UPDATE ". BB_CAPTCHA ." SET
|
||||
cap_id = -cap_id,
|
||||
cap_expire = $cap_expire_time
|
||||
WHERE cap_id > 0
|
||||
ORDER BY cap_id
|
||||
LIMIT $expire_img_count
|
||||
");
|
||||
|
||||
//
|
||||
// Удаление старых
|
||||
//
|
||||
$del_ids = DB('cap')->fetch_rowset("SELECT cap_id FROM ". BB_CAPTCHA ." WHERE cap_id < 0 AND cap_expire < ". TIMENOW, 'cap_id');
|
||||
|
||||
foreach ($del_ids as $del_id)
|
||||
{
|
||||
$cap_img_path = CAPTCHA()->get_img_path(abs($del_id));
|
||||
if (@fopen($cap_img_path, 'r'))
|
||||
{
|
||||
unlink($cap_img_path);
|
||||
}
|
||||
DB('cap')->query("DELETE FROM ". BB_CAPTCHA ." WHERE cap_id = $del_id LIMIT 1");
|
||||
}
|
80
library/includes/cron/jobs/clean_dlstat.php
Normal file
80
library/includes/cron/jobs/clean_dlstat.php
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
// Delete staled dl-status records
|
||||
$keeping_dlstat = array(
|
||||
DL_STATUS_WILL => (int) $bb_cfg['dl_will_days_keep'],
|
||||
DL_STATUS_DOWN => (int) $bb_cfg['dl_down_days_keep'],
|
||||
DL_STATUS_COMPLETE => (int) $bb_cfg['dl_complete_days_keep'],
|
||||
DL_STATUS_CANCEL => (int) $bb_cfg['dl_cancel_days_keep'],
|
||||
);
|
||||
|
||||
$delete_dlstat_sql = array();
|
||||
|
||||
foreach ($keeping_dlstat as $dl_status => $days_to_keep)
|
||||
{
|
||||
if ($days_to_keep)
|
||||
{
|
||||
$delete_dlstat_sql[] = "
|
||||
user_status = $dl_status
|
||||
AND
|
||||
last_modified_dlstatus < DATE_SUB(NOW(), INTERVAL $days_to_keep DAY)
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
if ($delete_dlstat_sql = join(') OR (', $delete_dlstat_sql))
|
||||
{
|
||||
DB()->query("DELETE QUICK FROM ". BB_BT_DLSTATUS ." WHERE ($delete_dlstat_sql)");
|
||||
}
|
||||
|
||||
// Delete orphans
|
||||
DB()->query("
|
||||
DELETE QUICK dl
|
||||
FROM ". BB_BT_DLSTATUS ." dl
|
||||
LEFT JOIN ". BB_USERS ." u USING(user_id)
|
||||
WHERE u.user_id IS NULL
|
||||
");
|
||||
|
||||
DB()->query("
|
||||
DELETE QUICK dl
|
||||
FROM ". BB_BT_DLSTATUS ." dl
|
||||
LEFT JOIN ". BB_TOPICS ." t USING(topic_id)
|
||||
WHERE t.topic_id IS NULL
|
||||
");
|
||||
|
||||
// Tor-Stats cleanup
|
||||
if ($torstat_days_keep = intval($bb_cfg['torstat_days_keep']))
|
||||
{
|
||||
DB()->query("DELETE QUICK FROM ". BB_BT_TORSTAT ." WHERE last_modified_torstat < DATE_SUB(NOW(), INTERVAL $torstat_days_keep DAY)");
|
||||
}
|
||||
|
||||
DB()->query("
|
||||
DELETE QUICK tst
|
||||
FROM ". BB_BT_TORSTAT ." tst
|
||||
LEFT JOIN ". BB_BT_TORRENTS ." tor USING(topic_id)
|
||||
WHERE tor.topic_id IS NULL
|
||||
");
|
||||
|
||||
DB()->query("
|
||||
UPDATE
|
||||
". BB_BT_USERS ."
|
||||
SET
|
||||
up_yesterday = up_today,
|
||||
down_yesterday = down_today,
|
||||
up_release_yesterday = up_release_today,
|
||||
up_bonus_yesterday = up_bonus_today,
|
||||
points_yesterday = points_today
|
||||
");
|
||||
|
||||
DB()->query("
|
||||
UPDATE
|
||||
". BB_BT_USERS ."
|
||||
SET
|
||||
up_today = 0,
|
||||
down_today = 0,
|
||||
up_release_today = 0,
|
||||
up_bonus_today = 0,
|
||||
points_today = 0
|
||||
");
|
10
library/includes/cron/jobs/clean_log.php
Normal file
10
library/includes/cron/jobs/clean_log.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
$log_days_keep = (int) $bb_cfg['log_days_keep'];
|
||||
|
||||
DB()->query("
|
||||
DELETE FROM ". BB_LOG ."
|
||||
WHERE log_time < ". (TIMENOW - 86400*$log_days_keep) ."
|
||||
");
|
10
library/includes/cron/jobs/clean_search_results.php
Normal file
10
library/includes/cron/jobs/clean_search_results.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
$search_results_expire = TIMENOW - 3*3600;
|
||||
|
||||
DB()->query("
|
||||
DELETE FROM ". BB_SEARCH ."
|
||||
WHERE search_time < $search_results_expire
|
||||
");
|
5
library/includes/cron/jobs/ds_update_cat_forums.php
Normal file
5
library/includes/cron/jobs/ds_update_cat_forums.php
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
$datastore->update('cat_forums');
|
5
library/includes/cron/jobs/ds_update_stats.php
Normal file
5
library/includes/cron/jobs/ds_update_stats.php
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
$datastore->update('stats');
|
26
library/includes/cron/jobs/flash_topic_view.php
Normal file
26
library/includes/cron/jobs/flash_topic_view.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
// Lock tables
|
||||
DB()->lock(array(
|
||||
BB_TOPICS .' t',
|
||||
BUF_TOPIC_VIEW .' buf',
|
||||
));
|
||||
|
||||
// Flash buffered records
|
||||
DB()->query("
|
||||
UPDATE
|
||||
". BB_TOPICS ." t,
|
||||
". BUF_TOPIC_VIEW ." buf
|
||||
SET
|
||||
t.topic_views = t.topic_views + buf.topic_views
|
||||
WHERE
|
||||
t.topic_id = buf.topic_id
|
||||
");
|
||||
|
||||
// Delete buffered records
|
||||
DB()->query("DELETE buf FROM ". BUF_TOPIC_VIEW ." buf");
|
||||
|
||||
// Unlock tables
|
||||
DB()->unlock();
|
15
library/includes/cron/jobs/prune_forums.php
Normal file
15
library/includes/cron/jobs/prune_forums.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
require_once(INC_DIR .'functions_admin.php');
|
||||
|
||||
if ($bb_cfg['prune_enable'])
|
||||
{
|
||||
$sql = "SELECT forum_id, prune_days FROM ". BB_FORUMS ." WHERE prune_days != 0";
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row)
|
||||
{
|
||||
topic_delete('prune', $row['forum_id'], (TIMENOW - 86400*$row['prune_days']));
|
||||
}
|
||||
}
|
57
library/includes/cron/jobs/prune_inactive_users.php
Normal file
57
library/includes/cron/jobs/prune_inactive_users.php
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
require_once(INC_DIR .'functions_admin.php');
|
||||
|
||||
$users_per_cycle = 1000;
|
||||
|
||||
while (true)
|
||||
{
|
||||
@set_time_limit(600);
|
||||
|
||||
$prune_users = $not_activated_users = $not_active_users = array();
|
||||
|
||||
if ($not_activated_days = intval($bb_cfg['user_not_activated_days_keep']))
|
||||
{
|
||||
$sql = DB()->fetch_rowset("SELECT user_id FROM ". BB_USERS ."
|
||||
WHERE user_level = 0
|
||||
AND user_lastvisit = 0
|
||||
AND user_session_time = 0
|
||||
AND user_regdate <= ". (TIMENOW - 86400 * $not_activated_days) ."
|
||||
AND user_id NOT IN(". EXCLUDED_USERS_CSV .")
|
||||
LIMIT $users_per_cycle");
|
||||
|
||||
foreach ($sql as $row)
|
||||
{
|
||||
$not_activated_users[] = $row['user_id'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($not_active_days = intval($bb_cfg['user_not_active_days_keep']))
|
||||
{
|
||||
$sql = DB()->fetch_rowset("SELECT user_id FROM ". BB_USERS ."
|
||||
WHERE user_level = 0
|
||||
AND user_posts = 0
|
||||
AND user_lastvisit <= ". (TIMENOW - 86400 * $not_active_days) ."
|
||||
AND user_id NOT IN(". EXCLUDED_USERS_CSV .")
|
||||
LIMIT $users_per_cycle");
|
||||
|
||||
foreach ($sql as $row)
|
||||
{
|
||||
$not_active_users[] = $row['user_id'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($prune_users = $not_activated_users + $not_active_users)
|
||||
{
|
||||
user_delete($prune_users);
|
||||
}
|
||||
|
||||
if (count($prune_users) < $users_per_cycle)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
sleep(3);
|
||||
}
|
14
library/includes/cron/jobs/prune_topic_moved.php
Normal file
14
library/includes/cron/jobs/prune_topic_moved.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
if ($bb_cfg['topic_moved_days_keep'])
|
||||
{
|
||||
$prune_time = TIMENOW - 86400*$bb_cfg['topic_moved_days_keep'];
|
||||
|
||||
DB()->query("
|
||||
DELETE FROM ". BB_TOPICS ."
|
||||
WHERE topic_status = ". TOPIC_MOVED ."
|
||||
AND topic_time < $prune_time
|
||||
");
|
||||
}
|
47
library/includes/cron/jobs/sessions_cleanup.php
Normal file
47
library/includes/cron/jobs/sessions_cleanup.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
$user_session_expire_time = TIMENOW - intval($bb_cfg['user_session_duration']);
|
||||
$admin_session_expire_time = TIMENOW - intval($bb_cfg['admin_session_duration']);
|
||||
|
||||
$user_session_gc_time = $user_session_expire_time - intval($bb_cfg['user_session_gc_ttl']);
|
||||
$admin_session_gc_time = $admin_session_expire_time;
|
||||
|
||||
// ############################ Tables LOCKED ################################
|
||||
DB()->lock(array(
|
||||
BB_USERS .' u',
|
||||
BB_SESSIONS .' s',
|
||||
));
|
||||
|
||||
// Update user's session time
|
||||
DB()->query("
|
||||
UPDATE
|
||||
". BB_USERS ." u,
|
||||
". BB_SESSIONS ." s
|
||||
SET
|
||||
u.user_session_time = IF(u.user_session_time < s.session_time, s.session_time, u.user_session_time)
|
||||
WHERE
|
||||
u.user_id = s.session_user_id
|
||||
AND s.session_user_id != ". GUEST_UID ."
|
||||
AND (
|
||||
(s.session_time < $user_session_expire_time AND s.session_admin = 0)
|
||||
OR
|
||||
(s.session_time < $admin_session_expire_time AND s.session_admin != 0)
|
||||
)
|
||||
");
|
||||
|
||||
DB()->unlock();
|
||||
// ############################ Tables UNLOCKED ##############################
|
||||
|
||||
sleep(5);
|
||||
|
||||
// Delete staled sessions
|
||||
DB()->query("
|
||||
DELETE s
|
||||
FROM ". BB_SESSIONS ." s
|
||||
WHERE
|
||||
(s.session_time < $user_session_gc_time AND s.session_admin = 0)
|
||||
OR
|
||||
(s.session_time < $admin_session_gc_time AND s.session_admin != 0)
|
||||
");
|
18
library/includes/cron/jobs/sitemap.php
Normal file
18
library/includes/cron/jobs/sitemap.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
require(CLASS_DIR .'sitemap.php');
|
||||
|
||||
$map = new sitemap();
|
||||
$map->create();
|
||||
|
||||
if (@file_exists(BB_ROOT. "/sitemap/sitemap.xml"))
|
||||
{
|
||||
$map_link = make_url('/sitemap/sitemap.xml');
|
||||
|
||||
$map->send_url("http://google.com/webmasters/sitemaps/ping?sitemap=", $map_link);
|
||||
$map->send_url("http://ping.blogs.yandex.ru/ping?sitemap=", $map_link);
|
||||
$map->send_url("http://www.bing.com/ping?sitemap=", $map_link);
|
||||
$map->send_url("http://rpc.weblogs.com/pingSiteForm?name=InfraBlog&url=", $map_link);
|
||||
}
|
205
library/includes/cron/jobs/tr_cleanup_and_dlstat.php
Normal file
205
library/includes/cron/jobs/tr_cleanup_and_dlstat.php
Normal file
|
@ -0,0 +1,205 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
$releaser = DL_STATUS_RELEASER;
|
||||
|
||||
define('NEW_BB_BT_LAST_TORSTAT', 'new_bt_last_torstat');
|
||||
define('OLD_BB_BT_LAST_TORSTAT', 'old_bt_last_torstat');
|
||||
define('NEW_BB_BT_LAST_USERSTAT', 'new_bt_last_userstat');
|
||||
define('OLD_BB_BT_LAST_USERSTAT', 'old_bt_last_userstat');
|
||||
|
||||
DB()->query("DROP TABLE IF EXISTS ". NEW_BB_BT_LAST_TORSTAT .", ". NEW_BB_BT_LAST_USERSTAT);
|
||||
DB()->query("DROP TABLE IF EXISTS ". OLD_BB_BT_LAST_TORSTAT .", ". OLD_BB_BT_LAST_USERSTAT);
|
||||
|
||||
DB()->query("CREATE TABLE ". NEW_BB_BT_LAST_TORSTAT ." LIKE ". BB_BT_LAST_TORSTAT);
|
||||
DB()->query("CREATE TABLE ". NEW_BB_BT_LAST_USERSTAT ." LIKE ". BB_BT_LAST_USERSTAT);
|
||||
|
||||
DB()->expect_slow_query(600);
|
||||
|
||||
// Update dlstat (part 1)
|
||||
if ($tr_cfg['update_dlstat'])
|
||||
{
|
||||
// ############################ Tables LOCKED ################################
|
||||
DB()->lock(array(
|
||||
BB_BT_TRACKER,
|
||||
NEW_BB_BT_LAST_TORSTAT,
|
||||
));
|
||||
|
||||
// Get PER TORRENT user's dlstat from tracker
|
||||
DB()->query("
|
||||
INSERT INTO ". NEW_BB_BT_LAST_TORSTAT ."
|
||||
(topic_id, user_id, dl_status, up_add, down_add, release_add, speed_up, speed_down)
|
||||
SELECT
|
||||
topic_id, user_id, IF(releaser, $releaser, seeder), SUM(up_add), SUM(down_add), IF(releaser, SUM(up_add), 0), SUM(speed_up), SUM(speed_down)
|
||||
FROM ". BB_BT_TRACKER ."
|
||||
WHERE (up_add != 0 OR down_add != 0)
|
||||
GROUP BY topic_id, user_id
|
||||
");
|
||||
|
||||
// Reset up/down additions in tracker
|
||||
DB()->query("UPDATE ". BB_BT_TRACKER ." SET up_add = 0, down_add = 0");
|
||||
|
||||
DB()->unlock();
|
||||
// ############################ Tables UNLOCKED ##############################
|
||||
}
|
||||
|
||||
// Update last seeder info in BUF
|
||||
DB()->query("
|
||||
REPLACE INTO ". BUF_LAST_SEEDER ."
|
||||
(topic_id, seeder_last_seen)
|
||||
SELECT
|
||||
topic_id, ". TIMENOW ."
|
||||
FROM ". BB_BT_TRACKER ."
|
||||
WHERE seeder = 1
|
||||
GROUP BY topic_id
|
||||
");
|
||||
|
||||
// Clean peers table
|
||||
if ($tr_cfg['autoclean'])
|
||||
{
|
||||
$announce_interval = max(intval($bb_cfg['announce_interval']), 60);
|
||||
$expire_factor = max(floatval($tr_cfg['expire_factor']), 1);
|
||||
$peer_expire_time = TIMENOW - floor($announce_interval * $expire_factor);
|
||||
|
||||
DB()->query("DELETE FROM ". BB_BT_TRACKER ." WHERE update_time < $peer_expire_time");
|
||||
}
|
||||
|
||||
// Update dlstat (part 2)
|
||||
if ($tr_cfg['update_dlstat'])
|
||||
{
|
||||
// Set "only 1 seeder" bonus
|
||||
DB()->query("
|
||||
UPDATE
|
||||
". NEW_BB_BT_LAST_TORSTAT ." tb,
|
||||
". BB_BT_TRACKER_SNAP ." sn
|
||||
SET
|
||||
tb.bonus_add = tb.up_add
|
||||
WHERE
|
||||
tb.topic_id = sn.topic_id
|
||||
AND sn.seeders = 1
|
||||
AND tb.up_add != 0
|
||||
AND tb.dl_status = ". DL_STATUS_COMPLETE ."
|
||||
");
|
||||
|
||||
// Get SUMMARIZED user's dlstat
|
||||
DB()->query("
|
||||
INSERT INTO ". NEW_BB_BT_LAST_USERSTAT ."
|
||||
(user_id, up_add, down_add, release_add, bonus_add, speed_up, speed_down)
|
||||
SELECT
|
||||
user_id, SUM(up_add), SUM(down_add), SUM(release_add), SUM(bonus_add), SUM(speed_up), SUM(speed_down)
|
||||
FROM ". NEW_BB_BT_LAST_TORSTAT ."
|
||||
GROUP BY user_id
|
||||
");
|
||||
|
||||
// Update TOTAL user's dlstat
|
||||
DB()->query("
|
||||
UPDATE
|
||||
". BB_BT_USERS ." u,
|
||||
". NEW_BB_BT_LAST_USERSTAT ." ub
|
||||
SET
|
||||
u.u_up_total = u.u_up_total + ub.up_add,
|
||||
u.u_down_total = u.u_down_total + ub.down_add,
|
||||
u.u_up_release = u.u_up_release + ub.release_add,
|
||||
u.u_up_bonus = u.u_up_bonus + ub.bonus_add,
|
||||
u.up_today = u.up_today + ub.up_add,
|
||||
u.down_today = u.down_today + ub.down_add,
|
||||
u.up_release_today = u.up_release_today + ub.release_add,
|
||||
u.up_bonus_today = u.up_bonus_today + ub.bonus_add
|
||||
WHERE u.user_id = ub.user_id
|
||||
");
|
||||
|
||||
// Delete from dl_list what exists in BUF but not exsits in NEW
|
||||
DB()->query("
|
||||
DELETE dl
|
||||
FROM ". BB_BT_DLSTATUS ." dl
|
||||
INNER JOIN ". NEW_BB_BT_LAST_TORSTAT ." buf USING(user_id, topic_id)
|
||||
WHERE buf.user_id IS NULL
|
||||
AND buf.topic_id IS NULL
|
||||
");
|
||||
|
||||
// Update DL-Status
|
||||
DB()->query("
|
||||
REPLACE INTO ". BB_BT_DLSTATUS ."
|
||||
(user_id, topic_id, user_status)
|
||||
SELECT
|
||||
user_id, topic_id, dl_status
|
||||
FROM ". NEW_BB_BT_LAST_TORSTAT ."
|
||||
");
|
||||
|
||||
// Update PER TORRENT DL-Status (for "completed" counter)
|
||||
DB()->query("
|
||||
INSERT IGNORE INTO ". BB_BT_TORSTAT ."
|
||||
(topic_id, user_id)
|
||||
SELECT
|
||||
topic_id, user_id
|
||||
FROM ". NEW_BB_BT_LAST_TORSTAT ."
|
||||
WHERE dl_status = ". DL_STATUS_COMPLETE ."
|
||||
");
|
||||
}
|
||||
|
||||
DB()->query("
|
||||
RENAME TABLE
|
||||
". BB_BT_LAST_TORSTAT ." TO ". OLD_BB_BT_LAST_TORSTAT .",
|
||||
". NEW_BB_BT_LAST_TORSTAT ." TO ". BB_BT_LAST_TORSTAT ."
|
||||
");
|
||||
DB()->query("DROP TABLE IF EXISTS ". NEW_BB_BT_LAST_TORSTAT .", ". OLD_BB_BT_LAST_TORSTAT);
|
||||
|
||||
DB()->query("
|
||||
RENAME TABLE
|
||||
". BB_BT_LAST_USERSTAT ." TO ". OLD_BB_BT_LAST_USERSTAT .",
|
||||
". NEW_BB_BT_LAST_USERSTAT ." TO ". BB_BT_LAST_USERSTAT ."
|
||||
");
|
||||
DB()->query("DROP TABLE IF EXISTS ". NEW_BB_BT_LAST_USERSTAT .", ". OLD_BB_BT_LAST_USERSTAT);
|
||||
|
||||
DB()->expect_slow_query(10);
|
||||
|
||||
if($bb_cfg['seed_bonus_enabled'] && $bb_cfg['seed_bonus_points'] && $bb_cfg['seed_bonus_release'])
|
||||
{
|
||||
DB()->query("
|
||||
CREATE TEMPORARY TABLE tmp_bonus (
|
||||
user_id INT UNSIGNED NOT NULL DEFAULT '0',
|
||||
release_count INT UNSIGNED NOT NULL DEFAULT '0'
|
||||
) ENGINE = MEMORY
|
||||
");
|
||||
|
||||
$tor_size = ($bb_cfg['seed_bonus_tor_size'] * 1073741824);
|
||||
|
||||
DB()->query("INSERT INTO tmp_bonus
|
||||
SELECT bt.user_id, count(bt.seeder) AS release_count
|
||||
FROM ". BB_BT_TRACKER ." bt, ". BB_BT_TORRENTS ." tor
|
||||
WHERE tor.topic_id = bt.topic_id
|
||||
AND tor.size > $tor_size
|
||||
AND bt.seeder > 0
|
||||
GROUP BY user_id
|
||||
");
|
||||
|
||||
$seed_bonus = unserialize($bb_cfg['seed_bonus_points']);
|
||||
$seed_release = unserialize($bb_cfg['seed_bonus_release']);
|
||||
|
||||
foreach($seed_bonus as $i => $points)
|
||||
{
|
||||
if(!$points || !$seed_release[$i]) continue;
|
||||
|
||||
$user_points = ($points / 4);
|
||||
$release = $seed_release[$i];
|
||||
$user_regdate = (TIMENOW - $bb_cfg['seed_bonus_user_regdate'] * 86400);
|
||||
|
||||
DB()->query("
|
||||
UPDATE ". BB_USERS ." u, ". BB_BT_USERS ." bu, tmp_bonus b
|
||||
SET
|
||||
u.user_points = u.user_points + $user_points,
|
||||
bu.points_today = bu.points_today + $user_points,
|
||||
b.user_id = 0
|
||||
WHERE
|
||||
b.user_id = u.user_id
|
||||
AND bu.user_id = u.user_id
|
||||
AND b.release_count <= $release
|
||||
AND u.user_regdate < $user_regdate
|
||||
AND u.user_active = 1
|
||||
AND u.user_id not IN(". EXCLUDED_USERS_CSV .")
|
||||
");
|
||||
}
|
||||
|
||||
DB()->query("DROP TEMPORARY TABLE IF EXISTS tmp_bonus");
|
||||
}
|
48
library/includes/cron/jobs/tr_complete_count.php
Normal file
48
library/includes/cron/jobs/tr_complete_count.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
global $bb_cfg;
|
||||
|
||||
if ($bb_cfg['ocelot']['enabled'])
|
||||
{
|
||||
// Update TORRENT "completed" counters
|
||||
DB()->query("
|
||||
UPDATE
|
||||
". BB_BT_TORRENTS ." tor,
|
||||
". BB_BT_TRACKER_SNAP. " snap
|
||||
SET
|
||||
tor.complete_count = snap.complete
|
||||
WHERE
|
||||
tor.topic_id = snap.topic_id
|
||||
");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get complete counts
|
||||
DB()->query("
|
||||
CREATE TEMPORARY TABLE tmp_complete_count
|
||||
SELECT
|
||||
topic_id, COUNT(*) AS compl_cnt
|
||||
FROM ". BB_BT_TORSTAT ."
|
||||
WHERE completed = 0
|
||||
GROUP BY topic_id
|
||||
");
|
||||
|
||||
// Update USER "completed" counters
|
||||
DB()->query("UPDATE ". BB_BT_TORSTAT ." SET completed = 1");
|
||||
|
||||
// Update TORRENT "completed" counters
|
||||
DB()->query("
|
||||
UPDATE
|
||||
". BB_BT_TORRENTS ." tor,
|
||||
tmp_complete_count tmp
|
||||
SET
|
||||
tor.complete_count = tor.complete_count + tmp.compl_cnt
|
||||
WHERE
|
||||
tor.topic_id = tmp.topic_id
|
||||
");
|
||||
|
||||
// Drop tmp table
|
||||
DB()->query("DROP TEMPORARY TABLE tmp_complete_count");
|
||||
}
|
56
library/includes/cron/jobs/tr_maintenance.php
Normal file
56
library/includes/cron/jobs/tr_maintenance.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
if (empty($bb_cfg['seeder_last_seen_days_keep']) || empty($bb_cfg['seeder_never_seen_days_keep']))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$last_seen_time = TIMENOW - 86400*$bb_cfg['seeder_last_seen_days_keep'];
|
||||
$never_seen_time = TIMENOW - 86400*$bb_cfg['seeder_never_seen_days_keep'];
|
||||
$limit_sql = 3000;
|
||||
|
||||
$topics_sql = $attach_sql = array();
|
||||
|
||||
$sql = "SELECT topic_id, attach_id
|
||||
FROM ". BB_BT_TORRENTS ."
|
||||
WHERE reg_time < $never_seen_time
|
||||
AND seeder_last_seen < $last_seen_time
|
||||
LIMIT $limit_sql";
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row)
|
||||
{
|
||||
$topics_sql[] = $row['topic_id'];
|
||||
$attach_sql[] = $row['attach_id'];
|
||||
}
|
||||
$dead_tor_sql = join(',', $topics_sql);
|
||||
$attach_sql = join(',', $attach_sql);
|
||||
|
||||
if ($dead_tor_sql && $attach_sql)
|
||||
{
|
||||
// Delete torstat
|
||||
DB()->query("
|
||||
DELETE FROM ". BB_BT_TORSTAT ."
|
||||
WHERE topic_id IN($dead_tor_sql)
|
||||
");
|
||||
|
||||
// Update attach
|
||||
DB()->query("
|
||||
UPDATE
|
||||
". BB_ATTACHMENTS_DESC ." a,
|
||||
". BB_BT_TORRENTS ." tor
|
||||
SET
|
||||
a.tracker_status = 0,
|
||||
a.download_count = tor.complete_count
|
||||
WHERE
|
||||
a.attach_id = tor.attach_id
|
||||
AND tor.attach_id IN($attach_sql)
|
||||
");
|
||||
|
||||
// Remove torrents
|
||||
DB()->query("
|
||||
DELETE FROM ". BB_BT_TORRENTS ."
|
||||
WHERE topic_id IN($dead_tor_sql)
|
||||
");
|
||||
}
|
205
library/includes/cron/jobs/tr_make_snapshot.php
Normal file
205
library/includes/cron/jobs/tr_make_snapshot.php
Normal file
|
@ -0,0 +1,205 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
global $bb_cfg;
|
||||
|
||||
DB()->expect_slow_query(600);
|
||||
|
||||
//
|
||||
// Make tracker snapshot
|
||||
//
|
||||
if (!$bb_cfg['ocelot']['enabled'])
|
||||
{
|
||||
define('NEW_BB_BT_TRACKER_SNAP', 'new_tracker_snap');
|
||||
define('OLD_BB_BT_TRACKER_SNAP', 'old_tracker_snap');
|
||||
|
||||
DB()->query("DROP TABLE IF EXISTS " . NEW_BB_BT_TRACKER_SNAP . ", " . OLD_BB_BT_TRACKER_SNAP);
|
||||
DB()->query("CREATE TABLE " . NEW_BB_BT_TRACKER_SNAP . " LIKE " . BB_BT_TRACKER_SNAP);
|
||||
}
|
||||
|
||||
$per_cycle = 50000;
|
||||
$row = DB()->fetch_row("SELECT MIN(topic_id) AS start_id, MAX(topic_id) AS finish_id FROM ". BB_BT_TRACKER);
|
||||
$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;
|
||||
|
||||
$val = array();
|
||||
|
||||
if (!$bb_cfg['ocelot']['enabled'])
|
||||
{
|
||||
$sql = "
|
||||
SELECT
|
||||
topic_id, SUM(seeder) AS seeders, (COUNT(*) - SUM(seeder)) AS leechers,
|
||||
SUM(speed_up) AS speed_up, SUM(speed_down) AS speed_down
|
||||
FROM " . BB_BT_TRACKER . "
|
||||
WHERE topic_id BETWEEN $start_id AND $end_id
|
||||
GROUP BY topic_id
|
||||
";
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = "
|
||||
SELECT
|
||||
topic_id, SUM(speed_up) AS speed_up, SUM(speed_down) AS speed_down
|
||||
FROM " . BB_BT_TRACKER . "
|
||||
WHERE topic_id BETWEEN $start_id AND $end_id
|
||||
GROUP BY topic_id
|
||||
";
|
||||
}
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row)
|
||||
{
|
||||
$val[] = join(',', $row);
|
||||
}
|
||||
|
||||
if ($val)
|
||||
{
|
||||
if (!$bb_cfg['ocelot']['enabled'])
|
||||
{
|
||||
DB()->query("
|
||||
REPLACE INTO " . NEW_BB_BT_TRACKER_SNAP . "
|
||||
(topic_id, seeders, leechers, speed_up, speed_down)
|
||||
VALUES(" . join('),(', $val) . ")
|
||||
");
|
||||
}
|
||||
else
|
||||
{
|
||||
DB()->query("
|
||||
INSERT INTO " . BB_BT_TRACKER_SNAP . "
|
||||
(topic_id, speed_up, speed_down)
|
||||
VALUES(". join('),(', $val) .")
|
||||
ON DUPLICATE KEY UPDATE speed_up = VALUES(speed_up), speed_down = VALUES(speed_down)
|
||||
");
|
||||
}
|
||||
}
|
||||
|
||||
if ($end_id > $finish_id)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (!($start_id % ($per_cycle*10)))
|
||||
{
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
$start_id += $per_cycle;
|
||||
}
|
||||
|
||||
if (!$bb_cfg['ocelot']['enabled'])
|
||||
{
|
||||
DB()->query("
|
||||
RENAME TABLE
|
||||
". BB_BT_TRACKER_SNAP ." TO ". OLD_BB_BT_TRACKER_SNAP .",
|
||||
". NEW_BB_BT_TRACKER_SNAP ." TO ". BB_BT_TRACKER_SNAP ."
|
||||
");
|
||||
|
||||
DB()->query("DROP TABLE IF EXISTS ". NEW_BB_BT_TRACKER_SNAP .", ". OLD_BB_BT_TRACKER_SNAP);
|
||||
}
|
||||
|
||||
//
|
||||
// Make dl-list snapshot
|
||||
//
|
||||
define('NEW_BB_BT_DLSTATUS_SNAP', 'new_dlstatus_snap');
|
||||
define('OLD_BB_BT_DLSTATUS_SNAP', 'old_dlstatus_snap');
|
||||
|
||||
DB()->query("DROP TABLE IF EXISTS ". NEW_BB_BT_DLSTATUS_SNAP .", ". OLD_BB_BT_DLSTATUS_SNAP);
|
||||
|
||||
DB()->query("CREATE TABLE ". NEW_BB_BT_DLSTATUS_SNAP ." LIKE ". BB_BT_DLSTATUS_SNAP);
|
||||
|
||||
if ($bb_cfg['bt_show_dl_list'] && $bb_cfg['bt_dl_list_only_count'])
|
||||
{
|
||||
DB()->query("
|
||||
INSERT INTO ". NEW_BB_BT_DLSTATUS_SNAP ."
|
||||
(topic_id, dl_status, users_count)
|
||||
SELECT
|
||||
topic_id, user_status, COUNT(*)
|
||||
FROM ". BB_BT_DLSTATUS ."
|
||||
WHERE user_status != ". DL_STATUS_RELEASER ."
|
||||
GROUP BY topic_id, user_status
|
||||
");
|
||||
}
|
||||
|
||||
DB()->query("
|
||||
RENAME TABLE
|
||||
". BB_BT_DLSTATUS_SNAP ." TO ". OLD_BB_BT_DLSTATUS_SNAP .",
|
||||
". NEW_BB_BT_DLSTATUS_SNAP ." TO ". BB_BT_DLSTATUS_SNAP ."
|
||||
");
|
||||
|
||||
DB()->query("DROP TABLE IF EXISTS ". NEW_BB_BT_DLSTATUS_SNAP .", ". OLD_BB_BT_DLSTATUS_SNAP);
|
||||
|
||||
//
|
||||
// TORHELP
|
||||
//
|
||||
if ($bb_cfg['torhelp_enabled'])
|
||||
{
|
||||
$tor_min_seeders = 0; // "<="
|
||||
$tor_min_leechers = 2; // ">="
|
||||
$tor_min_completed = 10; // ">="
|
||||
$tor_seed_last_seen_days = 3; // "<="
|
||||
$tor_downloaded_days_ago = 60; // ">="
|
||||
$user_last_seen_online = 15; // minutes
|
||||
$users_limit = 3000;
|
||||
$dl_status_ary = array(DL_STATUS_COMPLETE);
|
||||
|
||||
define('NEW_BB_BT_TORHELP', 'new_torhelp');
|
||||
define('OLD_BB_BT_TORHELP', 'old_torhelp');
|
||||
|
||||
DB()->query("DROP TABLE IF EXISTS ". NEW_BB_BT_TORHELP .", ". OLD_BB_BT_TORHELP);
|
||||
|
||||
DB()->query("CREATE TABLE ". NEW_BB_BT_TORHELP ." LIKE ". BB_BT_TORHELP);
|
||||
|
||||
// Select users
|
||||
$sql = "
|
||||
SELECT DISTINCT session_user_id AS uid
|
||||
FROM ". BB_SESSIONS ."
|
||||
WHERE session_time > (UNIX_TIMESTAMP() - $user_last_seen_online*60)
|
||||
AND session_user_id != ". GUEST_UID ."
|
||||
ORDER BY session_time DESC
|
||||
LIMIT $users_limit
|
||||
";
|
||||
$online_users_ary = array();
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row)
|
||||
{
|
||||
$online_users_ary[] = $row['uid'];
|
||||
}
|
||||
|
||||
if ($online_users_csv = join(',', $online_users_ary))
|
||||
{
|
||||
DB()->query("
|
||||
INSERT INTO ". NEW_BB_BT_TORHELP ." (user_id, topic_id_csv)
|
||||
SELECT
|
||||
dl.user_id, GROUP_CONCAT(dl.topic_id)
|
||||
FROM ". BB_BT_TRACKER_SNAP ." trsn
|
||||
INNER JOIN ". BB_BT_TORRENTS ." tor ON (tor.topic_id = trsn.topic_id)
|
||||
INNER JOIN ". BB_BT_DLSTATUS ." dl ON (dl.topic_id = tor.topic_id)
|
||||
WHERE
|
||||
trsn.seeders <= $tor_min_seeders
|
||||
AND trsn.leechers >= $tor_min_leechers
|
||||
AND tor.forum_id != ". (int) $bb_cfg['trash_forum_id'] ."
|
||||
AND tor.complete_count >= $tor_min_completed
|
||||
AND tor.seeder_last_seen <= (UNIX_TIMESTAMP() - $tor_seed_last_seen_days*86400)
|
||||
AND dl.user_id IN($online_users_csv)
|
||||
AND dl.user_status IN(". get_id_csv($dl_status_ary) .")
|
||||
AND dl.last_modified_dlstatus > DATE_SUB(NOW(), INTERVAL $tor_downloaded_days_ago DAY)
|
||||
GROUP BY dl.user_id
|
||||
LIMIT 10000
|
||||
");
|
||||
}
|
||||
|
||||
DB()->query("
|
||||
RENAME TABLE
|
||||
". BB_BT_TORHELP ." TO ". OLD_BB_BT_TORHELP .",
|
||||
". NEW_BB_BT_TORHELP ." TO ". BB_BT_TORHELP ."
|
||||
");
|
||||
|
||||
DB()->query("DROP TABLE IF EXISTS ". NEW_BB_BT_TORHELP .", ". OLD_BB_BT_TORHELP);
|
||||
}
|
||||
|
||||
DB()->expect_slow_query(10);
|
15
library/includes/cron/jobs/tr_update_seeder_last_seen.php
Normal file
15
library/includes/cron/jobs/tr_update_seeder_last_seen.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
DB()->query("
|
||||
UPDATE
|
||||
". BUF_LAST_SEEDER ." b,
|
||||
". BB_BT_TORRENTS ." tor
|
||||
SET
|
||||
tor.seeder_last_seen = b.seeder_last_seen
|
||||
WHERE
|
||||
tor.topic_id = b.topic_id
|
||||
");
|
||||
|
||||
DB()->query("TRUNCATE TABLE ". BUF_LAST_SEEDER);
|
31
library/includes/cron/jobs/update_forums_atom.php
Normal file
31
library/includes/cron/jobs/update_forums_atom.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
global $bb_cfg;
|
||||
|
||||
require_once(INC_DIR .'functions_atom.php');
|
||||
|
||||
$timecheck = TIMENOW - 600;
|
||||
$forums_data = DB()->fetch_rowset("SELECT forum_id, allow_reg_tracker, forum_name FROM ". BB_FORUMS);
|
||||
|
||||
if (file_exists($bb_cfg['atom']['path'] .'/f/0.atom'))
|
||||
{
|
||||
if (filemtime($bb_cfg['atom']['path'] .'/f/0.atom') <= $timecheck) update_forum_feed(0, $forums_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
update_forum_feed(0, $forums_data);
|
||||
}
|
||||
|
||||
foreach ($forums_data as $forum_data)
|
||||
{
|
||||
if (file_exists($bb_cfg['atom']['path'] .'/f/'. $forum_data['forum_id'] .'.atom'))
|
||||
{
|
||||
if (filemtime($bb_cfg['atom']['path'] .'/f/'. $forum_data['forum_id'] .'.atom') <= $timecheck) update_forum_feed($forum_data['forum_id'], $forum_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
update_forum_feed($forum_data['forum_id'], $forum_data);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue