mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-13 07:53:16 +00:00
Update providers and repositories for new import job fields
This commit is contained in:
@@ -43,11 +43,6 @@ class ImportJob extends Model
|
||||
public $validStatus
|
||||
= [
|
||||
'new',
|
||||
'configuring',
|
||||
'configured',
|
||||
'running',
|
||||
'error',
|
||||
'finished',
|
||||
];
|
||||
/**
|
||||
* The attributes that should be casted to native types.
|
||||
@@ -56,9 +51,14 @@ class ImportJob extends Model
|
||||
*/
|
||||
protected $casts
|
||||
= [
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
'configuration' => 'array',
|
||||
'extended_status' => 'array',
|
||||
'transactions' => 'array',
|
||||
];
|
||||
/** @var array */
|
||||
protected $fillable = ['key', 'user_id', 'file_type', 'source', 'status', 'stage', 'configuration', 'extended_status', 'transactions'];
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
@@ -86,9 +86,11 @@ class ImportJob extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*
|
||||
* @param int $count
|
||||
*/
|
||||
public function addTotalSteps(int $count)
|
||||
public function addTotalSteps(int $count): void
|
||||
{
|
||||
$status = $this->extended_status;
|
||||
$status['steps'] += $count;
|
||||
@@ -97,88 +99,9 @@ class ImportJob extends Model
|
||||
Log::debug(sprintf('Add %d to total steps for job "%s" making total steps %d', $count, $this->key, $status['steps']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $status
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function change(string $status): void
|
||||
{
|
||||
if (\in_array($status, $this->validStatus)) {
|
||||
Log::debug(sprintf('Job status set (in model) to "%s"', $status));
|
||||
$this->status = $status;
|
||||
$this->save();
|
||||
|
||||
return;
|
||||
}
|
||||
throw new FireflyException(sprintf('Status "%s" is invalid for job "%s".', $status, $this->key));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getConfigurationAttribute($value)
|
||||
{
|
||||
if (null === $value) {
|
||||
return [];
|
||||
}
|
||||
if (0 === \strlen($value)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return json_decode($value, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getExtendedStatusAttribute($value)
|
||||
{
|
||||
if (0 === \strlen((string)$value)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return json_decode($value, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param $value
|
||||
*/
|
||||
public function setConfigurationAttribute($value)
|
||||
{
|
||||
$this->attributes['configuration'] = json_encode($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param $value
|
||||
*/
|
||||
public function setExtendedStatusAttribute($value)
|
||||
{
|
||||
$this->attributes['extended_status'] = json_encode($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
public function setStatusAttribute(string $value)
|
||||
{
|
||||
if (\in_array($value, $this->validStatus)) {
|
||||
$this->attributes['status'] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @deprecated
|
||||
* @throws \Illuminate\Contracts\Encryption\DecryptException
|
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||
*/
|
||||
|
@@ -108,34 +108,34 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param string $importProvider
|
||||
*
|
||||
* @return ImportJob
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function create(string $type): ImportJob
|
||||
public function create(string $importProvider): ImportJob
|
||||
{
|
||||
$count = 0;
|
||||
$type = strtolower($type);
|
||||
$count = 0;
|
||||
$importProvider = strtolower($importProvider);
|
||||
|
||||
while ($count < 30) {
|
||||
$key = Str::random(12);
|
||||
$existing = $this->findByKey($key);
|
||||
if (null === $existing->id) {
|
||||
$importJob = new ImportJob;
|
||||
$importJob->user()->associate($this->user);
|
||||
$importJob->file_type = $type;
|
||||
$importJob->key = Str::random(12);
|
||||
$importJob->status = 'new';
|
||||
$importJob->configuration = [];
|
||||
$importJob->extended_status = [
|
||||
'steps' => 0,
|
||||
'done' => 0,
|
||||
'tag' => 0,
|
||||
'errors' => [],
|
||||
];
|
||||
$importJob->save();
|
||||
$importJob = ImportJob::create(
|
||||
[
|
||||
'user_id' => $this->user->id,
|
||||
'source' => $importProvider,
|
||||
'file_type' => '',
|
||||
'key' => Str::random(12),
|
||||
'status' => 'new',
|
||||
'stage' => 'new',
|
||||
'configuration' => [],
|
||||
'extended_status' => [],
|
||||
'transactions' => [],
|
||||
]
|
||||
);
|
||||
|
||||
// breaks the loop:
|
||||
return $importJob;
|
||||
|
@@ -67,11 +67,11 @@ interface ImportJobRepositoryInterface
|
||||
public function countByHash(string $hash): int;
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param string $importProvider
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function create(string $type): ImportJob;
|
||||
public function create(string $importProvider): ImportJob;
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
|
55
app/Support/Binder/ImportProvider.php
Normal file
55
app/Support/Binder/ImportProvider.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* ImportProvider.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Binder;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Routing\Route;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* Class ImportProvider.
|
||||
*/
|
||||
class ImportProvider implements BinderInterface
|
||||
{
|
||||
/**
|
||||
* @param string $value
|
||||
* @param Route $route
|
||||
*
|
||||
* @return Carbon
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
|
||||
*/
|
||||
public static function routeBinder(string $value, Route $route): string
|
||||
{
|
||||
$providers = (array)config('import.enabled');
|
||||
$allowed = [];
|
||||
foreach ($providers as $name => $enabled) {
|
||||
if ($enabled || (bool)config('app.debug') === true) {
|
||||
$allowed[] = $name;
|
||||
}
|
||||
}
|
||||
if (\in_array($value, $allowed, true)) {
|
||||
return $value;
|
||||
}
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user