mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2025-12-14 12:06:46 +00:00
✨ Add Nostr publishing and login keys cleanup commands
This commit is contained in:
35
app/Console/Commands/Database/CleanupLoginKeys.php
Normal file
35
app/Console/Commands/Database/CleanupLoginKeys.php
Normal 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;
|
||||
}
|
||||
}
|
||||
47
app/Console/Commands/Nostr/PublishUnpublishedItems.php
Normal file
47
app/Console/Commands/Nostr/PublishUnpublishedItems.php
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user