mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-14 00:04:24 +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
|
public $validStatus
|
||||||
= [
|
= [
|
||||||
'new',
|
'new',
|
||||||
'configuring',
|
|
||||||
'configured',
|
|
||||||
'running',
|
|
||||||
'error',
|
|
||||||
'finished',
|
|
||||||
];
|
];
|
||||||
/**
|
/**
|
||||||
* The attributes that should be casted to native types.
|
* The attributes that should be casted to native types.
|
||||||
@@ -58,7 +53,12 @@ class ImportJob extends Model
|
|||||||
= [
|
= [
|
||||||
'created_at' => 'datetime',
|
'created_at' => 'datetime',
|
||||||
'updated_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
|
* @param $value
|
||||||
@@ -86,9 +86,11 @@ class ImportJob extends Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*
|
||||||
* @param int $count
|
* @param int $count
|
||||||
*/
|
*/
|
||||||
public function addTotalSteps(int $count)
|
public function addTotalSteps(int $count): void
|
||||||
{
|
{
|
||||||
$status = $this->extended_status;
|
$status = $this->extended_status;
|
||||||
$status['steps'] += $count;
|
$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']));
|
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
|
* @return string
|
||||||
*
|
* @deprecated
|
||||||
* @throws \Illuminate\Contracts\Encryption\DecryptException
|
* @throws \Illuminate\Contracts\Encryption\DecryptException
|
||||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||||
*/
|
*/
|
||||||
|
@@ -108,34 +108,34 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $type
|
* @param string $importProvider
|
||||||
*
|
*
|
||||||
* @return ImportJob
|
* @return ImportJob
|
||||||
*
|
*
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function create(string $type): ImportJob
|
public function create(string $importProvider): ImportJob
|
||||||
{
|
{
|
||||||
$count = 0;
|
$count = 0;
|
||||||
$type = strtolower($type);
|
$importProvider = strtolower($importProvider);
|
||||||
|
|
||||||
while ($count < 30) {
|
while ($count < 30) {
|
||||||
$key = Str::random(12);
|
$key = Str::random(12);
|
||||||
$existing = $this->findByKey($key);
|
$existing = $this->findByKey($key);
|
||||||
if (null === $existing->id) {
|
if (null === $existing->id) {
|
||||||
$importJob = new ImportJob;
|
$importJob = ImportJob::create(
|
||||||
$importJob->user()->associate($this->user);
|
[
|
||||||
$importJob->file_type = $type;
|
'user_id' => $this->user->id,
|
||||||
$importJob->key = Str::random(12);
|
'source' => $importProvider,
|
||||||
$importJob->status = 'new';
|
'file_type' => '',
|
||||||
$importJob->configuration = [];
|
'key' => Str::random(12),
|
||||||
$importJob->extended_status = [
|
'status' => 'new',
|
||||||
'steps' => 0,
|
'stage' => 'new',
|
||||||
'done' => 0,
|
'configuration' => [],
|
||||||
'tag' => 0,
|
'extended_status' => [],
|
||||||
'errors' => [],
|
'transactions' => [],
|
||||||
];
|
]
|
||||||
$importJob->save();
|
);
|
||||||
|
|
||||||
// breaks the loop:
|
// breaks the loop:
|
||||||
return $importJob;
|
return $importJob;
|
||||||
|
@@ -67,11 +67,11 @@ interface ImportJobRepositoryInterface
|
|||||||
public function countByHash(string $hash): int;
|
public function countByHash(string $hash): int;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $type
|
* @param string $importProvider
|
||||||
*
|
*
|
||||||
* @return ImportJob
|
* @return ImportJob
|
||||||
*/
|
*/
|
||||||
public function create(string $type): ImportJob;
|
public function create(string $importProvider): ImportJob;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $key
|
* @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