2019-07-12 16:21:30 +01:00
|
|
|
<?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'));
|
|
|
|
|
2019-07-13 10:27:35 +01:00
|
|
|
$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)
|
|
|
|
{
|
2019-07-12 16:21:30 +01:00
|
|
|
$fullClassName = sprintf('App\AlbumSources\%s', $queueStorage->source);
|
|
|
|
|
|
|
|
/** @var IAnalysisQueueSource $source */
|
|
|
|
$source = new $fullClassName;
|
2019-07-13 10:27:35 +01:00
|
|
|
if (!$source instanceof IAnalysisQueueSource)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-07-12 16:21:30 +01:00
|
|
|
$source->setConfiguration($queueStorage);
|
|
|
|
|
|
|
|
return $source;
|
|
|
|
}
|
|
|
|
}
|