blue-twilight/app/Helpers/AnalysisQueueHelper.php

66 lines
1.6 KiB
PHP
Raw Normal View History

<?php
namespace App\Helpers;
use App\AlbumSources\IAnalysisQueueSource;
use App\Facade\UserConfig;
use App\Storage;
class AnalysisQueueHelper
{
/**
* Gets the storage queue source in use.
* @return IAnalysisQueueSource
*/
public static function getStorageQueueSource()
{
$queueStorage = Storage::find(UserConfig::get('analysis_queue_storage_location'));
$queueSource = self::createStorageSource($queueStorage);
if (is_null($queueSource))
{
throw new \Exception(sprintf('Queue storage \'%s\' does not support the analysis queue', $queueStorage->name));
}
return $queueSource;
}
/**
* Gets a list of compatible storage sources for the analysis queue.
* @return array
*/
public static function getCompatibleStorages()
{
$storageSources = [];
foreach (Storage::where('is_active', true)->orderBy('name')->get() as $storage)
{
$queueSource = self::createStorageSource($storage);
if (is_null($queueSource))
{
continue;
}
$storageSources[$storage->id] = $storage->name;
}
return $storageSources;
}
private static function createStorageSource(Storage $queueStorage)
{
$fullClassName = sprintf('App\AlbumSources\%s', $queueStorage->source);
/** @var IAnalysisQueueSource $source */
$source = new $fullClassName;
if (!$source instanceof IAnalysisQueueSource)
{
return null;
}
$source->setConfiguration($queueStorage);
return $source;
}
}