replace torrents.Time by torrents.created; phpstan cleansing

This commit is contained in:
Spine
2023-08-12 01:17:32 +00:00
parent 2b35070697
commit 0cceae3f56
25 changed files with 131 additions and 250 deletions

View File

@@ -3,7 +3,6 @@
namespace Gazelle\Better;
class Checksum extends AbstractBetter {
public function mode(): string {
return 'torrent';
}
@@ -20,7 +19,7 @@ class Checksum extends AbstractBetter {
INNER JOIN torrents_leech_stats tls ON (tls.TorrentID = t.ID)";
$this->where[] = "t.HasLogDB = '1' AND t.LogChecksum = '0'";
$this->orderBy = "ORDER BY tls.Snatched DESC, t.Time ASC";
$this->orderBy = "ORDER BY tls.Snatched DESC, t.created ASC";
if ($this->filter === 'snatched') {
$this->where[] = "EXISTS (

View File

@@ -256,7 +256,7 @@ class Contest extends BaseObject {
LADDER.nr,
T.ID,
TG.Name,
T.Time
T.created
", $this->id, ...$args
);
$n = self::$db->affected_rows();

View File

@@ -14,7 +14,7 @@ trait TorrentLeaderboard {
l.user_id,
l.entry_count,
l.last_entry_id,
t.Time as last_upload,
t.created as last_upload,
t.GroupID as group_id
FROM contest_leaderboard l
INNER JOIN torrents t ON (t.ID = l.last_entry_id)
@@ -23,7 +23,7 @@ trait TorrentLeaderboard {
WHERE um.Enabled = '1'
AND xfu.remaining = 0
AND l.contest_id = ?
ORDER BY l.entry_count DESC, t.Time ASC, l.user_id ASC
ORDER BY l.entry_count DESC, t.created ASC, l.user_id ASC
LIMIT ? OFFSET ?
", $this->id, $limit, $offset
);

View File

@@ -28,7 +28,7 @@ class UploadFlac extends AbstractContest {
)
)
AND ula.last_access >= ?
AND t.Time BETWEEN ? AND ?
AND t.created BETWEEN ? AND ?
GROUP By um.ID
",
[ $this->begin, $this->begin, $this->end ]
@@ -46,7 +46,7 @@ class UploadFlac extends AbstractContest {
WHERE um.Enabled = '1'
AND u.created <= c.date_end
AND xfu.remaining = 0
AND t.Time BETWEEN c.date_begin AND c.date_end
AND t.created BETWEEN c.date_begin AND c.date_end
AND t.Format = 'FLAC'
AND (t.Media IN ('SACD', 'Vinyl', 'WEB')
OR (t.Media = 'CD'
@@ -77,7 +77,7 @@ class UploadFlac extends AbstractContest {
OR (
xfu.remaining = 0
AND t.Format = 'FLAC'
AND t.Time BETWEEN c.date_begin AND c.date_end
AND t.created BETWEEN c.date_begin AND c.date_end
AND (
t.Media IN ('Vinyl', 'WEB', 'SACD')
OR (t.Media = 'CD'

View File

@@ -5,7 +5,6 @@ namespace Gazelle\Contest;
/* how many non-Single 100% flacs uploaded? */
class UploadFlacNoSingle extends AbstractContest {
use TorrentLeaderboard;
public function ranker(): array {
@@ -30,7 +29,7 @@ class UploadFlacNoSingle extends AbstractContest {
AND t.LogChecksum = '1'
)
)
AND t.Time BETWEEN ? AND ?
AND t.created BETWEEN ? AND ?
GROUP By um.ID
",
[ $this->begin, $this->begin, $this->end ]
@@ -51,7 +50,7 @@ class UploadFlacNoSingle extends AbstractContest {
AND ula.last_access >= c.date_begin
AND r.Name != 'Single'
AND t.Format = 'FLAC'
AND t.Time BETWEEN c.date_begin AND c.date_end
AND t.created BETWEEN c.date_begin AND c.date_end
AND (t.Media IN ('Vinyl', 'WEB', 'SACD')
OR (t.Media = 'CD'
AND t.HasLog = '1'
@@ -84,7 +83,7 @@ class UploadFlacNoSingle extends AbstractContest {
(t.ID IS NULL
OR (r.Name != 'Single'
AND t.Format = 'FLAC'
AND t.Time BETWEEN c.date_begin AND c.date_end
AND t.created BETWEEN c.date_begin AND c.date_end
AND (
t.Media IN ('Vinyl', 'WEB', 'SACD')
OR (t.Media = 'CD'

View File

@@ -5,7 +5,6 @@ namespace Gazelle\Contest;
/* how many perfect 100% CD flacs uploaded? */
class UploadPerfectFlac extends AbstractContest {
use TorrentLeaderboard;
public function ranker(): array {
@@ -24,7 +23,7 @@ class UploadPerfectFlac extends AbstractContest {
AND t.HasCue = '1'
AND t.LogScore = 100
AND t.LogChecksum = '1'
AND t.Time BETWEEN ? AND ?
AND t.created BETWEEN ? AND ?
GROUP By um.ID
",
[ $this->begin, $this->begin, $this->end ]
@@ -42,7 +41,7 @@ class UploadPerfectFlac extends AbstractContest {
WHERE um.Enabled = '1'
AND ula.last_access >= c.date_begin
AND t.Format = 'FLAC'
AND t.Time BETWEEN c.date_begin AND c.date_end
AND t.created BETWEEN c.date_begin AND c.date_end
AND t.Media = 'CD'
AND t.HasLog = '1'
AND t.HasCue = '1'
@@ -69,7 +68,7 @@ class UploadPerfectFlac extends AbstractContest {
AND
(t.ID IS NULL
OR (t.Format = 'FLAC'
AND t.Time BETWEEN c.date_begin AND c.date_end
AND t.created BETWEEN c.date_begin AND c.date_end
AND t.Media = 'CD'
AND t.HasLog = '1'
AND t.HasCue = '1'

View File

@@ -118,7 +118,7 @@ class Bonus extends \Gazelle\Base {
INNER JOIN user_attr ua ON (ua.ID = uha.UserAttrID AND ua.Name IN ('disable-bonus-points', 'no-fl-gifts'))
WHERE uha.UserID = um.ID
)
AND t.Time >= ?
AND t.created >= ?
", $since
);
return $this->addMultiPoints($points, self::$db->collect('ID', false));

View File

@@ -296,7 +296,7 @@ class Torrent extends \Gazelle\BaseManager {
INNER JOIN torrents_leech_stats tls ON (tls.TorrentID = t.ID)
WHERE t.Size > 0
AND tls.Seeders > 0
AND t.Time > now() - INTERVAL ? DAY
AND t.created > now() - INTERVAL ? DAY
ORDER BY ln(t.Size) * tls.Snatched + ln(t.Size) * tls.Leechers DESC, t.ID DESC
LIMIT 20
", $days
@@ -531,7 +531,7 @@ class Torrent extends \Gazelle\BaseManager {
WHERE t.GroupID = ttex.GroupID
AND ttex.TagID IN (" . placeholders(HOMEPAGE_TAG_IGNORE) . ")
)
ORDER BY t.Time DESC
ORDER BY t.created DESC
", ...HOMEPAGE_TAG_IGNORE
);
$latest = [];

View File

@@ -44,7 +44,7 @@ class Torrent extends \Gazelle\Base {
coalesce(sum(Size), 0),
coalesce(sum(FileCount), 0)
FROM torrents
WHERE Time > now() - INTERVAL 1 DAY
WHERE created > now() - INTERVAL 1 DAY
");
[$info['week']['count'], $info['week']['size'], $info['week']['files']] = self::$db->row("
@@ -52,7 +52,7 @@ class Torrent extends \Gazelle\Base {
coalesce(sum(Size), 0),
coalesce(sum(FileCount), 0)
FROM torrents
WHERE Time > now() - INTERVAL 7 DAY
WHERE created > now() - INTERVAL 7 DAY
");
[$info['month']['count'], $info['month']['size'], $info['month']['files']] = self::$db->row("
@@ -60,7 +60,7 @@ class Torrent extends \Gazelle\Base {
coalesce(sum(Size), 0),
coalesce(sum(FileCount), 0)
FROM torrents
WHERE Time > now() - INTERVAL 30 DAY
WHERE created > now() - INTERVAL 30 DAY
");
[$info['quarter']['count'], $info['quarter']['size'], $info['quarter']['files']] = self::$db->row('
@@ -68,7 +68,7 @@ class Torrent extends \Gazelle\Base {
coalesce(sum(Size), 0),
coalesce(sum(FileCount), 0)
FROM torrents
WHERE Time > now() - INTERVAL 120 DAY
WHERE created > now() - INTERVAL 120 DAY
');
self::$db->prepared_query("
@@ -81,7 +81,7 @@ class Torrent extends \Gazelle\Base {
self::$db->prepared_query("
SELECT Format, Encoding, count(*) as n
FROM torrents
WHERE Time > now() - INTERVAL 1 MONTH
WHERE created > now() - INTERVAL 1 MONTH
GROUP BY Format, Encoding WITH ROLLUP
");
$info['format-month'] = self::$db->to_array(false, MYSQLI_NUM, false);
@@ -117,11 +117,11 @@ class Torrent extends \Gazelle\Base {
$flow = self::$cache->get_value(self::TORRENT_FLOW);
if ($flow === false) {
self::$db->prepared_query("
SELECT date_format(t.Time,'%Y-%m') AS Month,
SELECT date_format(t.created,'%Y-%m') AS Month,
count(*) as t_net
FROM torrents t
GROUP BY Month
ORDER BY Time DESC
ORDER BY created DESC
LIMIT 12
");
$flow = self::$db->to_array('Month', MYSQLI_ASSOC, false);
@@ -129,12 +129,12 @@ class Torrent extends \Gazelle\Base {
$endMonth = reset($flow)['Month'] . '-01';
self::$db->prepared_query("
SELECT date_format(Time,'%Y-%m') as Month,
SELECT date_format(created,'%Y-%m') as Month,
sum(Message LIKE 'Torrent % was uploaded by %') AS t_add,
sum(Message LIKE 'Torrent % was deleted %') AS t_del
FROM log
WHERE Time BETWEEN ? AND last_day(?)
GROUP BY Month order by Time DESC
WHERE created BETWEEN ? AND last_day(?)
GROUP BY Month order by created DESC
", $beginMonth, $endMonth
);
$delta = self::$db->to_array('Month', MYSQLI_ASSOC, false);

View File

@@ -203,7 +203,7 @@ class TGroup extends BaseObject {
group_concat(tt.NegativeVotes ORDER BY tt.PositiveVotes - tt.NegativeVotes DESC, tag.Name) AS tagDownvotes,
(tgha.TorrentGroupID IS NOT NULL) AS noCoverArt,
max(coalesce(t.Size, 0)) AS max_torrent_size,
max(coalesce(t.Time, '2000-01-01 00:00:00')) AS most_recent_upload
max(coalesce(t.created, '2000-01-01 00:00:00')) AS most_recent_upload
FROM torrents_group AS tg
LEFT JOIN torrents AS t ON (t.GroupID = tg.ID)
LEFT JOIN torrents_tags AS tt ON (tt.GroupID = tg.ID)
@@ -669,7 +669,7 @@ class TGroup extends BaseObject {
tls.Leechers,
tls.Snatched,
t.FreeTorrent,
t.Time,
t.created,
t.Description,
t.FileList,
t.FilePath,
@@ -800,7 +800,7 @@ class TGroup extends BaseObject {
HasCue, FreeTorrent, Media, Format, Encoding, Description, RemasterYear, RemasterTitle,
RemasterRecordLabel, RemasterCatalogueNumber, FileList, TagList, VoteScore, ArtistName)
SELECT
t.ID, g.ID, g.Name, g.Year, g.CategoryID, t.Time, g.ReleaseType,
t.ID, g.ID, g.Name, g.Year, g.CategoryID, t.created, g.ReleaseType,
g.RecordLabel, g.CatalogueNumber, g.VanityHouse, t.Size, tls.Snatched, tls.Seeders,
tls.Leechers, t.LogScore, cast(t.Scene AS CHAR), cast(t.HasLog AS CHAR), cast(t.HasCue AS CHAR),
cast(t.FreeTorrent AS CHAR), t.Media, t.Format, t.Encoding, t.Description,

View File

@@ -11,7 +11,7 @@ class Freeleech extends \Gazelle\Task {
FROM torrents
WHERE FreeTorrent = '1'
AND FreeLeechType = '3'
AND Time < now() - INTERVAL 7 HOUR");
AND created < now() - INTERVAL 7 HOUR");
self::$db->prepared_query("
UPDATE torrents
@@ -19,7 +19,7 @@ class Freeleech extends \Gazelle\Task {
FreeLeechType = '0'
WHERE FreeTorrent = '1'
AND FreeLeechType = '3'
AND Time < now() - INTERVAL 7 HOUR");
AND created < now() - INTERVAL 7 HOUR");
self::$db->set_query_id($qId);
while ([$groupID] = self::$db->next_record()) {

View File

@@ -3,12 +3,25 @@
namespace Gazelle\Top10;
class Torrent extends \Gazelle\Base {
private string $baseQuery = "
SELECT
t.ID,
g.ID,
((t.Size * tls.Snatched) + (t.Size * 0.5 * tls.Leechers)) AS Data
FROM torrents AS t
INNER JOIN torrents_leech_stats tls ON (tls.TorrentID = t.ID)
INNER JOIN torrents_group AS g ON (g.ID = t.GroupID)
%s
GROUP BY %s
ORDER BY %s
LIMIT %s";
public function __construct (
protected readonly array $formats,
protected readonly \Gazelle\User $viewer,
) {}
public function getTopTorrents($getParameters, $details = 'all', $limit = 10) {
public function getTopTorrents($getParameters, $details = 'all', $limit = 10): array {
$cacheKey = 'top10_v2_' . $details . '_' . md5(implode('', $getParameters)) . '_' . $limit;
$topTorrents = self::$cache->get_value($cacheKey);
@@ -16,7 +29,7 @@ class Torrent extends \Gazelle\Base {
return $topTorrents;
}
if (self::$cache->get_value("{$cacheKey}_lock")) {
return false;
return [];
}
self::$cache->cache_value("{$cacheKey}_lock", true, 3600);
@@ -82,67 +95,56 @@ class Torrent extends \Gazelle\Base {
return (bool)$this->viewer->option('DisableFreeTorrentTop10');
}
private function orderBy($details) {
private function orderBy($details): string {
return match ($details) {
'snatched' => 'tls.Snatched',
'seeded' => 'tls.Seeders',
'data' => 'Data',
default => '(tls.Seeders + tls.Leechers)',
'seeded' => 'tls.Seeders',
'data' => 'Data',
default => '(tls.Seeders + tls.Leechers)',
};
}
private function detailsWhere($detailsParameters) {
private function detailsWhere(string $detailsParameters): array {
return match ($detailsParameters) {
'day' => ["parameters" => null, "where" => "t.Time > now() - INTERVAL 1 DAY"],
'week' => ["parameters" => null, "where" => "t.Time > now() - INTERVAL 1 WEEK"],
'month' => ["parameters" => null, "where" => "t.Time > now() - INTERVAL 1 MONTH"],
'year' => ["parameters" => null, "where" => "t.Time > now() - INTERVAL 1 YEAR"],
'day' => ["parameters" => null, "where" => "t.created > now() - INTERVAL 1 DAY"],
'week' => ["parameters" => null, "where" => "t.created > now() - INTERVAL 1 WEEK"],
'month' => ["parameters" => null, "where" => "t.created > now() - INTERVAL 1 MONTH"],
'year' => ["parameters" => null, "where" => "t.created > now() - INTERVAL 1 YEAR"],
default => [],
};
}
private function excludedArtistClause($artistParameter) {
if (!empty($artistParameter)) {
$artists = preg_split('/\r\n|\r|\n/', trim($artistParameter));
$artistPrepare = fn($artist) => trim($artist);
$artists = array_map($artistPrepare, $artists);
$sql = "
LEFT JOIN (
SELECT COUNT(*) AS ArtistCount, ta.GroupID
FROM torrents_artists AS ta
INNER JOIN artists_alias AS aa ON (ta.AliasID = aa.AliasID)
WHERE ta.Importance != '2' AND aa.Name IN (" . placeholders($artists) . ")
GROUP BY ta.GroupID
) AS ta ON (g.ID = ta.GroupID)";
return [$sql, $artists];
private function excludedArtistClause(string $artistParameter): array {
$artists = preg_split('/\r\n|\r|\n/', trim($artistParameter));
if ($artists) {
return [
" LEFT JOIN (
SELECT COUNT(*) AS ArtistCount, ta.GroupID
FROM torrents_artists AS ta
INNER JOIN artists_alias AS aa ON (ta.AliasID = aa.AliasID)
WHERE ta.Importance != '2' AND aa.Name IN (" . placeholders($artists) . ")
GROUP BY ta.GroupID
) AS ta ON (g.ID = ta.GroupID)",
array_map('trim', $artists)
];
}
return ['', []];
}
private function formatWhere($formatParameters) {
private function formatWhere(string $formatParameters): array {
if (in_array($formatParameters, $this->formats)) {
return ["parameters" => $formatParameters, "where" => "t.Format = ?"];
}
}
private function freeleechWhere($getParameters) {
$disableFreeTorrentTop10 = $this->viewer->option('DisableFreeTorrentTop10') ?? false;
if (isset($getParameters['freeleech'])) {
$disableFreeTorrentTop10 = ($getParameters['freeleech'] == 'hide' ? 1 : 0);
}
if ($disableFreeTorrentTop10) {
return ["parameters" => null, "where" => "t.FreeTorrent = '0'"];
}
return [];
}
private function tagWhere($getParameters, $any = false) {
private function freeleechWhere(array $getParameters): array {
return ($getParameters['freeleech'] ?? '') == 'hide' || (bool)$this->viewer->option('DisableFreeTorrentTop10')
? ["parameters" => null, "where" => "t.FreeTorrent = '0'"]
: [];
}
private function tagWhere(string $getParameters, bool $any = false): array {
if (!empty($getParameters)) {
$tags = explode(',', trim($getParameters));
$replace = fn($tag) => preg_replace('/[^a-z0-9.]/', '', $tag);
@@ -168,22 +170,9 @@ class Torrent extends \Gazelle\Base {
return [];
}
private function flatten(array $array) {
private function flatten(array $array): array {
$return = [];
array_walk_recursive($array, function($a) use (&$return) { $return[] = $a; });
return $return;
}
private string $baseQuery = "
SELECT
t.ID,
g.ID,
((t.Size * tls.Snatched) + (t.Size * 0.5 * tls.Leechers)) AS Data
FROM torrents AS t
INNER JOIN torrents_leech_stats tls ON (tls.TorrentID = t.ID)
INNER JOIN torrents_group AS g ON (g.ID = t.GroupID)
%s
GROUP BY %s
ORDER BY %s
LIMIT %s";
}

View File

@@ -13,8 +13,8 @@ class Torrent extends TorrentAbstract {
final const SNATCHED_UPDATE_INTERVAL = 3600; // How often we want to update users' snatch lists
protected $tokenCache;
protected $updateTime;
protected array $tokenCache;
protected string $updateTime;
public function location(): string { return "torrents.php?id={$this->groupId()}&torrentid={$this->id}#torrent{$this->id}"; }
public function tableName(): string { return 'torrents'; }
@@ -80,19 +80,20 @@ class Torrent extends TorrentAbstract {
* Check if the viewer has an active freeleech token on this torrent
*/
public function hasToken(int $userId): bool {
if (!$this->tokenCache) {
if (!isset($this->tokenCache)) {
$key = "users_tokens_" . $userId;
$this->tokenCache = self::$cache->get_value($key);
if ($this->tokenCache === false) {
$tokenCache = self::$cache->get_value($key);
if ($tokenCache === false) {
$qid = self::$db->get_query_id();
self::$db->prepared_query("
SELECT TorrentID FROM users_freeleeches WHERE Expired = 0 AND UserID = ?
", $userId
);
$this->tokenCache = array_fill_keys(self::$db->collect('TorrentID', false), true);
$tokenCache = array_fill_keys(self::$db->collect(0, false), true);
self::$db->set_query_id($qid);
self::$cache->cache_value($key, $this->tokenCache, 3600);
self::$cache->cache_value($key, $tokenCache, 3600);
}
$this->tokenCache = $tokenCache;
}
return isset($this->tokenCache[$this->id]);
}
@@ -113,7 +114,7 @@ class Torrent extends TorrentAbstract {
default => [$tgroup->name()],
}
);
$maxLength -= strlen($this->id) + 1 + ($asText ? 4 : 8);
$maxLength -= strlen((string)$this->id) + 1 + ($asText ? 4 : 8);
$filename = safeFilename(shortenString($filename, $maxLength, true, false))
. "-" . $this->id;
return $asText ? "$filename.txt" : "$filename.torrent";
@@ -125,7 +126,7 @@ class Torrent extends TorrentAbstract {
public function torrentBody(string $announceUrl): string {
$filer = new \Gazelle\File\Torrent;
$contents = $filer->get($this->id);
if (is_null($contents)) {
if ($contents == false) {
return '';
}
$tor = new \OrpheusNET\BencodeTorrent\BencodeTorrent;
@@ -362,6 +363,17 @@ class Torrent extends TorrentAbstract {
(new \Gazelle\User\Bonus($this->uploader()))->removePointsForUpload($this);
}
$edition = $this->edition();
$groupId = $this->group()->id();
$infohash = $this->infohash();
$sizeMB = number_format($this->size() / (1024 * 1024), 2) . ' MiB';
$name = $this->name();
(new \Gazelle\Tracker)->update_tracker('delete_torrent', [
'id' => $this->id,
'info_hash' => rawurlencode($this->infohashBinary()),
'reason' => $trackerReason,
]);
$manager = new \Gazelle\DB;
$manager->relaxConstraints(true);
[$ok, $message] = $manager->softDelete(SQLDB, 'torrents_leech_stats', [['TorrentID', $this->id]], false);
@@ -369,14 +381,7 @@ class Torrent extends TorrentAbstract {
return [false, $message];
}
[$ok, $message] = $manager->softDelete(SQLDB, 'torrents', [['ID', $this->id]]);
$infohash = $this->infohash();
$manager->relaxConstraints(false);
(new \Gazelle\Tracker)->update_tracker('delete_torrent', [
'id' => $this->id,
'info_hash' => rawurlencode(hex2bin($infohash)),
'reason' => $trackerReason,
]);
self::$cache->decrement('stats_torrent_count');
$manager->softDelete(SQLDB, 'torrents_files', [['TorrentID', $this->id]]);
$manager->softDelete(SQLDB, 'torrents_bad_files', [['TorrentID', $this->id]]);
@@ -433,7 +438,6 @@ class Torrent extends TorrentAbstract {
$deleteKeys = self::$db->collect('ck', false);
$manager->softDelete(SQLDB, 'users_notify_torrents', [['TorrentID', $this->id]]);
$groupId = $this->group()->id();
if (!is_null($user)) {
$key = sprintf(self::USER_RECENT_UPLOAD, $user->id());
$recent = self::$cache->get_value($key);
@@ -451,15 +455,13 @@ class Torrent extends TorrentAbstract {
array_push($deleteKeys, "zz_t_" . $this->id, sprintf(self::CACHE_KEY, $this->id), "torrent_group_" . $groupId);
self::$cache->delete_multi($deleteKeys);
self::$cache->decrement('stats_torrent_count');
$this->group()->refresh();
$this->flush();
$sizeMB = number_format($this->info()['Size'] / (1024 * 1024), 2) . ' MiB';
$userInfo = $user ? " by " . $user->username() : '';
(new Log)->general(
"Torrent "
. $this->id . " (" . $this->name() . ") [" . $this->edition() .
"] ($sizeMB $infohash) was deleted" . $userInfo . " for reason: $reason"
)
"Torrent {$this->id} ($name) [$edition] ($sizeMB $infohash) was deleted$userInfo for reason: $reason")
->torrent(
$groupId, $this->id, $user?->id(),
"deleted torrent ($sizeMB $infohash) for reason: $reason"
@@ -470,7 +472,7 @@ class Torrent extends TorrentAbstract {
}
public function expireToken(int $userId): bool {
$hash = self::$db->scalar("
$hash = (string)self::$db->scalar("
SELECT info_hash FROM torrents WHERE ID = ?
", $this->id
);
@@ -500,7 +502,7 @@ class Torrent extends TorrentAbstract {
return self::$db->to_array(false, MYSQLI_NUM, false);
}
public function seederList(int $userId, int $limit, int $offset) {
public function seederList(int $userId, int $limit, int $offset): array {
$key = sprintf(self::CACHE_KEY_PEERLIST_PAGE, $this->id, $offset);
$list = self::$cache->get_value($key);
if ($list === false) {
@@ -536,7 +538,7 @@ class Torrent extends TorrentAbstract {
}
public function downloadTotal(): int {
return self::$db->scalar("
return (int)self::$db->scalar("
SELECT count(DISTINCT UserID) FROM users_downloads WHERE TorrentID = ?
", $this->id
);

View File

@@ -15,7 +15,7 @@ class Deleted extends \Gazelle\Base {
t.Scene, t.HasLog, t.HasCue, t.HasLogDB, t.LogScore, t.LogChecksum,
hex(t.info_hash) as info_hash, t.info_hash as info_hash_raw,
t.FileCount, t.FileList, t.FilePath, t.Size,
t.FreeTorrent, t.FreeLeechType, t.Time, t.Description, t.LastReseedRequest,
t.FreeTorrent, t.FreeLeechType, t.created, t.Description, t.LastReseedRequest,
0 AS Seeders, 0 AS Leechers, 0 AS Snatched, '2000-01-01 00:00:00' AS last_action,
tbt.TorrentID AS BadTags, tbf.TorrentID AS BadFolders, tfi.TorrentID AS BadFiles, ml.TorrentID AS MissingLineage,
ca.TorrentID AS CassetteApproved, lma.TorrentID AS LossymasterApproved, lwa.TorrentID AS LossywebApproved,
@@ -69,7 +69,7 @@ class Deleted extends \Gazelle\Base {
'Seeders' => 0,
'Size' => 0,
'Snatched' => 0,
'Time' => null,
'created' => null,
'UserID' => 0,
'info_hash' => '',
'info_hash_raw' => '',

View File

@@ -72,7 +72,7 @@ class Reaper extends \Gazelle\Base {
return $this->initialList(
cond: [
'tls.last_action IS NULL',
't.Time < now() - INTERVAL ? HOUR', // interval
't.created < now() - INTERVAL ? HOUR', // interval
],
interval: NOTIFY_NEVER_SEEDED_INITIAL_HOUR,
state: ReaperState::NEVER,

View File

@@ -316,8 +316,6 @@ abstract class TorrentAbstract extends BaseObject {
/**
* The infohash of this torrent
*
* @return string hexified infohash
*/
public function infohash(): string {
return $this->info()['info_hash'];
@@ -325,8 +323,6 @@ abstract class TorrentAbstract extends BaseObject {
/**
* The infohash of this torrent (binary)
*
* @return string raw infohash
*/
public function infohashBinary(): string {
return $this->info()['info_hash_raw'];
@@ -577,7 +573,7 @@ abstract class TorrentAbstract extends BaseObject {
public function isUploadGracePeriod(): bool {
return strtotime($this->created()) > date('U') - 3600;
}
/**
* Was it active more then 14 days ago? If never active has it been 3 days? (Reseed grace period)
*/
@@ -592,7 +588,7 @@ abstract class TorrentAbstract extends BaseObject {
default => false,
};
}
/**
* The uploader ID of this torrent
*/

View File

@@ -1741,7 +1741,7 @@ class User extends BaseObject {
AND g.CategoryID = '1'
AND t.UserID = ?
GROUP BY g.ID
ORDER BY t.Time DESC
ORDER BY t.created DESC
LIMIT ?
", $this->id, $limit
);

View File

@@ -96,12 +96,12 @@ class Bookmark extends \Gazelle\BaseUser {
$bookmarkList = self::$cache->get_value($key);
$bookmarkList = false;
self::$db->prepared_query("
SELECT GroupID AS tgroup_id,
Sort AS sequence,
`Time` AS created
FROM bookmarks_torrents
WHERE UserID = ?
ORDER BY Sort, `Time`
SELECT b.GroupID AS tgroup_id,
b.Sort AS sequence,
b.Time AS created
FROM bookmarks_torrents b
WHERE b.UserID = ?
ORDER BY b.Sort, b.Time
", $this->user->id()
);
$bookmarkList = self::$db->to_array(false, MYSQLI_ASSOC, false);

View File

@@ -57,7 +57,7 @@ $db->prepared_query("
SELECT g.ID as gid, t.ID as tid
FROM torrents_group g
LEFT JOIN torrents t on (t.GroupID = g.ID)
WHERE g.Name regexp '^(?:phpunit (?:category new|collfree|notify|reaper|request|seedbox|torman) [a-z]{6}|Some [a-z]{8} songs)$'
WHERE g.Name regexp '^(?:phpunit (?:category new|collfree|notify|reaper|request|seedbox|torman) [a-z]{6}|php split title [a-z]{10}|Some [a-z]{8} songs)$'
");
$groupList = $db->collect('gid', false);
$torrentList = $db->collect('tid', false);
@@ -101,7 +101,7 @@ foreach ($db->collect(0, false) as $collageId) {
$db->prepared_query("
SELECT um.ID
FROM users_main um
WHERE um.Username regexp '^(?:(?:donor|u(?:[1-3]|ser))\.[a-z0-9]{6}|(?:collfree|feat|re(?:aper|g[1-5]|q)|tgcat|token|torman|um[123]|user)\.[a-z0-9]{10}|notf(?:\.(new|enc))?\.[^.]+)$'
WHERE um.Username regexp '^(?:(?:donor|inbox\.(?:recv|send)|tgroup\.[au]|u(?:[1-3]|ser))\.[a-z]{6}|tag\.[a-z]{8}|(?:admin|art(?:2|ist|y)|backlog|collfree|comment|enc\.med|feat|new\.grp|re(?:aper|clab|g[1-5]|lease|port|q)|sbox|tag(?:no|2(?:no|yes))|tgcat|token|torman|um[123]|uploader|user|year|xva)\.[a-z]{10}|notf(?:\.(new|enc))?\.[^.]+)$'
");
$userMan = new Gazelle\Manager\User;

View File

@@ -1480,101 +1480,11 @@ parameters:
count: 1
path: ../app/Top10/Tag.php
-
message: "#^Method Gazelle\\\\Top10\\\\Torrent\\:\\:detailsWhere\\(\\) has no return type specified\\.$#"
count: 1
path: ../app/Top10/Torrent.php
-
message: "#^Method Gazelle\\\\Top10\\\\Torrent\\:\\:excludedArtistClause\\(\\) has no return type specified\\.$#"
count: 1
path: ../app/Top10/Torrent.php
-
message: "#^Method Gazelle\\\\Top10\\\\Torrent\\:\\:flatten\\(\\) has no return type specified\\.$#"
count: 1
path: ../app/Top10/Torrent.php
-
message: "#^Method Gazelle\\\\Top10\\\\Torrent\\:\\:formatWhere\\(\\) has no return type specified\\.$#"
count: 1
path: ../app/Top10/Torrent.php
-
message: "#^Method Gazelle\\\\Top10\\\\Torrent\\:\\:freeleechWhere\\(\\) has no return type specified\\.$#"
count: 1
path: ../app/Top10/Torrent.php
-
message: "#^Method Gazelle\\\\Top10\\\\Torrent\\:\\:getTopTorrents\\(\\) has no return type specified\\.$#"
count: 1
path: ../app/Top10/Torrent.php
-
message: "#^Method Gazelle\\\\Top10\\\\Torrent\\:\\:orderBy\\(\\) has no return type specified\\.$#"
count: 1
path: ../app/Top10/Torrent.php
-
message: "#^Method Gazelle\\\\Top10\\\\Torrent\\:\\:tagWhere\\(\\) has no return type specified\\.$#"
count: 1
path: ../app/Top10/Torrent.php
-
message: "#^Parameter \\#2 \\$array of function array_map expects array, array\\<int, string\\>\\|false given\\.$#"
count: 1
path: ../app/Top10/Torrent.php
-
message: "#^Method Gazelle\\\\Top10\\\\User\\:\\:fetch\\(\\) has no return type specified\\.$#"
count: 1
path: ../app/Top10/User.php
-
message: "#^Call to function is_null\\(\\) with string\\|false will always evaluate to false\\.$#"
count: 1
path: ../app/Torrent.php
-
message: "#^Method Gazelle\\\\Torrent\\:\\:downloadTotal\\(\\) should return int but returns bool\\|float\\|int\\|string\\|null\\.$#"
count: 1
path: ../app/Torrent.php
-
message: "#^Method Gazelle\\\\Torrent\\:\\:seederList\\(\\) has no return type specified\\.$#"
count: 1
path: ../app/Torrent.php
-
message: "#^Parameter \\#1 \\$data of method OrpheusNET\\\\BencodeTorrent\\\\BencodeTorrent\\:\\:decodeString\\(\\) expects string, string\\|false given\\.$#"
count: 1
path: ../app/Torrent.php
-
message: "#^Parameter \\#1 \\$string of function rawurlencode expects string, float\\|int\\<min, \\-1\\>\\|int\\<1, max\\>\\|string\\|true given\\.$#"
count: 1
path: ../app/Torrent.php
-
message: "#^Parameter \\#1 \\$string of function rawurlencode expects string, string\\|false given\\.$#"
count: 1
path: ../app/Torrent.php
-
message: "#^Parameter \\#1 \\$string of function strlen expects string, int given\\.$#"
count: 1
path: ../app/Torrent.php
-
message: "#^Property Gazelle\\\\Torrent\\:\\:\\$tokenCache has no type specified\\.$#"
count: 1
path: ../app/Torrent.php
-
message: "#^Property Gazelle\\\\Torrent\\:\\:\\$updateTime has no type specified\\.$#"
count: 1
path: ../app/Torrent.php
-
message: "#^Cannot call method addFlag\\(\\) on bool\\|Gazelle\\\\TorrentAbstract\\.$#"
count: 1

View File

@@ -155,7 +155,7 @@ switch ($Action) {
case 'uploaded':
$Title = "%s &rsaquo; Comments on their uploads";
$Join[] = 'INNER JOIN torrents t ON (t.GroupID = tg.ID)';
$condition[] = 'C.AddedTime > t.Time';
$condition[] = 'C.AddedTime > t.created';
$condition[] = "C.AuthorID != ?";
$condition[] = "t.UserID = ?";
$condArgs[] = $UserID;

View File

@@ -185,20 +185,7 @@ foreach ($context as $c) {
<td style="text-align: right;" class="sign leechers"><img src="<?= $urlStem ?>leechers.png" alt="Leechers" title="Leechers" class="tooltip" /></td>
<td style="text-align: right;">Transferred</td>
</tr>
<?php
// Server is already processing a top10 query. Starting another one will make things slow
if ($details === false) {
?>
<tr class="rowb">
<td colspan="9" class="center">
Server is busy processing another top list request. Please try again in a minute.
</td>
</tr>
</table><br />
<?php
continue;
} elseif (empty($details)) {
?>
<?php if (!$details) { ?>
<tr class="rowb">
<td colspan="9" class="center">
Found no torrents matching the criteria.

View File

@@ -19,7 +19,7 @@ if (!empty($_GET['searchstr']) || !empty($_GET['groupname'])) {
$imgTag = '<img src="' . (new Gazelle\User\Stylesheet($Viewer))->imagePath() . '%s.png" class="tooltip" alt="%s" title="%s"/>';
$headerMap = [
'year' => ['defaultSort' => 'desc', 'text' => 'Year'],
'time' => ['defaultSort' => 'desc', 'text' => 'Time'],
'time' => ['defaultSort' => 'desc', 'text' => 'Created', 'dbColumn' => 'created'],
'size' => ['defaultSort' => 'desc', 'text' => 'Size'],
'snatched' => ['defaultSort' => 'desc', 'text' => sprintf($imgTag, 'snatched', 'Snatches', 'Snatches')],
'seeders' => ['defaultSort' => 'desc', 'text' => sprintf($imgTag, 'seeders', 'Seeders', 'Seeders')],

View File

@@ -203,7 +203,7 @@ switch ($_GET['type']) {
error(403);
}
$join = "";
$time = 'unix_timestamp(t.Time)';
$time = 'unix_timestamp(t.created)';
$userField = 't.UserID';
break;
case 'uploaded-unseeded':
@@ -212,7 +212,7 @@ switch ($_GET['type']) {
}
$join = "LEFT JOIN xbt_files_users AS xfu ON (xfu.fid = t.ID AND xfu.uid = t.UserID)";
$cond[] = 'xfu.fid IS NULL';
$time = 'unix_timestamp(t.Time)';
$time = 'unix_timestamp(t.created)';
$userField = 't.UserID';
break;
case 'downloaded':

View File

@@ -131,7 +131,7 @@ class ReaperTest extends TestCase {
$db = Gazelle\DB::DB();
$db->prepared_query("
SELECT t.ID,
t.Time,
t.created,
tu.unseeded_date < tls.last_action,
coalesce(tls.last_action, 'null'),
coalesce(tu.unseeded_date, 'null'),
@@ -202,7 +202,7 @@ class ReaperTest extends TestCase {
// reset the time of the never seeded alert back in time to hit the initial timeout
$hour = NOTIFY_NEVER_SEEDED_INITIAL_HOUR + 1;
$neverSeededInitialDate = date('Y-m-d H:i:s', strtotime("-{$hour} hours"));
$this->torrentList[0]->setField('Time', $neverSeededInitialDate)->modify();
$this->torrentList[0]->setField('created', $neverSeededInitialDate)->modify();
// look for never seeded
$neverInitial = $reaper->initialNeverSeededList();
@@ -235,7 +235,7 @@ class ReaperTest extends TestCase {
// reset the unseeded entries and time out a second upload
$this->removeUnseededAlert($this->torrentList);
$this->torrentList[1]->setField('Time', $neverSeededInitialDate)->modify();
$this->torrentList[1]->setField('created', $neverSeededInitialDate)->modify();
$neverInitial = $reaper->initialNeverSeededList();
$this->assertCount(1, $neverInitial, 'never-initial-2'); // one user ...
@@ -269,7 +269,7 @@ class ReaperTest extends TestCase {
// reseed one of the torrents by the uploader
$this->generateReseed($this->torrentList[0], $this->torrentList[0]->uploader());
$this->torrentList[1]->setField('Time', date('Y-m-d H:i:s'))->modify();
$this->torrentList[1]->setField('created', date('Y-m-d H:i:s'))->modify();
// reset the time of the remaing never seeded alert back in time to hit
// the final timeout.
@@ -339,7 +339,7 @@ class ReaperTest extends TestCase {
// reset the last action and time of the unseeded alert back in time to hit the initial timeout
foreach ($this->torrentList as $torrent) {
$hour = NOTIFY_UNSEEDED_INITIAL_HOUR + 1;
$torrent->setField('Time', date('Y-m-d H:i:s', strtotime("-{$hour} hours")))->modify();
$torrent->setField('created', date('Y-m-d H:i:s', strtotime("-{$hour} hours")))->modify();
$this->modifyLastAction($torrent, NOTIFY_UNSEEDED_INITIAL_HOUR + 2);
// pretend they were snatched
foreach ($this->userList as $user) {
@@ -503,7 +503,7 @@ class ReaperTest extends TestCase {
// reset the last action and time of the unseeded alert back in time to hit the initial timeout
foreach ($this->torrentList as $torrent) {
$hour = NOTIFY_NEVER_SEEDED_INITIAL_HOUR + 1;
$torrent->setField('Time', date('Y-m-d H:i:s', strtotime("-{$hour} hours")))->modify();
$torrent->setField('created', date('Y-m-d H:i:s', strtotime("-{$hour} hours")))->modify();
$this->modifyLastAction($torrent, NOTIFY_NEVER_SEEDED_INITIAL_HOUR + 2);
}
@@ -530,7 +530,7 @@ class ReaperTest extends TestCase {
// reset the last action and time of the unseeded alert back in time to hit the initial timeout
foreach ($this->torrentList as $torrent) {
$hour = NOTIFY_UNSEEDED_INITIAL_HOUR + 1;
$torrent->setField('Time', date('Y-m-d H:i:s', strtotime("-{$hour} hours")))->modify();
$torrent->setField('created', date('Y-m-d H:i:s', strtotime("-{$hour} hours")))->modify();
$this->modifyLastAction($torrent, NOTIFY_UNSEEDED_INITIAL_HOUR + 2);
$this->generateSnatch($torrent, $this->userList[1]);
}
@@ -557,7 +557,7 @@ class ReaperTest extends TestCase {
// Check that the unseeded_date can be extended
foreach ($this->torrentList as $torrent) {
$hour = NOTIFY_UNSEEDED_INITIAL_HOUR + 1;
$torrent->setField('Time', date('Y-m-d H:i:s', strtotime("-{$hour} hours")))->modify();
$torrent->setField('created', date('Y-m-d H:i:s', strtotime("-{$hour} hours")))->modify();
$this->modifyLastAction($torrent, NOTIFY_UNSEEDED_INITIAL_HOUR + 2);
}