76 lines
2.2 KiB
PHP
76 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\Sitemaps\Builders;
|
|
|
|
use App\Models\Artwork;
|
|
use App\Models\Collection;
|
|
use App\Models\NovaCard;
|
|
use App\Models\Story;
|
|
use App\Models\User;
|
|
use App\Services\Sitemaps\SitemapUrl;
|
|
use App\Services\Sitemaps\SitemapUrlBuilder;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
final class UsersSitemapBuilder extends AbstractIdShardableSitemapBuilder
|
|
{
|
|
public function __construct(private readonly SitemapUrlBuilder $urls)
|
|
{
|
|
}
|
|
|
|
public function name(): string
|
|
{
|
|
return 'users';
|
|
}
|
|
|
|
protected function shardConfigKey(): string
|
|
{
|
|
return 'users';
|
|
}
|
|
|
|
protected function mapRecord(Model $record): ?SitemapUrl
|
|
{
|
|
return $this->urls->profile($record, $record->updated_at);
|
|
}
|
|
|
|
protected function query(): Builder
|
|
{
|
|
return User::query()
|
|
->where('is_active', true)
|
|
->whereNull('deleted_at')
|
|
->whereNotNull('username')
|
|
->where('username', '!=', '')
|
|
->where(function (Builder $builder): void {
|
|
$builder->whereExists(
|
|
Artwork::query()
|
|
->selectRaw('1')
|
|
->public()
|
|
->published()
|
|
->whereColumn('artworks.user_id', 'users.id')
|
|
)->orWhereExists(
|
|
Collection::query()
|
|
->selectRaw('1')
|
|
->public()
|
|
->whereNull('canonical_collection_id')
|
|
->whereColumn('collections.user_id', 'users.id')
|
|
)->orWhereExists(
|
|
NovaCard::query()
|
|
->selectRaw('1')
|
|
->publiclyVisible()
|
|
->whereColumn('nova_cards.user_id', 'users.id')
|
|
)->orWhereExists(
|
|
Story::query()
|
|
->selectRaw('1')
|
|
->published()
|
|
->whereColumn('stories.creator_id', 'users.id')
|
|
);
|
|
});
|
|
}
|
|
|
|
protected function qualifiedIdColumn(): string
|
|
{
|
|
return 'users.id';
|
|
}
|
|
} |