move into sonardesk

This commit is contained in:
Mark Gregory
2026-10-12 13:25:16 +01:00
parent 563f0979b3
commit b4e040999d
212 changed files with 7976 additions and 0 deletions
@@ -0,0 +1,59 @@
<?php
namespace App\Console\Commands;
use Modules\Licensing\Models\License;
use App\Models\User;
use App\Services\Accounts\PurchasedAccountProvisioner;
use Illuminate\Console\Command;
final class SonarDeskAccountsBackfill extends Command
{
protected $signature = 'sonardesk:accounts:backfill {--dry-run : Report missing customer accounts without creating them} {--no-email : Create accounts without sending password setup links}';
protected $description = 'Create portal accounts for existing licence holders that do not already have one.';
public function handle(PurchasedAccountProvisioner $accounts): int
{
$customers = License::query()
->whereNotNull('customer_email')
->where('customer_email', '<>', '')
->select(['customer_email', 'customer_name'])
->orderBy('customer_email')
->get()
->unique(fn (License $license) => strtolower(trim((string) $license->customer_email)));
$missing = 0;
$created = 0;
foreach ($customers as $license) {
$email = strtolower(trim((string) $license->customer_email));
if ($email === '') {
continue;
}
if (User::query()->whereRaw('lower(email) = ?', [$email])->exists()) {
continue;
}
$missing++;
if ($this->option('dry-run')) {
$this->line("MISSING {$email}");
continue;
}
if ($accounts->ensure($email, $license->customer_name, ! $this->option('no-email'))) {
$created++;
$this->info("CREATED {$email}");
}
}
if ($this->option('dry-run')) {
$this->info("{$missing} account(s) would be created.");
} else {
$this->info("{$created} account(s) created.");
}
return self::SUCCESS;
}
}
@@ -0,0 +1,36 @@
<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
final class SonarDeskAdminCreate extends Command
{
protected $signature = 'sonardesk:admin {email} {--name=Administrator}';
protected $description = 'Create or promote an SonarDesk licensing administrator';
public function handle(): int
{
$email = strtolower(trim($this->argument('email')));
$password = Str::password(24, true, true, false, false);
$u = User::firstOrNew(['email' => $email]);
$u->name = $this->option('name');
$u->is_admin = true;
$u->email_verified_at = now();
if (! $u->exists) {
$u->password = Hash::make($password);
} $u->save();
$this->info("Administrator ready: {$email}");
if (! $u->wasRecentlyCreated) {
$this->line('Existing password retained.');
} else {
$this->warn("Temporary password (shown once): {$password}");
}
return self::SUCCESS;
}
}
@@ -0,0 +1,59 @@
<?php
namespace App\Console\Commands;
use App\Models\CmsPage;
use App\Services\IndexNowService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Route;
use Throwable;
final class SubmitIndexNow extends Command
{
protected $signature = 'indexnow:submit {urls?* : Absolute URLs to submit} {--all : Submit all public indexable SonarDesk URLs}';
protected $description = 'Submit public SonarDesk URLs to IndexNow';
public function handle(IndexNowService $indexNow): int
{
if (! config('indexnow.enabled')) {
$this->warn('IndexNow is disabled. Set INDEXNOW_ENABLED=true to enable submissions.');
return self::FAILURE;
}
$urls = $this->argument('urls');
if ($this->option('all') || $urls === []) {
$urls = $this->allPublicUrls();
}
try {
$response = $indexNow->submit($urls);
} catch (Throwable $e) {
$this->error($e->getMessage());
return self::FAILURE;
}
if ($response === null || ! $response->successful()) {
$this->error('IndexNow rejected the submission'.($response ? ' (HTTP '.$response->status().').' : '.'));
return self::FAILURE;
}
$this->info('Submitted '.count($urls).' URL(s) to IndexNow (HTTP '.$response->status().').');
return self::SUCCESS;
}
/** @return array<int, string> */
private function allPublicUrls(): array
{
$routes = ['home', 'features', 'buy', 'release', 'support', 'privacy', 'terms', 'refund', 'cookies'];
$urls = collect($routes)->filter(fn (string $name) => Route::has($name))->map(fn (string $name) => route($name));
$pages = CmsPage::query()
->where('is_published', true)
->where('robots_index', true)
->where(fn ($query) => $query->whereNull('published_at')->orWhere('published_at', '<=', now()))
->pluck('slug')
->map(fn (string $slug) => route('cms.show', ['slug' => $slug]));
return $urls->merge($pages)->unique()->values()->all();
}
}