Add Nostr publishing and login keys cleanup commands

This commit is contained in:
HolgerHatGarKeineNode
2025-11-21 16:34:38 +01:00
parent efe44cf344
commit 7adefecfbb
4 changed files with 197 additions and 5 deletions

View File

@@ -0,0 +1,35 @@
<?php
namespace App\Console\Commands\Database;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class CleanupLoginKeys extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'loginkeys:cleanup';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Execute the console command.
*/
public function handle(): int
{
DB::table('login_keys')
->where('created_at', '<', now()->subDays(1))
->delete();
return Command::SUCCESS;
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Console\Commands\Nostr;
use App\Traits\NostrTrait;
use Illuminate\Console\Command;
class PublishUnpublishedItems extends Command
{
use NostrTrait;
/**
* The name and signature of the console command.
* @var string
*/
protected $signature = 'nostr:publish {--model=}';
/**
* The console command description.
* @var string
*/
protected $description = 'Command description';
/**
* Execute the console command.
*/
public function handle(): void
{
config(['app.user-timezone' => 'Europe/Berlin']);
$modelName = $this->option('model');
$className = '\\App\Models\\' . $modelName;
$model = $className::query()
->whereNull('nostr_status')
->when($modelName === 'BitcoinEvent', fn($q) => $q->where('from', '>', now()))
->when($modelName === 'CourseEvent', fn($q) => $q->where('from', '>', now()))
->when($modelName === 'MeetupEvent', fn($q) => $q->where('start', '>', now()))
->when($modelName === 'LibraryItem', fn($q) => $q
->where('type', '<>', 'markdown_article')
->where('type', '<>', 'bindle')
)
->orderByDesc('created_at')
->first();
if ($model) {
$this->publishOnNostr($model, $this->getText($model));
}
}
}