mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 11:27:24 +08:00
add promotion and announce_waint log
This commit is contained in:
@@ -444,6 +444,10 @@ class ExamRepository extends BaseRepository
|
||||
do_log("examUser: {$examUser->id} status not normal, won't update progress.");
|
||||
return false;
|
||||
}
|
||||
if ($examUser->is_done == ExamUser::IS_DONE_YES) {
|
||||
do_log("examUser: {$examUser->id} is done, won't update progress.");
|
||||
return false;
|
||||
}
|
||||
$exam = $examUser->exam;
|
||||
if (!$user instanceof User) {
|
||||
$user = $examUser->user()->select(['id', 'uploaded', 'downloaded', 'seedtime', 'leechtime', 'seedbonus'])->first();
|
||||
@@ -799,7 +803,7 @@ class ExamRepository extends BaseRepository
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function cronjobCheckout($ignoreTimeRange = false)
|
||||
public function cronjobCheckout($ignoreTimeRange = false): int
|
||||
{
|
||||
$now = Carbon::now()->toDateTimeString();
|
||||
$examUserTable = (new ExamUser())->getTable();
|
||||
@@ -906,7 +910,34 @@ class ExamRepository extends BaseRepository
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function updateProgressBulk(): array
|
||||
{
|
||||
$query = ExamUser::query()
|
||||
->where('status', ExamUser::STATUS_NORMAL)
|
||||
->where('is_done', ExamUser::IS_DONE_NO);
|
||||
$page = 1;
|
||||
$size = 1000;
|
||||
$total = $success = 0;
|
||||
while (true) {
|
||||
$logPrefix = "[UPDATE_EXAM_PROGRESS], page: $page, size: $size";
|
||||
$rows = $query->forPage($page, $size)->get();
|
||||
$count = $rows->count();
|
||||
$total += $count;
|
||||
do_log("$logPrefix, " . last_query() . ", count: $count");
|
||||
if ($rows->isEmpty()) {
|
||||
do_log("$logPrefix, no more data...");
|
||||
break;
|
||||
}
|
||||
foreach ($rows as $row) {
|
||||
$result = $this->updateProgress($row);
|
||||
do_log("$logPrefix, examUser: " . $row->toJson() . ", result type: " . gettype($result));
|
||||
if ($result != false) {
|
||||
$success += 1;
|
||||
}
|
||||
}
|
||||
$page++;
|
||||
}
|
||||
return compact('total', 'success');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,15 +24,15 @@ class Attendance
|
||||
{
|
||||
do_log(json_encode(func_get_args()));
|
||||
if($this->check(true)) return false;
|
||||
$res = sql_query(sprintf('SELECT DATEDIFF(%s, `added`) AS diff, `days`, `total_days` FROM `attendance` WHERE `uid` = %u ORDER BY `id` DESC LIMIT 1', sqlesc($this->curdate), $this->userid)) or sqlerr(__FILE__,__LINE__);
|
||||
$res = sql_query(sprintf('SELECT id, DATEDIFF(%s, `added`) AS diff, `days`, `total_days` FROM `attendance` WHERE `uid` = %u ORDER BY `id` DESC LIMIT 1', sqlesc($this->curdate), $this->userid)) or sqlerr(__FILE__,__LINE__);
|
||||
$doUpdate = mysql_num_rows($res);
|
||||
if ($doUpdate) {
|
||||
$row = mysql_fetch_row($res);
|
||||
do_log("uid: {$this->userid}, row: " . json_encode($row));
|
||||
} else {
|
||||
$row = [0, 0, 0];
|
||||
$row = [0, 0, 0, 0];
|
||||
}
|
||||
list($datediff, $days, $totalDays) = $row;
|
||||
list($id, $datediff, $days, $totalDays) = $row;
|
||||
$points = min($initial + $step * $totalDays, $maximum);
|
||||
$cdays = $datediff == 1 ? ++$days : 1;
|
||||
if($cdays > 1){
|
||||
@@ -47,8 +47,8 @@ class Attendance
|
||||
// sql_query(sprintf('INSERT INTO `attendance` (`uid`,`added`,`points`,`days`) VALUES (%u, %s, %u, %u)', $this->userid, sqlesc(date('Y-m-d H:i:s')), $points, $cdays)) or sqlerr(__FILE__, __LINE__);
|
||||
if ($doUpdate) {
|
||||
$sql = sprintf(
|
||||
'UPDATE `attendance` set added = %s, points = %s, days = %s, total_days= %s where uid = %s order by id desc limit 1',
|
||||
sqlesc(date('Y-m-d H:i:s')), $points, $cdays, $totalDays + 1, $this->userid
|
||||
'UPDATE `attendance` set added = %s, points = %s, days = %s, total_days= %s where id = %s limit 1',
|
||||
sqlesc(date('Y-m-d H:i:s')), $points, $cdays, $totalDays + 1, $id
|
||||
);
|
||||
} else {
|
||||
$sql = sprintf(
|
||||
|
||||
+8
-1
@@ -223,7 +223,6 @@ function delete_user(\Illuminate\Database\Eloquent\Builder $query, $reasonKey)
|
||||
return $uidArr;
|
||||
}
|
||||
|
||||
|
||||
function docleanup($forceAll = 0, $printProgress = false) {
|
||||
//require_once(get_langfile_path("cleanup.php",true));
|
||||
global $lang_cleanup_target;
|
||||
@@ -294,6 +293,14 @@ function docleanup($forceAll = 0, $printProgress = false) {
|
||||
printProgress($log);
|
||||
}
|
||||
|
||||
$examRep = new \App\Repositories\ExamRepository();
|
||||
$updateExamProgressResult = $examRep->updateProgressBulk();
|
||||
$log = 'update exam progress';
|
||||
do_log($log . ", result: " . json_encode($updateExamProgressResult));
|
||||
if ($printProgress) {
|
||||
printProgress($log);
|
||||
}
|
||||
|
||||
//Priority Class 2: cleanup every 30 mins
|
||||
$res = sql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime2'");
|
||||
$row = mysql_fetch_array($res);
|
||||
|
||||
+35
-12
@@ -3956,6 +3956,8 @@ function get_torrent_promotion_append($promotion = 1,$forcemode = "",$showtimele
|
||||
|
||||
$sp_torrent = "";
|
||||
$onmouseover = "";
|
||||
$log = "[GET_PROMOTION], promotion: $promotion, forcemode: $forcemode, showtimeleft: $showtimeleft, added: $added, promotionTimeType: $promotionTimeType, promotionUntil: $promotionUntil";
|
||||
$log .= ", get_global_sp_state() == " . get_global_sp_state();
|
||||
if (get_global_sp_state() == 1) {
|
||||
switch ($promotion){
|
||||
case 2:
|
||||
@@ -4057,39 +4059,60 @@ function get_torrent_promotion_append($promotion = 1,$forcemode = "",$showtimele
|
||||
}
|
||||
}
|
||||
if (($CURUSER['appendpromotion'] == 'word' && $forcemode == "" ) || $forcemode == 'word'){
|
||||
$log .= ", user appendpromotion = word";
|
||||
if(($promotion==2 && get_global_sp_state() == 1) || get_global_sp_state() == 2){
|
||||
$log .= ", promotion or global_sp_state = 2";
|
||||
$sp_torrent = " <b>[<font class='free' ".$onmouseover.">".$lang_functions['text_free']."</font>]</b>";
|
||||
}
|
||||
elseif(($promotion==3 && get_global_sp_state() == 1) || get_global_sp_state() == 3){
|
||||
$log .= ", promotion or global_sp_state = 3";
|
||||
$sp_torrent = " <b>[<font class='twoup' ".$onmouseover.">".$lang_functions['text_two_times_up']."</font>]</b>";
|
||||
}
|
||||
elseif(($promotion==4 && get_global_sp_state() == 1) || get_global_sp_state() == 4){
|
||||
$log .= ", promotion or global_sp_state = 4";
|
||||
$sp_torrent = " <b>[<font class='twoupfree' ".$onmouseover.">".$lang_functions['text_free_two_times_up']."</font>]</b>";
|
||||
}
|
||||
elseif(($promotion==5 && get_global_sp_state() == 1) || get_global_sp_state() == 5){
|
||||
$log .= ", promotion or global_sp_state = 5";
|
||||
$sp_torrent = " <b>[<font class='halfdown' ".$onmouseover.">".$lang_functions['text_half_down']."</font>]</b>";
|
||||
}
|
||||
elseif(($promotion==6 && get_global_sp_state() == 1) || get_global_sp_state() == 6){
|
||||
$log .= ", promotion or global_sp_state = 6";
|
||||
$sp_torrent = " <b>[<font class='twouphalfdown' ".$onmouseover.">".$lang_functions['text_half_down_two_up']."</font>]</b>";
|
||||
}
|
||||
elseif(($promotion==7 && get_global_sp_state() == 1) || get_global_sp_state() == 7){
|
||||
$log .= ", promotion or global_sp_state = 7";
|
||||
$sp_torrent = " <b>[<font class='thirtypercent' ".$onmouseover.">".$lang_functions['text_thirty_percent_down']."</font>]</b>";
|
||||
}
|
||||
}
|
||||
elseif (($CURUSER['appendpromotion'] == 'icon' && $forcemode == "") || $forcemode == 'icon'){
|
||||
if(($promotion==2 && get_global_sp_state() == 1) || get_global_sp_state() == 2)
|
||||
$sp_torrent = " <img class=\"pro_free\" src=\"pic/trans.gif\" alt=\"Free\" ".($onmouseover ? $onmouseover : "title=\"".$lang_functions['text_free']."\"")." />";
|
||||
elseif(($promotion==3 && get_global_sp_state() == 1) || get_global_sp_state() == 3)
|
||||
$sp_torrent = " <img class=\"pro_2up\" src=\"pic/trans.gif\" alt=\"2X\" ".($onmouseover ? $onmouseover : "title=\"".$lang_functions['text_two_times_up']."\"")." />";
|
||||
elseif(($promotion==4 && get_global_sp_state() == 1) || get_global_sp_state() == 4)
|
||||
$sp_torrent = " <img class=\"pro_free2up\" src=\"pic/trans.gif\" alt=\"2X Free\" ".($onmouseover ? $onmouseover : "title=\"".$lang_functions['text_free_two_times_up']."\"")." />";
|
||||
elseif(($promotion==5 && get_global_sp_state() == 1) || get_global_sp_state() == 5)
|
||||
$sp_torrent = " <img class=\"pro_50pctdown\" src=\"pic/trans.gif\" alt=\"50%\" ".($onmouseover ? $onmouseover : "title=\"".$lang_functions['text_half_down']."\"")." />";
|
||||
elseif(($promotion==6 && get_global_sp_state() == 1) || get_global_sp_state() == 6)
|
||||
$sp_torrent = " <img class=\"pro_50pctdown2up\" src=\"pic/trans.gif\" alt=\"2X 50%\" ".($onmouseover ? $onmouseover : "title=\"".$lang_functions['text_half_down_two_up']."\"")." />";
|
||||
elseif(($promotion==7 && get_global_sp_state() == 1) || get_global_sp_state() == 7)
|
||||
$sp_torrent = " <img class=\"pro_30pctdown\" src=\"pic/trans.gif\" alt=\"30%\" ".($onmouseover ? $onmouseover : "title=\"".$lang_functions['text_thirty_percent_down']."\"")." />";
|
||||
$log .= ", user appendpromotion = icon";
|
||||
if(($promotion==2 && get_global_sp_state() == 1) || get_global_sp_state() == 2) {
|
||||
$log .= ", promotion or global_sp_state = 2";
|
||||
$sp_torrent = " <img class=\"pro_free\" src=\"pic/trans.gif\" alt=\"Free\" ".($onmouseover ? $onmouseover : "title=\"".$lang_functions['text_free']."\"")." />";
|
||||
}
|
||||
elseif(($promotion==3 && get_global_sp_state() == 1) || get_global_sp_state() == 3) {
|
||||
$log .= ", promotion or global_sp_state = 3";
|
||||
$sp_torrent = " <img class=\"pro_2up\" src=\"pic/trans.gif\" alt=\"2X\" ".($onmouseover ? $onmouseover : "title=\"".$lang_functions['text_two_times_up']."\"")." />";
|
||||
}
|
||||
elseif(($promotion==4 && get_global_sp_state() == 1) || get_global_sp_state() == 4) {
|
||||
$log .= ", promotion or global_sp_state = 4";
|
||||
$sp_torrent = " <img class=\"pro_free2up\" src=\"pic/trans.gif\" alt=\"2X Free\" ".($onmouseover ? $onmouseover : "title=\"".$lang_functions['text_free_two_times_up']."\"")." />";
|
||||
}
|
||||
elseif(($promotion==5 && get_global_sp_state() == 1) || get_global_sp_state() == 5) {
|
||||
$log .= ", promotion or global_sp_state = 5";
|
||||
$sp_torrent = " <img class=\"pro_50pctdown\" src=\"pic/trans.gif\" alt=\"50%\" ".($onmouseover ? $onmouseover : "title=\"".$lang_functions['text_half_down']."\"")." />";
|
||||
}
|
||||
elseif(($promotion==6 && get_global_sp_state() == 1) || get_global_sp_state() == 6) {
|
||||
$log .= ", promotion or global_sp_state = 6";
|
||||
$sp_torrent = " <img class=\"pro_50pctdown2up\" src=\"pic/trans.gif\" alt=\"2X 50%\" ".($onmouseover ? $onmouseover : "title=\"".$lang_functions['text_half_down_two_up']."\"")." />";
|
||||
}
|
||||
elseif(($promotion==7 && get_global_sp_state() == 1) || get_global_sp_state() == 7) {
|
||||
$log .= ", promotion or global_sp_state = 7";
|
||||
$sp_torrent = " <img class=\"pro_30pctdown\" src=\"pic/trans.gif\" alt=\"30%\" ".($onmouseover ? $onmouseover : "title=\"".$lang_functions['text_thirty_percent_down']."\"")." />";
|
||||
}
|
||||
}
|
||||
do_log("$log, sp_torrent: $sp_torrent");
|
||||
return $sp_torrent;
|
||||
}
|
||||
|
||||
|
||||
+12
-6
@@ -79,15 +79,15 @@ $seeder = ($left == 0) ? "yes" : "no";
|
||||
|
||||
// check passkey
|
||||
if (!$az = $Cache->get_value('user_passkey_'.$passkey.'_content')){
|
||||
$res = sql_query("SELECT id, downloadpos, enabled, uploaded, downloaded, class, parked, clientselect, showclienterror,passkey FROM users WHERE passkey=". sqlesc($passkey)." LIMIT 1");
|
||||
$az = $currentUser = mysql_fetch_array($res);
|
||||
do_log("[check passkey], currentUser: " . nexus_json_encode($currentUser), 'error');
|
||||
$res = sql_query("SELECT id, downloadpos, enabled, uploaded, downloaded, class, parked, clientselect, showclienterror, passkey FROM users WHERE passkey=". sqlesc($passkey)." LIMIT 1");
|
||||
$az = mysql_fetch_array($res);
|
||||
do_log("[check passkey], currentUser: " . nexus_json_encode($az), 'error');
|
||||
$Cache->cache_value('user_passkey_'.$passkey.'_content', $az, 950);
|
||||
}
|
||||
if (!$az) err("Invalid passkey! Re-download the .torrent from $BASEURL");
|
||||
$userid = intval($az['id'] ?? 0);
|
||||
unset($GLOBALS['CURUSER']);
|
||||
$CURUSER = $GLOBALS["CURUSER"] = $currentUser;
|
||||
$CURUSER = $GLOBALS["CURUSER"] = $az;
|
||||
|
||||
//3. CHECK IF CLIENT IS ALLOWED
|
||||
$clicheck_res = check_client($peer_id,$agent,$client_familyid);
|
||||
@@ -206,8 +206,14 @@ if (!isset($self))
|
||||
}
|
||||
|
||||
// min announce time
|
||||
if(isset($self) && $self['prevts'] > (TIMENOW - $announce_wait))
|
||||
err('There is a minimum announce time of ' . $announce_wait . ' seconds');
|
||||
if(isset($self) && $self['prevts'] > (TIMENOW - $announce_wait)) {
|
||||
do_log(sprintf(
|
||||
'timezone: %s, self prevts(%s, %s) > now(%s, %s) - announce_wait(%s)',
|
||||
ini_get('date.timezone'), $self['prevts'], date('Y-m-d H:i:s', $self['prevts']), TIMENOW, date('Y-m-d H:i:s', TIMENOW), $announce_wait
|
||||
));
|
||||
err('There is a minimum announce time of ' . $announce_wait . ' seconds');
|
||||
}
|
||||
|
||||
|
||||
// current peer_id, or you could say session with tracker not found in table peers
|
||||
if (!isset($self))
|
||||
|
||||
Reference in New Issue
Block a user