Skip to content

Commit

Permalink
prepare to migrate to chihaya
Browse files Browse the repository at this point in the history
  • Loading branch information
pjc09h committed May 22, 2024
1 parent e79d86c commit 46dcde8
Show file tree
Hide file tree
Showing 30 changed files with 626 additions and 85 deletions.
2 changes: 1 addition & 1 deletion app/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public function hydrateUserInfo(int $userId, array $data = [])
$app->dbNew->do($query, [$userId]);

# update ocelot and commit
Tracker::update_tracker("add_user", ["id" => $userId, "passkey" => $torrent_pass]);
\TrackerOld::update_tracker("add_user", ["id" => $userId, "passkey" => $torrent_pass]);
$app->dbNew->commit();
} catch (Throwable $e) {
$app->dbNew->rollBack();
Expand Down
2 changes: 1 addition & 1 deletion app/AutoEnable.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public static function handle_token($Token)
// Good request, decrement cache value and enable account
$app->cache->decrement(AutoEnable::CACHE_KEY_NAME);
$VisibleTrIP = ($Visible && \Gazelle\Crypto::decrypt($IP) !== '127.0.0.1') ? '1' : '0';
Tracker::update_tracker('add_user', array('id' => $UserID, 'passkey' => $TorrentPass, 'visible' => $VisibleTrIP));
\TrackerOld::update_tracker('add_user', array('id' => $UserID, 'passkey' => $TorrentPass, 'visible' => $VisibleTrIP));

$app->dbOld->query("
UPDATE
Expand Down
2 changes: 1 addition & 1 deletion app/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function get_ocelot_requests()
{
/*
if (class_exists("Tracker")) {
return Tracker::$Requests;
return \TrackerOld::$Requests;
}
*/
}
Expand Down
10 changes: 7 additions & 3 deletions app/Models/Collages.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class Collages extends ObjectCrud
"subscriberCount" => "subscriberCount",
"maximumGroups" => "maximumGroups",
"groupsPerUser" => "groupsPerUser",
"isFeatured" => "isFeatured",
"isLocked" => "isLocked",
"isFeatured" => "isFeatured", # bool
"isLocked" => "isLocked", # bool
"created_at" => "createdAt",
"updated_at" => "updatedAt",
"deleted_at" => "deletedAt",
Expand All @@ -62,8 +62,12 @@ public function read(int|string $identifier = null): void
# parent method
parent::read($identifier);

# decode the boolean fields
$this->attributes->isFeatured = boolval($this->attributes->isFeatured);
$this->attributes->isLocked = boolval($this->attributes->isLocked);

# decode the json fields
$this->attributes->tags = json_decode($this->attributes->tags ?? []);
$this->attributes->tags = json_decode($this->attributes->tags ?? "{}");
}


Expand Down
32 changes: 14 additions & 18 deletions app/Models/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,20 @@ class Requests extends ObjectCrud

# ["database" => "display"]
protected array $maps = [
"uuid" => "uuid",
"ID" => "id",
"UserID" => "userId",
#"TimeAdded" => "createdAt",
"LastVote" => "lastVote",
"CategoryID" => "categoryId",
"Title" => "title",
"Title2" => "subject",
"TitleJP" => "object",
"Image" => "picture",
"Description" => "description",
"CatalogueNumber" => "identifier",
"DLsiteID" => null,
"FillerID" => "fillerId",
"TorrentID" => "torrentId",
"TimeFilled" => "filledAt",
"Visible" => "isVisible",
"GroupID" => "groupId",
"id" => "id",
"categoryId" => "categoryId",
"userId" => "userId",
"groupId" => "groupId",
"torrentId" => "torrentId",
"filledById" => "filledById",
"filledAt" => "filledAt",
"lastVote" => "lastVote",
"identifier" => "identifier",
"title" => "title",
"subject" => "subject",
"object" => "object",
"description" => "description",
"picture" => "picture",
"created_at" => "createdAt",
"updated_at" => "updatedAt",
"deleted_at" => "deletedAt",
Expand Down
20 changes: 13 additions & 7 deletions app/Models/Roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class Roles extends ObjectCrud
"machineName" => "machineName",
"friendlyName" => "friendlyName",
"description" => "description",
"isPrimaryRole" => "isPrimaryRole",
"isSecondaryRole" => "isSecondaryRole",
"isDefaultRole" => "isDefaultRole",
"isStaffRole" => "isStaffRole",
"isPrimaryRole" => "isPrimaryRole", # bool
"isSecondaryRole" => "isSecondaryRole", # bool
"isDefaultRole" => "isDefaultRole", # bool
"isStaffRole" => "isStaffRole", # bool
"maxPersonalCollages" => "maxPersonalCollages",
"permissionsLevel" => "permissionsLevel",
"permissionsList" => "permissionsList",
"permissionsList" => "permissionsList", # json
"created_at" => "createdAt",
"updated_at" => "updatedAt",
"deleted_at" => "deletedAt",
Expand Down Expand Up @@ -86,8 +86,14 @@ public function read(int|string $identifier = null): void
# normal read
parent::read($identifier);

# decode the permissions
$this->attributes->permissionsList = json_decode($this->attributes->permissionsList ?? "{}", true);
# decode the boolean fields
$this->attributes->isPrimaryRole = boolval($this->attributes->isPrimaryRole);
$this->attributes->isSecondaryRole = boolval($this->attributes->isSecondaryRole);
$this->attributes->isDefaultRole = boolval($this->attributes->isDefaultRole);
$this->attributes->isStaffRole = boolval($this->attributes->isStaffRole);

# decode the json fields
$this->attributes->permissionsList = json_decode($this->attributes->permissionsList ?? "{}");

# get the user count
$query = "select count(userId) from users_main where permissionId = ?";
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Torrents.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ public static function delete_torrent($ID, $GroupID = 0, $OcelotReason = -1)
$app->dbOld->query("
DELETE FROM torrents
WHERE ID = $ID");
Tracker::update_tracker('delete_torrent', array('info_hash' => rawurlencode($InfoHash), 'id' => $ID, 'reason' => $OcelotReason));
\TrackerOld::update_tracker('delete_torrent', array('info_hash' => rawurlencode($InfoHash), 'id' => $ID, 'reason' => $OcelotReason));

$app->cache->decrement('stats_torrent_count');

Expand Down Expand Up @@ -1074,7 +1074,7 @@ public static function freeleech_torrents($TorrentIDs, $FreeNeutral = 1, $FreeLe

foreach ($Torrents as $Torrent) {
list($TorrentID, $GroupID, $InfoHash) = $Torrent;
Tracker::update_tracker('update_torrent', array('info_hash' => rawurlencode($InfoHash), 'freetorrent' => $FreeNeutral));
\TrackerOld::update_tracker('update_torrent', array('info_hash' => rawurlencode($InfoHash), 'freetorrent' => $FreeNeutral));
$app->cache->delete("torrent_download_$TorrentID");
Misc::write_log(($app->user->core["username"] ?? 'System') . " marked torrent $TorrentID freeleech type $FreeLeechType");
Torrents::write_group_log($GroupID, $TorrentID, ($app->user->core["id"] ?? 0), "marked as freeleech type $FreeLeechType", 0);
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ public function updateSettings(array $data): void
$newPassKey = Text::random(32);

# update the tracker
Tracker::update_tracker(
\TrackerOld::update_tracker(
"change_passkey",
["oldpasskey" => $oldPassKey, "newpasskey" => $newPassKey]
);
Expand Down
4 changes: 2 additions & 2 deletions app/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ public static function disable_users($UserIDs, $AdminComment, $BanReason = 1)
$Concat = '';
foreach ($PassKeys as $PassKey) {
if (strlen($Concat) > 3950) { // Ocelot's read buffer is 4 KiB and anything exceeding it is truncated
Tracker::update_tracker('remove_users', array('passkeys' => $Concat));
\TrackerOld::update_tracker('remove_users', array('passkeys' => $Concat));
$Concat = $PassKey;
} else {
$Concat .= $PassKey;
}
}

Tracker::update_tracker('remove_users', array('passkeys' => $Concat));
\TrackerOld::update_tracker('remove_users', array('passkeys' => $Concat));
$app->dbOld->set_query_id($QueryID);
}

Expand Down
4 changes: 2 additions & 2 deletions app/Torrents.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ public static function delete_torrent($ID, $GroupID = 0, $OcelotReason = -1)
$app->dbOld->query("
DELETE FROM torrents
WHERE ID = $ID");
Tracker::update_tracker('delete_torrent', array('info_hash' => rawurlencode($InfoHash), 'id' => $ID, 'reason' => $OcelotReason));
\TrackerOld::update_tracker('delete_torrent', array('info_hash' => rawurlencode($InfoHash), 'id' => $ID, 'reason' => $OcelotReason));

$app->cache->decrement('stats_torrent_count');

Expand Down Expand Up @@ -1136,7 +1136,7 @@ public static function freeleech_torrents($TorrentIDs, $FreeNeutral = 1, $FreeLe

foreach ($Torrents as $Torrent) {
list($TorrentID, $GroupID, $InfoHash) = $Torrent;
Tracker::update_tracker('update_torrent', array('info_hash' => rawurlencode($InfoHash), 'freetorrent' => $FreeNeutral));
\TrackerOld::update_tracker('update_torrent', array('info_hash' => rawurlencode($InfoHash), 'freetorrent' => $FreeNeutral));
$app->cache->delete("torrent_download_$TorrentID");
Misc::write_log(($app->user->core["username"] ?? 'System') . " marked torrent $TorrentID freeleech type $FreeLeechType");
Torrents::write_group_log($GroupID, $TorrentID, ($app->user->core["id"] ?? 0), "marked as freeleech type $FreeLeechType", 0);
Expand Down
6 changes: 4 additions & 2 deletions app/Tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@


/**
* Tracker
* Gazelle\Tracker
*
* Handles interactions with Ocelot.
* todo: Turn this into a class with nice functions like update_user, delete_torrent, etc.
*/

namespace Gazelle;

class Tracker
{
public const STATS_MAIN = 0;
Expand All @@ -29,7 +31,7 @@ class Tracker
* Send a GET request over a socket directly to the tracker.
*
* For example, this call:
* Tracker::update_tracker(
* \TrackerOld::update_tracker(
* "change_passkey",
* ["oldpasskey" => $oldPassKey, "newpasskey" => $newPassKey]
* );
Expand Down
Loading

0 comments on commit 46dcde8

Please sign in to comment.