Skip to content

Commit

Permalink
Move torrent delete pm to user manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Spine authored and itismadness committed Aug 15, 2021
1 parent 306047a commit 4faf07a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 71 deletions.
61 changes: 61 additions & 0 deletions app/Manager/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,67 @@ protected function deliverPM(int $toId, int $fromId, string $subject, string $bo
);
}

public function sendRemovalPM(int $torrentId, int $uploaderId, string $name, string $Log, int $trumpId, bool $pmUploader): int {
$subject = 'Torrent deleted: ' . $name;
$message = 'A torrent %s '
. (!$trumpId
? ' has been deleted.'
: " has been trumped. You can find the new torrent [url=torrents.php?torrentid={$trumpId}]here[/url]."
)
. "\n\n[url=log.php?search=Torrent+{$torrentId}]Log message[/url]: {$Log}.";

if ($pmUploader) {
$this->sendPM($uploaderId, 0, $subject, sprintf($message, 'you uploaded'));
}
$seen = [$uploaderId];

$this->db->prepared_query("
SELECT DISTINCT xfu.uid
FROM xbt_files_users AS xfu
INNER JOIN users_info AS ui ON (xfu.uid = ui.UserID)
WHERE ui.NotifyOnDeleteSeeding = '1'
AND xfu.fid = ?
AND xfu.uid NOT IN (" . placeholders($seen) . ")
", $torrentId, ...$seen
);
$ids = $this->db->collect('uid');
foreach ($ids as $userId) {
$this->sendPM($userId, 0, $subject, sprintf($message, 'you are seeding'));
}
$seen = array_merge($seen, $ids);

$this->db->prepared_query("
SELECT DISTINCT xs.uid
FROM xbt_snatched AS xs
INNER JOIN users_info AS ui ON (xs.uid = ui.UserID)
WHERE ui.NotifyOnDeleteSnatched = '1'
AND xs.fid = ?
AND xs.uid NOT IN (" . placeholders($seen) . ")
", $torrentId, ...$seen
);
$ids = $this->db->collect('uid');
foreach ($ids as $userId) {
$this->sendPM($userId, 0, $subject, sprintf($message, 'you have snatched'));
}
$seen = array_merge($seen, $ids);

$this->db->prepared_query("
SELECT DISTINCT ud.UserID
FROM users_downloads AS ud
INNER JOIN users_info AS ui ON (ud.UserID = ui.UserID)
WHERE ui.NotifyOnDeleteDownloaded = '1'
AND ud.TorrentID = ?
AND ud.UserID NOT IN (" . placeholders($seen) . ")
", $torrentId, ...$seen
);
$ids = $this->db->collect('UserID');
foreach ($ids as $userId) {
$this->sendPM($userId, 0, $subject, sprintf($message, 'you have downloaded'));
}

return count(array_merge($seen, $ids));
}

/**
* Warn a user.
*
Expand Down
61 changes: 0 additions & 61 deletions classes/torrents.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,67 +252,6 @@ public static function torrent_properties(&$Torrent, &$Flags) {
}
}

public static function send_pm($TorrentID, $UploaderID, $Name, $Log, $TrumpID = 0, $PMUploader = false) {
global $DB;

$Subject = 'Torrent deleted: ' . $Name;

$MessageStart = 'A torrent ';
if ($TrumpID > 0) {
$MessageEnd = ' has been trumped. You can find the new torrent [url=torrents.php?torrentid='.$TrumpID.']here[/url].';
}
else {
$MessageEnd = ' has been deleted.';
}
$MessageEnd .= "\n\n[url=log.php?search=Torrent+{$TorrentID}]Log message[/url]: {$Log}.";

// Uploader
$userMan = new \Gazelle\Manager\User;
if ($PMUploader) {
$userMan->sendPM($UploaderID, 0, $Subject, $MessageStart.'you uploaded'.$MessageEnd);
}
$PMedUsers = [$UploaderID];

// Seeders
$DB->prepared_query("
SELECT DISTINCT(xfu.uid)
FROM
xbt_files_users AS xfu
JOIN users_info AS ui ON xfu.uid = ui.UserID
WHERE xfu.fid = ?
AND ui.NotifyOnDeleteSeeding='1'
AND xfu.uid NOT IN (" . placeholders($PMedUsers) . ")
", $TorrentID, ...$PMedUsers);
$UserIDs = $DB->collect('uid');
foreach ($UserIDs as $UserID) {
$userMan->sendPM($UserID, 0, $Subject, $MessageStart . "you're seeding" . $MessageEnd);
}
$PMedUsers = array_merge($PMedUsers, $UserIDs);

// Snatchers
$DB->prepared_query("
SELECT DISTINCT(xs.uid)
FROM xbt_snatched AS xs JOIN users_info AS ui ON xs.uid = ui.UserID
WHERE xs.fid=? AND ui.NotifyOnDeleteSnatched='1' AND xs.uid NOT IN (" . placeholders($PMedUsers) . ")
", $TorrentID, ...$PMedUsers);
$UserIDs = $DB->collect('uid');
foreach ($UserIDs as $UserID) {
$userMan->sendPM($UserID, 0, $Subject, $MessageStart . "you've snatched" . $MessageEnd);
}
$PMedUsers = array_merge($PMedUsers, $UserIDs);

// Downloaders
$DB->prepared_query("
SELECT DISTINCT(ud.UserID)
FROM users_downloads AS ud JOIN users_info AS ui ON ud.UserID = ui.UserID
WHERE ud.TorrentID=? AND ui.NotifyOnDeleteDownloaded='1' AND ud.UserID NOT IN (" . placeholders($PMedUsers) . ")
", $TorrentID, ...$PMedUsers);
$UserIDs = $DB->collect('UserID');
foreach ($UserIDs as $UserID) {
$userMan->sendPM($UserID, 0, $Subject, $MessageStart . "you've downloaded" . $MessageEnd);
}
}

/**
* Delete a group, called after all of its torrents have been deleted.
* IMPORTANT: Never call this unless you're certain the group is no longer used by any torrents
Expand Down
17 changes: 8 additions & 9 deletions sections/reportsv2/takeresolve.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
exit;
}

$torMan = new Gazelle\Manager\Torrent;
$reportMan = new Gazelle\Manager\ReportV2;
$Types = $reportMan->types();
if (!isset($_POST['resolve_type'])) {
Expand Down Expand Up @@ -146,7 +147,8 @@
$report->setTorrentFlag('torrents_lossymaster_approved');
}

$uploader = new \Gazelle\User($uploaderId);
$userMan = new Gazelle\Manager\User;
$uploader = $userMan->findById($uploaderId);
$rawName = trim($_POST['raw_name']);
$adminMessage = trim($_POST['admin_message']);
$logMessage = isset($_POST['log_message']) ? trim($_POST['log_message']) : null;
Expand All @@ -159,22 +161,20 @@
. " was deleted by " . $LoggedUser['Username']
. ($_POST['resolve_type'] == 'custom' ? '' : ' for the reason: ' . $ResolveType['title'] . ".")
. ($logMessage ? " $logMessage" : '');
(new Gazelle\Manager\Torrent)
->findById($torrentId)
$torMan->findById($torrentId)
->remove(
$LoggedUser['ID'],
sprintf('%s (%s)', $ResolveType['title'], $logMessage ?? 'none'),
$ResolveType['reason']
);

$TrumpID = 0;
if ($_POST['resolve_type'] === 'trump') {
if (preg_match('/torrentid=([0-9]+)/', $logMessage, $Matches) === 1) {
$TrumpID = $Matches[1];
}
if ($_POST['resolve_type'] === 'trump' && preg_match('/torrentid=([0-9]+)/', $logMessage, $match) === 1) {
$TrumpID = $match[1];
}

Torrents::send_pm($torrentId, $uploaderId, $rawName, $Log, $TrumpID, (!$_POST['uploader_pm'] && $weeksWarned <= 0 && !isset($_POST['delete']) && !$SendPM));
$pmUploader = !$_POST['uploader_pm'] && $weeksWarned <= 0 && !isset($_POST['delete']) && !$SendPM;
$userMan->sendRemovalPM($torrentId, $uploaderId, $rawName, $Log, $TrumpID, $pmUploader);
}

//Warnings / remove upload
Expand All @@ -183,7 +183,6 @@
$uploader->revokeUpload();
}

$userMan = new Gazelle\Manager\User;
if ($weeksWarned > 0) {
$WarnLength = $weeksWarned * (7 * 86400);
$Reason = "Uploader of torrent ($torrentId) $rawName which was resolved with the preset: ".$ResolveType['title'].'.';
Expand Down
2 changes: 1 addition & 1 deletion sections/torrents/takedelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
error($message);
}

Torrents::send_pm(
(new Gazelle\Manager\User)->sendRemovalPM(
$torrentId,
$torrent['UserID'],
$name,
Expand Down

0 comments on commit 4faf07a

Please sign in to comment.