Skip to content

Commit

Permalink
update: commands
Browse files Browse the repository at this point in the history
  • Loading branch information
HDVinnie committed May 6, 2024
1 parent 8f9769f commit 99f5f33
Show file tree
Hide file tree
Showing 50 changed files with 189 additions and 514 deletions.
1 change: 0 additions & 1 deletion .env.example
Expand Up @@ -15,7 +15,6 @@ DB_PORT=3306
DB_DATABASE=unit3d
DB_USERNAME=root
DB_PASSWORD=
#PRISTINE_DB_FILE=/home/vagrant/code/database/unit3d_test.sql

BROADCAST_CONNECTION=redis
CACHE_STORE=redis
Expand Down
8 changes: 3 additions & 5 deletions app/Console/Commands/AutoBanDisposableUsers.php
Expand Up @@ -22,10 +22,8 @@
use App\Services\Unit3dAnnounce;
use Illuminate\Console\Command;
use Exception;
use Throwable;

/**
* @see \Tests\Todo\Unit\Console\Commands\AutoBanDisposableUsersTest
*/
class AutoBanDisposableUsers extends Command
{
/**
Expand All @@ -45,9 +43,9 @@ class AutoBanDisposableUsers extends Command
/**
* Execute the console command.
*
* @throws Exception
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
$bannedGroup = cache()->rememberForever('banned_group', fn () => Group::where('slug', '=', 'banned')->pluck('id'));

Expand Down
20 changes: 1 addition & 19 deletions app/Console/Commands/AutoCacheRandomMediaIds.php
Expand Up @@ -20,12 +20,6 @@
use Illuminate\Support\Facades\Redis;
use Throwable;

/**
* Class AutoCacheRandomMediaIds.
*
* This class is responsible for caching valid media ids for the random media component.
* It is a console command that can be executed manually or scheduled.
*/
class AutoCacheRandomMediaIds extends Command
{
/**
Expand All @@ -45,40 +39,28 @@ class AutoCacheRandomMediaIds extends Command
/**
* Execute the console command.
*
* This method is the entry point of the command. It fetches the ids of movies and tv shows that have torrents and a backdrop,
* and stores them in the cache for use by the random media component.
*
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
// Fetch the ids of movies that have torrents and a backdrop.
$movieIds = Movie::query()
->select('id')
->whereHas('torrents')
->whereNotNull('backdrop')
->pluck('id');

// Fetch the ids of tv shows that have torrents and a backdrop.
$tvIds = Tv::query()
->select('id')
->whereHas('torrents')
->whereNotNull('backdrop')
->pluck('id');

// Define the cache key for movies.
$cacheKey = config('cache.prefix').':random-media-movie-ids';

// Store the movie ids in the cache.
Redis::connection('cache')->command('SADD', [$cacheKey, ...$movieIds]);

// Define the cache key for tv shows.
$cacheKey = config('cache.prefix').':random-media-tv-ids';

// Store the tv show ids in the cache.
Redis::connection('cache')->command('SADD', [$cacheKey, ...$tvIds]);

// Output a success message to the console.
$this->comment($movieIds->count().' movie ids and '.$tvIds->count().' tv ids cached.');
}
}
5 changes: 3 additions & 2 deletions app/Console/Commands/AutoCacheUserLeechCounts.php
Expand Up @@ -16,6 +16,7 @@
use App\Models\User;
use Illuminate\Console\Command;
use Exception;
use Throwable;

class AutoCacheUserLeechCounts extends Command
{
Expand All @@ -36,9 +37,9 @@ class AutoCacheUserLeechCounts extends Command
/**
* Execute the console command.
*
* @throws Exception
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
$peerCounts = User::withoutGlobalScopes()
->selectRaw("CONCAT('user-leeching-count:', id) as cacheKey")
Expand Down
8 changes: 3 additions & 5 deletions app/Console/Commands/AutoCorrectHistory.php
Expand Up @@ -18,10 +18,8 @@
use Illuminate\Support\Carbon;
use Exception;
use Illuminate\Support\Facades\DB;
use Throwable;

/**
* @see \Tests\Unit\Console\Commands\AutoCorrectHistoryTest
*/
class AutoCorrectHistory extends Command
{
/**
Expand All @@ -41,9 +39,9 @@ class AutoCorrectHistory extends Command
/**
* Execute the console command.
*
* @throws Exception
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
History::select(['id', 'active', 'updated_at'])
->where('active', '=', 1)
Expand Down
9 changes: 5 additions & 4 deletions app/Console/Commands/AutoDeactivateWarning.php
Expand Up @@ -18,12 +18,11 @@
use App\Notifications\UserWarningExpire;
use App\Services\Unit3dAnnounce;
use Carbon\Carbon;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Throwable;

/**
* @see \Tests\Unit\Console\Commands\AutoDeactivateWarningTest
*/
class AutoDeactivateWarning extends Command
{
/**
Expand All @@ -42,8 +41,10 @@ class AutoDeactivateWarning extends Command

/**
* Execute the console command.
*
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
$current = Carbon::now();
$warnings = Warning::with(['warneduser', 'torrenttitle'])
Expand Down
15 changes: 2 additions & 13 deletions app/Console/Commands/AutoDeleteStoppedPeers.php
Expand Up @@ -18,12 +18,6 @@
use Illuminate\Support\Facades\DB;
use Throwable;

/**
* Class AutoDeleteStoppedPeers.
*
* TThis class is responsible for deleting all stopped peers from the database.
* It uses the DB facade to directly interact with the 'peers' table in the database.
*/
class AutoDeleteStoppedPeers extends Command
{
/**
Expand All @@ -43,22 +37,17 @@ class AutoDeleteStoppedPeers extends Command
/**
* Execute the console command.
*
* This method is the entry point of the command. It deletes all records from the 'peers' table
* where 'active' is 0 and 'updated_at' is more than 2 hours ago.
*
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
// Start a database transaction.
DB::transaction(static function (): void {
DB::table('peers')
->where('active', '=', 0)
->where('updated_at', '>', now()->subHours(2))
->delete();
}, 5); // 5 is the number of attempts if deadlock occurs.
}, 5);

// Output a message to the console.
$this->comment('Automated delete stopped peers command complete');
}
}
8 changes: 3 additions & 5 deletions app/Console/Commands/AutoDisableInactiveUsers.php
Expand Up @@ -20,10 +20,8 @@
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Exception;
use Throwable;

/**
* @see \Tests\Unit\Console\Commands\AutoDisableInactiveUsersTest
*/
class AutoDisableInactiveUsers extends Command
{
/**
Expand All @@ -43,9 +41,9 @@ class AutoDisableInactiveUsers extends Command
/**
* Execute the console command.
*
* @throws Exception
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
if (config('pruning.user_pruning')) {
$disabledGroup = cache()->rememberForever('disabled_group', fn () => Group::where('slug', '=', 'disabled')->pluck('id'));
Expand Down
8 changes: 3 additions & 5 deletions app/Console/Commands/AutoFlushPeers.php
Expand Up @@ -19,10 +19,8 @@
use Illuminate\Support\Carbon;
use Exception;
use Illuminate\Support\Facades\DB;
use Throwable;

/**
* @see \Tests\Unit\Console\Commands\AutoFlushPeersTest
*/
class AutoFlushPeers extends Command
{
/**
Expand All @@ -42,9 +40,9 @@ class AutoFlushPeers extends Command
/**
* Execute the console command.
*
* @throws Exception
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
$carbon = new Carbon();
$peers = Peer::select(['id', 'torrent_id', 'user_id', 'seeder', 'updated_at'])
Expand Down
9 changes: 5 additions & 4 deletions app/Console/Commands/AutoGroup.php
Expand Up @@ -17,13 +17,12 @@
use App\Models\Group;
use App\Models\User;
use App\Services\Unit3dAnnounce;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Throwable;

/**
* @see \Tests\Unit\Console\Commands\AutoGroupTest
*/
class AutoGroup extends Command
{
/**
Expand All @@ -42,8 +41,10 @@ class AutoGroup extends Command

/**
* Execute the console command.
*
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
$now = now();
$current = Carbon::now();
Expand Down
9 changes: 5 additions & 4 deletions app/Console/Commands/AutoHighspeedTag.php
Expand Up @@ -17,12 +17,11 @@
use App\Models\Scopes\ApprovedScope;
use App\Models\Seedbox;
use App\Models\Torrent;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Throwable;

/**
* @see \Tests\Unit\Console\Commands\AutoHighspeedTagTest
*/
class AutoHighspeedTag extends Command
{
/**
Expand All @@ -41,8 +40,10 @@ class AutoHighspeedTag extends Command

/**
* Execute the console command.
*
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
$seedboxIps = Seedbox::all()
->pluck('ip')
Expand Down
17 changes: 3 additions & 14 deletions app/Console/Commands/AutoNerdStat.php
Expand Up @@ -17,21 +17,12 @@
use Illuminate\Console\Command;
use Exception;
use Illuminate\Support\Facades\DB;
use Throwable;

/**
* Class AutoNerdStat.
*
* This class is responsible for posting daily nerd stats to the chatbox.
* It is a console command that can be executed manually or scheduled.
*
* @package App\Console\Commands
*/
class AutoNerdStat extends Command
{
/**
* AutoNerdStat Constructor.
*
* @param ChatRepository $chatRepository The chat repository instance.
*/
public function __construct(private readonly ChatRepository $chatRepository)
{
Expand All @@ -55,11 +46,9 @@ public function __construct(private readonly ChatRepository $chatRepository)
/**
* Execute the console command.
*
* This method is the entry point of the command. It posts a random nerd stat to the shoutbox.
*
* @throws Exception If there is an error during the execution of the command.
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
// Check if the nerd bot is enabled in the configuration.
if (config('chat.nerd_bot')) {
Expand Down
8 changes: 3 additions & 5 deletions app/Console/Commands/AutoPreWarning.php
Expand Up @@ -19,10 +19,8 @@
use Carbon\Carbon;
use Illuminate\Console\Command;
use Exception;
use Throwable;

/**
* @see \Tests\Unit\Console\Commands\AutoPreWarningTest
*/
class AutoPreWarning extends Command
{
/**
Expand All @@ -42,9 +40,9 @@ class AutoPreWarning extends Command
/**
* Execute the console command.
*
* @throws Exception
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
if (config('hitrun.enabled') === true) {
$carbon = new Carbon();
Expand Down
9 changes: 5 additions & 4 deletions app/Console/Commands/AutoRecycleAudits.php
Expand Up @@ -14,12 +14,11 @@
namespace App\Console\Commands;

use App\Models\Audit;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Throwable;

/**
* @see \Tests\Unit\Console\Commands\AutoRecycleAuditsTest
*/
class AutoRecycleAudits extends Command
{
/**
Expand All @@ -38,8 +37,10 @@ class AutoRecycleAudits extends Command

/**
* Execute the console command.
*
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
public function handle(): void
final public function handle(): void
{
$current = Carbon::now();
$audits = Audit::where('created_at', '<', $current->copy()->subDays(config('audit.recycle'))->toDateTimeString())->get();
Expand Down

0 comments on commit 99f5f33

Please sign in to comment.