mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Optimise tests and coverage.
This commit is contained in:
@@ -26,9 +26,10 @@ use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Import\Prerequisites\PrerequisitesInterface;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Log;
|
||||
use View;
|
||||
|
||||
|
||||
/**
|
||||
* Class FileController.
|
||||
*/
|
||||
@@ -37,6 +38,9 @@ class IndexController extends Controller
|
||||
/** @var ImportJobRepositoryInterface */
|
||||
public $repository;
|
||||
|
||||
/** @var UserRepositoryInterface */
|
||||
public $userRepository;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -48,7 +52,8 @@ class IndexController extends Controller
|
||||
function ($request, $next) {
|
||||
app('view')->share('mainTitleIcon', 'fa-archive');
|
||||
app('view')->share('title', trans('firefly.import_index_title'));
|
||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||
$this->userRepository = app(UserRepositoryInterface::class);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
@@ -66,6 +71,8 @@ class IndexController extends Controller
|
||||
*/
|
||||
public function create(string $importProvider)
|
||||
{
|
||||
// can only create "fake" for demo user.
|
||||
|
||||
if (
|
||||
!(bool)config('app.debug')
|
||||
&& !(bool)config(sprintf('import.enabled.%s', $importProvider)) === true
|
||||
@@ -124,34 +131,59 @@ class IndexController extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// get all import routines:
|
||||
/** @var array $config */
|
||||
$config = config('import.enabled');
|
||||
$providers = [];
|
||||
foreach ($config as $name => $enabled) {
|
||||
if ($enabled || (bool)config('app.debug') || \in_array(config('app.env'), ['demo', 'testing'])) {
|
||||
$providers[$name] = [];
|
||||
}
|
||||
}
|
||||
|
||||
// has prereq or config?
|
||||
foreach (array_keys($providers) as $name) {
|
||||
$providers[$name]['has_prereq'] = (bool)config('import.has_prereq.' . $name);
|
||||
$providers[$name]['has_config'] = (bool)config('import.has_config.' . $name);
|
||||
$class = (string)config('import.prerequisites.' . $name);
|
||||
$result = false;
|
||||
if ($class !== '' && class_exists($class)) {
|
||||
/** @var PrerequisitesInterface $object */
|
||||
$object = app($class);
|
||||
$object->setUser(auth()->user());
|
||||
$result = $object->isComplete();
|
||||
}
|
||||
$providers[$name]['prereq_complete'] = $result;
|
||||
}
|
||||
|
||||
$providers = $this->getProviders();
|
||||
$subTitle = trans('import.index_breadcrumb');
|
||||
$subTitleIcon = 'fa-home';
|
||||
|
||||
return view('import.index', compact('subTitle', 'subTitleIcon', 'providers'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getProviders(): array
|
||||
{
|
||||
// get and filter all import routines:
|
||||
/** @var array $config */
|
||||
$providerNames = array_keys(config('import.enabled'));
|
||||
$providers = [];
|
||||
$isDemoUser = $this->userRepository->hasRole(auth()->user(), 'demo');
|
||||
foreach ($providerNames as $providerName) {
|
||||
Log::debug(sprintf('Now with provider %s', $providerName));
|
||||
// only consider enabled providers
|
||||
$enabled = (bool)config(sprintf('import.enabled.%s', $providerName));
|
||||
$allowedForDemo = (bool)config(sprintf('import.allowed_for_demo.%s', $providerName));
|
||||
$allowedForUser = (bool)config(sprintf('import.allowed_for_user.%s', $providerName));
|
||||
if ($enabled === false) {
|
||||
Log::debug('Provider is not enabled. NEXT!');
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($isDemoUser === true && $allowedForDemo === false) {
|
||||
Log::debug('User is demo and this provider is not allowed for demo user. NEXT!');
|
||||
continue;
|
||||
}
|
||||
if ($isDemoUser === false && $allowedForUser === false) {
|
||||
Log::debug('User is not demo and this provider is not allowed for such users. NEXT!');
|
||||
continue;
|
||||
}
|
||||
|
||||
$providers[$providerName] = [
|
||||
'has_prereq' => (bool)config('import.has_prereq.' . $providerName),
|
||||
'has_config' => (bool)config('import.has_config.' . $providerName),
|
||||
];
|
||||
$class = (string)config(sprintf('import.prerequisites.%s', $providerName));
|
||||
$result = false;
|
||||
if ($class !== '' && class_exists($class)) {
|
||||
Log::debug('Will not check prerequisites.');
|
||||
/** @var PrerequisitesInterface $object */
|
||||
$object = app($class);
|
||||
$object->setUser(auth()->user());
|
||||
$result = $object->isComplete();
|
||||
}
|
||||
$providers[$providerName]['prereq_complete'] = $result;
|
||||
}
|
||||
|
||||
return $providers;
|
||||
}
|
||||
}
|
||||
|
@@ -117,12 +117,9 @@ class JobStatusController extends Controller
|
||||
{
|
||||
// catch impossible status:
|
||||
$allowed = ['ready_to_run', 'need_job_config'];
|
||||
// todo remove error and running.
|
||||
|
||||
if (null !== $importJob && !\in_array($importJob->status, $allowed, true)) {
|
||||
Log::error('Job is not ready.');
|
||||
|
||||
// kill the job:
|
||||
$this->repository->setStatus($importJob, 'error');
|
||||
|
||||
return response()->json(['status' => 'NOK', 'message' => 'JobStatusController::start expects status "ready_to_run".']);
|
||||
@@ -138,9 +135,6 @@ class JobStatusController extends Controller
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
// set job to be running:
|
||||
$this->repository->setStatus($importJob, 'running');
|
||||
|
||||
/** @var RoutineInterface $routine */
|
||||
$routine = app($className);
|
||||
$routine->setImportJob($importJob);
|
||||
|
Reference in New Issue
Block a user