replace id() method with id property in BaseUser derived classes

This commit is contained in:
Spine
2025-04-11 02:59:56 +00:00
parent 82376f08df
commit 13e41b2a9b
29 changed files with 257 additions and 260 deletions

View File

@@ -136,7 +136,7 @@ abstract class BaseObject extends Base {
$set[] = "$field = now()";
}
}
$args[] = $this->id();
$args[] = $this->id;
self::$db->prepared_query(
"UPDATE /* BaseObject */ " . static::tableName . " SET " . implode(', ', $set) . " WHERE " . static::pkName . " = ?",
...$args

View File

@@ -5,13 +5,8 @@ namespace Gazelle;
abstract class BaseUser extends BaseObject {
public function __construct(
protected User $user,
) {}
/**
* The id() of a BaseUser is the id() of the underlying BaseObject
*/
public function id(): int {
return $this->user->id;
) {
parent::__construct($user->id);
}
/**

View File

@@ -52,12 +52,12 @@ class UserToken extends \Gazelle\BaseManager {
* Normally you should never need this, all tokens are found by their token instance
*/
public function findById(int $id): ?\Gazelle\User\Token {
$info = $this->pg()->rowAssoc("
[$token, $userId] = $this->pg()->row("
select id_user_token, id_user from user_token where id_user_token = ?
", $id
);
return $info
? new \Gazelle\User\Token($info['id_user_token'], new \Gazelle\User($info['id_user']))
return isset($token)
? new \Gazelle\User\Token($token, new \Gazelle\User($userId))
: null;
}

View File

@@ -16,7 +16,7 @@ class AuditTrail extends \Gazelle\BaseUser {
(id_user, event, note, id_user_creator)
values (?, ?, ?, ?)
returning id_user_audit_trail
", $this->id(), $event->value, $note, $creator?->id()
", $this->user->id, $event->value, $note, $creator?->id
);
}
@@ -44,7 +44,7 @@ class AuditTrail extends \Gazelle\BaseUser {
(id_user, event, note, created, id_user_creator)
values (?, ?, ?, ?, ?)
returning id_user_audit_trail
", $this->id(), $event->value, $note, $date, (int)$creator?->id()
", $this->user->id, $event->value, $note, $date, (int)$creator?->id
);
}
@@ -54,7 +54,7 @@ class AuditTrail extends \Gazelle\BaseUser {
from user_audit_trail
where id_user = ?
and event = ?
", $this->id(), $event->value
", $this->user->id, $event->value
);
}
@@ -69,7 +69,7 @@ class AuditTrail extends \Gazelle\BaseUser {
where id_user = ?
and id_user_audit_trail in (" . placeholders($idList) . ")
order by {$order->value}
", $this->id(), ...$idList
", $this->user->id, ...$idList
);
}
@@ -83,7 +83,7 @@ class AuditTrail extends \Gazelle\BaseUser {
from user_audit_trail
where id_user = ?
order by {$order->value}
", $this->id()
", $this->user->id
);
}
@@ -97,7 +97,7 @@ class AuditTrail extends \Gazelle\BaseUser {
where id_user = ?
order by id_user_audit_trail desc
limit 1
", $this->id()
", $this->user->id
);
}
@@ -141,14 +141,14 @@ class AuditTrail extends \Gazelle\BaseUser {
delete from user_audit_trail
where id_user_audit_trail = ?
and id_user = ?
", $eventId, $this->id()
", $eventId, $this->user->id
);
}
public function resetAuditTrail(): int {
return $this->pg()->prepared_query("
delete from user_audit_trail where id_user = ?
", $this->id()
", $this->user->id
);
}

View File

@@ -174,7 +174,7 @@ class AutoEnable extends \Gazelle\BaseUser {
CheckedBy = ?,
Outcome = ?
WHERE ID = ?
", $viewer->id(), $status, $this->id
", $viewer->id, $status, $this->id
);
self::$cache->delete_value(self::CACHE_TOTAL_OPEN);
return self::$db->affected_rows();

View File

@@ -23,8 +23,8 @@ class Bonus extends \Gazelle\BaseUser {
public function flush(): static {
$this->user->flush();
self::$cache->delete_multi([
sprintf(self::CACHE_HISTORY, $this->id(), 0),
sprintf(self::CACHE_POOL_HISTORY, $this->id()),
sprintf(self::CACHE_HISTORY, $this->user->id, 0),
sprintf(self::CACHE_POOL_HISTORY, $this->user->id),
]);
return $this;
}
@@ -32,7 +32,7 @@ class Bonus extends \Gazelle\BaseUser {
public function pointsSpent(): int {
return (int)self::$db->scalar("
SELECT sum(Price) FROM bonus_history WHERE UserID = ?
", $this->id()
", $this->user->id
);
}
@@ -112,12 +112,12 @@ class Bonus extends \Gazelle\BaseUser {
AND bh.OtherUserID = ?
ORDER BY bh.PurchaseDate DESC
LIMIT 1
", $this->id(), $other->id()
", $this->user->id, $other->id
) ?? [];
}
public function summary(): array {
$key = sprintf(self::CACHE_SUMMARY, $this->id());
$key = sprintf(self::CACHE_SUMMARY, $this->user->id);
$summary = self::$cache->get_value($key);
if ($summary === false) {
$summary = self::$db->rowAssoc('
@@ -125,7 +125,7 @@ class Bonus extends \Gazelle\BaseUser {
coalesce(sum(price), 0) AS total
FROM bonus_history
WHERE UserID = ?
', $this->id()
', $this->user->id
);
self::$cache->cache_value($key, $summary, 86400 * 7);
}
@@ -134,7 +134,7 @@ class Bonus extends \Gazelle\BaseUser {
public function history(int $limit, int $offset): array {
$page = $offset / $limit;
$key = sprintf(self::CACHE_HISTORY, $this->id(), $page);
$key = sprintf(self::CACHE_HISTORY, $this->user->id, $page);
$history = self::$cache->get_value($key);
if ($history === false) {
self::$db->prepared_query('
@@ -144,12 +144,12 @@ class Bonus extends \Gazelle\BaseUser {
WHERE h.UserID = ?
ORDER BY PurchaseDate DESC
LIMIT ? OFFSET ?
', $this->id(), $limit, $offset
', $this->user->id, $limit, $offset
);
$history = self::$db->to_array();
self::$cache->cache_value($key, $history, 86400 * 3);
/* since we had to fetch this page, invalidate the next one */
self::$cache->delete_value(sprintf(self::CACHE_HISTORY, $this->id(), $page + 1));
self::$cache->delete_value(sprintf(self::CACHE_HISTORY, $this->user->id, $page + 1));
}
return $history;
}
@@ -175,7 +175,7 @@ class Bonus extends \Gazelle\BaseUser {
}
public function poolHistory(): array {
$key = sprintf(self::CACHE_POOL_HISTORY, $this->id());
$key = sprintf(self::CACHE_POOL_HISTORY, $this->user->id);
$history = self::$cache->get_value($key);
if ($history === false) {
self::$db->prepared_query('
@@ -185,7 +185,7 @@ class Bonus extends \Gazelle\BaseUser {
WHERE c.user_id = ?
GROUP BY p.until_date, p.name
ORDER BY p.until_date, p.name
', $this->id()
', $this->user->id
);
$history = self::$db->to_array();
self::$cache->cache_value($key, $history, 86400 * 3);
@@ -199,7 +199,7 @@ class Bonus extends \Gazelle\BaseUser {
* @return array of [title, total]
*/
public function purchaseHistory(): array {
$key = sprintf(self::CACHE_PURCHASE, $this->id());
$key = sprintf(self::CACHE_PURCHASE, $this->user->id);
$history = self::$cache->get_value($key);
if ($history === false) {
self::$db->prepared_query("
@@ -212,7 +212,7 @@ class Bonus extends \Gazelle\BaseUser {
WHERE bh.UserID = ?
GROUP BY bi.Title
ORDER BY bi.sequence
", $this->id()
", $this->user->id
);
$history = self::$db->to_array('id', MYSQLI_ASSOC, false);
self::$cache->cache_value($key, $history, 86400 * 3);
@@ -233,7 +233,7 @@ class Bonus extends \Gazelle\BaseUser {
um.Invites = um.Invites + 1
WHERE ub.points >= ?
AND ub.user_id = ?
', $price, $price, $this->id()
', $price, $price, $this->user->id
);
if (self::$db->affected_rows() != 2) {
return false;
@@ -275,7 +275,7 @@ class Bonus extends \Gazelle\BaseUser {
um.collage_total = um.collage_total + 1
WHERE ub.points >= ?
AND ub.user_id = ?
', $price, $price, $this->id()
', $price, $price, $this->user->id
);
$rows = self::$db->affected_rows();
if (($price > 0 && $rows !== 2) || ($price === 0 && $rows !== 1)) {
@@ -286,7 +286,7 @@ class Bonus extends \Gazelle\BaseUser {
'personal-collage',
(int)self::$db->scalar("
SELECT collage_total FROM users_main WHERE ID = ?
", $this->id()
", $this->user->id
)
);
$this->addPurchaseHistory($item['ID'], $price);
@@ -303,7 +303,7 @@ class Bonus extends \Gazelle\BaseUser {
ub.points = ub.points - ?
WHERE ub.points >= ?
AND ub.user_id = ?
', $price, $price, $this->id()
', $price, $price, $this->user->id
);
if (self::$db->affected_rows() != 1) {
self::$db->rollback();
@@ -314,7 +314,7 @@ class Bonus extends \Gazelle\BaseUser {
INSERT INTO user_has_attr
(UserID, UserAttrID)
VALUES (?, (SELECT ID FROM user_attr WHERE Name = ?))
", $this->id(), 'feature-seedbox'
", $this->user->id, 'feature-seedbox'
);
} catch (\Gazelle\DB\MysqlDuplicateKeyException) {
// no point in buying a second time
@@ -336,7 +336,7 @@ class Bonus extends \Gazelle\BaseUser {
ub.points = ub.points - ?
WHERE ub.points >= ?
AND ub.user_id = ?
', $price, $price, $this->id()
', $price, $price, $this->user->id
);
if (self::$db->affected_rows() != 1) {
self::$db->rollback();
@@ -347,7 +347,7 @@ class Bonus extends \Gazelle\BaseUser {
INSERT INTO user_has_attr
(UserID, UserAttrID)
VALUES (?, (SELECT ID FROM user_attr WHERE Name = ?))
", $this->id(), 'feature-file-count'
", $this->user->id, 'feature-file-count'
);
} catch (\Gazelle\DB\MysqlDuplicateKeyException) {
// no point in buying a second time
@@ -374,7 +374,7 @@ class Bonus extends \Gazelle\BaseUser {
uf.tokens = uf.tokens + ?
WHERE ub.user_id = ?
AND ub.points >= ?
', $price, $amount, $this->id(), $price
', $price, $amount, $this->user->id, $price
);
if (self::$db->affected_rows() != 2) {
return false;
@@ -389,7 +389,7 @@ class Bonus extends \Gazelle\BaseUser {
* tokens purchased (for use in a response to the receiver).
*/
public function purchaseTokenOther(\Gazelle\User $receiver, string $label, string $message): int {
if ($this->id() === $receiver->id()) {
if ($this->user->id === $receiver->id) {
return 0;
}
$item = $this->items()[$label];
@@ -419,12 +419,12 @@ class Bonus extends \Gazelle\BaseUser {
AND other.ID = ?
AND self.ID = ?
AND ub.points >= ?
", $price, $amount, $receiver->id(), $this->id(), $price
", $price, $amount, $receiver->id, $this->user->id, $price
);
if (self::$db->affected_rows() != 2) {
return 0;
}
$this->addPurchaseHistory($item['ID'], $price, $receiver->id());
$this->addPurchaseHistory($item['ID'], $price, $receiver->id);
$this->sendPmToOther($receiver, $amount, $message);
$this->flush();
$receiver->flush();
@@ -447,15 +447,15 @@ class Bonus extends \Gazelle\BaseUser {
private function addPurchaseHistory(int $itemId, int $price, int|null $otherUserId = null): int {
self::$cache->delete_multi([
sprintf(self::CACHE_PURCHASE, $this->id()),
sprintf(self::CACHE_SUMMARY, $this->id()),
sprintf(self::CACHE_HISTORY, $this->id(), 0)
sprintf(self::CACHE_PURCHASE, $this->user->id),
sprintf(self::CACHE_SUMMARY, $this->user->id),
sprintf(self::CACHE_HISTORY, $this->user->id, 0)
]);
self::$db->prepared_query("
INSERT INTO bonus_history
(ItemID, UserID, Price, OtherUserID)
VALUES (?, ?, ?, ?)
", $itemId, $this->id(), $price, $otherUserId
", $itemId, $this->user->id, $price, $otherUserId
);
return self::$db->affected_rows();
}
@@ -465,7 +465,7 @@ class Bonus extends \Gazelle\BaseUser {
UPDATE user_bonus SET
points = ?
WHERE user_id = ?
", $points, $this->id()
", $points, $this->user->id
);
$affected = self::$db->affected_rows();
$this->flush();
@@ -477,7 +477,7 @@ class Bonus extends \Gazelle\BaseUser {
UPDATE user_bonus SET
points = points + ?
WHERE user_id = ?
", $points, $this->id()
", $points, $this->user->id
);
$affected = self::$db->affected_rows();
$this->flush();
@@ -493,13 +493,13 @@ class Bonus extends \Gazelle\BaseUser {
// allow points to go negative
self::$db->prepared_query('
UPDATE user_bonus SET points = points - ? WHERE user_id = ?
', $points, $this->id()
', $points, $this->user->id
);
} else {
// Fail if points would go negative
self::$db->prepared_query('
UPDATE user_bonus SET points = points - ? WHERE points >= ? AND user_id = ?
', $points, $points, $this->id()
', $points, $points, $this->user->id
);
if (self::$db->affected_rows() != 1) {
return false;
@@ -521,7 +521,7 @@ class Bonus extends \Gazelle\BaseUser {
INNER JOIN torrents AS t ON (t.ID = xfu.fid)
INNER JOIN torrents_leech_stats tls ON (tls.TorrentID = t.ID)
WHERE xfu.uid = ?
", $this->id(), $this->id()
", $this->user->id, $this->user->id
);
}
@@ -551,7 +551,7 @@ class Bonus extends \Gazelle\BaseUser {
INNER JOIN torrents AS t ON (t.ID = xfu.fid)
INNER JOIN torrents_leech_stats tls ON (tls.TorrentID = t.ID)
WHERE xfu.uid = ?
", $this->id(), $this->id()
", $this->user->id, $this->user->id
);
$stats['total_size'] = (int)$stats['total_size'];
return $stats;
@@ -582,7 +582,7 @@ class Bonus extends \Gazelle\BaseUser {
ORDER BY $orderBy $orderWay
LIMIT ?
OFFSET ?
", $this->id(), $this->id(), $limit, $offset
", $this->user->id, $this->user->id, $limit, $offset
);
$list = [];
foreach (self::$db->to_array('ID', MYSQLI_ASSOC, false) as $r) {

View File

@@ -14,7 +14,7 @@ class Donor extends \Gazelle\BaseUser {
}
public function flush(): static {
self::$cache->delete_value(sprintf(self::CACHE_KEY, $this->id()));
self::$cache->delete_value(sprintf(self::CACHE_KEY, $this->user->id));
unset($this->isDonor);
$this->info = [];
return $this;
@@ -24,7 +24,7 @@ class Donor extends \Gazelle\BaseUser {
if (isset($this->info) && !empty($this->info)) {
return $this->info;
}
$key = sprintf(self::CACHE_KEY, $this->id());
$key = sprintf(self::CACHE_KEY, $this->user->id);
$info = self::$cache->get_value($key);
if ($info === false) {
$info = self::$db->rowAssoc("
@@ -56,7 +56,7 @@ class Donor extends \Gazelle\BaseUser {
LEFT JOIN donor_rewards dr USING (UserID)
LEFT JOIN donor_forum_usernames dfu USING (UserID)
WHERE udr.UserID = ?
", $this->id()
", $this->user->id
) ?? [
'donor_rank' => 0,
'special_rank' => 0,
@@ -107,7 +107,7 @@ class Donor extends \Gazelle\BaseUser {
UPDATE users_donor_ranks SET
Hidden = ?
WHERE UserID = ?
", $visible ? 0 : 1, $this->id()
", $visible ? 0 : 1, $this->user->id
);
return $this->flush()->isVisible();
}
@@ -137,7 +137,7 @@ class Donor extends \Gazelle\BaseUser {
FROM users_donor_ranks
) LEADER
WHERE LEADER.UserID = ?
", $this->id()
", $this->user->id
);
}
@@ -429,7 +429,7 @@ class Donor extends \Gazelle\BaseUser {
FROM donations
WHERE UserID = ?
ORDER BY Time DESC
", $this->id()
", $this->user->id
);
return self::$db->to_array(false, MYSQLI_ASSOC, false);
}
@@ -441,13 +441,13 @@ class Donor extends \Gazelle\BaseUser {
donor_rank = donor_rank + ?,
TotalRank = TotalRank + ?
WHERE UserID = ?
", $rankDelta, $totalDelta, $this->id()
", $rankDelta, $totalDelta, $this->user->id
);
self::$db->prepared_query("
INSERT INTO donations
(UserID, donor_rank, TotalRank, Reason, AddedBy, Amount, xbt, Currency, Source)
VALUES (?, ?, ?, ?, ?, 0, 0, '', 'moderation')
", $this->id(), $rankDelta, $totalDelta, trim($reason), $adjuster->id()
", $this->user->id, $rankDelta, $totalDelta, trim($reason), $adjuster->id
);
$affected = self::$db->affected_rows();
self::$db->commit();
@@ -496,17 +496,17 @@ class Donor extends \Gazelle\BaseUser {
TotalRank = TotalRank + ?,
DonationTime = now(),
RankExpirationTime = now()
', $this->id(),
', $this->user->id,
$rankDelta, $rankDelta, $rankDelta, $rankDelta
);
if (!(bool)self::$db->scalar("SELECT 1 FROM donor_rewards WHERE UserID = ?", $this->id())) {
if (!(bool)self::$db->scalar("SELECT 1 FROM donor_rewards WHERE UserID = ?", $this->user->id)) {
self::$db->prepared_query("
INSERT INTO donor_rewards (
UserID, IconMouseOverText, AvatarMouseOverText, CustomIcon, CustomIconLink, SecondAvatar,
ProfileInfo1, ProfileInfo2, ProfileInfo3, ProfileInfo4,
ProfileInfoTitle1, ProfileInfoTitle2, ProfileInfoTitle3, ProfileInfoTitle4
) VALUES (?, '', '', '', '', '', '', '', '', '', '', '', '', '')
", $this->id()
", $this->user->id
);
}
$this->flush(); // so that rank() etc are updated
@@ -542,7 +542,7 @@ class Donor extends \Gazelle\BaseUser {
$columns = implode(', ', $cond);
self::$db->prepared_query("
UPDATE users_donor_ranks SET $columns WHERE UserID = ?
", ...[...$args, $this->id()]
", ...[...$args, $this->user->id]
);
}
if ($newInvites) {
@@ -550,7 +550,7 @@ class Donor extends \Gazelle\BaseUser {
UPDATE users_main
SET Invites = Invites + ?
WHERE ID = ?
', $newInvites, $this->id()
', $newInvites, $this->user->id
);
}
@@ -560,8 +560,8 @@ class Donor extends \Gazelle\BaseUser {
INSERT INTO donations
(UserID, Amount, Source, Reason, Currency, AddedBy, donor_rank, TotalRank, xbt)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
', $this->id(), round($fiatAmount, 2), trim($source), trim($reason), $currency,
$who?->id() ?? $this->id(), $this->rank(), $this->totalRank(), $xbtAmount
', $this->user->id, round($fiatAmount, 2), trim($source), trim($reason), $currency,
$who->id ?? $this->user->id, $this->rank(), $this->totalRank(), $xbtAmount
);
$affected = self::$db->affected_rows();
self::$db->commit();
@@ -637,7 +637,7 @@ class Donor extends \Gazelle\BaseUser {
UPDATE users_donor_ranks SET
SpecialRank = ?
WHERE UserID = ?
", $rank, $this->id()
", $rank, $this->user->id
);
return $this->flush()->specialRank();
}
@@ -654,7 +654,7 @@ class Donor extends \Gazelle\BaseUser {
Prefix = ?,
Suffix = ?,
UseComma = ?
", $this->id(), $prefix, $suffix, (int)$useComma, $prefix, $suffix, (int)$useComma
", $this->user->id, $prefix, $suffix, (int)$useComma, $prefix, $suffix, (int)$useComma
);
$this->flush();
return true;
@@ -678,7 +678,7 @@ class Donor extends \Gazelle\BaseUser {
SpecialRank = 0,
TotalRank = 0
WHERE UserID = ?
', $this->id()
', $this->user->id
);
self::$db->commit();
$this->flush();
@@ -701,7 +701,7 @@ class Donor extends \Gazelle\BaseUser {
LEFT JOIN donor_forum_usernames dfu USING (UserID)
LEFT JOIN users_donor_ranks udr USING (UserID)
WHERE d.UserID = ?
", $this->id()
", $this->user->id
);
$affected = self::$db->affected_rows();
$this->flush();

View File

@@ -16,7 +16,7 @@ class Friend extends \Gazelle\BaseUser {
FROM friends
WHERE UserID = ?
AND FriendID = ?
", $this->user->id, $friend->id()
", $this->user->id, $friend->id
);
}
@@ -27,7 +27,7 @@ class Friend extends \Gazelle\BaseUser {
INNER JOIN friends b ON (b.UserID = a.FriendID AND b.FriendID = ?)
WHERE a.UserID = ?
AND a.FriendID = ?
", $this->user->id, $this->user->id, $friend->id()
", $this->user->id, $this->user->id, $friend->id
);
}

View File

@@ -30,7 +30,7 @@ class History extends \Gazelle\BaseUser {
FROM users_history_emails AS h
WHERE h.UserID = ?
ORDER BY h.created DESC
", $this->id()
", $this->user->id
);
$asnList = $asn->findByIpList(self::$db->collect('ipv4', false));
$list = self::$db->to_array(false, MYSQLI_ASSOC, false);
@@ -61,7 +61,7 @@ class History extends \Gazelle\BaseUser {
WHERE uhe.UserID != ?
AND uhe.Email in (SELECT DISTINCT Email FROM users_history_emails WHERE UserID = ?)
ORDER BY uhe.Email, uhe.created DESC
", $this->id(), $this->id()
", $this->user->id, $this->user->id
);
$asnList = $asn->findByIpList(self::$db->collect('ipv4', false));
$list = self::$db->to_array(false, MYSQLI_ASSOC, false);
@@ -80,7 +80,7 @@ class History extends \Gazelle\BaseUser {
public function emailTotal(): int {
return (int)self::$db->scalar("
SELECT count(*) FROM users_history_emails WHERE UserID = ?
", $this->id()
", $this->user->id
);
}
@@ -102,7 +102,7 @@ class History extends \Gazelle\BaseUser {
INSERT INTO users_history_emails
(UserID, Email, IP, useragent)
VALUES (?, ?, ?, ?)
", $this->id(), $newEmail, $ipaddr, $useragent
", $this->user->id, $newEmail, $ipaddr, $useragent
);
$affected = self::$db->affected_rows();
if ($notify) {
@@ -133,19 +133,19 @@ class History extends \Gazelle\BaseUser {
self::$db->prepared_query("
DELETE FROM users_history_emails
WHERE UserID = ?
", $this->id()
", $this->user->id
);
self::$db->prepared_query("
INSERT INTO users_history_emails
(UserID, Email, IP, useragent)
VALUES (?, ?, ?, 'email-reset')
", $this->id(), $email, $ipaddr
", $this->user->id, $email, $ipaddr
);
self::$db->prepared_query("
UPDATE users_main SET
Email = ?
WHERE ID = ?
", $email, $this->id()
", $email, $this->user->id
);
$affected = self::$db->affected_rows();
$this->flush();
@@ -186,7 +186,7 @@ class History extends \Gazelle\BaseUser {
total = EXCLUDED.total,
seen = s.seen + EXCLUDED.seen
returning total
", $this->id(), $ipaddr, $this->id(), $ipaddr, $this->id(), $ipaddr, $delay
", $this->user->id, $ipaddr, $this->user->id, $ipaddr, $this->user->id, $ipaddr, $delay
);
}
@@ -204,7 +204,7 @@ class History extends \Gazelle\BaseUser {
from ip_site_history
where id_user = ?
order by $orderBy
", $this->id()
", $this->user->id
);
$asnList = $asn->findByIpList(array_unique(array_map(fn ($r) => $r['ipv4'], $result)));
foreach ($result as &$row) {
@@ -230,7 +230,7 @@ class History extends \Gazelle\BaseUser {
WHERE uid = ?
GROUP BY IP
ORDER BY $orderBy
", $this->id()
", $this->user->id
);
$asnList = $asn->findByIpList(self::$db->collect('ipv4', false));
$list = self::$db->to_array(false, MYSQLI_ASSOC, false);
@@ -246,40 +246,40 @@ class History extends \Gazelle\BaseUser {
public function resetIp(): int {
$n = $this->pg()->prepared_query("
delete from ip_history where id_user = ?
", $this->id()
", $this->user->id
);
$n += $this->pg()->prepared_query("
delete from ip_site_history where id_user = ?
", $this->id()
", $this->user->id
);
self::$db->prepared_query("
DELETE FROM users_history_ips WHERE UserID = ?
", $this->id()
", $this->user->id
);
$n += self::$db->affected_rows();
self::$db->prepared_query("
UPDATE users_main SET IP = '127.0.0.1' WHERE ID = ?
", $this->id()
", $this->user->id
);
$n += self::$db->affected_rows();
self::$db->prepared_query("
UPDATE xbt_snatched SET IP = '' WHERE uid = ?
", $this->id()
", $this->user->id
);
$n += self::$db->affected_rows();
self::$db->prepared_query("
UPDATE users_history_passwords SET ChangerIP = '', useragent = 'reset-ip-history' WHERE UserID = ?
", $this->id()
", $this->user->id
);
$n += self::$db->affected_rows();
self::$db->prepared_query("
UPDATE users_history_passkeys SET ChangerIP = '' WHERE UserID = ?
", $this->id()
", $this->user->id
);
$n += self::$db->affected_rows();
self::$db->prepared_query("
UPDATE users_sessions SET IP = '127.0.0.1' WHERE UserID = ?
", $this->id()
", $this->user->id
);
$n += self::$db->affected_rows();
$this->flush();
@@ -290,7 +290,7 @@ class History extends \Gazelle\BaseUser {
self::$db->prepared_query('
DELETE FROM users_downloads
WHERE UserID = ?
', $this->id()
', $this->user->id
);
return self::$db->affected_rows();
}
@@ -302,7 +302,7 @@ class History extends \Gazelle\BaseUser {
RatioWatchDownload = 0,
RatioWatchTimes = 0
WHERE UserID = ?
", $this->id()
", $this->user->id
);
$this->flush();
return self::$db->affected_rows();
@@ -312,7 +312,7 @@ class History extends \Gazelle\BaseUser {
self::$db->prepared_query("
DELETE FROM xbt_snatched
WHERE uid = ?
", $this->id()
", $this->user->id
);
$this->user->snatch()->flush();
return self::$db->affected_rows();

View File

@@ -16,7 +16,7 @@ class Inbox extends \Gazelle\BaseUser {
protected string $searchTerm;
public function flush(): static {
self::$cache->delete_value(sprintf(self::CACHE_NEW, $this->id()));
self::$cache->delete_value(sprintf(self::CACHE_NEW, $this->user->id));
$this->user->flush();
return $this;
}
@@ -30,8 +30,8 @@ class Inbox extends \Gazelle\BaseUser {
* create() a PM
*/
public function create(?\Gazelle\User $from, string $subject, string $body): ?\Gazelle\PM {
$fromId = $from?->id() ?? 0;
if ($this->id() === $fromId) {
$fromId = (int)$from?->id;
if ($this->user->id === $fromId) {
// Don't allow users to send messages to the system or themselves
return null;
}
@@ -48,7 +48,7 @@ class Inbox extends \Gazelle\BaseUser {
"(?, ?, '1', '0', '1')",
"(?, ?, '0', '1', '0')",
];
$args = [$this->id(), $convId, $fromId, $convId];
$args = [$this->user->id, $convId, $fromId, $convId];
self::$db->prepared_query("
INSERT INTO pm_conversations_users
@@ -68,14 +68,14 @@ class Inbox extends \Gazelle\BaseUser {
$senderName = $from?->username() ?? 'System';
$notifMan = new \Gazelle\Manager\Notification();
$pushTokens = $notifMan->pushableTokensById([$this->id()], NotificationType::INBOX);
$pushTokens = $notifMan->pushableTokensById([$this->user->id], NotificationType::INBOX);
$notifMan->push($pushTokens,
"Message from $senderName", "Subject: $subject", SITE_URL . '/inbox.php');
$this->flush();
self::$cache->delete_multi([
sprintf(\Gazelle\PM::CACHE_KEY, $convId, $fromId),
sprintf(\Gazelle\PM::CACHE_KEY, $convId, $this->id()),
sprintf(\Gazelle\PM::CACHE_KEY, $convId, $this->user->id),
]);
return new \Gazelle\PM($convId, $this->user);
@@ -185,7 +185,7 @@ class Inbox extends \Gazelle\BaseUser {
}
public function unreadTotal(): int {
$key = sprintf(self::CACHE_NEW, $this->id());
$key = sprintf(self::CACHE_NEW, $this->user->id);
$unread = self::$cache->get_value($key);
if ($unread === false) {
$unread = (int)self::$db->scalar("
@@ -194,7 +194,7 @@ class Inbox extends \Gazelle\BaseUser {
WHERE UnRead = '1'
AND InInbox = '1'
AND UserID = ?
", $this->id()
", $this->user->id
);
self::$cache->cache_value($key, $unread, 0);
}

View File

@@ -20,7 +20,7 @@ class Invite extends \Gazelle\BaseUser {
UPDATE users_main SET
Invites = GREATEST(Invites, 1) - 1
WHERE ID = ?
", $this->id()
", $this->user->id
);
$affected = self::$db->affected_rows();
$this->flush();
@@ -30,7 +30,7 @@ class Invite extends \Gazelle\BaseUser {
public function pendingTotal(): int {
return (int)self::$db->scalar("
SELECT count(*) FROM invites WHERE InviterID = ?
", $this->id()
", $this->user->id
);
}
@@ -45,7 +45,7 @@ class Invite extends \Gazelle\BaseUser {
LEFT JOIN invite_source ivs USING (invite_source_id)
WHERE i.InviterID = ?
ORDER BY i.Expires
", $this->id()
", $this->user->id
);
return self::$db->to_array('invite_key', MYSQLI_ASSOC, false);
}
@@ -53,7 +53,7 @@ class Invite extends \Gazelle\BaseUser {
public function total(): int {
return (int)self::$db->scalar("
SELECT count(*) FROM users_main WHERE inviter_user_id = ?
", $this->id()
", $this->user->id
);
}
@@ -66,7 +66,7 @@ class Invite extends \Gazelle\BaseUser {
WHERE um.inviter_user_id = ?
ORDER BY $orderBy $direction
LIMIT ? OFFSET ?
", $this->id(), $limit, $offset
", $this->user->id, $limit, $offset
);
return self::$db->collect(0, false);
}
@@ -98,7 +98,7 @@ class Invite extends \Gazelle\BaseUser {
UPDATE users_main SET
Invites = Invites + 1
WHERE ID = ?
", $this->id()
", $this->user->id
);
$affected += self::$db->affected_rows();
self::$db->commit();

View File

@@ -88,7 +88,7 @@ class InviteTree extends \Gazelle\BaseUser {
)
WHERE r.user_id != ?
ORDER BY path
", $width, $this->id(), $width, $this->id()
", $width, $this->user->id, $width, $this->user->id
);
$userclassMap = []; // how many people per userclass
$userlevelMap = []; // sort userclasses by level rather than name

View File

@@ -44,7 +44,7 @@ class Notification extends \Gazelle\BaseUser {
inner join user_has_attr uha using (id_user_attr)
inner join user_attr_notification uhan using (id_user_attr)
where uha.id_user = ?;
", $this->id()
", $this->user->id
);
$typeConfig = [];

View File

@@ -22,10 +22,10 @@ class Blog extends AbstractNotification {
// You must be new around here.
$newJoiner = is_null($lastRead) && $latest->createdEpoch() > strtotime($this->user->created());
if ($newJoiner || $latest->id() > $lastRead) {
if ($newJoiner || $latest->id > $lastRead) {
$this->title = "Blog: " . $latest->title();
$this->url = $latest->url();
$this->context = $latest->id();
$this->context = $latest->id;
return true;
}
return false;

View File

@@ -12,10 +12,10 @@ class Collage extends AbstractNotification {
UPDATE users_collage_subs SET
LastVisit = now()
WHERE UserID = ?
", $this->id()
", $this->user->id
);
$affected = self::$db->affected_rows();
self::$cache->delete_value(sprintf(\Gazelle\Collage::SUBS_NEW_KEY, $this->id()));
self::$cache->delete_value(sprintf(\Gazelle\Collage::SUBS_NEW_KEY, $this->user->id));
return $affected;
}
@@ -36,10 +36,10 @@ class Collage extends AbstractNotification {
UPDATE users_collage_subs SET
LastVisit = now()
WHERE UserID = ? AND CollageID = ?
", $this->id(), $collage->id()
", $this->user->id, $collage->id
);
$affected = self::$db->affected_rows();
self::$cache->delete_value(sprintf(\Gazelle\Collage::SUBS_NEW_KEY, $this->id()));
self::$cache->delete_value(sprintf(\Gazelle\Collage::SUBS_NEW_KEY, $this->user->id));
return $affected;
}
}

View File

@@ -18,14 +18,14 @@ class Ordinal extends \Gazelle\BaseUser {
protected array $info;
public function flush(): static {
self::$cache->delete_value(sprintf(self::CACHE_KEY, $this->id()));
self::$cache->delete_value(sprintf(self::CACHE_KEY, $this->user->id));
unset($this->info);
return $this;
}
public function info(): array {
if (!isset($this->info)) {
$key = sprintf(self::CACHE_KEY, $this->id());
$key = sprintf(self::CACHE_KEY, $this->user->id);
$info = self::$cache->get_value($key);
if ($info === false) {
self::$db->prepared_query("
@@ -45,7 +45,7 @@ class Ordinal extends \Gazelle\BaseUser {
FROM user_ordinal uo
LEFT JOIN user_has_ordinal uho USING (user_ordinal_id)
WHERE uho.user_id = ?
", $this->id(), $this->id()
", $this->user->id, $this->user->id
);
$info = self::$db->to_array('name', MYSQLI_ASSOC, false);
self::$cache->cache_value($key, $info, 86400);
@@ -91,7 +91,7 @@ class Ordinal extends \Gazelle\BaseUser {
FROM user_ordinal
WHERE name = ?
ON DUPLICATE KEY UPDATE value = ?
", $this->id(), $value, $name, $value
", $this->user->id, $value, $name, $value
);
$affected = self::$db->affected_rows();
$this->flush();
@@ -107,7 +107,7 @@ class Ordinal extends \Gazelle\BaseUser {
FROM user_ordinal
WHERE name = ?
)
", $this->id(), $name
", $this->user->id, $name
);
$affected = self::$db->affected_rows();
$this->flush();

View File

@@ -8,7 +8,7 @@ class Privilege extends \Gazelle\BaseUser {
public function flush(): static {
unset($this->info);
self::$cache->delete_value(sprintf(self::CACHE_KEY, $this->id()));
self::$cache->delete_value(sprintf(self::CACHE_KEY, $this->user->id));
return $this;
}
@@ -34,7 +34,7 @@ class Privilege extends \Gazelle\BaseUser {
INNER JOIN users_info ui ON (ui.UserID = um.ID)
INNER JOIN permissions p ON (p.ID = um.PermissionID)
WHERE um.ID = ?
", $this->id()
", $this->user->id
);
$info = [
'level' => $config['class_level'],
@@ -232,7 +232,7 @@ class Privilege extends \Gazelle\BaseUser {
LEFT JOIN users_levels AS l ON (l.PermissionID = p.ID AND l.UserID = ?)
WHERE p.Secondary = 1
ORDER BY p.Name
", $this->id()
", $this->user->id
);
return self::$db->to_array('permName', MYSQLI_ASSOC, false);
}
@@ -250,7 +250,7 @@ class Privilege extends \Gazelle\BaseUser {
INSERT INTO users_levels
(UserID, PermissionID)
VALUES (?, ?)
", $this->id(), $userclassId
", $this->user->id, $userclassId
);
$affected = self::$db->affected_rows();
$this->flush();
@@ -263,7 +263,7 @@ class Privilege extends \Gazelle\BaseUser {
FROM users_levels
WHERE UserID = ?
AND PermissionID = ?
", $this->id(), $userclassId
", $this->user->id, $userclassId
);
$affected = self::$db->affected_rows();
$this->flush();
@@ -282,7 +282,7 @@ class Privilege extends \Gazelle\BaseUser {
UPDATE users_main SET
CustomPermissions = NULL
WHERE ID = ?
", $this->id()
", $this->user->id
);
$affected = self::$db->affected_rows();
$this->flush();
@@ -301,7 +301,7 @@ class Privilege extends \Gazelle\BaseUser {
UPDATE users_main SET
CustomPermissions = ?
WHERE ID = ?
", count($delta) ? serialize($delta) : null, $this->id()
", count($delta) ? serialize($delta) : null, $this->user->id
);
$affected = self::$db->affected_rows();
$this->flush();

View File

@@ -14,7 +14,7 @@ class Quote extends \Gazelle\BaseUser {
protected bool $showAll = false;
public function flush(): static {
self::$cache->delete_value(sprintf(self::UNREAD_QUOTE_KEY, $this->id()));
self::$cache->delete_value(sprintf(self::UNREAD_QUOTE_KEY, $this->user->id));
return $this;
}
@@ -30,12 +30,12 @@ class Quote extends \Gazelle\BaseUser {
INSERT IGNORE INTO users_notify_quoted
(UserID, Page, PageID, QuoterID, PostID)
VALUES (?, ?, ?, ?, ?)
', $this->id(), $page, $pageId, $quoter->id(), $postId
', $this->user->id, $page, $pageId, $quoter->id, $postId
);
$affected = self::$db->affected_rows();
$notifMan->push(
$notifMan->pushableTokensById([$this->id()], NotificationType::INBOX),
$notifMan->pushableTokensById([$this->user->id], NotificationType::INBOX),
"{$quoter->username()} quoted you on the forum",
"",
SITE_URL . '/' . $postMan->findById($postId)->location()
@@ -66,7 +66,7 @@ class Quote extends \Gazelle\BaseUser {
UnRead = false
WHERE Unread = true
AND UserID = ?
", $this->id()
", $this->user->id
);
$this->flush();
return self::$db->affected_rows();
@@ -83,7 +83,7 @@ class Quote extends \Gazelle\BaseUser {
AND UserID = ?
AND PageID = ?
AND PostID BETWEEN ? AND ?
", $this->id(), $thread->id(), $firstPost, $lastPost
", $this->user->id, $thread->id, $firstPost, $lastPost
);
$this->flush();
return self::$db->affected_rows();
@@ -125,7 +125,7 @@ class Quote extends \Gazelle\BaseUser {
"(q.Page != 'forums' OR " . join(' AND ', $forumCond) . ")",
];
$args = array_merge(
[$this->id()],
[$this->user->id],
$forumArgs,
);
@@ -264,12 +264,12 @@ class Quote extends \Gazelle\BaseUser {
* @return int Number of unread quote notifications
*/
public function unreadTotal(): int {
$key = sprintf(self::UNREAD_QUOTE_KEY, $this->id());
$key = sprintf(self::UNREAD_QUOTE_KEY, $this->user->id);
$total = self::$cache->get_value($key);
if ($total === false) {
$forMan = new \Gazelle\Manager\Forum();
[$cond, $args] = $forMan->configureForUser(new \Gazelle\User($this->id()));
$args[] = $this->id(); // for q.UserID
[$cond, $args] = $forMan->configureForUser(new \Gazelle\User($this->user->id));
$args[] = $this->user->id; // for q.UserID
$total = (int)self::$db->scalar("
SELECT count(*)
FROM users_notify_quoted AS q

View File

@@ -29,7 +29,7 @@ class Snatch extends \Gazelle\BaseUser {
protected array $snatchVec = [];
public function flush(): static {
self::$cache->delete_value(sprintf(self::USER_RECENT_SNATCH, $this->id()));
self::$cache->delete_value(sprintf(self::USER_RECENT_SNATCH, $this->user->id));
foreach (array_values($this->snatchVec) as $vector) {
$vector->flush();
}
@@ -48,7 +48,7 @@ class Snatch extends \Gazelle\BaseUser {
}
public function isSnatched(\Gazelle\TorrentAbstract $torrent): bool {
$offset = (int)floor($torrent->id() / self::RANGE_BIT);
$offset = (int)floor($torrent->id / self::RANGE_BIT);
if (!isset($this->snatchVec[$offset])) {
$vector = new CacheVector(sprintf(self::CACHE_KEY, $this->user->id, $offset), self::RANGE_BIT / 8, self::CACHE_EXPIRY);
if ($vector->isEmpty()) {
@@ -57,7 +57,7 @@ class Snatch extends \Gazelle\BaseUser {
}
$this->snatchVec[$offset] = $vector;
}
return $this->snatchVec[$offset]->get($torrent->id() - $offset * self::RANGE_BIT);
return $this->snatchVec[$offset]->get($torrent->id - $offset * self::RANGE_BIT);
}
public function showSnatch(\Gazelle\TorrentAbstract $torrent): bool {
@@ -70,7 +70,7 @@ class Snatch extends \Gazelle\BaseUser {
* This technique should be revisited, possibly by adding the limit to the key.
*/
public function recentSnatchList(int $limit = 5, bool $forceNoCache = false): array {
$key = sprintf(self::USER_RECENT_SNATCH, $this->id());
$key = sprintf(self::USER_RECENT_SNATCH, $this->user->id);
$recent = self::$cache->get_value($key);
if ($forceNoCache) {
$recent = false;
@@ -88,7 +88,7 @@ class Snatch extends \Gazelle\BaseUser {
GROUP BY g.ID
ORDER BY s.tstamp DESC
LIMIT ?
", $this->id(), $limit
", $this->user->id, $limit
);
$recent = self::$db->collect(0, false);
if (!$forceNoCache) {

View File

@@ -8,7 +8,7 @@ class Stylesheet extends \Gazelle\BaseUser {
public function flush(): static {
unset($this->info);
self::$cache->delete_value(sprintf(self::CACHE_KEY, $this->id()));
self::$cache->delete_value(sprintf(self::CACHE_KEY, $this->user->id));
return $this;
}
@@ -16,7 +16,7 @@ class Stylesheet extends \Gazelle\BaseUser {
if (isset($this->info)) {
return $this->info;
}
$key = sprintf(self::CACHE_KEY, $this->id());
$key = sprintf(self::CACHE_KEY, $this->user->id);
$info = self::$cache->get_value($key);
if ($info === false) {
$info = self::$db->rowAssoc("
@@ -28,7 +28,7 @@ class Stylesheet extends \Gazelle\BaseUser {
FROM stylesheets s
INNER JOIN users_main um ON (um.stylesheet_id = s.ID)
WHERE um.ID = ?
", $this->id()
", $this->user->id
);
self::$cache->cache_value($key, $info, 0);
}
@@ -43,7 +43,7 @@ class Stylesheet extends \Gazelle\BaseUser {
stylesheet_url = ?
WHERE ID = ?
", $stylesheetId, empty($stylesheetUrl) ? null : trim($stylesheetUrl),
$this->id()
$this->user->id
);
$affected = self::$db->affected_rows();
$this->flush();

View File

@@ -29,14 +29,14 @@ class Subscription extends \Gazelle\BaseUser {
DELETE FROM users_subscriptions
WHERE UserID = ?
AND TopicID = ?
', $this->user->id, $thread->id()
', $this->user->id, $thread->id
);
$affected = self::$db->affected_rows();
} else {
self::$db->prepared_query('
INSERT IGNORE INTO users_subscriptions (UserID, TopicID)
VALUES (?, ?)
', $this->user->id, $thread->id()
', $this->user->id, $thread->id
);
$affected = self::$db->affected_rows();
}
@@ -176,7 +176,7 @@ class Subscription extends \Gazelle\BaseUser {
}
public function isSubscribed(ForumThread $thread): bool {
return array_search($thread->id(), $this->subscriptionList()) !== false;
return array_search($thread->id, $this->subscriptionList()) !== false;
}
/**

View File

@@ -12,7 +12,10 @@ class Token extends \Gazelle\BaseUser {
return $this;
}
public function __construct(protected int $tokenId, \Gazelle\User $user) {
public function __construct(
public readonly int $tokenId,
\Gazelle\User $user,
) {
parent::__construct($user);
}
@@ -25,7 +28,7 @@ class Token extends \Gazelle\BaseUser {
from user_token
where id_user_token = ?
and id_user = ?
", $this->tokenId, $this->user()->id()
", $this->tokenId, $this->user->id
);
}
return $this->info;
@@ -45,7 +48,7 @@ class Token extends \Gazelle\BaseUser {
from user_token
where expiry > now()
and id_user_token = ?
", $this->id()
", $this->tokenId
);
}

View File

@@ -103,7 +103,7 @@ class UserLink extends \Gazelle\BaseUser {
INSERT INTO users_dupes
(UserID, GroupID)
VALUES (?, ?)
", $target->id(), $sourceGroupId
", $target->id, $sourceGroupId
);
$linkGroupId = $sourceGroupId;
} else {
@@ -114,7 +114,7 @@ class UserLink extends \Gazelle\BaseUser {
(UserID, GroupID)
VALUES (?, ?),
(?, ?)
", $target->id(), $linkGroupId, $sourceId, $linkGroupId
", $target->id, $linkGroupId, $sourceId, $linkGroupId
);
}
@@ -167,7 +167,7 @@ class UserLink extends \Gazelle\BaseUser {
}
public function removeUser(\Gazelle\User $target, \Gazelle\User $admin): int {
$targetId = $target->id();
$targetId = $target->id;
$target->auditTrail()->addEvent(
UserAuditEvent::link,
"[user]{$target->username()}[/user] unlinked",

View File

@@ -93,10 +93,10 @@ class UserclassRateLimit extends \Gazelle\BaseUser {
INSERT INTO ratelimit_torrent
(user_id, torrent_id)
VALUES (?, ?)
", $this->id(), $torrent->id()
", $this->user->id, $torrent->id
);
$id = self::$db->inserted_id();
$key = "user_429_flood_{$this->id()}";
$key = "user_429_flood_{$this->user->id}";
if (self::$cache->get_value($key)) {
self::$cache->increment($key);
} else {

View File

@@ -27,10 +27,10 @@ class Vote extends \Gazelle\BaseUser {
public function flush(): static {
self::$cache->delete_multi([
sprintf(self::VOTE_RECENT, $this->id()),
sprintf(self::VOTE_TOTAL, $this->id()),
sprintf(self::VOTE_USER_KEY, $this->id()),
sprintf(self::VOTED_USER, $this->id()),
sprintf(self::VOTE_RECENT, $this->user->id),
sprintf(self::VOTE_TOTAL, $this->user->id),
sprintf(self::VOTE_USER_KEY, $this->user->id),
sprintf(self::VOTED_USER, $this->user->id),
]);
unset($this->info);
return $this;
@@ -38,8 +38,8 @@ class Vote extends \Gazelle\BaseUser {
protected function tgroupFlush(\Gazelle\TGroup $tgroup): static {
self::$cache->delete_multi([
sprintf(self::VOTED_GROUP, $tgroup->id()),
sprintf(self::VOTE_PAIR_KEY, $tgroup->id()),
sprintf(self::VOTED_GROUP, $tgroup->id),
sprintf(self::VOTE_PAIR_KEY, $tgroup->id),
]);
return $this->flush();
}
@@ -48,7 +48,7 @@ class Vote extends \Gazelle\BaseUser {
if (isset($this->info)) {
return $this->info;
}
$key = sprintf(self::VOTE_USER_KEY, $this->id());
$key = sprintf(self::VOTE_USER_KEY, $this->user->id);
$info = self::$cache->get_value($key);
if ($info === false) {
self::$db->prepared_query("
@@ -59,7 +59,7 @@ class Vote extends \Gazelle\BaseUser {
END as Vote
FROM users_votes
WHERE UserID = ?
", $this->id()
", $this->user->id
);
$info = self::$db->to_pair('GroupID', 'Vote', false);
self::$cache->cache_value($key, $info, 0);
@@ -172,7 +172,7 @@ class Vote extends \Gazelle\BaseUser {
$ranks = $this->voteRanks(self::$db->to_pair('GroupID', 'Score', false));
self::$cache->cache_value($key, $ranks, 259200); // 3 days
}
return $ranks[$tgroup->id()] ?? false;
return $ranks[$tgroup->id] ?? false;
}
/**
@@ -196,7 +196,7 @@ class Vote extends \Gazelle\BaseUser {
$ranks = $this->voteRanks(self::$db->to_pair('GroupID', 'Score', false));
self::$cache->cache_value($key, $ranks, 259200);
}
return $ranks[$tgroup->id()] ?? false;
return $ranks[$tgroup->id] ?? false;
}
/**
@@ -222,7 +222,7 @@ class Vote extends \Gazelle\BaseUser {
$ranks = $this->voteRanks(self::$db->to_pair('GroupID', 'Score', false));
self::$cache->cache_value($key, $ranks, 259200); // 3 days
}
return $ranks[$tgroup->id()] ?? false;
return $ranks[$tgroup->id] ?? false;
}
public function topVotes(): array {
@@ -291,9 +291,9 @@ class Vote extends \Gazelle\BaseUser {
public function links(\Gazelle\TGroup $tgroup): string {
return self::$twig->render('vote/links.twig', [
'group_id' => $tgroup->id(),
'group_id' => $tgroup->id,
'score' => $this->score($tgroup),
'vote' => $this->info()[$tgroup->id()] ?? 0,
'vote' => $this->info()[$tgroup->id] ?? 0,
'viewer' => $this->user,
]);
}
@@ -311,7 +311,7 @@ class Vote extends \Gazelle\BaseUser {
}
public function vote(\Gazelle\TGroup $tgroup): int {
return $this->info()[$tgroup->id()] ?? 0;
return $this->info()[$tgroup->id] ?? 0;
}
/**
@@ -319,12 +319,12 @@ class Vote extends \Gazelle\BaseUser {
* @return array (Ups, Total, Score)
*/
public function tgroupInfo(\Gazelle\TGroup $tgroup): array {
$key = sprintf(self::VOTED_GROUP, $tgroup->id());
$key = sprintf(self::VOTED_GROUP, $tgroup->id);
$tgroupInfo = self::$cache->get_value($key);
if ($tgroupInfo === false) {
$tgroupInfo = self::$db->rowAssoc("
SELECT Ups, `Total`, Score FROM torrents_votes WHERE GroupID = ?
", $tgroup->id()
", $tgroup->id
) ?? ['Ups' => 0, 'Total' => 0, 'Score' => 0];
self::$cache->cache_value($key, $tgroupInfo, 259200); // 3 days
}
@@ -336,7 +336,7 @@ class Vote extends \Gazelle\BaseUser {
* @return array [groupId => 0|1]
*/
public function userVotes(): array {
$key = sprintf(self::VOTED_USER, $this->id());
$key = sprintf(self::VOTED_USER, $this->user->id);
$votes = self::$cache->get_value($key);
if ($votes === false) {
self::$db->prepared_query("
@@ -344,7 +344,7 @@ class Vote extends \Gazelle\BaseUser {
CASE WHEN Type = 'Up' THEN 1 ELSE 0 END AS vote
FROM users_votes
WHERE UserID = ?
", $this->id()
", $this->user->id
);
$votes = self::$db->to_pair('GroupID', 'vote', false);
self::$cache->cache_value($key, $votes, 86400);
@@ -398,7 +398,7 @@ class Vote extends \Gazelle\BaseUser {
coalesce(sum(if(v.Type = 'Up', 1, 0)), 0) AS Ups
FROM users_votes AS v
WHERE v.GroupID = ?
", $tgroup->id()
", $tgroup->id
);
return [$total, (int)$ups, $this->calcScore($total, (int)$ups)];
}
@@ -409,7 +409,7 @@ class Vote extends \Gazelle\BaseUser {
* @return array [bool success, string reason]
*/
protected function castVote(\Gazelle\TGroup $tgroup, int $direction): array {
if (isset($this->info()[$tgroup->id()])) {
if (isset($this->info()[$tgroup->id])) {
return [false, 'already-voted'];
}
$up = $direction === 1 ? 1 : 0;
@@ -420,7 +420,7 @@ class Vote extends \Gazelle\BaseUser {
INSERT IGNORE INTO users_votes
(UserID, GroupID, upvote, Type)
VALUES (?, ?, ?, ?)
", $this->id(), $tgroup->id(), $up, $up ? 'Up' : 'Down'
", $this->user->id, $tgroup->id, $up, $up ? 'Up' : 'Down'
);
[$total, $ups, $score] = $this->summary($tgroup);
self::$db->prepared_query("
@@ -431,13 +431,13 @@ class Vote extends \Gazelle\BaseUser {
Total = ?,
Ups = ?,
Score = ?
", $tgroup->id(), $ups, $score, $total, $ups, $score
", $tgroup->id, $ups, $score, $total, $ups, $score
);
self::$db->commit();
// update cache
$this->info[$tgroup->id()] = $direction;
self::$cache->cache_value(sprintf(self::VOTE_USER_KEY, $this->id()), $this->info, 259200); // 3 days
$this->info[$tgroup->id] = $direction;
self::$cache->cache_value(sprintf(self::VOTE_USER_KEY, $this->user->id), $this->info, 259200); // 3 days
$this->tgroupFlush($tgroup);
return [true, 'voted'];
@@ -447,7 +447,7 @@ class Vote extends \Gazelle\BaseUser {
* Clear a vote on this release group
*/
public function clear(\Gazelle\TGroup $tgroup): array {
if (!isset($this->info()[$tgroup->id()])) {
if (!isset($this->info()[$tgroup->id])) {
return [false, 'not-voted'];
}
@@ -455,7 +455,7 @@ class Vote extends \Gazelle\BaseUser {
self::$db->prepared_query("
DELETE FROM users_votes
WHERE UserID = ? AND GroupID = ?
", $this->id(), $tgroup->id()
", $this->user->id, $tgroup->id
);
[$total, $ups, $score] = $this->summary($tgroup);
self::$db->prepared_query("
@@ -464,20 +464,20 @@ class Vote extends \Gazelle\BaseUser {
Ups = ?,
Score = ?
WHERE GroupID = ?
", $total, $ups, $score, $tgroup->id()
", $total, $ups, $score, $tgroup->id
);
self::$db->commit();
// Update cache
unset($this->info[$tgroup->id()]);
self::$cache->cache_value(sprintf(self::VOTE_USER_KEY, $this->id()), $this->info, 259200);
unset($this->info[$tgroup->id]);
self::$cache->cache_value(sprintf(self::VOTE_USER_KEY, $this->user->id), $this->info, 259200);
$this->tgroupFlush($tgroup);
return [true, 'cleared'];
}
public function recent(\Gazelle\Manager\TGroup $tgMan): array {
$key = sprintf(self::VOTE_RECENT, $this->id());
$key = sprintf(self::VOTE_RECENT, $this->user->id);
$recent = self::$cache->get_value($key);
if ($recent === false) {
self::$db->prepared_query("
@@ -489,7 +489,7 @@ class Vote extends \Gazelle\BaseUser {
AND uv.UserID = ?
ORDER BY uv.Time DESC
LIMIT 5
", $this->id()
", $this->user->id
);
$recent = self::$db->to_array();
self::$cache->cache_value($key, $recent, 0);
@@ -502,12 +502,12 @@ class Vote extends \Gazelle\BaseUser {
public function userTotal(int $mask): int {
if (!isset($this->voteSummary)) {
$key = sprintf(self::VOTE_TOTAL, $this->id());
$key = sprintf(self::VOTE_TOTAL, $this->user->id);
$voteSummary = self::$cache->get_value($key);
if ($voteSummary === false) {
$voteSummary = self::$db->rowAssoc("
SELECT count(*) AS total, coalesce(sum(Type='Up'), 0) AS up FROM users_votes WHERE UserID = ?
", $this->id()
", $this->user->id
);
self::$cache->cache_value($key, $voteSummary, 0);
}
@@ -522,7 +522,7 @@ class Vote extends \Gazelle\BaseUser {
public function userPage(\Gazelle\Manager\TGroup $tgMan, int $mask, int $limit, int $offset): array {
$cond = ['UserID = ?'];
$args = [$this->id()];
$args = [$this->user->id];
if ($mask === self::UPVOTE) {
$cond[] = 'Type = ?';
$args[] = 'Up';

View File

@@ -26,7 +26,7 @@ class Warning extends \Gazelle\BaseUser {
coalesce((select warning_end from cte), now()) + ?::interval
))
returning to_char(upper(warning), 'YYYY-MM-DD HH24:MI')
", $this->id(), $this->id(), $warner->id(), $reason, $interval
", $this->user->id, $this->user->id, $warner->id, $reason, $interval
);
$this->user()->auditTrail()->addEvent(
\Gazelle\Enum\UserAuditEvent::warning,
@@ -43,7 +43,7 @@ class Warning extends \Gazelle\BaseUser {
from user_warning
where now() < upper(warning)
and id_user = ?
", $this->id()
", $this->user->id
);
$this->info = ['expiry' => is_null($expiry) ? null : (string)$expiry];
}
@@ -72,7 +72,7 @@ class Warning extends \Gazelle\BaseUser {
from user_warning
where id_user = ?
order by id_user_warning
", $this->id()
", $this->user->id
);
}
@@ -85,7 +85,7 @@ class Warning extends \Gazelle\BaseUser {
warning = NULL
where upper(warning) > now()
and id_user = ?
", $this->id()
", $this->user->id
);
$this->flush();
return $affected;

View File

@@ -47,26 +47,26 @@ class ArtistTest extends TestCase {
$this->assertNull($manager->findById(-666), 'artist-find-fail');
$artist = $manager->create('phpunit.' . randomString(12));
$this->artistIdList[] = $artist->id();
$this->artistIdList[] = $artist->id;
(DB::DB())->prepared_query("
INSERT INTO artist_usage
(artist_id, role, uses)
VALUES (?, ?, ?)
", $artist->id(), '1', RANDOM_ARTIST_MIN_ENTRIES
", $artist->id, '1', RANDOM_ARTIST_MIN_ENTRIES
);
// If the following test fails locally:
// before test run: TRUNCATE TABLE artist_usage;
// after test run: (new Stats\Artists)->updateUsage();
$this->assertEquals($artist->id(), $manager->findRandom()->id(), 'artist-find-random');
$this->assertNull($manager->findByIdAndRevision($artist->id(), -666), 'artist-find-revision-fail');
$this->assertEquals($artist->id, $manager->findRandom()->id, 'artist-find-random');
$this->assertNull($manager->findByIdAndRevision($artist->id, -666), 'artist-find-revision-fail');
$this->assertGreaterThan(0, $artist->id(), 'artist-create-artist-id');
$this->assertGreaterThan(0, $artist->id, 'artist-create-artist-id');
$this->assertGreaterThan(0, $artist->aliasId(), 'artist-create-alias-id');
$artist = $manager->findById($artist->id());
$artist = $manager->findById($artist->id);
$this->assertInstanceOf(Artist::class, $artist, 'artist-is-an-artist');
$this->assertNull($manager->findByIdAndRevision($artist->id(), -1), 'artist-is-an-unrevised-artist');
$this->assertNull($manager->findByIdAndRevision($artist->id, -1), 'artist-is-an-unrevised-artist');
// empty, but at least it tests the SQL
$this->assertCount(0, $artist->tagLeaderboard(), 'artist-tag-leaderboard');
}
@@ -74,10 +74,10 @@ class ArtistTest extends TestCase {
public function testArtistInfo(): void {
$manager = new Manager\Artist();
$artist = $manager->create('phpunit.' . randomString(12));
$this->artistIdList[] = $artist->id();
$this->artistIdList[] = $artist->id;
$this->assertEquals("<a href=\"artist.php?id={$artist->id()}\">{$artist->name()}</a>", $artist->link(), 'artist-link');
$this->assertEquals("artist.php?id={$artist->id()}", $artist->location(), 'artist-location');
$this->assertEquals("<a href=\"artist.php?id={$artist->id}\">{$artist->name()}</a>", $artist->link(), 'artist-link');
$this->assertEquals("artist.php?id={$artist->id}", $artist->location(), 'artist-location');
$this->assertNull($artist->body(), 'artist-body-null');
$this->assertNull($artist->image(), 'artist-image-null');
$this->assertFalse($artist->isLocked(), 'artist-is-unlocked');
@@ -88,7 +88,7 @@ class ArtistTest extends TestCase {
public function testArtistRevision(): void {
$manager = new Manager\Artist();
$artist = $manager->create('phpunit.' . randomString(12));
$this->artistIdList[] = $artist->id();
$this->artistIdList[] = $artist->id;
$revision = $artist->createRevision(
body: 'phpunit body test',
@@ -108,11 +108,11 @@ class ArtistTest extends TestCase {
$this->assertEquals($revision + 1, $rev2, 'artist-revision-2');
$this->assertEquals('https://example.com/artist-revised.jpg', $artist->image(), 'artist-image-revised');
$artistV1 = $manager->findByIdAndRevision($artist->id(), $revision);
$artistV1 = $manager->findByIdAndRevision($artist->id, $revision);
$this->assertNotNull($artistV1, 'artist-revision-1-found');
$this->assertEquals('phpunit body test', $artistV1->body(), 'artist-body-rev-1');
$artistV2 = $manager->findByIdAndRevision($artist->id(), $rev2);
$artistV2 = $manager->findByIdAndRevision($artist->id, $rev2);
$this->assertEquals('https://example.com/artist-revised.jpg', $artistV2->image(), 'artist-image-rev-2');
$list = $artist->revisionList();
@@ -127,10 +127,10 @@ class ArtistTest extends TestCase {
public function testArtistAlias(): void {
$manager = new Manager\Artist();
$artist = $manager->create('phpunit.' . randomString(12));
$this->artistIdList[] = $artist->id();
$this->artistIdList[] = $artist->id;
$this->assertEquals($artist->id(), $artist->id(), 'artist-find-by-alias-id');
$this->assertEquals($artist->id(), $manager->findByName($artist->name())->id(), 'artist-find-by-alias-name');
$this->assertEquals($artist->id, $artist->id, 'artist-find-by-alias-id');
$this->assertEquals($artist->id, $manager->findByName($artist->name())->id, 'artist-find-by-alias-name');
$this->assertEquals($artist->aliasId(), $manager->findByName($artist->name())->aliasId(), 'artist-find-aliasid-by-alias-name');
$this->assertEquals(1, $manager->aliasUseTotal($artist->aliasId()), 'artist-sole-alias');
$this->assertCount(0, $manager->tgroupList($artist->aliasId(), new Manager\TGroup()), 'artist-no-tgroup');
@@ -141,7 +141,7 @@ class ArtistTest extends TestCase {
$this->assertEquals(2, $manager->aliasUseTotal($artist->aliasId()), 'artist-two-alias');
$artist = $manager->findByName($aliasName);
$this->assertEquals($artist->id(), $artist->id(), 'artist-fetch-artist-id');
$this->assertEquals($artist->id, $artist->id, 'artist-fetch-artist-id');
$this->assertEquals($newId, $artist->aliasId(), 'artist-fetch-alias-id');
$this->assertEquals(1, $artist->removeAlias($newId), 'artist-remove-alias');
@@ -150,10 +150,10 @@ class ArtistTest extends TestCase {
public function testArtistNonRedirAlias(): void {
$manager = new Manager\Artist();
$artist = $manager->create('phpunit.' . randomString(12));
$this->artistIdList[] = $artist->id();
$this->artistIdList[] = $artist->id;
$aliasName = $artist->name() . '-reformed';
$newId = $artist->addAlias($aliasName, $artist->id(), $this->user);
$newId = $artist->addAlias($aliasName, $artist->id, $this->user);
$this->assertEquals($artist->aliasId() + 1, $newId, 'artist-new-non-redirect');
}
@@ -162,25 +162,25 @@ class ArtistTest extends TestCase {
$oldName = 'phpunit.artist.' . randomString(12);
$old = $manager->create($oldName);
$oldAliasId = $old->aliasId();
$this->artistIdList[] = $old->id();
$this->artistIdList[] = $old->id;
$newName = 'phpunit.artist.' . randomString(12);
$new = $manager->create($newName);
$this->artistIdList[] = $new->id();
$this->artistIdList[] = $new->id;
$userBk = new User\Bookmark($this->user);
$userBk->create('artist', $old->id());
$userBk->create('artist', $old->id);
$commentMan = new Manager\Comment();
$postList = [
$commentMan->create($this->user, 'artist', $old->id(), 'phpunit merge ' . randomString(6)),
$commentMan->create($this->user, 'artist', $new->id(), 'phpunit merge ' . randomString(6)),
$commentMan->create($this->user, 'artist', $old->id, 'phpunit merge ' . randomString(6)),
$commentMan->create($this->user, 'artist', $new->id, 'phpunit merge ' . randomString(6)),
];
$this->extra = Helper::makeUser('merge.' . randomString(10), 'merge');
$extraBk = new User\Bookmark($this->extra);
$extraBk->create('artist', $old->id());
$extraBk->create('artist', $new->id());
$extraBk->create('artist', $old->id);
$extraBk->create('artist', $new->id);
$collMan = new Manager\Collage();
$this->collage = $collMan->create(
@@ -220,19 +220,19 @@ class ArtistTest extends TestCase {
),
'artist-merge-n',
);
$this->assertNull($manager->findById($old->id()), 'art-merge-no-old');
$this->assertTrue($userBk->isArtistBookmarked($new->id()), 'art-merge-user-bookmarked-new');
$this->assertTrue($extraBk->isArtistBookmarked($new->id()), 'art-merge-extra-bookmarked-new');
$this->assertNull($manager->findById($old->id), 'art-merge-no-old');
$this->assertTrue($userBk->isArtistBookmarked($new->id), 'art-merge-user-bookmarked-new');
$this->assertTrue($extraBk->isArtistBookmarked($new->id), 'art-merge-extra-bookmarked-new');
$this->assertCount(1, $extraBk->artistList(), 'art-merge-extra-bookmarked-list');
// FIXME: flushed collage objects cannot be refreshed
$merged = $collMan->findById($this->collage->id());
$this->assertEquals([$new->id()], $merged->entryList(), 'art-merge-collage');
$merged = $collMan->findById($this->collage->id);
$this->assertEquals([$new->id], $merged->entryList(), 'art-merge-collage');
$comment = new Comment\Artist($new->id(), 1, 0);
$comment = new Comment\Artist($new->id, 1, 0);
$comment->load(); // FIXME: load() should not be necessary
$this->assertEquals(
[$postList[0]->id(), $postList[1]->id()],
[$postList[0]->id, $postList[1]->id],
array_map(fn($p) => $p['ID'], $comment->thread()),
'art-merge-comments'
);
@@ -242,7 +242,7 @@ class ArtistTest extends TestCase {
++$n;
$artistRole = $tgroup->flush()->artistRole();
$this->assertEquals(
[ARTIST_MAIN => [['id' => $new->id(), 'name' => $oldName, 'aliasid' => $oldAliasId]]],
[ARTIST_MAIN => [['id' => $new->id, 'name' => $oldName, 'aliasid' => $oldAliasId]]],
$artistRole->idList(),
"art-merge-ar-$n"
);
@@ -252,7 +252,7 @@ class ArtistTest extends TestCase {
public function testArtistModify(): void {
$manager = new Manager\Artist();
$artist = $manager->create('phpunit.' . randomString(12));
$this->artistIdList[] = $artist->id();
$this->artistIdList[] = $artist->id;
$this->assertTrue(
$artist->setField('body', 'body modification')->setUpdateUser($this->user)->modify(),
@@ -278,7 +278,7 @@ class ArtistTest extends TestCase {
public function testArtistRename(): void {
$manager = new Manager\Artist();
$artist = $manager->create('phpunit.' . randomString(12));
$this->artistIdList[] = $artist->id();
$this->artistIdList[] = $artist->id;
$oldName = $artist->name();
$rename = $artist->name() . '-rename';
@@ -296,10 +296,10 @@ class ArtistTest extends TestCase {
public function testArtistRenamePrimary(): void {
$manager = new Manager\Artist();
$artist = $manager->create('phpunit.' . randomString(12));
$this->artistIdList[] = $artist->id();
$this->artistIdList[] = $artist->id;
$commentMan = new Manager\Comment();
$post = $commentMan->create($this->user, 'artist', $artist->id(), 'phpunit smart rename ' . randomString(6));
$post = $commentMan->create($this->user, 'artist', $artist->id, 'phpunit smart rename ' . randomString(6));
$requestMan = new Manager\Request();
$request = $requestMan->create(
@@ -345,20 +345,20 @@ class ArtistTest extends TestCase {
);
$this->assertEquals($name, $artist->name(), 'artist-is-smart-renamed');
$commentPage = new Comment\Artist($artist->id(), 1, 0);
$commentPage = new Comment\Artist($artist->id, 1, 0);
$commentPage->load();
$threadList = $commentPage->threadList(new Manager\User());
$this->assertCount(1, $threadList, 'artist-renamed-comments');
$this->assertEquals($post->id(), $threadList[0]['postId'], 'artist-renamed-comments');
$this->assertEquals($post->id, $threadList[0]['postId'], 'artist-renamed-comments');
$request->flush();
$idList = $request->artistRole()->idList();
$this->assertEquals($artist->id(), $idList[ARTIST_MAIN][0]['id'], 'artist-renamed-request');
$this->assertEquals($artist->id, $idList[ARTIST_MAIN][0]['id'], 'artist-renamed-request');
$request->remove();
$this->tgroupList[0]->flush();
$idList = $this->tgroupList[0]->artistRole()->idList();
$this->assertEquals($artist->id(), $idList[ARTIST_MAIN][0]['id'], 'artist-renamed-tgroup');
$this->assertEquals($artist->id, $idList[ARTIST_MAIN][0]['id'], 'artist-renamed-tgroup');
}
public function testRenameAliasCapchange(): void {
@@ -430,14 +430,14 @@ class ArtistTest extends TestCase {
public function testArtistSimilar(): void {
$manager = new Manager\Artist();
$artist = $manager->create('phpunit.artsim.' . randomString(12));
$this->artistIdList[] = $artist->id();
$this->artistIdList[] = $artist->id;
$this->extra = Helper::makeUser('art2.' . randomString(10), 'artist');
$other1 = $manager->create('phpunit.other1.' . randomString(12));
$other2 = $manager->create('phpunit.other2.' . randomString(12));
$this->artistIdList[] = $other1->id();
$this->artistIdList[] = $other2->id();
$this->artistIdList[] = $other1->id;
$this->artistIdList[] = $other2->id;
$this->assertFalse($artist->similar()->voteSimilar($this->extra, $artist, true), 'artist-vote-self');
@@ -453,13 +453,13 @@ class ArtistTest extends TestCase {
$this->assertEquals(
[
[
'artist_id' => $other1->id(),
'artist_id' => $other1->id,
'name' => $other1->name(),
'score' => 300,
'similar_id' => $artist->similar()->findSimilarId($other1),
],
[
'artist_id' => $other2->id(),
'artist_id' => $other2->id,
'name' => $other2->name(),
'score' => 200,
'similar_id' => $artist->similar()->findSimilarId($other2),
@@ -472,12 +472,12 @@ class ArtistTest extends TestCase {
$graph = $artist->similar()->similarGraph(100, 100);
$this->assertCount(2, $graph, 'artist-similar-count');
$this->assertEquals(
[$other1->id(), $other2->id()],
[$other1->id, $other2->id],
array_values(array_map(fn($sim) => $sim['artist_id'], $graph)),
'artist-similar-id-list'
);
$this->assertEquals($other2->id(), $graph[$other1->id()]['related'][0], 'artist-sim-related');
$this->assertLessThan($graph[$other1->id()]['proportion'], $graph[$other2->id()]['proportion'], 'artist-sim-proportion');
$this->assertEquals($other2->id, $graph[$other1->id]['related'][0], 'artist-sim-related');
$this->assertLessThan($graph[$other1->id]['proportion'], $graph[$other2->id]['proportion'], 'artist-sim-proportion');
$requestMan = new Manager\Request();
$this->assertFalse($artist->similar()->removeSimilar($artist, $this->extra), 'artist-remove-similar-self');
@@ -488,7 +488,7 @@ class ArtistTest extends TestCase {
public function testArtistJson(): void {
$manager = new Manager\Artist();
$artist = $manager->create('phpunit.' . randomString(12));
$this->artistIdList[] = $artist->id();
$this->artistIdList[] = $artist->id;
$json = (new Json\Artist(
$artist,
@@ -507,7 +507,7 @@ class ArtistTest extends TestCase {
array_keys($payload),
'artist-json-payload'
);
$this->assertEquals($artist->id(), $payload['id'], 'artist-payload-id');
$this->assertEquals($artist->id, $payload['id'], 'artist-payload-id');
$this->assertEquals($artist->name(), $payload['name'], 'artist-payload-name');
$this->assertCount(0, $payload['tags'], 'artist-payload-tags');
$this->assertCount(0, $payload['similarArtists'], 'artist-payload-similar-artists');
@@ -525,7 +525,7 @@ class ArtistTest extends TestCase {
$composer = $name;
}
$artist = $manager->create($name);
$this->artistIdList[] = $artist->id();
$this->artistIdList[] = $artist->id;
$tgroup = Helper::makeTGroupMusic(
$this->user,
'phpunit artist autocomp ' . randomString(10),
@@ -552,13 +552,13 @@ class ArtistTest extends TestCase {
$name = 'phpunit.' . randomString(12);
$manager = new Manager\Artist();
$artist = $manager->create($name);
$this->artistIdList[] = $artist->id();
$this->artistIdList[] = $artist->id;
(new User\Bookmark($this->user))->create('artist', $artist->id());
(new User\Bookmark($this->user))->create('artist', $artist->id);
$json = new Json\Bookmark\Artist(new User\Bookmark($this->user));
$this->assertEquals(
[[
'artistId' => $artist->id(),
'artistId' => $artist->id,
'artistName' => $name,
]],
$json->payload(),
@@ -569,7 +569,7 @@ class ArtistTest extends TestCase {
public function testArtistDiscogs(): void {
$manager = new Manager\Artist();
$artist = $manager->create('phpunit.' . randomString(12));
$this->artistIdList[] = $artist->id();
$this->artistIdList[] = $artist->id;
$id = -100000 + random_int(1, 100000);
$discogs = new Util\Discogs(

View File

@@ -415,9 +415,9 @@ class DonorTest extends TestCase {
$this->assertGreaterThan(0, $manager->topDonorList(100, $userMan), 'donor-top-donor');
$this->assertGreaterThan($initial + DONOR_RANK_PRICE, $manager->totalMonth(1), 'donor-manager-month');
$username = $this->donor->user()->username();
$entry = array_values(array_filter($manager->rewardPage(null, 100, 0), fn($d) => $d['user_id'] == $this->donor->id()))[0];
$entry = array_values(array_filter($manager->rewardPage(null, 100, 0), fn($d) => $d['user_id'] == $this->donor->user()->id))[0];
$this->assertEquals($username, $entry['Username'], 'donor-manager-reward-username');
$entry = array_values(array_filter($manager->rewardPage($username, 100, 0), fn($d) => $d['user_id'] == $this->donor->id()))[0];
$entry = array_values(array_filter($manager->rewardPage($username, 100, 0), fn($d) => $d['user_id'] == $this->donor->user()->id))[0];
$this->assertEquals($username, $entry['Username'], 'donor-manager-reward-search');
$timeline = $manager->timeline();

View File

@@ -25,11 +25,10 @@ class UserTokenTest extends TestCase {
$manager = new Manager\UserToken();
$userToken = $manager->create(UserTokenType::password, $this->user);
$this->assertTrue(Helper::recentDate($userToken->expiry()), 'usertoken-expiry');
$this->assertInstanceOf(User\Token::class, $manager->findById($userToken->id()), 'usertoken-find-by-id');
$this->assertInstanceOf(User\Token::class, $manager->findById($userToken->tokenId), 'usertoken-find-by-id');
$this->assertInstanceOf(User\Token::class, $manager->findByToken($userToken->value()), 'usertoken-find-by-token');
$this->assertEquals(UserTokenType::password, $userToken->type(), 'usertoken-type');
$this->assertTrue($userToken->isValid(), 'usertoken-create');
$this->assertTrue($userToken->isValid(), 'usertoken-valid');
$this->assertTrue($userToken->consume(), 'usertoken-consume');
Helper::sleepTick();