consistent findById() logic

This commit is contained in:
Spine
2025-04-20 02:41:25 +00:00
parent 2b41498c51
commit 2be870508f
56 changed files with 648 additions and 453 deletions

1
.gitignore vendored
View File

@@ -20,6 +20,7 @@
__MACOSX/
/cache
/coverage
/misc/docker/data/
/misc/mysql-dump.sql
/misc/postgresql-dump.sql

View File

@@ -13,6 +13,7 @@ help:
echo ' check-php - check that the modified PHP files are syntactically correct'
echo ' composer-dev-update - run local composer update'
echo ' composer-live-update - run production composer install from composer.lock'
echo ' coverage - generate HTML coverage report from unit tests'
echo ' config-css - generate the configuration variables to build the CSS files'
echo ' dump-all - create tarballs of the following:'
echo ' dump-riplog - create a tarball of the rip logs'
@@ -51,6 +52,10 @@ composer-dev-update:
composer-live-update:
composer install --no-dev --optimize-autoloader --no-progress
.PHONY: coverage
coverage:
docker compose exec -e XDEBUG_MODE=coverage web vendor/bin/phpunit -c misc/phpunit.xml -d memory_limit=2G --coverage-html coverage/
.PHONY: dump-all
dump-all: dump-riplog dump-riploghtml dump-torrent

View File

@@ -16,19 +16,19 @@ class Applicant extends \Gazelle\Base {
return $this;
}
public function findById(int $applicantId): ?\Gazelle\Applicant {
$key = sprintf(self::ID_KEY, $applicantId);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = (int)self::$db->scalar("
public function findById(int $id): ?\Gazelle\Applicant {
$key = sprintf(self::ID_KEY, $id);
$applicantId = self::$cache->get_value($key);
if ($applicantId === false) {
$applicantId = (int)self::$db->scalar("
SELECT ID FROM applicant WHERE ID = ?
", $applicantId
", $id
);
if ($id) {
self::$cache->cache_value($key, $id, 0);
if ($applicantId) {
self::$cache->cache_value($key, $applicantId, 0);
}
}
return $id ? new \Gazelle\Applicant($id) : null;
return $applicantId ? new \Gazelle\Applicant($applicantId) : null;
}
public function list(): array {
@@ -47,7 +47,7 @@ class Applicant extends \Gazelle\Base {
$list = self::$db->collect(0, false);
self::$cache->cache_value(self::LIST_KEY, $list, 0);
}
return array_map(fn($id) => $this->findById($id), $list);
return array_map(fn ($id) => $this->findById($id), $list);
}
public function resolvedList(): array {

View File

@@ -18,19 +18,19 @@ class ApplicantRole extends \Gazelle\Base {
return new \Gazelle\ApplicantRole($id);
}
public function findById(int $roleId): ?\Gazelle\ApplicantRole {
$key = sprintf(self::ID_KEY, $roleId);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = self::$db->scalar("
public function findById(int $id): ?\Gazelle\ApplicantRole {
$key = sprintf(self::ID_KEY, $id);
$roleId = self::$cache->get_value($key);
if ($roleId === false) {
$roleId = self::$db->scalar("
SELECT ID FROM applicant_role WHERE ID = ?
", $roleId
", $id
);
if (!is_null($id)) {
self::$cache->cache_value($key, $id, 7200);
if (!is_null($roleId)) {
self::$cache->cache_value($key, $roleId, 7200);
}
}
return $id ? new \Gazelle\ApplicantRole($id) : null;
return $roleId ? new \Gazelle\ApplicantRole($roleId) : null;
}
public function flush(): static {
@@ -47,7 +47,7 @@ class ApplicantRole extends \Gazelle\Base {
$list = self::$db->collect(0, false);
self::$cache->cache_value(self::LIST_KEY, $list, 0);
}
return array_map(fn($id) => $this->findById($id), $list);
return array_map(fn ($id) => $this->findById($id), $list);
}
public function publishedList(): array {

View File

@@ -51,31 +51,31 @@ class Artist extends \Gazelle\BaseManager {
return new \Gazelle\Artist($artistId);
}
public function findById(int $artistId): ?\Gazelle\Artist {
$key = sprintf(self::ID_KEY, $artistId);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = self::$db->scalar("
public function findById(int $id): ?\Gazelle\Artist {
$key = sprintf(self::ID_KEY, $id);
$artistId = self::$cache->get_value($key);
if ($artistId === false) {
$artistId = self::$db->scalar("
SELECT ArtistID FROM artists_group WHERE ArtistID = ?
", $artistId
", $id
);
if (!is_null($id)) {
self::$cache->cache_value($key, $id, 7200);
if (!is_null($artistId)) {
self::$cache->cache_value($key, $artistId, 7200);
}
}
return $id ? new \Gazelle\Artist($id) : null;
return $artistId ? new \Gazelle\Artist($artistId) : null;
}
public function findByIdAndRevision(int $artistId, int $revisionId): ?\Gazelle\Artist {
$id = (int)self::$db->scalar("
public function findByIdAndRevision(int $id, int $revisionId): ?\Gazelle\Artist {
$artistId = (int)self::$db->scalar("
SELECT ag.ArtistID
FROM artists_group ag
INNER JOIN wiki_artists wa ON (wa.PageID = ag.ArtistID)
WHERE wa.PageID = ?
AND wa.RevisionID = ?
", $artistId, $revisionId
", $id, $revisionId
);
return $id ? new \Gazelle\Artist($id, null, $revisionId) : null;
return $artistId ? new \Gazelle\Artist($artistId, null, $revisionId) : null;
}
public function findByName(string $name): ?\Gazelle\Artist {
@@ -181,7 +181,7 @@ class Artist extends \Gazelle\BaseManager {
);
return array_filter(
array_map(
fn($id) => $tgMan->findById($id),
fn ($id) => $tgMan->findById($id),
self::$db->collect(0, false)
),
fn ($tgroup) => !empty($tgroup)

View File

@@ -49,12 +49,14 @@ class AutoEnable extends \Gazelle\BaseManager {
return $this->findById($enablerId);
}
public function findById(int $enableId): ?\Gazelle\User\AutoEnable {
[$id, $userId] = self::$db->row("
public function findById(int $id): ?\Gazelle\User\AutoEnable {
[$enableId, $userId] = self::$db->row("
SELECT ID, UserID FROM users_enable_requests WHERE ID = ?
", $enableId
", $id
);
return is_null($id) ? null : new \Gazelle\User\AutoEnable($id, new \Gazelle\User($userId));
return $enableId
? new \Gazelle\User\AutoEnable($enableId, new \Gazelle\User($userId))
: null;
}
/**

View File

@@ -31,19 +31,19 @@ class Blog extends \Gazelle\BaseManager {
return new \Gazelle\Blog(self::$db->inserted_id());
}
public function findById(int $blogId): ?\Gazelle\Blog {
$key = sprintf(self::ID_KEY, $blogId);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = self::$db->scalar("
public function findById(int $id): ?\Gazelle\Blog {
$key = sprintf(self::ID_KEY, $id);
$blogId = self::$cache->get_value($key);
if ($blogId === false) {
$blogId = (int)self::$db->scalar("
SELECT ID FROM blog WHERE ID = ?
", $blogId
", $id
);
if (!is_null($id)) {
self::$cache->cache_value($key, (int)$id, 7200);
if ($blogId) {
self::$cache->cache_value($key, $blogId, 7200);
}
}
return $id ? new \Gazelle\Blog((int)$id) : null;
return $blogId ? new \Gazelle\Blog($blogId) : null;
}
/**

View File

@@ -53,13 +53,13 @@ class Collage extends \Gazelle\BaseManager {
return new \Gazelle\Collage($id, $categoryId);
}
public function findById(int $collageId): ?\Gazelle\Collage {
$key = sprintf(self::ID_KEY, $collageId);
public function findById(int $id): ?\Gazelle\Collage {
$key = sprintf(self::ID_KEY, $id);
$idCategory = self::$cache->get_value($key);
if ($idCategory === false) {
$idCategory = self::$db->row("
SELECT ID, CategoryID FROM collages WHERE ID = ?
", $collageId
", $id
);
if ($idCategory) {
self::$cache->cache_value($key, $idCategory, 7200);

View File

@@ -55,23 +55,23 @@ class Comment extends \Gazelle\BaseManager {
}
public function findById(
int $postId,
int $id,
): \Gazelle\Comment\Artist|\Gazelle\Comment\Collage|\Gazelle\Comment\Request|\Gazelle\Comment\Torrent|null {
[$page, $pageId] = self::$db->row("
SELECT Page, PageID FROM comments WHERE ID = ?
", $postId
", $id
);
if (is_null($page)) {
return null;
}
$className = $this->className($page);
return new $className($pageId, 0, $postId); /** @phpstan-ignore-line */
return new $className($pageId, 0, $id); /** @phpstan-ignore-line */
}
public function findBodyById(int $postId): ?string {
public function findBodyById(int $id): ?string {
$body = self::$db->scalar("
SELECT Body FROM comments WHERE ID = ?
", $postId
", $id
);
return is_null($body) ? null : (string)$body;
}

View File

@@ -35,12 +35,12 @@ class Contest extends \Gazelle\Base {
return $this->findById($contestId);
}
public function findById(int $contestId): ?\Gazelle\Contest {
$id = (int)self::$db->scalar("
public function findById(int $id): ?\Gazelle\Contest {
$contestId = (int)self::$db->scalar("
SELECT contest_id FROM contest WHERE contest_id = ?
", $contestId
", $id
);
return $id ? new \Gazelle\Contest($id) : null;
return $contestId ? new \Gazelle\Contest($contestId) : null;
}
/**

View File

@@ -72,7 +72,7 @@ class FeaturedAlbum extends \Gazelle\BaseManager {
ON DUPLICATE KEY UPDATE
Started = now(),
Ended = NULL
", $tgroup->id(), $forum->lastThreadId(), $featureType->value
", $tgroup->id, $forum->lastThreadId(), $featureType->value
);
$tgroup->setFreeleech(
tracker: $tracker,
@@ -84,15 +84,15 @@ class FeaturedAlbum extends \Gazelle\BaseManager {
);
self::$db->commit();
return (new \Gazelle\FeaturedAlbum($featureType, $tgroup->id()))->flush();
return (new \Gazelle\FeaturedAlbum($featureType, $tgroup->id))->flush();
}
public function findById(int $tgroupId): ?\Gazelle\FeaturedAlbum {
public function findById(int $id): ?\Gazelle\FeaturedAlbum {
$type = self::$db->scalar("
SELECT Type
FROM featured_albums
WHERE GroupID = ?
", $tgroupId
", $id
);
if (is_null($type)) {
return null;
@@ -102,19 +102,19 @@ class FeaturedAlbum extends \Gazelle\BaseManager {
1 => FeaturedAlbumType::Showcase,
default => FeaturedAlbumType::AlbumOfTheMonth,
},
$tgroupId
$id
);
}
public function findByType(FeaturedAlbumType $type): ?\Gazelle\FeaturedAlbum {
$id = (int)self::$db->scalar("
$tgroupId = (int)self::$db->scalar("
SELECT GroupID
FROM featured_albums
WHERE Ended IS NULL
AND Type = ?
", $type->value
);
return $id ? new \Gazelle\FeaturedAlbum($type, $id) : null;
return $tgroupId ? new \Gazelle\FeaturedAlbum($type, $tgroupId) : null;
}
public function lookupFeaturedAlbumType(int $featuredAlbumType): FeaturedAlbumType {

View File

@@ -37,19 +37,19 @@ class Forum extends \Gazelle\BaseManager {
/**
* Instantiate a forum by its ID
*/
public function findById(int $forumId): ?\Gazelle\Forum {
$key = sprintf(self::ID_KEY, $forumId);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = self::$db->scalar("
public function findById(int $id): ?\Gazelle\Forum {
$key = sprintf(self::ID_KEY, $id);
$forumId = self::$cache->get_value($key);
if ($forumId === false) {
$forumId = (int)self::$db->scalar("
SELECT ID FROM forums WHERE ID = ?
", $forumId
", $id
);
if (!is_null($id)) {
self::$cache->cache_value($key, $id, 7200);
if ($forumId) {
self::$cache->cache_value($key, $forumId, 7200);
}
}
return $id ? new \Gazelle\Forum($id) : null;
return $forumId ? new \Gazelle\Forum($forumId) : null;
}
public function forumList(): array {

View File

@@ -21,19 +21,19 @@ class ForumCategory extends \Gazelle\BaseManager {
return $this->findById($id);
}
public function findById(int $fcatId): ?\Gazelle\ForumCategory {
$key = sprintf(self::ID_KEY, $fcatId);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = self::$db->scalar("
public function findById(int $id): ?\Gazelle\ForumCategory {
$key = sprintf(self::ID_KEY, $id);
$fcatId = self::$cache->get_value($key);
if ($fcatId === false) {
$fcatId = (int)self::$db->scalar("
SELECT ID FROM forums_categories WHERE ID = ?
", $fcatId
", $id
);
if (!is_null($id)) {
self::$cache->cache_value($key, $id, 7200);
if ($fcatId) {
self::$cache->cache_value($key, $fcatId, 7200);
}
}
return $id ? new \Gazelle\ForumCategory($id) : null;
return $fcatId ? new \Gazelle\ForumCategory($fcatId) : null;
}
/**

View File

@@ -18,38 +18,31 @@ class ForumPoll extends \Gazelle\BaseManager {
INSERT INTO forums_polls
(TopicID, Question, Answers)
Values (?, ?, ?)
", $thread->id(), $question, serialize($answerList)
", $thread->id, $question, serialize($answerList)
);
return $this->findById($thread->id());
return $this->findById($thread->id);
}
/**
* Instantiate a poll by its thread ID
*/
public function findById(int $threadId): ?\Gazelle\ForumPoll {
$key = sprintf(self::ID_KEY, $threadId);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = (int)self::$db->scalar("
public function findById(int $id): ?\Gazelle\ForumPoll {
$key = sprintf(self::ID_KEY, $id);
$threadId = self::$cache->get_value($key);
if ($threadId === false) {
$threadId = (int)self::$db->scalar("
SELECT TopicID FROM forums_polls WHERE TopicID = ?
", $threadId
", $id
);
if ($id) {
self::$cache->cache_value($key, $id, 7200);
if ($threadId) {
self::$cache->cache_value($key, $threadId, 7200);
}
}
return $id
? new \Gazelle\ForumPoll(new \Gazelle\ForumThread($id))
return $threadId
? new \Gazelle\ForumPoll(new \Gazelle\ForumThread($threadId))
: null;
}
/**
* Instantiate a poll by its thread
*/
public function findByThread(\Gazelle\Thread $thread): ?\Gazelle\ForumPoll {
return $this->findById($thread->id());
}
/**
* Find the poll featured on the front page.
*/

View File

@@ -19,11 +19,11 @@ class ForumPost extends \Gazelle\BaseManager {
/**
* Instantiate a post by its ID
*/
public function findById(int $postId): ?\Gazelle\ForumPost {
$id = self::$db->scalar("
public function findById(int $id): ?\Gazelle\ForumPost {
$postId = (int)self::$db->scalar("
SELECT ID FROM forums_posts WHERE ID = ?
", $postId
", $id
);
return $id ? new \Gazelle\ForumPost((int)$id) : null;
return $postId ? new \Gazelle\ForumPost($postId) : null;
}
}

View File

@@ -15,7 +15,7 @@ class ForumThread extends \Gazelle\BaseManager {
INSERT INTO forums_topics
(ForumID, Title, AuthorID, LastPostAuthorID)
Values (?, ?, ?, ?)
", $forum->id(), $title, $user->id, $user->id
", $forum->id, $title, $user->id, $user->id
);
$thread = new \Gazelle\ForumThread(self::$db->inserted_id());
$thread->addPost($user, $body);
@@ -28,30 +28,30 @@ class ForumThread extends \Gazelle\BaseManager {
/**
* Instantiate a thread by its ID
*/
public function findById(int $threadId): ?\Gazelle\ForumThread {
$key = sprintf(self::ID_KEY, $threadId);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = self::$db->scalar("
public function findById(int $id): ?\Gazelle\ForumThread {
$key = sprintf(self::ID_KEY, $id);
$threadId = self::$cache->get_value($key);
if ($threadId === false) {
$threadId = (int)self::$db->scalar("
SELECT ID FROM forums_topics WHERE ID = ?
", $threadId
", $id
);
if (!is_null($id)) {
self::$cache->cache_value($key, $id, 7200);
if ($threadId) {
self::$cache->cache_value($key, $threadId, 7200);
}
}
return $id ? new \Gazelle\ForumThread($id) : null;
return $threadId ? new \Gazelle\ForumThread($threadId) : null;
}
/**
* Find the thread from a post ID.
*/
public function findByPostId(int $postId): ?\Gazelle\ForumThread {
$id = (int)self::$db->scalar("
$threadId = (int)self::$db->scalar("
SELECT TopicID FROM forums_posts WHERE ID = ?
", $postId
);
return $id ? new \Gazelle\ForumThread($id) : null;
return $threadId ? new \Gazelle\ForumThread($threadId) : null;
}
public function lockOldThreads(): int {

View File

@@ -24,22 +24,22 @@ class ForumTransition extends \Gazelle\BaseManager {
$privilegeList = empty(trim($privileges))
? []
: array_map(fn($p) => trim($p), explode(',', trim($privileges)));
: array_map(fn ($p) => trim($p), explode(',', trim($privileges)));
$secondaryClassList = empty(trim($secondaryClasses))
? []
: array_map(fn($id) => (int)(trim($id)), explode(',', trim($secondaryClasses)));
: array_map(fn ($id) => (int)(trim($id)), explode(',', trim($secondaryClasses)));
$userIdList = empty(trim($userIds))
? []
: array_map(fn($id) => (int)(trim($id)), explode(',', trim($userIds)));
: array_map(fn ($id) => (int)(trim($id)), explode(',', trim($userIds)));
self::$db->prepared_query("
INSERT INTO forums_transitions
(source, destination, label, permission_class, permission_levels, permissions, user_ids)
VALUES (?, ?, ?, ?, ?, ?, ?)
", $source->id(),
$destination->id(),
", $source->id,
$destination->id,
$label,
$userClass,
implode(',', $secondaryClassList),
@@ -51,19 +51,19 @@ class ForumTransition extends \Gazelle\BaseManager {
return new \Gazelle\ForumTransition($id);
}
public function findById($transId): ?\Gazelle\ForumTransition {
$key = sprintf(self::ID_KEY, $transId);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = self::$db->scalar("
public function findById(int $id): ?\Gazelle\ForumTransition {
$key = sprintf(self::ID_KEY, $id);
$transitionId = self::$cache->get_value($key);
if ($transitionId === false) {
$transitionId = (int)self::$db->scalar("
SELECT forums_transitions_id FROM forums_transitions WHERE forums_transitions_id = ?
", $transId
", $id
);
if (!is_null($id)) {
self::$cache->cache_value($key, $id, 7200);
if ($transitionId) {
self::$cache->cache_value($key, $transitionId, 7200);
}
}
return $id ? new \Gazelle\ForumTransition($id) : null;
return $transitionId ? new \Gazelle\ForumTransition($transitionId) : null;
}
public function transitionList(): array {
@@ -97,10 +97,16 @@ class ForumTransition extends \Gazelle\BaseManager {
* skip the transition if the viewer is not staff.
*/
public function userThreadTransitionList(\Gazelle\User $user, \Gazelle\ForumThread $thread): array {
return array_filter($this->transitionList(), fn ($t) => $t->hasUserForThread($user, $thread));
return array_filter(
$this->transitionList(),
fn ($t) => $t->hasUserForThread($user, $thread)
);
}
public function threadTransitionList(\Gazelle\User $user, \Gazelle\ForumThread $thread): array {
return array_filter($this->userThreadTransitionList($user, $thread), fn ($t) => $t->sourceId() == $thread->forum()->id());
return array_filter(
$this->userThreadTransitionList($user, $thread),
fn ($t) => $t->sourceId() == $thread->forum()->id
);
}
}

View File

@@ -10,19 +10,19 @@ class NotificationTicket {
public function create(\Gazelle\Torrent $torrent): \Gazelle\NotificationTicket {
$this->pg()->prepared_query("
INSERT INTO notification_ticket (id_torrent) VALUES (?)
", $torrent->id()
", $torrent->id
);
return $this->findById($torrent->id());
return $this->findById($torrent->id);
}
public function findById(int $torrentId): ?\Gazelle\NotificationTicket {
public function findById(int $id): ?\Gazelle\NotificationTicket {
if (
$this->pg()->scalar("
select 1 from notification_ticket where id_torrent = ?
", $torrentId
", $id
)
) {
return new \Gazelle\NotificationTicket($torrentId);
return new \Gazelle\NotificationTicket($id);
}
return null;
}

View File

@@ -19,34 +19,34 @@ class PM extends \Gazelle\BaseUser {
return $this->user()->location();
}
public function findById(int $pmId): ?\Gazelle\PM {
$key = sprintf(self::ID_KEY, $pmId, $this->user->id);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = (int)self::$db->scalar("
public function findById(int $id): ?\Gazelle\PM {
$key = sprintf(self::ID_KEY, $id, $this->user->id);
$pmId = self::$cache->get_value($key);
if ($pmId === false) {
$pmId = (int)self::$db->scalar("
SELECT pcu.ConvID
FROM pm_conversations_users pcu
WHERE pcu.ConvID = ?
AND pcu.UserID = ?
", $pmId, $this->user->id
", $id, $this->user->id
);
if ($id) {
self::$cache->cache_value($key, $id, 7200);
if ($pmId) {
self::$cache->cache_value($key, $pmId, 7200);
}
}
return $id ? new \Gazelle\PM($id, $this->user) : null;
return $pmId ? new \Gazelle\PM($pmId, $this->user) : null;
}
public function findByPostId(int $postId): ?\Gazelle\PM {
$id = (int)self::$db->scalar("
public function findByPostId(int $id): ?\Gazelle\PM {
$pmId = (int)self::$db->scalar("
SELECT pcu.ConvID
FROM pm_conversations_users pcu
INNER JOIN pm_messages pm USING (ConvID)
WHERE pcu.UserID = ?
AND pm.ID = ?
", $this->user->id, $postId
", $this->user->id, $id
);
return $id ? new \Gazelle\PM($id, $this->user) : null;
return $pmId ? new \Gazelle\PM($pmId, $this->user) : null;
}
public function remove(): int {

View File

@@ -25,27 +25,27 @@ class Privilege extends \Gazelle\BaseManager {
return new \Gazelle\Privilege(self::$db->inserted_id());
}
public function findById(int $privilegeId): ?\Gazelle\Privilege {
$key = sprintf(self::ID_KEY, $privilegeId);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = (int)self::$db->scalar("
public function findById(int $id): ?\Gazelle\Privilege {
$key = sprintf(self::ID_KEY, $id);
$privilegeId = self::$cache->get_value($key);
if ($privilegeId === false) {
$privilegeId = (int)self::$db->scalar("
SELECT ID FROM permissions WHERE ID = ?
", $privilegeId
", $id
);
if ($id) {
self::$cache->cache_value($key, $id, 7200);
if ($privilegeId) {
self::$cache->cache_value($key, $privilegeId, 7200);
}
}
return $id ? new \Gazelle\Privilege($id) : null;
return $privilegeId ? new \Gazelle\Privilege($privilegeId) : null;
}
public function findByLevel(int $level): ?\Gazelle\Privilege {
$id = (int)self::$db->scalar("
$privilegeId = (int)self::$db->scalar("
SELECT ID FROM permissions WHERE Level = ?
", $level
);
return $id ? new \Gazelle\Privilege($id) : null;
return $privilegeId ? new \Gazelle\Privilege($privilegeId) : null;
}
protected function info(): array {

View File

@@ -24,22 +24,21 @@ class Report extends \Gazelle\BaseManager {
return $this->findById($id);
}
public function findById(int $reportId): ?\Gazelle\Report {
$key = sprintf(self::ID_KEY, $reportId);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = self::$db->scalar("
public function findById(int $id): ?\Gazelle\Report {
$key = sprintf(self::ID_KEY, $id);
$reportId = self::$cache->get_value($key);
if ($reportId === false) {
$reportId = (int)self::$db->scalar("
SELECT ID FROM reports WHERE ID = ?
", $reportId
", $id
);
if (!is_null($id)) {
self::$cache->cache_value($key, $id, 7200);
if ($reportId) {
self::$cache->cache_value($key, $reportId, 7200);
}
}
if (!$id) {
return null;
}
return (new \Gazelle\Report($id))->setUserManager($this->userMan);
return $reportId
? (new \Gazelle\Report($reportId))->setUserManager($this->userMan)
: null;
}
public function findByReportedUser(\Gazelle\User $user): array {
@@ -52,7 +51,7 @@ class Report extends \Gazelle\BaseManager {
", $user->id
);
$reportList = self::$db->collect(0, false);
return array_map(fn($id) => $this->findById($id), $reportList);
return array_map(fn ($id) => $this->findById($id), $reportList);
}
public function decorate(

View File

@@ -29,7 +29,7 @@ class ReportAuto extends \Gazelle\BaseManager {
}
public function create(\Gazelle\User $user, \Gazelle\ReportAuto\Type $type, array $data, string|null $time = null): \Gazelle\ReportAuto {
$args = [$user->id, $type->id(), json_encode($data)];
$args = [$user->id, $type->id, json_encode($data)];
if ($time) {
// time is an iso timestring
$qryCols = ', created';
@@ -51,14 +51,18 @@ class ReportAuto extends \Gazelle\BaseManager {
return $this->instantiateReportAuto((int)$id, $category);
}
public function findById(int $reportId): ?\Gazelle\ReportAuto {
[$id, $category] = $this->pg()->row("
SELECT ra.id_report_auto, rat.id_report_auto_category
FROM report_auto ra JOIN report_auto_type rat USING (id_report_auto_type)
public function findById(int $id): ?\Gazelle\ReportAuto {
[$reportId, $category] = $this->pg()->row("
SELECT ra.id_report_auto,
rat.id_report_auto_category
FROM report_auto ra
INNER JOIN report_auto_type rat USING (id_report_auto_type)
WHERE ra.id_report_auto = ?
", $reportId
", $id
);
return is_null($id) ? null : $this->instantiateReportAuto((int)$id, $category);
return $reportId
? $this->instantiateReportAuto($reportId, $category)
: null;
}
/**
@@ -74,9 +78,11 @@ class ReportAuto extends \Gazelle\BaseManager {
return $this->pg()->prepared_query("
UPDATE report_auto SET
id_owner = ?
WHERE id_user = ? AND id_owner IS NULL
WHERE id_owner IS NULL
AND id_user = ?
$typeWhere
", $claimer->id(), $userId, ...$args);
", $claimer->id, $userId, ...$args
);
}
/**
@@ -90,11 +96,14 @@ class ReportAuto extends \Gazelle\BaseManager {
$args[] = $typeId;
}
return $this->pg()->prepared_query("
UPDATE report_auto
SET id_owner = ?, resolved = now()
WHERE id_user = ? AND resolved IS NULL
UPDATE report_auto SET
resolved = now(),
id_owner = ?
WHERE resolved IS NULL
AND id_user = ?
$typeWhere
", $resolver->id(), $userId, ...$args);
", $resolver->id, $userId, ...$args
);
}
/**
@@ -105,8 +114,10 @@ class ReportAuto extends \Gazelle\BaseManager {
public function deleteComment(int $commentId, \Gazelle\User $user): int {
return $this->pg()->prepared_query("
DELETE FROM report_auto_comment
WHERE id_report_auto_comment = ? AND id_user = ?
", $commentId, $user->id);
WHERE id_report_auto_comment = ?
AND id_user = ?
", $commentId, $user->id
);
}
/**
@@ -117,9 +128,11 @@ class ReportAuto extends \Gazelle\BaseManager {
public function editComment(int $commentId, \Gazelle\User $user, string $message): int {
return $this->pg()->prepared_query("
UPDATE report_auto_comment SET
comment = ?
WHERE id_report_auto_comment = ? AND id_user = ?
", $message, $commentId, $user->id);
comment = ?
WHERE id_report_auto_comment = ?
AND id_user = ?
", $message, $commentId, $user->id
);
}
protected function instantiateReportAuto(int $id, ?int $category): \Gazelle\ReportAuto {

View File

@@ -21,8 +21,9 @@ class ReportAutoType extends \Gazelle\BaseManager {
public function findByName(string $name): ?\Gazelle\ReportAuto\Type {
$id = $this->pg()->scalar("
SELECT id_report_auto_type FROM report_auto_type WHERE name = ?
", $name);
SELECT id_report_auto_type FROM report_auto_type WHERE name = ?
", $name
);
return $id ? $this->findById($id) : null;
}

View File

@@ -40,19 +40,19 @@ class Request extends \Gazelle\BaseManager {
return $request;
}
public function findById(int $requestId): ?\Gazelle\Request {
$key = sprintf(self::ID_KEY, $requestId);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = (int)self::$db->scalar("
public function findById(int $id): ?\Gazelle\Request {
$key = sprintf(self::ID_KEY, $id);
$requestId = self::$cache->get_value($key);
if ($requestId === false) {
$requestId = (int)self::$db->scalar("
SELECT ID FROM requests WHERE ID = ?
", $requestId
", $id
);
if ($id) {
self::$cache->cache_value($key, $id, 7200);
if ($requestId) {
self::$cache->cache_value($key, $requestId, 7200);
}
}
return $id ? new \Gazelle\Request($id) : null;
return $requestId ? new \Gazelle\Request($requestId) : null;
}
/**
@@ -73,11 +73,14 @@ class Request extends \Gazelle\BaseManager {
LIMIT 0, ?
", $user->id, $limit
);
return array_map(fn($id) => $this->findById($id), self::$db->collect(0, false));
return array_map(
fn ($id) => $this->findById($id),
self::$db->collect(0, false)
);
}
public function findByArtist(\Gazelle\Artist $artist): array {
$key = sprintf(\Gazelle\Artist::CACHE_REQUEST_ARTIST, $artist->id());
$key = sprintf(\Gazelle\Artist::CACHE_REQUEST_ARTIST, $artist->id);
$requestList = self::$cache->get_value($key);
if ($requestList === false) {
self::$db->prepared_query("
@@ -90,7 +93,7 @@ class Request extends \Gazelle\BaseManager {
AND aa.ArtistID = ?
GROUP BY r.ID
ORDER BY count(v.UserID) DESC, sum(v.Bounty) DESC
", $artist->id()
", $artist->id
);
$requestList = self::$db->collect(0, false);
self::$cache->cache_value($key, $requestList, 3600);
@@ -99,7 +102,7 @@ class Request extends \Gazelle\BaseManager {
}
public function findByTGroup(\Gazelle\TGroup $tgroup): array {
$key = sprintf(\Gazelle\TGroup::CACHE_REQUEST_TGROUP, $tgroup->id());
$key = sprintf(\Gazelle\TGroup::CACHE_REQUEST_TGROUP, $tgroup->id);
$requestList = self::$cache->get_value($key);
if ($requestList === false) {
self::$db->prepared_query("
@@ -109,7 +112,7 @@ class Request extends \Gazelle\BaseManager {
WHERE r.TorrentID = 0
AND tg.ID = ?
ORDER BY r.TimeAdded ASC
", $tgroup->id()
", $tgroup->id
);
$requestList = self::$db->collect(0, false);
self::$cache->cache_value($key, $requestList, 3600);
@@ -124,7 +127,7 @@ class Request extends \Gazelle\BaseManager {
INNER JOIN reportsv2 AS rep ON (rep.TorrentID = req.TorrentID)
WHERE rep.Status != 'Resolved'
AND req.TorrentID = ?
", $torrent->id()
", $torrent->id
);
return array_map(fn($id) => $this->findById($id), self::$db->collect(0, false));
}

View File

@@ -23,12 +23,12 @@ class StaffBlog extends \Gazelle\Base {
return $this->findById($id);
}
public function findById(int $staffBlogId): ?\Gazelle\StaffBlog {
$id = (int)self::$db->scalar("
public function findById(int $id): ?\Gazelle\StaffBlog {
$staffBlogId = (int)self::$db->scalar("
SELECT ID FROM staff_blog WHERE ID = ?
", $staffBlogId
", $id
);
return $id ? new \Gazelle\StaffBlog($id) : null;
return $staffBlogId ? new \Gazelle\StaffBlog($staffBlogId) : null;
}
/**

View File

@@ -16,19 +16,19 @@ class StaffGroup extends \Gazelle\BaseManager {
return new \Gazelle\StaffGroup(self::$db->inserted_id());
}
public function findById(int $staffGroupId): ?\Gazelle\StaffGroup {
$key = sprintf(self::ID_KEY, $staffGroupId);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = self::$db->scalar("
public function findById(int $id): ?\Gazelle\StaffGroup {
$key = sprintf(self::ID_KEY, $id);
$staffGroupId = self::$cache->get_value($key);
if ($staffGroupId === false) {
$staffGroupId = (int)self::$db->scalar("
SELECT ID FROM staff_groups WHERE ID = ?
", $staffGroupId
", $id
);
if (!is_null($id)) {
self::$cache->cache_value($key, $id, 7200);
if ($staffGroupId) {
self::$cache->cache_value($key, $staffGroupId, 7200);
}
}
return $id ? new \Gazelle\StaffGroup($id) : null;
return $staffGroupId ? new \Gazelle\StaffGroup($staffGroupId) : null;
}
public function groupList(): array {

View File

@@ -27,27 +27,27 @@ class StaffPM extends \Gazelle\BaseManager {
return $this->findById($convId);
}
public function findById(int $pmId): ?\Gazelle\StaffPM {
$key = sprintf(self::ID_KEY, $pmId);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = self::$db->scalar("
public function findById(int $id): ?\Gazelle\StaffPM {
$key = sprintf(self::ID_KEY, $id);
$pmId = self::$cache->get_value($key);
if ($pmId === false) {
$pmId = (int)self::$db->scalar("
SELECT ID FROM staff_pm_conversations WHERE ID = ?
", $pmId
", $id
);
if (!is_null($id)) {
self::$cache->cache_value($key, $id, 7200);
if ($pmId) {
self::$cache->cache_value($key, $pmId, 7200);
}
}
return $id ? new \Gazelle\StaffPM((int)$id) : null;
return $pmId ? new \Gazelle\StaffPM($pmId) : null;
}
public function findByPostId(int $postId): ?\Gazelle\StaffPM {
$id = (int)self::$db->scalar("
$pmId = (int)self::$db->scalar("
SELECT ConvID FROM staff_pm_messages WHERE ID = ?
", $postId
);
return $id ? new \Gazelle\StaffPM($id) : null;
return $pmId ? new \Gazelle\StaffPM($pmId) : null;
}
public function findAllByUser(\Gazelle\User $user): array {

View File

@@ -27,7 +27,7 @@ class TGroup extends \Gazelle\BaseManager {
", $categoryId, $name, $description, $year, $recordLabel, $catalogueNumber, $image, $releaseType, (int)$showcase
);
$id = self::$db->inserted_id();
$tgroup = $this->findById((int)$id);
$tgroup = $this->findById($id);
self::$cache->increment_value('stats_group_count');
if ($tgroup->categoryName() === 'Music') {
self::$cache->decrement('stats_album_count');
@@ -87,22 +87,22 @@ class TGroup extends \Gazelle\BaseManager {
return $new;
}
public function findById(int $tgroupId): ?\Gazelle\TGroup {
$key = sprintf(self::ID_KEY, $tgroupId);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = self::$db->scalar("
public function findById(int $id): ?\Gazelle\TGroup {
$key = sprintf(self::ID_KEY, $id);
$tgroupId = self::$cache->get_value($key);
if ($tgroupId === false) {
$tgroupId = (int)self::$db->scalar("
SELECT ID FROM torrents_group WHERE ID = ?
", $tgroupId
", $id
);
if (!is_null($id)) {
self::$cache->cache_value($key, $id, 7200);
if ($tgroupId) {
self::$cache->cache_value($key, $tgroupId, 7200);
}
}
if (!$id) {
if (!$tgroupId) {
return null;
}
$tgroup = new \Gazelle\TGroup($id);
$tgroup = new \Gazelle\TGroup($tgroupId);
if (isset($this->viewer)) {
$tgroup->setViewer($this->viewer);
}

View File

@@ -36,19 +36,19 @@ class Tag extends \Gazelle\BaseManager {
: null;
}
public function findById(int $tagId): ?\Gazelle\Tag {
$key = sprintf(self::ID_KEY, $tagId);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = (int)self::$db->scalar("
public function findById(int $id): ?\Gazelle\Tag {
$key = sprintf(self::ID_KEY, $id);
$tagId = self::$cache->get_value($key);
if ($tagId === false) {
$tagId = (int)self::$db->scalar("
SELECT ID FROM tags WHERE ID = ?
", $tagId
", $id
);
if ($id) {
self::$cache->cache_value($key, $id, 7200);
if ($tagId) {
self::$cache->cache_value($key, $tagId, 7200);
}
}
return $id ? new \Gazelle\Tag($id) : null;
return $tagId ? new \Gazelle\Tag($tagId) : null;
}
public function findByName(string $name): ?\Gazelle\Tag {

View File

@@ -55,7 +55,7 @@ class Torrent extends \Gazelle\BaseManager {
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?
)", $tgroup->id(), $user->id, $media, $format, $encoding,
)", $tgroup->id, $user->id, $media, $format, $encoding,
$isRemaster ? '1' : '0', $remasterYear, $remasterTitle, $remasterRecordLabel, $remasterCatalogueNumber,
$infohash, $isScene ? '1' : '0', $logScore, $hasChecksum ? '1' : '0', $hasLog ? '1' : '0',
$hasCue ? '1' : '0', $hasLogInDB ? '1' : '0', $filePath, count($fileList), implode("\n", $fileList),
@@ -64,7 +64,7 @@ class Torrent extends \Gazelle\BaseManager {
$torrent = $this->findById(self::$db->inserted_id());
self::$db->prepared_query('
INSERT INTO torrents_leech_stats (TorrentID) VALUES (?)
', $torrent->id()
', $torrent->id
);
$tgroup->flush();
$torrent->lockUpload();
@@ -78,22 +78,22 @@ class Torrent extends \Gazelle\BaseManager {
return $torrent;
}
public function findById(int $torrentId): ?\Gazelle\Torrent {
$key = sprintf(self::ID_KEY, $torrentId);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = self::$db->scalar("
public function findById(int $id): ?\Gazelle\Torrent {
$key = sprintf(self::ID_KEY, $id);
$torrentId = self::$cache->get_value($key);
if ($torrentId === false) {
$torrentId = self::$db->scalar("
SELECT ID FROM torrents WHERE ID = ?
", $torrentId
", $id
);
if (!is_null($id)) {
self::$cache->cache_value($key, $id, 7200);
if ($torrentId) {
self::$cache->cache_value($key, $torrentId, 7200);
}
}
if (!$id) {
if (!$torrentId) {
return null;
}
$torrent = new \Gazelle\Torrent($id);
$torrent = new \Gazelle\Torrent($torrentId);
if (isset($this->viewer)) {
$torrent->setViewer($this->viewer);
}
@@ -221,7 +221,7 @@ class Torrent extends \Gazelle\BaseManager {
$torrent = $this->findById($torrentId);
if ($torrent) {
$result[$torrentId] = [
'id' => $torrent->id(),
'id' => $torrent->id,
'link' => $torrent->fullLink(),
];
}
@@ -605,7 +605,7 @@ class Torrent extends \Gazelle\BaseManager {
}
return $url . sprintf(
'<a title="%s" href="/torrents.php?id=%d&torrentid=%d#torrent%d">%s%s</a>%s',
$tgroup->hashTag(), $tgroup->id(), $id, $id, display_str($tgroup->name()), $label,
$tgroup->hashTag(), $tgroup->id, $id, $id, display_str($tgroup->name()), $label,
$meta . ($isDeleted ? ' <i>deleted</i>' : '')
);
}

View File

@@ -37,7 +37,7 @@ class Report extends \Gazelle\BaseManager {
INSERT INTO reportsv2
(ReporterID, TorrentID, Type, UserComment, ExtraID, Track, Image, Link)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
", $user->id, $torrent->id(), $reportType->type(), $reason, $otherIdList, $track, $image, $link
", $user->id, $torrent->id, $reportType->type(), $reason, $otherIdList, $track, $image, $link
);
$report = new \Gazelle\Torrent\Report(self::$db->inserted_id(), $this->torMan);
@@ -48,26 +48,28 @@ class Report extends \Gazelle\BaseManager {
);
}
self::$cache->delete_value(sprintf(\Gazelle\TorrentAbstract::CACHE_REPORTLIST, $torrent->id()));
self::$cache->delete_value(sprintf(\Gazelle\TorrentAbstract::CACHE_REPORTLIST, $torrent->id));
self::$cache->increment('num_torrent_reportsv2');
$torrent->flush();
return $report;
}
public function findById(int $reportId): ?\Gazelle\Torrent\Report {
$key = sprintf(self::ID_KEY, $reportId);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = (int)self::$db->scalar("
public function findById(int $id): ?\Gazelle\Torrent\Report {
$key = sprintf(self::ID_KEY, $id);
$reportId = self::$cache->get_value($key);
if ($reportId === false) {
$reportId = (int)self::$db->scalar("
SELECT ID FROM reportsv2 WHERE ID = ?
", $reportId
", $id
);
if ($id) {
self::$cache->cache_value($key, $id, 7200);
if ($reportId) {
self::$cache->cache_value($key, $reportId, 7200);
}
}
return $id ? new \Gazelle\Torrent\Report($reportId, $this->torMan) : null;
return $reportId
? new \Gazelle\Torrent\Report($reportId, $this->torMan)
: null;
}
public function findNewest(): ?\Gazelle\Torrent\Report {
@@ -75,28 +77,28 @@ class Report extends \Gazelle\BaseManager {
(int)self::$db->scalar("
SELECT ID
FROM reportsv2
WHERE r.Status = 'New'
ORDER BY ReportedTime ASC
WHERE Status = 'New'
ORDER BY ReportedTime DESC
LIMIT 1
")
);
}
public function existsRecent(int $torrentId, int $ViewerId): bool {
public function existsRecent(\Gazelle\Torrent $torrent, \Gazelle\User $user): bool {
return (bool)self::$db->scalar("
SELECT ID
FROM reportsv2
WHERE ReportedTime > now() - INTERVAL 5 SECOND
AND TorrentID = ?
AND ReporterID = ?
", $torrentId, $ViewerId);
", $torrent->id, $user->id);
}
public function categories(): array {
return $this->categories;
}
public function newSummary(ReportType $reportTypeMan): array {
public function newSummary(ReportType $reportTypeMan = new ReportType()): array {
self::$db->prepared_query("
SELECT Type AS type,
count(*) AS total
@@ -120,7 +122,7 @@ class Report extends \Gazelle\BaseManager {
return $list;
}
public function inProgressSummary(\Gazelle\Manager\User $userMan): array {
public function inProgressSummary(\Gazelle\Manager\User $userMan = new \Gazelle\Manager\User()): array {
self::$db->prepared_query("
SELECT r.ResolverID AS user_id,
count(*) AS total
@@ -132,7 +134,7 @@ class Report extends \Gazelle\BaseManager {
return $this->decorateUser($userMan, self::$db->to_array(false, MYSQLI_ASSOC, false));
}
public function resolvedSummary(\Gazelle\Manager\User $userMan): array {
public function resolvedSummary(\Gazelle\Manager\User $userMan = new \Gazelle\Manager\User()): array {
self::$db->prepared_query("
SELECT r.ResolverID AS user_id,
count(*) AS total
@@ -150,50 +152,50 @@ class Report extends \Gazelle\BaseManager {
count(*) AS total
FROM reportsv2 AS r
WHERE r.ResolverID > 0
AND r.LastChangeTime > now() - INTERVAL $interval
AND r.LastChangeTime > now() - INTERVAL $interval
GROUP BY r.ResolverID
ORDER BY total DESC
");
return $this->decorateUser($userMan, self::$db->to_array(false, MYSQLI_ASSOC, false));
}
public function resolvedLastDay(\Gazelle\Manager\User $userMan): array {
public function resolvedLastDay(\Gazelle\Manager\User $userMan = new \Gazelle\Manager\User()): array {
return $this->resolvedLastInterval($userMan, '1 DAY');
}
public function resolvedLastWeek(\Gazelle\Manager\User $userMan): array {
public function resolvedLastWeek(\Gazelle\Manager\User $userMan = new \Gazelle\Manager\User()): array {
return $this->resolvedLastInterval($userMan, '1 WEEK');
}
public function resolvedLastMonth(\Gazelle\Manager\User $userMan): array {
public function resolvedLastMonth(\Gazelle\Manager\User $userMan = new \Gazelle\Manager\User()): array {
return $this->resolvedLastInterval($userMan, '1 MONTH');
}
/**
* How many open reports exist for this group
*/
public function totalReportsGroup(int $groupId): int {
public function totalReportsTGroup(\Gazelle\TGroup $tgroup): int {
return (int)self::$db->scalar("
SELECT count(*)
FROM reportsv2 AS r
INNER JOIN torrents AS t ON (t.ID = r.TorrentID)
WHERE r.Status != 'Resolved'
AND t.GroupID = ?
", $groupId
", $tgroup->id
);
}
/**
* How many open reports exist for this uploader
*/
public function totalReportsUploader(int $userId): int {
public function totalReportsUploader(\Gazelle\User $user): int {
return (int)self::$db->scalar("
SELECT count(*)
FROM reportsv2 AS r
INNER JOIN torrents AS t ON (t.ID = r.TorrentID)
WHERE r.Status != 'Resolved'
AND t.UserID = ?
", $userId
", $user->id
);
}
@@ -203,7 +205,7 @@ class Report extends \Gazelle\BaseManager {
public function totalReportsTorrent(\Gazelle\Torrent|\Gazelle\TorrentDeleted $torrent): int {
return (int)self::$db->scalar("
SELECT count(*) FROM reportsv2 WHERE Status != 'Resolved' AND TorrentID = ?
", $torrent->id()
", $torrent->id
);
}
@@ -222,14 +224,14 @@ class Report extends \Gazelle\BaseManager {
$delargs = [];
if (isset($this->filter['reporter'])) {
$cond[] = 'r.ReporterID = ?';
$args[] = $this->filter['reporter']->id();
$args[] = $this->filter['reporter']->id;
}
if (isset($this->filter['handler'])) {
$cond[] = 'r.ResolverID = ?';
$args[] = $this->filter['handler']->id();
$args[] = $this->filter['handler']->id;
}
if (isset($this->filter['uploader'])) {
$userId = $this->filter['uploader']->id();
$userId = $this->filter['uploader']->id;
$cond[] = 't.UserID = ?';
$args[] = $userId;
$delcond[] = '(dt.UserID IS NULL OR dt.UserID = ?)';
@@ -288,7 +290,11 @@ class Report extends \Gazelle\BaseManager {
);
}
public function searchList(\Gazelle\Manager\User $userMan, int $limit, int $offset): array {
public function searchList(
int $limit,
int $offset,
\Gazelle\Manager\User $userMan = new \Gazelle\Manager\User(),
): array {
[$cond, $args, $delcond, $delargs] = $this->searchConfigure();
$where = (count($cond) == 0 && count($delcond) == 0)
? ''

View File

@@ -7,21 +7,21 @@ class ReportType extends \Gazelle\Base {
final public const NAME_KEY = 'zz_trtn_%s';
final public const TYPE_KEY = 'zz_trtt_%s';
public function findById(int $reportTypeId): ?\Gazelle\Torrent\ReportType {
$key = sprintf(self::ID_KEY, $reportTypeId);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = self::$db->scalar("
public function findById(int $id): ?\Gazelle\Torrent\ReportType {
$key = sprintf(self::ID_KEY, $id);
$reportTypeId = self::$cache->get_value($key);
if ($reportTypeId === false) {
$reportTypeId = (int)self::$db->scalar("
SELECT torrent_report_configuration_id
FROM torrent_report_configuration
WHERE torrent_report_configuration_id = ?
", $reportTypeId
", $id
);
if (!is_null($id)) {
self::$cache->cache_value($key, $id, 0);
if ($reportTypeId) {
self::$cache->cache_value($key, $reportTypeId, 0);
}
}
return $id ? new \Gazelle\Torrent\ReportType($id) : null;
return $reportTypeId ? new \Gazelle\Torrent\ReportType($reportTypeId) : null;
}
public function findByName(string $name): ?\Gazelle\Torrent\ReportType {

View File

@@ -13,21 +13,21 @@ class TorrentLog extends \Gazelle\Base {
INSERT INTO torrents_logs
(TorrentID, Score, `Checksum`, FileName, Ripper, RipperVersion, `Language`, ChecksumState, Details, LogcheckerVersion)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
', $torrent->id(), $logfile->score(), $logfile->checksumStatus(), $logfile->filename(),
', $torrent->id, $logfile->score(), $logfile->checksumStatus(), $logfile->filename(),
$logfile->ripper(), $logfile->ripperVersion(), $logfile->language(), $logfile->checksumState(), $logfile->detailsAsString(),
$checkerVersion
);
$logId = self::$db->inserted_id();
$this->ripFiler->put($logfile->filepath(), [$torrent->id(), $logId]);
$this->htmlFiler->put($logfile->text(), [$torrent->id(), $logId]);
$this->ripFiler->put($logfile->filepath(), [$torrent->id, $logId]);
$this->htmlFiler->put($logfile->text(), [$torrent->id, $logId]);
return $this->findById($torrent, $logId);
}
public function findById(\Gazelle\Torrent $torrent, int $logId): ?\Gazelle\TorrentLog {
$id = (int)self::$db->scalar("
public function findById(\Gazelle\Torrent $torrent, int $id): ?\Gazelle\TorrentLog {
$logId = (int)self::$db->scalar("
SELECT LogID FROM torrents_logs WHERE TorrentID = ? AND LogID = ?
", $torrent->id(), $logId
", $torrent->id, $id
);
return $id ? new \Gazelle\TorrentLog($torrent, $id) : null;
return $logId ? new \Gazelle\TorrentLog($torrent, $logId) : null;
}
}

View File

@@ -34,19 +34,19 @@ class User extends \Gazelle\BaseManager {
/**
* Get a User object based on their ID
*/
public function findById(int $userId): ?\Gazelle\User {
$key = sprintf(self::ID_KEY, $userId);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = self::$db->scalar("
public function findById(int $id): ?\Gazelle\User {
$key = sprintf(self::ID_KEY, $id);
$userId = self::$cache->get_value($key);
if ($userId === false) {
$userId = (int)self::$db->scalar("
SELECT ID FROM users_main WHERE ID = ?
", $userId
", $id
);
if (!is_null($id)) {
self::$cache->cache_value($key, $id, 7200);
if ($userId) {
self::$cache->cache_value($key, $userId, 7200);
}
}
return $id ? new \Gazelle\User($id) : null;
return $userId ? new \Gazelle\User($userId) : null;
}
/**
@@ -161,7 +161,7 @@ class User extends \Gazelle\BaseManager {
if ($user->warningExpiry()) {
$display .= '<a href="wiki.php?action=article&amp;name=warnings"><img loading="lazy" class="tooltip" src="'
. STATIC_SERVER . '/common/symbols/warned.png" alt="Warned" title="Warned'
. ($viewer->id() == $userId
. ($viewer->id == $userId
? ' - Expires ' . date('Y-m-d H:i', (int)strtotime($user->warningExpiry()))
: '')
. '" /></a>';
@@ -619,7 +619,7 @@ class User extends \Gazelle\BaseManager {
public function sendSnatchPm(\Gazelle\User $viewer, \Gazelle\Torrent $torrent, string $subject, string $body): int {
self::$db->prepared_query('
SELECT uid FROM xbt_snatched WHERE fid = ?
', $torrent->id()
', $torrent->id
);
$snatchers = self::$db->collect(0, false);
@@ -632,7 +632,7 @@ class User extends \Gazelle\BaseManager {
$total = count($snatchers);
$this->logger()->general(
$viewer->username() . " sent a mass PM to $total snatcher" . plural($total)
. " of torrent {$torrent->id()} ({$torrent->group()->text()})"
. " of torrent {$torrent->id} ({$torrent->group()->text()})"
);
return $total;
}
@@ -1728,7 +1728,7 @@ class User extends \Gazelle\BaseManager {
Expired = TRUE
WHERE TorrentID = ?
AND UserID = ?
", $torrent->id(), $user->id
", $torrent->id, $user->id
);
}
self::$cache->delete_multi(array_keys($clear));

View File

@@ -29,19 +29,19 @@ class UserNavigation extends \Gazelle\BaseManager {
return new \Gazelle\UserNavigation($id);
}
public function findById(int $controlId): ?\Gazelle\UserNavigation {
$key = sprintf(self::ID_KEY, $controlId);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = self::$db->scalar("
SELECT ID FROM forums_nav WHERE ID = ?
", $controlId
public function findById(int $id): ?\Gazelle\UserNavigation {
$key = sprintf(self::ID_KEY, $id);
$navigationId = self::$cache->get_value($key);
if ($navigationId === false) {
$navigationId = (int)self::$db->scalar("
SELECT id FROM nav_items WHERE id = ?
", $id
);
if (!is_null($id)) {
self::$cache->cache_value($key, $id, 7200);
if ($navigationId) {
self::$cache->cache_value($key, $navigationId, 7200);
}
}
return $id ? new \Gazelle\UserNavigation($id) : null;
return $navigationId ? new \Gazelle\UserNavigation($navigationId) : null;
}
public function userControlList(\Gazelle\User $user): array {

View File

@@ -34,19 +34,19 @@ class Wiki extends \Gazelle\BaseManager {
*
* @return \Gazelle\Wiki|null id of article if it exists
*/
public function findById(int $wikiId): ?\Gazelle\Wiki {
$key = sprintf(self::ID_KEY, $wikiId);
$id = self::$cache->get_value($key);
if ($id === false) {
$id = self::$db->scalar("
public function findById(int $id): ?\Gazelle\Wiki {
$key = sprintf(self::ID_KEY, $id);
$wikiId = self::$cache->get_value($key);
if ($wikiId === false) {
$wikiId = (int)self::$db->scalar("
SELECT ID FROM wiki_articles WHERE ID = ?
", $wikiId
", $id
);
if (!is_null($id)) {
self::$cache->cache_value($key, $id, 7200);
if ($wikiId) {
self::$cache->cache_value($key, $wikiId, 7200);
}
}
return $id ? new \Gazelle\Wiki($id) : null;
return $wikiId ? new \Gazelle\Wiki($wikiId) : null;
}
/**

View File

@@ -3,7 +3,7 @@
namespace Gazelle;
class ReleaseType extends Base {
protected const CACHE_KEY = 'release_type';
final public const CACHE_KEY = 'release_type';
protected array $list;

View File

@@ -9,7 +9,7 @@ class Type extends \Gazelle\Base {
protected array $info;
public function __construct(
protected int $id
public readonly int $id
) {}
public function info(): array {

View File

@@ -39,8 +39,8 @@ echo $Twig->render('reportsv2/new.twig', [
'size' => '(' . number_format($report->torrent()->size() / (1024 * 1024), 2) . ' MiB)',
'torrent' => $report->torrent(),
'other' => [
'group' => $reportMan->totalReportsGroup($report->torrent()->groupId()) - 1,
'uploader' => $reportMan->totalReportsUploader($report->torrent()->uploader()->id()) - 1,
'group' => $reportMan->totalReportsTGroup($report->torrent()->group()) - 1,
'uploader' => $reportMan->totalReportsUploader($report->torrent()->uploader()) - 1,
],
'viewer' => $Viewer,
]);

View File

@@ -28,7 +28,7 @@ if (is_null($other)) {
}
$reportMan = new Manager\Torrent\Report($torMan);
if ($reportMan->existsRecent($other->id(), $Viewer->id())) {
if ($reportMan->existsRecent($other, $Viewer)) {
json_error("too soon");
}
$report = $reportMan->findById((int)($_POST['reportid'] ?? 0));

View File

@@ -26,7 +26,7 @@ if (is_null($torrent)) {
}
$reportMan = new Manager\Torrent\Report($torMan);
if ($reportMan->existsRecent($torrent->id(), $Viewer->id())) {
if ($reportMan->existsRecent($torrent, $Viewer)) {
Error429::error("Slow down, you're moving too fast!");
}

View File

@@ -68,7 +68,7 @@ if (!$filter) {
} else {
$reportMan->setSearchFilter($filter);
$paginator->setTotal($reportMan->searchTotal());
$list = $reportMan->searchList($userMan, $paginator->limit(), $paginator->offset());
$list = $reportMan->searchList($paginator->limit(), $paginator->offset());
}
echo $Twig->render('reportsv2/search.twig', [

View File

@@ -94,8 +94,8 @@ if ($search->canUnclaim($Viewer)) {
'report' => $report,
'request_list' => $requestMan->findByTorrentReported($torrent),
'torrent' => $torrent,
'total_group' => $reportMan->totalReportsGroup($torrent->groupId()),
'total_uploader' => $reportMan->totalReportsUploader($torrent->uploaderId()),
'total_group' => $reportMan->totalReportsTGroup($torrent->group()),
'total_uploader' => $reportMan->totalReportsUploader($torrent->uploader()),
'total_torrent' => $reportMan->totalReportsTorrent($torrent),
'viewer' => $Viewer,
]);

View File

@@ -16,18 +16,16 @@ if (!$Viewer->permitted('admin_reports')) {
Error403::error();
}
$reportMan = new Manager\Torrent\Report(new Manager\Torrent());
$reportTypeMan = new Manager\Torrent\ReportType();
$userMan = new Manager\User();
$reportMan = new Manager\Torrent\Report(new Manager\Torrent());
echo $Twig->render('reportsv2/summary.twig', [
'in_progress' => $reportMan->inProgressSummary($userMan),
'new' => $reportMan->newSummary($reportTypeMan),
'in_progress' => $reportMan->inProgressSummary(),
'new' => $reportMan->newSummary(),
'resolved' => [
'day' => $reportMan->resolvedLastDay($userMan),
'week' => $reportMan->resolvedLastWeek($userMan),
'month' => $reportMan->resolvedLastMonth($userMan),
'total' => $reportMan->resolvedSummary($userMan),
'day' => $reportMan->resolvedLastDay(),
'week' => $reportMan->resolvedLastWeek(),
'month' => $reportMan->resolvedLastMonth(),
'total' => $reportMan->resolvedSummary(),
],
'viewer' => $Viewer,
]);

View File

@@ -89,7 +89,7 @@
<td>{{ config.needSitelink }}
<br /><select name="need_sitelink">
{% for value in config.needSitelinkList %}
<option value="{{ value }}"{{ selected(config.needSiteLink == value) }}>{{ value }}</option>
<option value="{{ value }}"{{ selected(config.needSitelink == value) }}>{{ value }}</option>
{% endfor %}
</select>
<br />The report (optionally) requires a link to page onsite.</td>

View File

@@ -11,6 +11,7 @@ class CategoryTest extends TestCase {
$this->assertEquals(1, $manager->findIdByName('Music'), 'cat-name-comics');
$this->assertEquals(7, $manager->findIdByName('Comics'), 'cat-name-comics');
$this->assertEquals('Comics', $manager->findNameById(7), 'cat-id-comics');
$this->assertNull($manager->findIdByName('thereisnospoon'), 'cat-name-bogus');
$this->assertEquals('Music', $manager->findNameById(1), 'cat-id-ebooks');

View File

@@ -35,6 +35,7 @@ class CommentTest extends TestCase {
public function testCommentArtist(): void {
$manager = new Manager\Comment();
$this->assertNull($manager->findById(0), 'comment-404-id');
$artMan = new Manager\Artist();
$this->artist = $artMan->create('phpunit.' . randomString(12));

View File

@@ -58,7 +58,7 @@ class ContestTest extends TestCase {
dateBegin : date('Y-m-d H:i:s'),
dateEnd : date('Y-m-d H:i:s', $now + 86400 * 15),
name : $name,
description : 'phpunit contest description',
description : 'phpunit contest description',
display : 10,
hasPool : false,
type : $contestTypes[1]['id'],
@@ -80,6 +80,7 @@ class ContestTest extends TestCase {
$this->assertEquals(0, $this->contest->totalEntries(), 'contest-no-entries-yet');
$this->assertNull($this->contest->rank($this->userList[0]), 'contest-no-rank-yet');
$this->assertEquals('none', $this->contest->bonusStatus(), 'contest-status-no-bonus-pool');
$this->assertEquals($this->contest->id, $manager->findById($this->contest->id)->id, 'contest-find-by-id');
$this->assertEquals(1, $this->contest->remove(), 'contest-remove');
unset($this->contest);
@@ -94,7 +95,7 @@ class ContestTest extends TestCase {
dateBegin : date('Y-m-d H:i:s', time() - 1),
dateEnd : (new \DateTime())->add(new \DateInterval("P15D"))->format('Y-m-d H:i:s'),
name : 'phpunit contest upload flac ' . randomString(6),
description : 'phpunit contest description',
description : 'phpunit contest description',
display : 10,
hasPool : true,
type : $contestTypes[1]['id'],
@@ -301,7 +302,7 @@ class ContestTest extends TestCase {
Helper::makeRequestMusic($this->userList[0], 'phpunit contest request fill 0-2'),
Helper::makeRequestMusic($this->userList[1], 'phpunit contest request fill 1-1'),
];
foreach($this->requestList as $r) {
foreach ($this->requestList as $r) {
// backdate the requests prior to the beginning of the contest, add bounty
$r->setField('created', date('Y-m-d H:i:s', time() - 10))->modify();
$r->vote($this->userList[0], 1024 * 1024);

View File

@@ -63,9 +63,9 @@ class ForumTest extends TestCase {
$this->assertCount($initial + 2, $fcatMan->forumCategoryList(), 'forum-cat-category-list');
$this->assertCount($initial + 2, $fcatMan->usageList(), 'forum-cat-usage-list');
$find = $fcatMan->findById($this->category->id());
$find = $fcatMan->findById($this->category->id);
$find->setField('Name', 'phpunit renamed')->modify();
$this->assertEquals($this->category->id(), $find->id(), 'forum-cat-find');
$this->assertEquals($this->category->id, $find->id, 'forum-cat-find');
$this->assertEquals('phpunit renamed', $find->name(), 'forum-cat-name');
$this->assertEquals(10001, $find->sequence(), 'forum-cat-sequence');
$this->assertEquals(1, $categoryEphemeral->remove(), 'forum-cat-remove-unused');
@@ -103,7 +103,7 @@ class ForumTest extends TestCase {
$this->assertEquals(0, $this->forum->lastPostEpoch(), 'forum-last-post-time');
$this->assertEquals(0, $this->forum->numPosts(), 'forum-post-total');
$this->assertEquals(0, $this->forum->numThreads(), 'forum-thread-total');
$this->assertEquals($admin->id(), $this->forum->lastAuthorId(), 'forum-last-author-id');
$this->assertEquals($admin->id, $this->forum->lastAuthorId(), 'forum-last-author-id');
$this->assertEquals(42, $this->forum->autoLockWeeks(), 'forum-autolock-weeks');
$this->assertEquals(150, $this->forum->sequence(), 'forum-sequence');
$this->assertEquals(100, $this->forum->minClassRead(), 'forum-min-class-read');
@@ -115,8 +115,8 @@ class ForumTest extends TestCase {
$this->assertNull($this->forum->lastThread(), 'forum-last-thread');
$this->assertNull($this->forum->lastThreadName(), 'forum-last-thread-name');
$find = $forumMan->findById($this->forum->id());
$this->assertEquals($this->forum->id(), $find->id(), 'forum-forum-find');
$find = $forumMan->findById($this->forum->id);
$this->assertEquals($this->forum->id, $find->id, 'forum-forum-find');
$this->extra = Helper::makeForum(
user: $this->userList['admin'],
@@ -132,15 +132,15 @@ class ForumTest extends TestCase {
);
$forumList = $forumMan->forumList();
$idList = array_map(fn ($f) => $f->id(), $forumList);
$idList = array_map(fn ($f) => $f->id, $forumList);
$this->assertCount($initial + 2, $idList, 'forum-id-list-count');
$this->assertTrue(in_array($this->extra->id(), $idList), 'forum-id-list-sequence');
$this->assertTrue(in_array($this->extra->id, $idList), 'forum-id-list-sequence');
$this->assertCount($userTocTotal + 1, $forumMan->tableOfContents($user), 'forum-test-toc-user');
$this->assertEquals(0, $forumMan->subscribedForumTotal($user), 'forum-subscribed-total-user');
$this->assertEquals(
[$forumName, 'phpunit announcements'],
$forumMan->nameList([$this->forum->id(), $this->extra->id()]),
$forumMan->nameList([$this->forum->id, $this->extra->id]),
'forum-name-list'
);
@@ -153,11 +153,11 @@ class ForumTest extends TestCase {
$this->assertEquals(0, $thread->lastCatalogue(), 'fthread-last-catalog');
$this->assertEquals(1, $this->forum->numThreads(), 'fthread-admin-number-thread-total');
$this->assertEquals($admin->id(), $thread->authorId(), 'fthread-author-id');
$this->assertEquals($admin->id, $thread->authorId(), 'fthread-author-id');
$this->assertEquals($admin->username(), $thread->author()->username(), 'fthread-author-username');
$this->assertEquals($this->forum->id(), $thread->forumId(), 'fthread-forum-id');
$this->assertEquals($this->forum->id, $thread->forumId(), 'fthread-forum-id');
$this->assertEquals($this->forum->name(), $thread->forum()->name(), 'fthread-forum-title');
$this->assertEquals($admin->id(), $thread->lastAuthorId(), 'fthread-forum-title');
$this->assertEquals($admin->id, $thread->lastAuthorId(), 'fthread-forum-title');
$this->assertEquals('thread title', $thread->title(), 'thread-title');
$this->assertEquals(0, $thread->pinnedPostId(), 'fthread-pinned-post-id');
@@ -200,7 +200,7 @@ class ForumTest extends TestCase {
$this->assertTrue($admin->writeAccess($secret), 'fthread-secret-admin-write');
$this->assertTrue($admin->createAccess($secret), 'fthread-secret-admin-create');
$user->setField('PermittedForums', $secret->id())->modify();
$user->setField('PermittedForums', $secret->id)->modify();
$this->assertTrue($user->readAccess($secret), 'fthread-secret-user-permitted-read');
$this->assertTrue($user->writeAccess($secret), 'fthread-secret-user-permitted-write');
$this->assertTrue($user->createAccess($secret), 'fthread-secret-user-permitted-create');
@@ -214,14 +214,17 @@ class ForumTest extends TestCase {
$this->assertTrue($userSub->isSubscribed($thread), 'fpost-user-is-now-subbed');
$list = $userSub->subscriptionList();
$this->assertCount(1, $list, 'fpost-subscriptions-list');
$this->assertEquals($thread->id(), $list[0], 'fpost-subscriptions-first');
$this->assertEquals($thread->id, $list[0], 'fpost-subscriptions-first');
$admin = $this->userList['admin'];
$this->assertEquals(1, $admin->stats()->forumPostTotal(), 'fpost-first-user-stats');
$message = 'first reply';
$post = $thread->addPost($admin, $message);
$this->assertEquals(2, $admin->stats()->flush()->forumPostTotal(), 'fpost-first-user-reply');
$this->assertEquals($post->id(), $this->forum->flush()->lastPostId(), 'fpost-is-last-post');
$this->assertEquals($post->id, $this->forum->flush()->lastPostId(), 'fpost-is-last-post');
$this->assertEquals(1, $post->page(), 'fpost-reply-page');
$this->assertEquals(1, $post->threadPageTotal(), 'fpost-reply-thread-page');
$this->assertEquals(2, $post->priorPostTotal(), 'fpost-reply-prior-page');
/* post first reply */
$postMan = new Manager\ForumPost();
@@ -236,14 +239,20 @@ class ForumTest extends TestCase {
/* quote first post in reply */
$body = "good job @{$admin->username()}";
$reply = $thread->addPost($user, $body);
// Should the following actions (quote and subscription handling) be performed by the addPost() method?
(new User\Notification\Quote($admin))->create(
'forums',
$thread->id(),
$reply->id(),
$thread->id,
$reply->id,
$body,
);
(new Manager\Subscription())->flushThread($thread);
$this->assertEquals(
$thread->id,
$threadMan->findByPostId($reply->id)->id,
'fpost-find-thread',
);
$this->assertEquals(1, $forumMan->unreadSubscribedForumTotal($admin), 'fpost-subscriptions-admin-forum-man-unread');
$this->assertEquals(1, $adminSub->flush()->unread(), 'fpost-subscriptions-admin-new-unread');
@@ -254,28 +263,28 @@ class ForumTest extends TestCase {
$page = $quote->page(10, 0);
$this->assertCount(1, $page, 'fpost-quote-page-count');
$this->assertEquals($admin->id(), $page[0]['quoter_id'], 'fpost-quote-page-0-quoter');
$this->assertEquals($postMan->findById($reply->id())->url(), $page[0]['jump'], 'fpost-quote-page-0-jump');
$this->assertEquals($admin->id, $page[0]['quoter_id'], 'fpost-quote-page-0-quoter');
$this->assertEquals($postMan->findById($reply->id)->url(), $page[0]['jump'], 'fpost-quote-page-0-jump');
$this->assertEquals(1, $quote->clearThread($thread, $post->id(), $reply->id()), 'fpost-clear-thread');
$this->assertEquals(1, $quote->clearThread($thread, $post->id, $reply->id), 'fpost-clear-thread');
$this->assertEquals(0, $quote->total(), 'fpost-quote-admin-total-clear');
$this->assertEquals(0, $quote->unreadTotal(), 'fpost-quote-admin-unread-total-clear');
$latest = $adminSub->latestSubscriptionList(true, 10, 0);
$this->assertCount(1, $latest, 'fpost-subscription-latest-total');
$this->assertEquals($thread->id(), $latest[0]['PageID'], 'fpost-quote-admin-unread-page-id');
$this->assertEquals($thread->id, $latest[0]['PageID'], 'fpost-quote-admin-unread-page-id');
$this->assertNull($latest[0]['PostID'], 'fpost-quote-admin-unread-post-id');
$thread->catchup($admin, $reply->id());
$thread->catchup($admin, $reply->id);
$this->assertEquals(1, $adminSub->unread(), 'fpost-subscriptions-admin-one-read');
$readLast = $this->forum->userLastRead($admin);
$this->assertCount(1, $readLast, 'forum-last-read-list-total');
$this->assertEquals(
[
$thread->id() => [
"TopicID" => $thread->id(),
"PostID" => $reply->id(),
$thread->id => [
"TopicID" => $thread->id,
"PostID" => $reply->id,
"Page" => 1,
]
],
@@ -306,7 +315,7 @@ class ForumTest extends TestCase {
$this->assertEquals([$user->id], $this->forum->autoSubscribeUserIdList(), 'forum-autosub-userlist');
$this->assertEquals([], $this->forum->autoSubscribeForUserList($user), 'forum-autosub-forum-list');
$user->addCustomPrivilege('site_forum_autosub');
$this->assertEquals([$this->forum->id()], $this->forum->autoSubscribeForUserList($user), 'forum-autosub-forum-list');
$this->assertEquals([$this->forum->id], $this->forum->autoSubscribeForUserList($user), 'forum-autosub-forum-list');
$threadMan = new Manager\ForumThread();
$this->threadList[] = $threadMan->create($this->forum, $this->userList['admin'], 'phpunit thread title', 'this is a new thread');
@@ -325,7 +334,7 @@ class ForumTest extends TestCase {
$this->forum = $forumMan->create(
user: $this->userList['admin'],
sequence: 151,
categoryId: $this->category->id(),
categoryId: $this->category->id,
name: 'phpunit forbid forum',
description: 'This is where it forbids',
minClassRead: 100,
@@ -338,7 +347,7 @@ class ForumTest extends TestCase {
$this->assertTrue($user->writeAccess($this->forum), 'forum-forbid-write-allowed');
$this->assertTrue($user->createAccess($this->forum), 'forum-forbid-create-allowed');
$user->setField('RestrictedForums', $this->forum->id())->modify();
$user->setField('RestrictedForums', $this->forum->id)->modify();
$this->assertFalse($user->readAccess($this->forum), 'forum-forbid-read-denied');
$this->assertFalse($user->writeAccess($this->forum), 'forum-forbid-write-denied');
$this->assertFalse($user->createAccess($this->forum), 'forum-forbid-create-denied');
@@ -460,6 +469,9 @@ class ForumTest extends TestCase {
'warn-user-inbox-pm-body-start'
);
$this->assertStringEndsWith($message . '[/quote]', $body, 'warn-user-inbox-pm-body-end');
$this->assertEquals(1, $post->edit($admin, 'cleaned'), 'fpost-edit');
$this->assertEquals(2, $post->remove(), 'fpost-remove');
}
public function testForumPoll(): void {
@@ -485,12 +497,12 @@ class ForumTest extends TestCase {
$this->assertFalse($poll->hasRevealVotes(), 'forum-poll-is-not-featured');
$this->assertFalse($poll->isFeatured(), 'forum-poll-is-not-featured');
$this->assertEquals(0, $poll->total(), 'forum-poll-total');
$this->assertEquals($thread->id(), $poll->thread()->id(), 'forum-poll-thread-id');
$this->assertEquals($thread->id, $poll->thread()->id, 'forum-poll-thread-id');
$this->assertCount(3, $poll->vote(), 'forum-poll-vote-count');
$this->assertEquals($answer[1], $poll->vote()[1]['answer'], 'forum-poll-vote-1');
$find = $pollMan->findById($poll->id());
$this->assertEquals($poll->id(), $find->id(), 'forum-poll-find-by-id');
$find = $pollMan->findById($poll->id);
$this->assertEquals($poll->id, $find->id, 'forum-poll-find-by-id');
$this->assertEquals(1, $poll->addAnswer('sushi'), 'forum-poll-add-answer');
@@ -644,8 +656,8 @@ class ForumTest extends TestCase {
);
$this->assertInstanceOf(ForumTransition::class, $transition, 'forum-trans-create');
$this->assertEquals('phpunit', $transition->label(), 'forum-trans-label');
$this->assertEquals($this->forum->id(), $transition->sourceId(), 'forum-trans-source');
$this->assertEquals($this->extra->id(), $transition->destinationId(), 'forum-trans-dest');
$this->assertEquals($this->forum->id, $transition->sourceId(), 'forum-trans-source');
$this->assertEquals($this->extra->id, $transition->destinationId(), 'forum-trans-dest');
$this->assertEquals($this->userList['admin']->classLevel(), $transition->classLevel(), 'forum-trans-class-level');
$this->assertCount(0, $transition->secondaryClassIdList(), 'forum-trans-empty-secondary');
$this->assertCount(0, $transition->userIdList(), 'forum-trans-empty-user-list');
@@ -662,7 +674,7 @@ class ForumTest extends TestCase {
userClass: $this->userList['admin']->classLevel(),
secondaryClasses: (string)FLS_TEAM,
privileges: '',
userIds: (string)$this->userList['specific']->id(),
userIds: (string)$this->userList['specific']->id,
);
(new User\Privilege($this->userList['FLS']))->addSecondaryClass(FLS_TEAM);
$this->assertTrue($this->userList['FLS']->isFLS(), 'user-is-fls');
@@ -681,8 +693,8 @@ class ForumTest extends TestCase {
$list = $manager->threadTransitionList($this->userList['FLS'], $thread);
$this->assertCount(1, $list, 'thread-transition-list');
$this->assertEquals(
$this->transitionList[0]->id(),
$list[$this->transitionList[0]->id()]->id(),
$this->transitionList[0]->id,
$list[$this->transitionList[0]->id]->id,
'forum-thread-transition-list'
);

View File

@@ -414,6 +414,33 @@ class TGroupTest extends TestCase {
$this->assertCount(1, $this->tgroupExtra->torrentIdList(), 'tgroup-split-has-one-torrent');
}
public function testReleaseType(): void {
global $Cache;
$Cache->delete_value(ReleaseType::CACHE_KEY);
$releaseType = new ReleaseType();
$this->assertCount(17, $releaseType->list(), 'rel-type-list');
$this->assertCount(
22,
$releaseType->extendedList(),
'rel-type-extended-list',
);
$this->assertEquals(
6,
$releaseType->findIdByName('Anthology'),
'rel-type-find-id',
);
$this->assertEquals(
'Anthology',
$releaseType->findNameById(6),
'rel-type-find-name',
);
$this->assertEquals(
'DJ Mixes',
$releaseType->sectionTitle($releaseType->findIdByName('DJ Mix')),
'rel-type-section-title',
);
}
public function testStatsRefresh(): void {
$this->assertGreaterThanOrEqual(
0,

View File

@@ -18,6 +18,9 @@ class UserNavigationTest extends TestCase {
public function testNavigationBasic(): void {
$manager = new Manager\UserNavigation();
$this->assertNull($manager->findById(0), 'user-nav-find-by-id');
global $Cache;
$Cache->delete_value(Manager\UserNavigation::LIST_KEY);
$fullList = $manager->fullList();
$this->assertCount(12, $fullList, 'user-nav-manager-full');

View File

@@ -336,6 +336,8 @@ class UserTest extends TestCase {
public function testStylesheet(): void {
$manager = new Manager\Stylesheet();
global $Cache;
$Cache->delete_value('csslist');
$list = $manager->list();
$this->assertGreaterThan(5, $list, 'we-can-haz-stylesheets');
$this->assertEquals(count($list), count($manager->usageList('name', 'ASC')), 'stylesheet-list-usage');

View File

@@ -41,13 +41,13 @@ class BlogTest extends TestCase {
$this->assertEquals(1, $this->blog->important(), 'blog-important');
$this->assertEquals(0, $this->blog->threadId(), 'blog-thread-id');
$this->assertEquals('phpunit blog', $this->blog->title(), 'blog-title');
$this->assertEquals($this->userList[0]->id(), $this->blog->userId(), 'blog-userId');
$this->assertEquals($this->userList[0]->id, $this->blog->userId(), 'blog-userId');
$this->assertEquals(1 + count($initial), count($manager->headlines()), 'blog-headlines');
$this->assertEquals($this->blog->id(), $manager->latest()->id(), 'blog-latest');
$this->assertEquals($this->blog->id(), $manager->latestId(), 'blog-id-latest');
$find = $manager->findById($this->blog->id());
$this->assertEquals($this->blog->id(), $find->id(), 'blog-find');
$this->assertEquals($this->blog->id, $manager->latest()->id, 'blog-latest');
$this->assertEquals($this->blog->id, $manager->latestId(), 'blog-id-latest');
$find = $manager->findById($this->blog->id);
$this->assertEquals($this->blog->id, $find->id, 'blog-find');
$this->assertEquals((int)strtotime($find->created()), $manager->latestEpoch(), 'blog-epoch');
$this->assertInstanceOf(Blog::class, $this->blog->flush(), 'blog-flush');
@@ -93,7 +93,7 @@ class BlogTest extends TestCase {
$witness = new WitnessTable\UserReadBlog();
$this->assertNull($witness->lastRead($this->userList[1]), 'blog-user-not-read');
$this->assertTrue($witness->witness($this->userList[1]));
$this->assertEquals($this->blog->id(), $witness->lastRead($this->userList[1]), 'blog-user-read');
$this->assertEquals($this->blog->id, $witness->lastRead($this->userList[1]), 'blog-user-read');
}
public function testBlogNotification(): void {
@@ -118,7 +118,7 @@ class BlogTest extends TestCase {
$this->assertInstanceOf(User\Notification\Blog::class, $alertBlog, 'alert-blog-instance');
$this->assertEquals('Blog', $alertBlog->type(), 'alert-blog-type');
$this->assertEquals("Blog: $title", $alertBlog->title(), 'alert-blog-title');
$this->assertEquals($this->blog->id(), $alertBlog->context(), 'alert-blog-context-is-blog');
$this->assertEquals($this->blog->id, $alertBlog->context(), 'alert-blog-context-is-blog');
$this->assertEquals($this->blog->url(), $alertBlog->notificationUrl(), 'alert-blog-url-is-blog');
}
}

View File

@@ -5,9 +5,6 @@ namespace Gazelle;
use PHPUnit\Framework\TestCase;
class TorManagerTest extends TestCase {
public function setup(): void {
}
public function testTor(): void {
$manager = new Manager\Tor();
$list = array_filter(

View File

@@ -37,6 +37,9 @@ class TorrentReportManagerTest extends TestCase {
foreach ($this->userList as $user) {
$user->remove();
}
DB::DB()->prepared_query("
DELETE FROM reportsv2 WHERE UserComment REGEXP '^phpunit (?:other|search|urgent) report$'
");
}
public function testWorkflowReport(): void {
@@ -59,31 +62,50 @@ class TorrentReportManagerTest extends TestCase {
),
];
$extraIdList = [$extra[0]->id(), $extra[1]->id()];
$this->assertInstanceOf(Torrent::class, $torrent, 'report-torrent-is-torrent');
$report = (new Manager\Torrent\Report($torMan))->create(
$manager = new Manager\Torrent\Report($torMan);
$typeManager = new Manager\Torrent\ReportType();
$this->assertCount(8, $manager->categories(), 'trep-categories');
$report = $manager->create(
torrent: $torrent,
user: $this->userList[1],
reportType: (new Manager\Torrent\ReportType())->findByName('other'),
reportType: $typeManager->findByName('other'),
reason: 'phpunit other report',
otherIdList: implode(' ', $extraIdList),
irc: new Util\Irc(),
);
$this->assertTrue(
$manager->existsRecent($torrent, $this->userList[1]),
'trep-recent',
);
$this->assertTrue(Helper::recentDate($report->created()), 'torrent-report-created');
$this->assertCount(0, $report->externalLink(), 'torrent-report-external-link');
$this->assertCount(0, $report->trackList(), 'torrent-report-track-list');
$this->assertStringEndsWith("id={$report->id()}", $report->location(), 'torrent-report-location');
$this->assertEquals('phpunit other report', $report->reason(), 'torrent-report-reason');
$this->assertEquals($this->userList[1]->id(), $report->reporterId(), 'torrent-report-reporter-id');
$this->assertEquals('New', $report->status(), 'torrent-report-report-status');
$this->assertEquals('Other', $report->reportType()->name(), 'torrent-report-report-type-name');
$this->assertEquals('other', $report->type(), 'torrent-report-name');
$this->assertEquals($this->tgroup->torrentIdList()[2], $report->torrentId(), 'torrent-report-torrent-id');
$this->assertEquals($this->tgroup->torrentIdList()[2], $report->torrent()->id(), 'torrent-report-torrent-object');
$this->assertEquals(
$report->id,
$manager->findById($report->id)->id,
'trep-find-by-id'
);
$this->assertEquals(
$report->id,
$manager->findNewest()->id,
'trep-newest'
);
$this->assertTrue(Helper::recentDate($report->created()), 'trep-created');
$this->assertCount(0, $report->externalLink(), 'trep-external-link');
$this->assertCount(0, $report->trackList(), 'trep-track-list');
$this->assertStringEndsWith("id={$report->id()}", $report->location(), 'trep-location');
$this->assertEquals('phpunit other report', $report->reason(), 'trep-reason');
$this->assertEquals($this->userList[1]->id(), $report->reporterId(), 'trep-reporter-id');
$this->assertEquals('New', $report->status(), 'trep-report-status');
$this->assertEquals('Other', $report->reportType()->name(), 'trep-report-type-name');
$this->assertEquals('other', $report->type(), 'trep-name');
$this->assertEquals($this->tgroup->torrentIdList()[2], $report->torrentId(), 'trep-torrent-id');
$this->assertEquals($this->tgroup->torrentIdList()[2], $report->torrent()->id(), 'trep-torrent-object');
$other = current(array_filter($manager->newSummary(), fn ($r) => $r['type'] === 'other'));
$this->assertEquals(1, $other['total'], 'trep-new-summary-other');
$this->assertEquals(
$extraIdList,
$report->otherIdList(),
'torrent-report-other-id-list'
'trep-other-id-list'
);
$this->assertEquals(
$title,
@@ -91,52 +113,105 @@ class TorrentReportManagerTest extends TestCase {
fn ($t) => $t->remasterTitle(),
$report->otherTorrentList(),
),
'torrent-report-other-torrent-list'
'trep-other-torrent-list'
);
$this->assertEquals(1, $report->claim($this->userList[0]), 'torrent-report-claim');
$this->assertEquals('InProgress', $report->status(), 'torrent-report-report-open-status');
$this->assertEquals(1, $report->addTorrentFlag(TorrentFlag::badFile, $this->userList[0]), 'torrent-report-add-flag');
$this->assertEquals(1, $report->modifyComment('phpunit'), 'torrent-report-modify-comment');
$this->assertEquals('phpunit', $report->comment(), 'torrent-report-final-comment');
$this->assertEquals(1, $report->unclaim(), 'torrent-report-claim');
$this->assertEquals(1, $report->claim($this->userList[0]), 'trep-claim');
$summary = $manager->inProgressSummary();
$this->assertCount(1, $summary, 'trep-in-progress-total');
$this->assertEquals($this->userList[0]->id, $summary[0]['user_id'], 'trep-in-progress-mod');
$this->assertEquals(
1,
$manager->totalReportsTorrent($torrent),
'trep-in-progress-torrent',
);
$this->assertEquals(
1,
$manager->totalReportsTGroup($torrent->group()),
'trep-in-progress-tgroup',
);
$this->assertEquals(
1,
$manager->totalReportsUploader($this->userList[0]),
'trep-in-progress-uploader',
);
$this->assertEquals(1, $report->resolve('phpunit resolve'), 'torrent-report-resolve');
$this->assertEquals('phpunit resolve', $report->comment(), 'torrent-report-resolved-comment');
$this->assertEquals('', $report->message(), 'torrent-report-message');
$this->assertEquals(1, $report->finalize('phpunit final message', 'phpunit final comment'), 'torrent-report-finalize');
$this->assertEquals('phpunit final comment', $report->comment(), 'torrent-report-final-comment');
$this->assertEquals('phpunit final message', $report->message(), 'torrent-report-final-message');
$this->assertEquals('Resolved', $report->status(), 'torrent-report-report-resolved-status');
$this->assertEquals('InProgress', $report->status(), 'trep-report-open-status');
$this->assertEquals(1, $report->addTorrentFlag(TorrentFlag::badFile, $this->userList[0]), 'trep-add-flag');
$this->assertEquals(1, $report->modifyComment('phpunit'), 'trep-modify-comment');
$this->assertEquals('phpunit', $report->comment(), 'trep-final-comment');
$this->assertEquals(1, $report->unclaim(), 'trep-claim');
$this->assertEquals(1, $report->resolve('phpunit resolve'), 'trep-resolve');
$this->assertEquals('phpunit resolve', $report->comment(), 'trep-resolved-comment');
$this->assertEquals('', $report->message(), 'trep-message');
$this->assertEquals(1, $report->finalize('phpunit final message', 'phpunit final comment'), 'trep-finalize');
$this->assertEquals('phpunit final comment', $report->comment(), 'trep-final-comment');
$this->assertEquals('phpunit final message', $report->message(), 'trep-final-message');
$this->assertEquals('Resolved', $report->status(), 'trep-report-resolved-status');
}
public function testModeratorResolve(): void {
$torMan = new Manager\Torrent();
$torrent = $torMan->findById($this->tgroup->torrentIdList()[0]);
$this->assertInstanceOf(Torrent::class, $torrent, 'report-torrent-is-torrent');
$report = (new Manager\Torrent\Report($torMan))->create(
torrent: $torrent,
$manager = new Manager\Torrent\Report($torMan);
$report = $manager->create(
torrent: $torMan->findById($this->tgroup->torrentIdList()[0]),
user: $this->userList[1],
reportType: (new Manager\Torrent\ReportType())->findByName('other'),
reason: 'phpunit other report',
otherIdList: '123 234',
irc: new Util\Irc(),
);
$this->assertEquals(1, $report->moderatorResolve($this->userList[0], 'phpunit moderator resolve'), 'torrent-report-moderator-resolve');
$this->assertEquals('phpunit moderator resolve', $report->comment(), 'torrent-report-final-comment');
$this->assertEquals(1, $report->moderatorResolve($this->userList[0], 'phpunit moderator resolve'), 'trep-moderator-resolve');
$this->assertEquals('phpunit moderator resolve', $report->comment(), 'trep-final-comment');
$this->assertCount(1, $manager->resolvedLastDay(), 'trep-resolve-day');
$this->assertCount(1, $manager->resolvedLastWeek(), 'trep-resolve-week');
$this->assertCount(1, $manager->resolvedLastMonth(), 'trep-resolve-month');
$this->assertGreaterThanOrEqual(1, $manager->resolvedSummary(), 'trep-resolve-summary');
}
public function testSearchTorrentReport(): void {
$torMan = new Manager\Torrent();
$manager = new Manager\Torrent\Report($torMan);
$torrent = $torMan->findById($this->tgroup->torrentIdList()[0]);
$report = $manager->create(
torrent: $torrent,
user: $this->userList[1],
reportType: (new Manager\Torrent\ReportType())->findByName('other'),
reason: 'phpunit search report',
otherIdList: '1234 5678',
irc: new Util\Irc(),
);
$manager->setSearchFilter([
'dt-from' => date('Y-m-d H:i:s', time() - 10),
'dt-until' => date('Y-m-d H:i:s', time() + 10),
'group' => $torrent->groupId(),
'reporter' => $this->userList[1],
'torrent' => $torrent->id,
'uploader' => $this->userList[0],
'report-type' => ['other', 'dupe'],
]);
$this->assertEquals(1, $manager->searchTotal(), 'trep-search-total');
$list = $manager->searchList(1, 0);
$this->assertEquals($report->id, $list[0]['report_id'], 'trep-search-report');
}
public function testModifyReport(): void {
$reportType = (new Manager\Torrent\ReportType())->findByName('other');
$reportType->setChangeset($this->userList[0], [['field' => 'is_admin', 'old' => $reportType->isAdmin(), 'new' => 0]]);
$this->assertFalse($reportType->setField('is_admin', false)->modify(), 'torrent-report-modify');
$this->assertFalse($reportType->setField('is_admin', false)->modify(), 'trep-modify');
}
public function testUrgentReport(): void {
$torMan = new Manager\Torrent();
$torMan->setViewer($this->userList[0]);
$torrent = $torMan->findById($this->tgroup->torrentIdList()[0]);
$this->assertInstanceOf(Torrent::class, $torrent, 'report-torrent-is-torrent');
$type = (new Manager\Torrent\ReportType())->findByName('urgent');
$this->assertInstanceOf(Torrent\ReportType::class, $type, 'torrent-report-instance-urgent');
$this->assertInstanceOf(Torrent\ReportType::class, $type, 'trep-instance-urgent');
$torrentId = $this->tgroup->torrentIdList()[0];
$torrent = $torMan->findById($torrentId);
@@ -155,4 +230,44 @@ class TorrentReportManagerTest extends TestCase {
$this->assertCount(1, $labelList, 'reporter-report-label');
$this->assertStringContainsString('Reported', $labelList[0], 'reporter-report-urgent');
}
public function testTorrentReportType(): void {
$manager = new Manager\Torrent\ReportType();
$this->assertCount(
51,
$manager->list(),
'trep-type-count'
);
$this->assertCount(
36,
$manager->categoryList(CATEGORY_MUSIC),
'trep-type-cat-count'
);
$dupe = $manager->findById(1);
$this->assertEquals(
'Dupe',
$dupe->name(),
'trep-type-find-by-id',
);
$this->assertEquals(
'required',
$dupe->needSitelink(),
'trep-type-site-link',
);
$this->assertEquals(
'dupe',
$manager->findByName('Dupe')->type(),
'trep-type-find-by-name',
);
$this->assertEquals(
1,
$manager->findByType('dupe')->id,
'trep-type-find-by-type',
);
$this->assertNull($manager->findById(0), 'trep-no-find-id');
$this->assertNull($manager->findByName('No Such Name'), 'trep-no-find-name');
$this->assertNull($manager->findByType('no-such-type'), 'trep-no-find-type');
}
}

View File

@@ -382,4 +382,13 @@ class UserManagerTest extends TestCase {
$this->assertGreaterThanOrEqual(0, count($recent), 'uman-userflow-recent-is-array');
$this->assertEquals(['Week', 'created', 'disabled'], array_keys($recent), 'userman-recent-keys');
}
public function testUserFind(): void {
$manager = new Manager\User();
$this->assertEquals(
$this->userList[0]->id,
$manager->findByEmail($this->userList[0]->email())->id,
'userman-find-by-email'
);
}
}