PHP stuff.
This commit is contained in:
parent
03fa0d1ff6
commit
40e8589755
|
@ -192,6 +192,15 @@ class StationMedia implements
|
|||
]
|
||||
protected int $art_updated_at = 0;
|
||||
|
||||
#[
|
||||
OA\Property(
|
||||
description: "The latest time (UNIX timestamp) when the search record for this entry was updated.",
|
||||
example: OpenApi::SAMPLE_TIMESTAMP
|
||||
),
|
||||
ORM\Column
|
||||
]
|
||||
protected int $search_updated_at = 0;
|
||||
|
||||
/** @var Collection<int, StationPlaylistMedia> */
|
||||
#[
|
||||
OA\Property(type: "array", items: new OA\Items()),
|
||||
|
|
|
@ -54,6 +54,8 @@ final class Environment
|
|||
|
||||
public const ENABLE_WEB_UPDATER = 'ENABLE_WEB_UPDATER';
|
||||
|
||||
public const MEILI_MASTER_KEY = 'MEILI_MASTER_KEY';
|
||||
|
||||
// Database and Cache Configuration Variables
|
||||
public const DB_HOST = 'MYSQL_HOST';
|
||||
public const DB_PORT = 'MYSQL_PORT';
|
||||
|
@ -90,6 +92,8 @@ final class Environment
|
|||
self::PROFILING_EXTENSION_HTTP_KEY => 'dev',
|
||||
|
||||
self::ENABLE_WEB_UPDATER => false,
|
||||
|
||||
self::MEILI_MASTER_KEY => 'azur4c457',
|
||||
];
|
||||
|
||||
public function __construct(array $elements = [])
|
||||
|
@ -370,6 +374,11 @@ final class Environment
|
|||
return $this->isDocker() && self::envToBool($this->data[self::ENABLE_WEB_UPDATER] ?? false);
|
||||
}
|
||||
|
||||
public function getMeiliMasterKey(): string
|
||||
{
|
||||
return $this->data[self::MEILI_MASTER_KEY] ?? $this->defaults[self::MEILI_MASTER_KEY];
|
||||
}
|
||||
|
||||
public static function getDefaultsForEnvironment(Environment $existingEnv): self
|
||||
{
|
||||
return new self([
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Message;
|
||||
|
||||
use App\MessageQueue\QueueManagerInterface;
|
||||
|
||||
final class AddMediaToSearchIndexMessage extends AbstractUniqueMessage
|
||||
{
|
||||
/** @var int The numeric identifier for the StorageLocation entity. */
|
||||
public int $storage_location_id;
|
||||
|
||||
/** @var int[] An array of media IDs to process. */
|
||||
public array $media;
|
||||
|
||||
public function getIdentifier(): string
|
||||
{
|
||||
$messageHash = md5(
|
||||
json_encode([
|
||||
'id' => $this->storage_location_id,
|
||||
'media' => $this->media,
|
||||
], JSON_THROW_ON_ERROR)
|
||||
);
|
||||
|
||||
return 'AddMediaToSearchIndexMessage_' . $messageHash;
|
||||
}
|
||||
|
||||
public function getQueue(): string
|
||||
{
|
||||
return QueueManagerInterface::QUEUE_MEDIA;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\Repository\CustomFieldRepository;
|
||||
use App\Entity\StorageLocation;
|
||||
use App\Environment;
|
||||
use GuzzleHttp\Client as GuzzleClient;
|
||||
use GuzzleHttp\Psr7\HttpFactory;
|
||||
use Meilisearch\Client;
|
||||
|
||||
final class Meilisearch
|
||||
{
|
||||
public const BATCH_SIZE = 50;
|
||||
|
||||
public function __construct(
|
||||
private readonly Environment $environment,
|
||||
private readonly GuzzleClient $httpClient,
|
||||
private readonly CustomFieldRepository $customFieldRepo,
|
||||
) {
|
||||
}
|
||||
|
||||
public function isSupported(): bool
|
||||
{
|
||||
return $this->environment->isDocker();
|
||||
}
|
||||
|
||||
public function getClient(): Client
|
||||
{
|
||||
static $client;
|
||||
|
||||
if (!$this->isSupported()) {
|
||||
throw new \RuntimeException('This feature is not supported on this installation.');
|
||||
}
|
||||
|
||||
if (!isset($client)) {
|
||||
$psrFactory = new HttpFactory();
|
||||
$client = new Client(
|
||||
'http://localhost:6070',
|
||||
$this->environment->getMeiliMasterKey(),
|
||||
$this->httpClient,
|
||||
requestFactory: $psrFactory,
|
||||
streamFactory: $psrFactory
|
||||
);
|
||||
}
|
||||
|
||||
return $client;
|
||||
}
|
||||
|
||||
public function setupIndex(StorageLocation $storageLocation): void
|
||||
{
|
||||
$indexSettings = [
|
||||
'primaryKey' => 'id',
|
||||
'filterableAttributes' => [
|
||||
'playlists',
|
||||
'is_requestable',
|
||||
'is_on_demand'
|
||||
],
|
||||
'sortableAttributes' => [
|
||||
'path',
|
||||
'mtime',
|
||||
'length',
|
||||
'title',
|
||||
'artist',
|
||||
'album',
|
||||
'genre',
|
||||
'isrc',
|
||||
],
|
||||
];
|
||||
|
||||
foreach($this->customFieldRepo->getFieldIds() as $fieldId => $fieldShortCode) {
|
||||
$indexSettings['sortableAttributes'][] = 'custom_field_'.$fieldId;
|
||||
}
|
||||
|
||||
$client = $this->getClient();
|
||||
$client->updateIndex(
|
||||
self::getIndexId($storageLocation),
|
||||
$indexSettings
|
||||
);
|
||||
}
|
||||
|
||||
public function addToIndex(
|
||||
StorageLocation $storageLocation,
|
||||
array $ids
|
||||
): void {
|
||||
|
||||
}
|
||||
|
||||
public static function getIndexId(StorageLocation $storageLocation): string
|
||||
{
|
||||
return 'media_'.$storageLocation->getIdRequired();
|
||||
}
|
||||
}
|
|
@ -84,6 +84,7 @@ final class ServiceControl
|
|||
'redis' => __('Cache'),
|
||||
'sftpgo' => __('SFTP service'),
|
||||
'centrifugo' => __('Live Now Playing updates'),
|
||||
'meilisearch' => __('Meilisearch'),
|
||||
];
|
||||
|
||||
if (!$this->centrifugo->isSupported()) {
|
||||
|
|
Loading…
Reference in New Issue