From ca0707841526a58de6f4ae0d1790603228cc0479 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Wed, 5 May 2021 22:28:19 +0800 Subject: [PATCH] update exam progress seed bonus --- app/Models/Exam.php | 4 ++-- app/Repositories/ExamRepository.php | 9 ++++++--- app/Repositories/ToolRepository.php | 28 ++++++++++++++-------------- include/cleanup.php | 9 ++++++--- public/getrss.php | 4 +++- resources/lang/en/exam.php | 2 +- resources/lang/zh_CN/exam.php | 2 +- resources/lang/zh_TW/exam.php | 2 +- 8 files changed, 34 insertions(+), 26 deletions(-) diff --git a/app/Models/Exam.php b/app/Models/Exam.php index 8897e4a6..c520abee 100644 --- a/app/Models/Exam.php +++ b/app/Models/Exam.php @@ -32,13 +32,13 @@ class Exam extends NexusModel const INDEX_UPLOADED = 1; const INDEX_SEED_TIME_AVERAGE = 2; const INDEX_DOWNLOADED = 3; - const INDEX_BONUS = 4; + const INDEX_SEED_BONUS = 4; public static $indexes = [ self::INDEX_UPLOADED => ['name' => 'Uploaded', 'unit' => 'GB'], self::INDEX_SEED_TIME_AVERAGE => ['name' => 'Seed time average', 'unit' => 'Hour'], self::INDEX_DOWNLOADED => ['name' => 'Downloaded', 'unit' => 'GB'], - self::INDEX_BONUS => ['name' => 'Bonus', 'unit' => ''], + self::INDEX_SEED_BONUS => ['name' => 'Seed bonus', 'unit' => ''], ]; const FILTER_USER_CLASS = 'classes'; diff --git a/app/Repositories/ExamRepository.php b/app/Repositories/ExamRepository.php index 9c3d0416..5415ef24 100644 --- a/app/Repositories/ExamRepository.php +++ b/app/Repositories/ExamRepository.php @@ -262,9 +262,12 @@ class ExamRepository extends BaseRepository $indexes = collect($exam->indexes)->keyBy('index'); do_log("examUser: " . $examUser->toJson() . ", indexes: " . $indexes->toJson()); - $torrentFields = ['id', 'visible', 'banned']; - $torrent = Torrent::query()->findOrFail($torrentId, $torrentFields); - $torrent->checkIsNormal($torrentFields); + if (!isset($indexAndValue[Exam::INDEX_SEED_BONUS])) { + //seed bonus is relative to user all torrents, not single one, torrentId = 0 + $torrentFields = ['id', 'visible', 'banned']; + $torrent = Torrent::query()->findOrFail($torrentId, $torrentFields); + $torrent->checkIsNormal($torrentFields); + } $insert = []; foreach ($indexAndValue as $indexId => $value) { diff --git a/app/Repositories/ToolRepository.php b/app/Repositories/ToolRepository.php index 982aaf3e..b010e468 100644 --- a/app/Repositories/ToolRepository.php +++ b/app/Repositories/ToolRepository.php @@ -29,12 +29,12 @@ class ToolRepository extends BaseRepository 'tar --exclude=vendor --exclude=.git -czf %s -C %s %s', $filename, dirname($webRoot), $dirName ); - $result = exec($command, $output, $resultCode); + $result = exec($command, $output, $result_code); do_log(sprintf( - "command: %s, output: %s, resultCode: %s, result: %s, filename: %s", - $command, json_encode($output), $resultCode, $result, $filename + "command: %s, output: %s, result_code: %s, result: %s, filename: %s", + $command, json_encode($output), $result_code, $result, $filename )); - return compact('result', 'filename'); + return compact('result_code', 'filename'); } public function backupDatabase() @@ -46,22 +46,22 @@ class ToolRepository extends BaseRepository 'mysqldump --user=%s --password=%s --port=%s --single-transaction --databases %s >> %s', $config['username'], $config['password'], $config['port'], $config['database'], $filename, ); - $result = exec($command, $output, $resultCode); + $result = exec($command, $output, $result_code); do_log(sprintf( - "command: %s, output: %s, resultCode: %s, result: %s, filename: %s", - $command, json_encode($output), $resultCode, $result, $filename + "command: %s, output: %s, result_code: %s, result: %s, filename: %s", + $command, json_encode($output), $result_code, $result, $filename )); - return compact('result', 'filename'); + return compact('result_code', 'filename'); } public function backupAll() { $backupWeb = $this->backupWebRoot(); - if ($backupWeb['result'] != 0) { + if ($backupWeb['result_code'] != 0) { throw new \RuntimeException("backup web fail: " . json_encode($backupWeb)); } $backupDatabase = $this->backupDatabase(); - if ($backupDatabase['result'] != 0) { + if ($backupDatabase['result_code'] != 0) { throw new \RuntimeException("backup database fail: " . json_encode($backupDatabase)); } $filename = sprintf('%s/%s.%s.tar.gz', sys_get_temp_dir(), basename(base_path()), date('Ymd.His')); @@ -71,12 +71,12 @@ class ToolRepository extends BaseRepository dirname($backupWeb['filename']), basename($backupWeb['filename']), dirname($backupDatabase['filename']), basename($backupDatabase['filename']) ); - $result = exec($command, $output, $resultCode); + $result = exec($command, $output, $result_code); do_log(sprintf( - "command: %s, output: %s, resultCode: %s, result: %s, filename: %s", - $command, json_encode($output), $resultCode, $result, $filename + "command: %s, output: %s, result_code: %s, result: %s, filename: %s", + $command, json_encode($output), $result_code, $result, $filename )); - return compact('result', 'filename'); + return compact('result_code', 'filename'); } } diff --git a/include/cleanup.php b/include/cleanup.php index 62815aa0..c2581d27 100644 --- a/include/cleanup.php +++ b/include/cleanup.php @@ -194,6 +194,7 @@ function docleanup($forceAll = 0, $printProgress = false) { $valuethree = $logofpointone / ($nzero_bonus - 1); $timenow = TIMENOW; $sectoweek = 7*24*60*60; + $examRep = new \App\Repositories\ExamRepository(); while ($arr = mysql_fetch_assoc($res)) //loop for different users { $A = 0; @@ -215,6 +216,8 @@ function docleanup($forceAll = 0, $printProgress = false) { if ($is_donor == 'yes' && $donortimes_bonus > 0) $all_bonus = $all_bonus * $donortimes_bonus; KPS("+",$all_bonus,$arr["userid"]); + //update exam progress + $examRep->addProgress($arr["userid"], 0, [\App\Models\Exam::INDEX_SEED_BONUS => $all_bonus]); } } $log = 'calculate seeding bonus'; @@ -523,7 +526,7 @@ function docleanup($forceAll = 0, $printProgress = false) { while ($arr = mysql_fetch_assoc($res)) { $dt = sqlesc(date("Y-m-d H:i:s")); - $subject = sqlesc($lang_cleanup_target[get_user_lang($arr['id'])]['msg_vip_status_removed']); + $subject = sqlesc($lang_cleanup_target[get_user_lang($arr['id'])]['msg_vip_status_removed']); $msg = sqlesc($lang_cleanup_target[get_user_lang($arr['id'])]['msg_vip_status_removed_body']); ///---AUTOSYSTEM MODCOMMENT---// $modcomment = htmlspecialchars($arr["modcomment"]); @@ -650,10 +653,10 @@ function docleanup($forceAll = 0, $printProgress = false) { //die("s" . $arr['id']); $res2 = sql_query("SELECT SUM(seedtime) as st, SUM(leechtime) as lt FROM snatched where userid = " . $arr['id'] . " LIMIT 1") or sqlerr(__FILE__, __LINE__); $arr2 = mysql_fetch_assoc($res2) or sqlerr(__FILE__, __LINE__); - + //die("ss" . $arr2['st']); //die("sss" . "UPDATE users SET seedtime = " . $arr2['st'] . ", leechtime = " . $arr2['lt'] . " WHERE id = " . $arr['id']); - + sql_query("UPDATE users SET seedtime = " . intval($arr2['st']) . ", leechtime = " . intval($arr2['lt']) . " WHERE id = " . $arr['id']) or sqlerr(__FILE__, __LINE__); } $log = "update total seeding and leeching time of users"; diff --git a/public/getrss.php b/public/getrss.php index 06abb2d1..85294047 100644 --- a/public/getrss.php +++ b/public/getrss.php @@ -39,6 +39,8 @@ if ($showaudiocodec) $audiocodecs = searchbox_item_list("audiocodecs"); } stdhead($lang_getrss['head_rss_feeds']); +$query = []; +$query[] = "passkey=" . $CURUSER['passkey']; if ($_SERVER['REQUEST_METHOD'] == "POST") { $allowed_showrows=array('10','20','30','40','50'); $link = get_protocol_prefix(). $BASEURL ."/torrentrss.php"; @@ -322,7 +324,7 @@ print($categories); - +