use id property in section/torrents

This commit is contained in:
Spine
2025-10-06 08:47:30 +00:00
parent 0a5c8d9443
commit 5bcc91657c
21 changed files with 59 additions and 61 deletions

View File

@@ -7,14 +7,14 @@ class Torrent extends \Gazelle\Base {
protected array $args;
public function __construct(
protected readonly int $userId,
protected readonly \Gazelle\User $user,
) {
$this->cond = ['unt.UserID = ?'];
$this->args = [$userId];
$this->args = [$user->id];
}
public function flush(): static {
self::$cache->delete_value('user_notify_upload_' . $this->userId);
self::$cache->delete_value('user_notify_upload_' . $this->user->id);
return $this;
}
@@ -57,7 +57,7 @@ class Torrent extends \Gazelle\Base {
UPDATE users_notify_torrents SET
UnRead = ?
WHERE UserID = ?
', 0, $this->userId
', 0, $this->user->id
);
$this->flush();
return $list;
@@ -68,7 +68,7 @@ class Torrent extends \Gazelle\Base {
UPDATE users_notify_torrents SET
UnRead = 0
WHERE UnRead = 1 AND UserID = ?
", $this->userId
", $this->user->id
);
if (self::$db->affected_rows()) {
$this->flush();
@@ -81,7 +81,7 @@ class Torrent extends \Gazelle\Base {
UPDATE users_notify_torrents SET
UnRead = 0
WHERE UnRead = 1 AND UserID = ? AND FilterID = ?
", $this->userId, $filterId
", $this->user->id, $filterId
);
if (self::$db->affected_rows()) {
$this->flush();
@@ -92,7 +92,7 @@ class Torrent extends \Gazelle\Base {
public function clearFilter(int $filterId): int {
self::$db->prepared_query("
DELETE FROM users_notify_torrents WHERE UnRead = 0 AND UserID = ? AND FilterID = ?
", $this->userId, $filterId
", $this->user->id, $filterId
);
$this->flush();
return self::$db->affected_rows();
@@ -101,7 +101,7 @@ class Torrent extends \Gazelle\Base {
public function clearRead(): int {
self::$db->prepared_query("
DELETE FROM users_notify_torrents WHERE UnRead = 0 AND UserID = ?
", $this->userId
", $this->user->id
);
$this->flush();
return self::$db->affected_rows();
@@ -113,7 +113,7 @@ class Torrent extends \Gazelle\Base {
}
self::$db->prepared_query("
DELETE FROM users_notify_torrents WHERE UserID = ? AND TorrentID IN (" . placeholders($torrentIds) . ")
", $this->userId, ...$torrentIds
", $this->user->id, ...$torrentIds
);
$this->flush();
return self::$db->affected_rows();

View File

@@ -120,15 +120,15 @@ class Torrent extends TorrentAbstract {
bool $adjusted,
int $adjScore,
bool $adjChecksum,
int $adjBy,
string $adjReason,
array $adjDetails,
User $adjBy,
): int {
self::$db->prepared_query("
UPDATE torrents_logs SET
Adjusted = ?, AdjustedScore = ?, AdjustedChecksum = ?, AdjustedBy = ?, AdjustmentReason = ?, AdjustmentDetails = ?
WHERE TorrentID = ? AND LogID = ?
", $adjusted ? '1' : '0', $adjScore, $adjChecksum ? '1' : '0', $adjBy, $adjReason, serialize($adjDetails),
", $adjusted ? '1' : '0', $adjScore, $adjChecksum ? '1' : '0', $adjBy->id, $adjReason, serialize($adjDetails),
$this->id, $logId
);
if (self::$db->affected_rows() > 0) {

View File

@@ -25,7 +25,7 @@ if (is_null($artist)) {
}
// save data in case removeArtist() deletes the artist
$artistId = $artist->id();
$artistId = $artist->id;
$artistName = $artist->name();
if ($tgroup->removeArtist($artist, $role)) {

View File

@@ -38,7 +38,7 @@ if ($status == DownloadStatus::ok) {
}
if ($status == DownloadStatus::flood) {
$key = "ratelimit_flood_" . $Viewer->id();
$key = "ratelimit_flood_" . $Viewer->id;
if ($Cache->get_value($key) === false) {
$Cache->cache_value($key, true, 3600);
Irc::sendMessage(

View File

@@ -18,9 +18,8 @@ $paginator = new Util\Paginator(PEERS_PER_PAGE, (int)($_GET['page'] ?? 1));
$paginator->setTotal($torrent->downloadTotal());
echo $Twig->render('torrent/downloadlist.twig', [
'list' => $torrent->downloadList($Viewer, $paginator->limit(), $paginator->offset()),
'paginator' => $paginator,
'torrent_id' => $torrent->id(),
'url_stem' => new User\Stylesheet($Viewer)->imagePath(),
'viewer_id' => $Viewer->id(),
'list' => $torrent->downloadList($Viewer, $paginator->limit(), $paginator->offset()),
'paginator' => $paginator,
'torrent' => $torrent,
'url_stem' => new User\Stylesheet($Viewer)->imagePath(),
]);

View File

@@ -13,7 +13,7 @@ if (is_null($torrent)) {
Error404::error();
}
if (($Viewer->id() != $torrent->uploaderId() && !$Viewer->permitted('torrents_edit')) || $Viewer->disableWiki()) {
if (($Viewer->id != $torrent->uploaderId() && !$Viewer->permitted('torrents_edit')) || $Viewer->disableWiki()) {
Error403::error();
}
@@ -40,7 +40,7 @@ if ($Viewer->permitted('torrents_edit') && ($Viewer->permitted('users_mod') || $
if (!($torrent->isRemastered() && !$torrent->remasterYear()) || $Viewer->permitted('edit_unknowns')) {
$torrentInfo = [
'ID' => $torrent->id(),
'ID' => $torrent->id,
'Media' => $torrent->media(),
'Format' => $torrent->format(),
'Bitrate' => $torrent->encoding(),
@@ -57,7 +57,7 @@ if (!($torrent->isRemastered() && !$torrent->remasterYear()) || $Viewer->permitt
'Title' => $tgroup->name(),
'Year' => $tgroup->year(),
'VanityHouse' => $tgroup->isShowcase(),
'GroupID' => $tgroup->id(),
'GroupID' => $tgroup->id,
'UploaderID' => $torrent->uploaderId(),
'HasLog' => $torrent->hasLog(),
'HasCue' => $torrent->hasCue(),

View File

@@ -9,8 +9,8 @@ if (!$Viewer->permitted('users_mod')) {
Error403::error();
}
$LogID = (int)($_POST['logid'] ?? 0);
if (!$LogID) {
$logId = (int)($_POST['logid'] ?? 0);
if (!$logId) {
Error404::error();
}
$torrent = new Manager\Torrent()->findById((int)($_POST['torrentid'] ?? 0));
@@ -74,6 +74,6 @@ foreach ($TrackDeductions as [$tag, $deduction, $label]) {
}
}
$torrent->adjustLogscore($LogID, $adjusted, max(0, $adjustedScore), $adjustedChecksum, $Viewer->id(), $adjustmentReason, $adjustmentDetails);
$torrent->adjustLogscore($logId, $adjusted, max(0, $adjustedScore), $adjustedChecksum, $adjustmentReason, $adjustmentDetails, $Viewer);
header('Location: ' . $torrent->location());

View File

@@ -17,7 +17,7 @@ $thread = new Manager\ForumThread()->create(
user: new User(SYSTEM_USER_ID),
title: "Editing request \xE2\x80\x93 Torrent Group: " . $tgroup->name(),
body: $Twig->render('forum/edit-request-body.twig', [
'link' => '[torrent]' . $tgroup->id() . '[/torrent]',
'link' => "[torrent]{$tgroup->id}[/torrent]",
'details' => trim($_POST['edit_details']),
'viewer' => $Viewer,
]),

View File

@@ -15,7 +15,7 @@ if (is_null($torrent)) {
}
echo $Twig->render('torrent/masspm.twig', [
'textarea' => new Util\Textarea('message', "[pl]{$torrent->id()}[/pl]", 60, 8),
'textarea' => new Util\Textarea('message', "[pl]{$torrent->id}[/pl]", 60, 8),
'torrent' => $torrent,
'viewer' => $Viewer,
]);

View File

@@ -19,7 +19,7 @@ $new = $tgMan->findById((int)($_POST['targetgroupid'] ?? 0));
if (is_null($new)) {
Error400::error('Target group does not exist.');
}
if ($new->id() === $old->id()) {
if ($new->id === $old->id) {
Error400::error('Old group ID is the same as new group ID!');
}
if ($old->categoryName() !== 'Music') {

View File

@@ -26,7 +26,7 @@ if ($new->categoryName() !== 'Music') {
Error400::error('Destination torrent group must be in the "Music" category.');
}
if ($torrent->groupId() === $new->id()) {
if ($torrent->groupId() === $new->id) {
header("Location: " . redirectUrl("torrents.php?action=edit&id=" . $torrent->groupId()));
exit;
}

View File

@@ -6,7 +6,7 @@ declare(strict_types=1);
namespace Gazelle;
authorize();
$notifier = new Notification\Torrent($Viewer->id());
$notifier = new Notification\Torrent($Viewer);
switch ($_GET['action']) {
case 'notify_catchup':

View File

@@ -15,10 +15,10 @@ $paginator = new Util\Paginator(PEERS_PER_PAGE, (int)($_GET['page'] ?? 1));
$paginator->setTotal($torrent->seederTotal());
echo $Twig->render('torrent/seederlist.twig', [
'is_admin' => $Viewer->permitted('users_mod'),
'list' => $torrent->seederList($Viewer, $paginator->limit(), $paginator->offset()),
'paginator' => $paginator,
'torrent_id' => $torrent->id(),
'url_stem' => new User\Stylesheet($Viewer)->imagePath(),
'user_id' => $Viewer->id(),
'is_admin' => $Viewer->permitted('users_mod'),
'list' => $torrent->seederList($Viewer, $paginator->limit(), $paginator->offset()),
'paginator' => $paginator,
'torrent' => $torrent,
'url_stem' => new User\Stylesheet($Viewer)->imagePath(),
'viewer' => $Viewer,
]);

View File

@@ -14,7 +14,7 @@ $user = new Manager\User()->findById((int)($_GET['userid'] ?? 0));
if (is_null($user)) {
Error404::error();
}
if ($user->id != $Viewer->id() && !$Viewer->isStaff()) {
if ($user->id != $Viewer->id && !$Viewer->isStaff()) {
Error403::error();
}

View File

@@ -18,9 +18,8 @@ $paginator = new Util\Paginator(PEERS_PER_PAGE, (int)($_GET['page'] ?? 1));
$paginator->setTotal($torrent->snatchTotal());
echo $Twig->render('torrent/snatchlist.twig', [
'list' => $torrent->snatchList($Viewer, $paginator->limit(), $paginator->offset()),
'paginator' => $paginator,
'torrent_id' => $torrent->id(),
'url_stem' => new User\Stylesheet($Viewer)->imagePath(),
'viewer_id' => $Viewer->id(),
'list' => $torrent->snatchList($Viewer, $paginator->limit(), $paginator->offset()),
'paginator' => $paginator,
'torrent' => $torrent,
'url_stem' => new User\Stylesheet($Viewer)->imagePath(),
]);

View File

@@ -9,11 +9,11 @@ declare(strict_types=1);
namespace Gazelle;
if (!isset($_GET['userid'])) {
header("Location: torrents.php?type={$_GET['type']}&userid=" . $Viewer->id());
header("Location: torrents.php?type={$_GET['type']}&userid={$Viewer->id}");
exit;
}
if ($_GET['userid'] == 'me') {
$_GET['userid'] = $Viewer->id();
$_GET['userid'] = $Viewer->id;
}
$user = new Manager\User()->findById((int)($_GET['userid'] ?? 0));
if (is_null($user)) {
@@ -222,7 +222,7 @@ switch ($_GET['type']) {
$userField = 't.UserID';
break;
case 'downloaded':
if (!($userId === $Viewer->id() || $Viewer->permitted('site_view_torrent_snatchlist'))) {
if (!($userId === $Viewer->id || $Viewer->permitted('site_view_torrent_snatchlist'))) {
Error403::error();
}
$join = "INNER JOIN users_downloads AS ud ON (ud.TorrentID = t.ID)";

View File

@@ -1,8 +1,8 @@
{% macro pager(action, torrent_id, page, pages) %}
{%- if pages > 1 %}
{%- for p in 1 .. pages %}
{%- if not loop.first %}·{% endif -%}
<span class="{% if p == page %}pager-cur {% endif %}pager-link pager-{{ p }}">{{ p }}</span>
{%- endfor %}
{%- endif %}
{% macro pager(action, torrent, paginator) %}
{%- if paginator.pages > 1 %}
{%- for p in 1 .. paginator.pages %}
{%- if not loop.first %}·{% endif -%}
<span class="{% if p == paginator.page %}pager-cur {% endif %}pager-link pager-{{ p }}">{{ p }}</span>
{%- endfor %}
{%- endif %}
{%- endmacro %}

View File

@@ -4,7 +4,7 @@
{% if loop.first %}
<h4 class="tooltip" title="List of users that have clicked the [DL] button">List of Downloaders</h4>
{% set linkbox %}
<div class="linkbox">{{ pager('show_downloads', torrent_id, paginator.page, paginator.pages)|raw }}</div>
<div class="linkbox">{{ pager('show_downloads', torrent, paginator)|raw }}</div>
{% endset %}
{{ linkbox|raw }}
<table>

View File

@@ -4,7 +4,7 @@
{% if loop.first %}
<h4>List of Peers</h4>
{% set linkbox %}
<div class="linkbox">{{ pager('show_seeders', torrent_id, paginator.page, paginator.pages)|raw }}</div>
<div class="linkbox">{{ pager('show_seeders', torrent, paginator)|raw }}</div>
{% endset %}
{{ linkbox|raw }}
<table>
@@ -23,7 +23,7 @@
</tr>
{% endif %}
<tr>
{% if is_admin or peer.user_id == user_id %}
{% if is_admin or peer.user_id == viewer.id %}
<td>{{ peer.user_id|user_url }}</td>
{% else %}
<td>Peer</td>
@@ -32,7 +32,7 @@
<td class="number_column">{{ peer.uploaded|octet_size }}</td>
<td class="number_column">{{ peer.downloaded|octet_size }}</td>
<td class="number_column">{{ ((peer.size - peer.remaining) / peer.size * 100)|number_format(2) }}</td>
{% if peer.user_id == user_id %}
{% if peer.user_id == viewer.id %}
{% if peer.seedbox %}
<td title="IP: {{ peer.ipv4addr }}, Useragent: {{ peer.useragent }}" colspan="2">Seedbox: <b>{{ peer.seedbox }}</b></td>
{% else %}

View File

@@ -4,7 +4,7 @@
{% if loop.first %}
<h4 class="tooltip" title="List of users that have reported a snatch to the tracker">List of Snatchers</h4>
{% set linkbox %}
<div class="linkbox">{{ pager('show_snatches', torrent_id, paginator.page, paginator.pages)|raw }}</div>
<div class="linkbox">{{ pager('show_snatches', torrent, paginator)|raw }}</div>
{% endset %}
{{ linkbox|raw }}
<table>

View File

@@ -271,7 +271,7 @@ class NotificationUploadTest extends TestCase {
$this->assertEquals(0, $this->userList['release']->removeNotificationFilter($filter['tag']), 'user-remove-other-filter');
// look for an unread user notification
$notifier = new Notification\Torrent($this->userList['artist']->id);
$notifier = new Notification\Torrent($this->userList['artist']);
$this->assertEquals(1, $notifier->total(), 'notifier-artist-total');
$unreadList = $notifier->unreadList(1, 0);
$this->assertCount(1, $unreadList, 'notifier-artist-unread-list');
@@ -279,13 +279,13 @@ class NotificationUploadTest extends TestCase {
// catch notifications
unset($notifier);
$notifier = new Notification\Torrent($this->userList['enc.med']->id);
$notifier = new Notification\Torrent($this->userList['enc.med']);
$this->assertEquals(1, $notifier->catchup(), 'notifier-encmed-catchup');
$this->assertCount(1, $notifier->unreadList(1, 0), 'notifier-encmed-unread'); // FIXME: it's actually read+unread
// clear unread user notifications
unset($notifier);
$notifier = new Notification\Torrent($this->userList['tag']->id);
$notifier = new Notification\Torrent($this->userList['tag']);
$this->assertEquals(1, $notifier->catchupFilter($filter['tag']), 'notifier-tag-catchup-filter');
$this->assertCount(1, $notifier->unreadList(1, 0), 'notifier-tag-catchup-unread');
$this->assertEquals(1, $notifier->clearFilter($filter['tag']), 'notifier-tag-clear-filter');
@@ -400,7 +400,7 @@ class NotificationUploadTest extends TestCase {
$manager = new Manager\Notification();
$manager->handleTicket($ticket, $this->torMan);
$notifier = new Notification\Torrent($this->userList['new.grp']->id);
$notifier = new Notification\Torrent($this->userList['new.grp']);
$this->assertEquals(1, $notifier->total(), 'notifier-new-group-1-total');
$this->assertEquals(1, $notifier->catchupFilter($filter), 'notifier-new-group-catchup');
$this->assertEquals(1, $notifier->clearFilter($filter), 'notifier-new-group-clear');
@@ -429,7 +429,7 @@ class NotificationUploadTest extends TestCase {
Helper::generateTorrentSeed($newTorrent, $newTorrent->uploader());
$manager->handleTicket($ticket, $this->torMan);
$notifier = new Notification\Torrent($this->userList['new.grp']->id);
$notifier = new Notification\Torrent($this->userList['new.grp']);
$this->assertEquals(0, $notifier->total(), 'notifier-no-new-group-2-total');
$stats = $manager->ticketStats();