Browse Source

More robust request unfilling when torrent has been deleted

spaghetti 8 years ago
parent
commit
78b97305ed
1 changed files with 45 additions and 13 deletions
  1. 45
    13
      sections/requests/take_unfill.php

+ 45
- 13
sections/requests/take_unfill.php View File

16
     r.FillerID,
16
     r.FillerID,
17
     r.Title,
17
     r.Title,
18
     u.Uploaded,
18
     u.Uploaded,
19
+    u.BonusPoints,
19
     r.GroupID,
20
     r.GroupID,
20
     t.UserID,
21
     t.UserID,
21
-    u2.Uploaded
22
   FROM requests AS r
22
   FROM requests AS r
23
     LEFT JOIN torrents AS t ON t.ID = TorrentID
23
     LEFT JOIN torrents AS t ON t.ID = TorrentID
24
     LEFT JOIN users_main AS u ON u.ID = FillerID
24
     LEFT JOIN users_main AS u ON u.ID = FillerID
25
-    LEFT JOIN users_main AS u2 ON u2.ID = t.UserID
26
   WHERE r.ID = $RequestID");
25
   WHERE r.ID = $RequestID");
27
-list($CategoryID, $UserID, $FillerID, $Title, $Uploaded, $GroupID, $UploaderID, $UploaderUploaded) = $DB->next_record();
26
+list($CategoryID, $UserID, $FillerID, $Title, $Uploaded, $BonusPoints, $GroupID, $UploaderID) = $DB->next_record();
28
 
27
 
29
 if (!$UploaderID) {
28
 if (!$UploaderID) {
30
   // If the torrent was deleted and we don't know who the uploader was, just assume it was the filler
29
   // If the torrent was deleted and we don't know who the uploader was, just assume it was the filler
58
 
57
 
59
 //Remove Filler portion of bounty
58
 //Remove Filler portion of bounty
60
 if (intval($RequestVotes['TotalBounty']*(1/4)) > $Uploaded) {
59
 if (intval($RequestVotes['TotalBounty']*(1/4)) > $Uploaded) {
61
-  // If we can't take it all out of upload, zero that out and add whatever is left as download.
60
+  // If we can't take it all out of upload, attempt to take the rest out of bonus points
62
   $DB->query("
61
   $DB->query("
63
     UPDATE users_main
62
     UPDATE users_main
64
     SET Uploaded = 0
63
     SET Uploaded = 0
65
     WHERE ID = $FillerID");
64
     WHERE ID = $FillerID");
66
-  $DB->query('
67
-    UPDATE users_main
68
-    SET Downloaded = Downloaded + '.intval($RequestVotes['TotalBounty']*(1/4) - $Uploaded)."
69
-    WHERE ID = $FillerID");
65
+  if (intval($RequestVotes['TotalBounty']*(1/4)-$Uploaded) > $BonusPoints) {
66
+    // If we can't take the rest as bonus points, turn the remaining bit to download
67
+    $DB->query("
68
+      UPDATE users_main
69
+      SET BonusPoints = 0
70
+      WHERE ID = $FillerID");
71
+    $DB->query('
72
+      UPDATE users_main
73
+      SET Downloaded = Downloaded + '.intval($RequestVotes['TotalBounty']*(1/4) - $Uploaded - $BonusPoints*1000)."
74
+      WHERE ID = $FillerID");
75
+  } else {
76
+    $DB->query('
77
+      UPDATE users_main
78
+      SET BonusPoints = BonusPoints - '.intval(($RequestVotes['TotalBounty']*(1/4) - $Uploaded)/1000)."
79
+      WHERE ID = $FillerID");
80
+  }
70
 } else {
81
 } else {
71
   $DB->query('
82
   $DB->query('
72
     UPDATE users_main
83
     UPDATE users_main
73
     SET Uploaded = Uploaded - '.intval($RequestVotes['TotalBounty']*(1/4))."
84
     SET Uploaded = Uploaded - '.intval($RequestVotes['TotalBounty']*(1/4))."
74
     WHERE ID = $FillerID");
85
     WHERE ID = $FillerID");
75
 }
86
 }
87
+
88
+$DB->query("
89
+  SELECT
90
+    Uploaded,
91
+    BonusPoints
92
+  FROM users_main
93
+  WHERE ID = $UploaderID");
94
+list($UploaderUploaded, $UploaderBonusPoints) = $DB->next_record();
95
+
76
 //Remove Uploader portion of bounty
96
 //Remove Uploader portion of bounty
77
 if (intval($RequestVotes['TotalBounty']*(3/4)) > $UploaderUploaded) {
97
 if (intval($RequestVotes['TotalBounty']*(3/4)) > $UploaderUploaded) {
78
-  // If we can't take it all out of upload, zero that out and add whatever is left as download.
98
+  // If we can't take it all out of upload, attempt to take the rest out of bonus points
79
   $DB->query("
99
   $DB->query("
80
     UPDATE users_main
100
     UPDATE users_main
81
     SET Uploaded = 0
101
     SET Uploaded = 0
82
     WHERE ID = $UploaderID");
102
     WHERE ID = $UploaderID");
83
-  $DB->query('
84
-    UPDATE users_main
85
-    SET Downloaded = Downloaded + '.intval($RequestVotes['TotalBounty']*(3/4) - $UploaderUploaded)."
86
-    WHERE ID = $UploaderID");
103
+  if (intval($RequestVotes['TotalBounty']*(3/4) - $UploaderUploaded) > $UploaderBonusPoints) {
104
+    // If we can't take the rest as bonus points, turn the remaining bit to download
105
+    $DB->query("
106
+      UPDATE users_main
107
+      SET BonusPoints = 0
108
+      WHERE ID = $UploaderID");
109
+    $DB->query('
110
+      UPDATE users_main
111
+      SET Downloaded = Downloaded + '.intval($RequestVotes['TotalBounty']*(3/4) - $UploaderUploaded - $UploaderBonusPoints*1000)."
112
+      WHERE ID = $UploaderID");
113
+  } else {
114
+    $DB->query('
115
+      UPDATE users_main
116
+      SET BonusPoints = BonusPoints - '.intval(($RequestVotes['TotalBounty']*(3/4) - $UploaderUploaded)/1000)."
117
+      WHERE ID = $UploaderID");
118
+  }
87
 } else {
119
 } else {
88
   $DB->query('
120
   $DB->query('
89
     UPDATE users_main
121
     UPDATE users_main

Loading…
Cancel
Save