forked from pixelfed/pixelfed
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
929 additions
and
418 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use App\Services\AccountService; | ||
use App\Services\Account\AccountStatService; | ||
use App\Status; | ||
use App\Profile; | ||
|
||
class AccountPostCountStatUpdate extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'app:account-post-count-stat-update'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Update post counts from recent activities'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
$ids = AccountStatService::getAllPostCountIncr(); | ||
if(!$ids || !count($ids)) { | ||
return; | ||
} | ||
foreach($ids as $id) { | ||
$acct = AccountService::get($id, true); | ||
if(!$acct) { | ||
AccountStatService::removeFromPostCount($id); | ||
continue; | ||
} | ||
$statusCount = Status::whereProfileId($id)->count(); | ||
if($statusCount != $acct['statuses_count']) { | ||
$profile = Profile::find($id); | ||
if(!$profile) { | ||
AccountStatService::removeFromPostCount($id); | ||
continue; | ||
} | ||
$profile->status_count = $statusCount; | ||
$profile->save(); | ||
AccountService::del($id); | ||
} | ||
AccountStatService::removeFromPostCount($id); | ||
} | ||
return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,298 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use App\Instance; | ||
use App\Profile; | ||
use App\Services\InstanceService; | ||
use App\Jobs\InstancePipeline\FetchNodeinfoPipeline; | ||
use function Laravel\Prompts\select; | ||
use function Laravel\Prompts\confirm; | ||
use function Laravel\Prompts\progress; | ||
use function Laravel\Prompts\search; | ||
use function Laravel\Prompts\table; | ||
|
||
class InstanceManager extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'app:instance-manager'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Manage Instances'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
$action = select( | ||
'What action do you want to perform?', | ||
[ | ||
'Recalculate Stats', | ||
'Ban Instance', | ||
'Unlist Instance', | ||
'Unlisted Instances', | ||
'Banned Instances', | ||
'Unban Instance', | ||
'Relist Instance', | ||
], | ||
); | ||
|
||
switch($action) { | ||
case 'Recalculate Stats': | ||
return $this->recalculateStats(); | ||
break; | ||
|
||
case 'Unlisted Instances': | ||
return $this->viewUnlistedInstances(); | ||
break; | ||
|
||
case 'Banned Instances': | ||
return $this->viewBannedInstances(); | ||
break; | ||
|
||
case 'Unlist Instance': | ||
return $this->unlistInstance(); | ||
break; | ||
|
||
case 'Ban Instance': | ||
return $this->banInstance(); | ||
break; | ||
|
||
case 'Unban Instance': | ||
return $this->unbanInstance(); | ||
break; | ||
|
||
case 'Relist Instance': | ||
return $this->relistInstance(); | ||
break; | ||
} | ||
} | ||
|
||
protected function recalculateStats() | ||
{ | ||
$instanceCount = Instance::count(); | ||
$confirmed = confirm('Do you want to recalculate stats for all ' . $instanceCount . ' instances?'); | ||
if(!$confirmed) { | ||
$this->error('Aborting...'); | ||
exit; | ||
} | ||
|
||
$users = progress( | ||
label: 'Updating instance stats...', | ||
steps: Instance::all(), | ||
callback: fn ($instance) => $this->updateInstanceStats($instance), | ||
); | ||
} | ||
|
||
protected function updateInstanceStats($instance) | ||
{ | ||
FetchNodeinfoPipeline::dispatch($instance)->onQueue('intbg'); | ||
} | ||
|
||
protected function unlistInstance() | ||
{ | ||
$id = search( | ||
'Search by domain', | ||
fn (string $value) => strlen($value) > 0 | ||
? Instance::whereUnlisted(false)->where('domain', 'like', "%{$value}%")->pluck('domain', 'id')->all() | ||
: [] | ||
); | ||
|
||
$instance = Instance::find($id); | ||
if(!$instance) { | ||
$this->error('Oops, an error occured'); | ||
exit; | ||
} | ||
|
||
$tbl = [ | ||
[ | ||
$instance->domain, | ||
number_format($instance->status_count), | ||
number_format($instance->user_count), | ||
] | ||
]; | ||
table( | ||
['Domain', 'Status Count', 'User Count'], | ||
$tbl | ||
); | ||
|
||
$confirmed = confirm('Are you sure you want to unlist this instance?'); | ||
if(!$confirmed) { | ||
$this->error('Aborting instance unlisting'); | ||
exit; | ||
} | ||
|
||
$instance->unlisted = true; | ||
$instance->save(); | ||
InstanceService::refresh(); | ||
$this->info('Successfully unlisted ' . $instance->domain . '!'); | ||
exit; | ||
} | ||
|
||
protected function relistInstance() | ||
{ | ||
$id = search( | ||
'Search by domain', | ||
fn (string $value) => strlen($value) > 0 | ||
? Instance::whereUnlisted(true)->where('domain', 'like', "%{$value}%")->pluck('domain', 'id')->all() | ||
: [] | ||
); | ||
|
||
$instance = Instance::find($id); | ||
if(!$instance) { | ||
$this->error('Oops, an error occured'); | ||
exit; | ||
} | ||
|
||
$tbl = [ | ||
[ | ||
$instance->domain, | ||
number_format($instance->status_count), | ||
number_format($instance->user_count), | ||
] | ||
]; | ||
table( | ||
['Domain', 'Status Count', 'User Count'], | ||
$tbl | ||
); | ||
|
||
$confirmed = confirm('Are you sure you want to re-list this instance?'); | ||
if(!$confirmed) { | ||
$this->error('Aborting instance re-listing'); | ||
exit; | ||
} | ||
|
||
$instance->unlisted = false; | ||
$instance->save(); | ||
InstanceService::refresh(); | ||
$this->info('Successfully re-listed ' . $instance->domain . '!'); | ||
exit; | ||
} | ||
|
||
protected function banInstance() | ||
{ | ||
$id = search( | ||
'Search by domain', | ||
fn (string $value) => strlen($value) > 0 | ||
? Instance::whereBanned(false)->where('domain', 'like', "%{$value}%")->pluck('domain', 'id')->all() | ||
: [] | ||
); | ||
|
||
$instance = Instance::find($id); | ||
if(!$instance) { | ||
$this->error('Oops, an error occured'); | ||
exit; | ||
} | ||
|
||
$tbl = [ | ||
[ | ||
$instance->domain, | ||
number_format($instance->status_count), | ||
number_format($instance->user_count), | ||
] | ||
]; | ||
table( | ||
['Domain', 'Status Count', 'User Count'], | ||
$tbl | ||
); | ||
|
||
$confirmed = confirm('Are you sure you want to ban this instance?'); | ||
if(!$confirmed) { | ||
$this->error('Aborting instance ban'); | ||
exit; | ||
} | ||
|
||
$instance->banned = true; | ||
$instance->save(); | ||
InstanceService::refresh(); | ||
$this->info('Successfully banned ' . $instance->domain . '!'); | ||
exit; | ||
} | ||
|
||
protected function unbanInstance() | ||
{ | ||
$id = search( | ||
'Search by domain', | ||
fn (string $value) => strlen($value) > 0 | ||
? Instance::whereBanned(true)->where('domain', 'like', "%{$value}%")->pluck('domain', 'id')->all() | ||
: [] | ||
); | ||
|
||
$instance = Instance::find($id); | ||
if(!$instance) { | ||
$this->error('Oops, an error occured'); | ||
exit; | ||
} | ||
|
||
$tbl = [ | ||
[ | ||
$instance->domain, | ||
number_format($instance->status_count), | ||
number_format($instance->user_count), | ||
] | ||
]; | ||
table( | ||
['Domain', 'Status Count', 'User Count'], | ||
$tbl | ||
); | ||
|
||
$confirmed = confirm('Are you sure you want to unban this instance?'); | ||
if(!$confirmed) { | ||
$this->error('Aborting instance unban'); | ||
exit; | ||
} | ||
|
||
$instance->banned = false; | ||
$instance->save(); | ||
InstanceService::refresh(); | ||
$this->info('Successfully un-banned ' . $instance->domain . '!'); | ||
exit; | ||
} | ||
|
||
protected function viewBannedInstances() | ||
{ | ||
$data = Instance::whereBanned(true) | ||
->get(['domain', 'user_count', 'status_count']) | ||
->map(function($d) { | ||
return [ | ||
'domain' => $d->domain, | ||
'user_count' => number_format($d->user_count), | ||
'status_count' => number_format($d->status_count), | ||
]; | ||
}) | ||
->toArray(); | ||
table( | ||
['Domain', 'User Count', 'Status Count'], | ||
$data | ||
); | ||
} | ||
|
||
protected function viewUnlistedInstances() | ||
{ | ||
$data = Instance::whereUnlisted(true) | ||
->get(['domain', 'user_count', 'status_count', 'banned']) | ||
->map(function($d) { | ||
return [ | ||
'domain' => $d->domain, | ||
'user_count' => number_format($d->user_count), | ||
'status_count' => number_format($d->status_count), | ||
'banned' => $d->banned ? '✅' : null | ||
]; | ||
}) | ||
->toArray(); | ||
table( | ||
['Domain', 'User Count', 'Status Count', 'Banned'], | ||
$data | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.