forked from OPSnet/Gazelle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove-upload
executable file
·47 lines (40 loc) · 1.5 KB
/
remove-upload
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#! /usr/bin/env php
<?php
/**
* Script to clean broken uploads
*
* Usage: remove-upload <admin-id> <torrent-id> [<torrent-id> ...]
*/
require_once(__DIR__ . '/../lib/bootstrap.php');
$Cache = new Gazelle\Cache;
$torMan = new Gazelle\Manager\Torrent;
$userMan = new Gazelle\Manager\User;
array_shift($argv);
$janitorId = array_shift($argv);
$janitor = $userMan->find($janitorId);
if (is_null($janitor)) {
die("No janitor [$janitorId]\n");
}
foreach ($argv as $torrentId) {
$torrent = $torMan->findById($torrentId);
if (is_null($torrent)) {
echo "No such torrent $torrentId\n";
continue;
}
$name = $torrent->group()->text()
. ' [' . implode('/', [$torrent->media(), $torrent->format(), $torrent->encoding()]) . ']';
$uploader = $torrent->uploader();
$bonus = new Gazelle\User\Bonus($uploader);
$points = 2 * $bonus->torrentValue($torrent);
[$success, $message] = $torrent->remove($janitor, "Broken upload - backend");
if (!$success) {
echo "Did not remove $torrentId: $message\n";
continue;
}
$bonus->addPoints($points);
$uploader->inbox()->createSystem(
"Your upload $name has been removed",
"Due to a transient bug, your upload $name was not completed by the backend. Since it did not break any rules (we hope), please feel free to re-upload it. Since this is on us, you have been gifted $points points."
);
echo "removed $torrentId ($name) for $points points, uploaded by " . $uploader->username() . "\n";
}