Fix various import bugs.

This commit is contained in:
James Cole 2017-06-24 08:37:09 +02:00
parent da3a56c144
commit 8e3ba7caf2
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
8 changed files with 25 additions and 22 deletions

View File

@ -81,11 +81,8 @@ class Import extends Command
$routine->run();
/** @var MessageBag $error */
foreach($routine->errors as $index => $error) {
if($error->count() > 0) {
$message = join(', ',$error->all());
$this->error(sprintf('Error importing line #%d: %s', $index, $message));
}
foreach ($routine->errors as $index => $error) {
$this->error(sprintf('Error importing line #%d: %s', $index, $error));
}
// display result to user:

View File

@ -15,6 +15,7 @@ namespace FireflyIII\Http\Controllers;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Http\Requests\TagFormRequest;
use FireflyIII\Models\Tag;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
@ -245,6 +246,7 @@ class TagController extends Controller
$periods = new Collection;
$apiKey = env('GOOGLE_MAPS_API_KEY', '');
$sum = '0';
$path = 'tags/show/' . $tag->id;
// prep for "all" view.
@ -253,6 +255,7 @@ class TagController extends Controller
$start = $repository->firstUseDate($tag);
$end = new Carbon;
$sum = $repository->sumOfTag($tag);
$path = 'tags/show/' . $tag->id . '/all';
}
// prep for "specific date" view.
@ -282,13 +285,13 @@ class TagController extends Controller
Log::info('Now at tag loop start.');
while ($count === 0 && $loop < 3) {
$loop++;
Log::info('Count is zero, search for journals.');
Log::info(sprintf('Count is zero, search for journals between %s and %s (pagesize %d, page %d).', $start, $end, $pageSize, $page));
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withOpposingAccount()
->setTag($tag)->withBudgetInformation()->withCategoryInformation();
->setTag($tag)->withBudgetInformation()->withCategoryInformation()->removeFilter(InternalTransferFilter::class);
$journals = $collector->getPaginatedJournals();
$journals->setPath('tags/show/' . $tag->id);
$journals->setPath($path);
$count = $journals->getCollection()->count();
if ($count === 0) {
$start->subDay();

View File

@ -99,6 +99,13 @@ class CsvConfigurator implements ConfiguratorInterface
*/
public function isJobConfigured(): bool
{
$config = $this->job->configuration;
$config['initial-config-complete'] = $config['initial-config-complete'] ?? false;
$config['column-roles-complete'] = $config['column-roles-complete'] ?? false;
$config['column-mapping-complete'] = $config['column-mapping-complete'] ?? false;
$this->job->configuration = $config;
$this->job->save();
if ($this->job->configuration['initial-config-complete']
&& $this->job->configuration['column-roles-complete']
&& $this->job->configuration['column-mapping-complete']

View File

@ -70,7 +70,6 @@ class CsvProcessor implements FileProcessorInterface
$index = 0;
Log::notice('Building importable objects from CSV file.');
foreach ($entries as $index => $row) {
sleep(1);
// verify if not exists already:
if ($this->rowAlreadyImported($row)) {
$message = sprintf('Row #%d has already been imported.', $index);
@ -198,8 +197,6 @@ class CsvProcessor implements FileProcessorInterface
->where('data', $json)
->where('name', 'importHash')
->first();
return rand(1, 10) === 3;
if (!is_null($entry)) {
return true;
}

View File

@ -58,13 +58,13 @@ class ImportRoutine
return false;
}
set_time_limit(0);
Log::debug(sprintf('Start with import job %s', $this->job->key));
Log::info(sprintf('Start with import job %s', $this->job->key));
$importObjects = $this->getImportObjects();
$this->lines = $importObjects->count();
// once done, use storage thing to actually store them:
Log::debug(sprintf('Returned %d valid objects from file processor', $this->lines));
Log::info(sprintf('Returned %d valid objects from file processor', $this->lines));
$storage = $this->storeObjects($importObjects);
@ -78,7 +78,7 @@ class ImportRoutine
// create tag, link tag to all journals:
$this->createImportTag();
Log::debug(sprintf('Done with import job %s', $this->job->key));
Log::info(sprintf('Done with import job %s', $this->job->key));
return true;
}

View File

@ -97,7 +97,6 @@ class ImportStorage
{
$this->defaultCurrency = Amount::getDefaultCurrencyByUser($this->job->user);
// routine below consists of 3 steps.
/**
* @var int $index
@ -283,10 +282,8 @@ class ImportStorage
private function storeImportJournal(int $index, ImportJournal $importJournal): bool
{
sleep(1);
Log::debug(sprintf('Going to store object #%d with description "%s"', $index, $importJournal->description));
$errors = new MessageBag;
$asset = $importJournal->asset->getAccount();
$amount = $importJournal->getAmount();
$currency = $this->getCurrency($importJournal);
@ -354,7 +351,6 @@ class ImportStorage
$this->job->addStepsDone(1);
$this->journals->push($journal);
$this->errors->push($errors);
return true;
}

View File

@ -121,16 +121,19 @@ function showStalledBox() {
*/
function jobIsStalled(data) {
console.log('jobIsStalled(' + numberOfSteps + ', ' + numberOfReports + ')');
if (data.steps === numberOfSteps) {
if (data.done === numberOfSteps) {
numberOfReports++;
console.log('Number of reports is now ' + numberOfReports);
}
if (data.done !== numberOfSteps) {
console.log(data.done + ' (data.done) is not ' + numberOfReports + ' (numberOfSteps)');
numberOfReports = 0;
}
if (numberOfReports > 20) {
return true;
}
numberOfSteps = data.done;
console.log('Number of steps is now ' + numberOfSteps);
return false;
}

View File

@ -107,7 +107,7 @@
<div class="box-body">
{% include 'list/journals' %}
{% if periods %}
{% if periods.count > 0 %}
<p>
<i class="fa fa-calendar" aria-hidden="true"></i>
<a href="{{ route('tags.show', [tag.id,'all']) }}">
@ -125,7 +125,7 @@
</div>
</div>
</div>
{% if periods %}
{% if periods.count > 0 %}
<div class="col-lg-2 col-md-2 col-sm-12 col-xs-12">
{% for period in periods %}
{% if period.spent != 0 or period.earned != 0 %}
@ -157,7 +157,7 @@
</div>
{% endif %}
</div>
{% if periods %}
{% if periods.count > 0 %}
<div class="row">
<div class="col-lg-offset-10 col-lg-2 col-md-offset-10 col-md-2 col-sm-12 col-xs-12">
<p class="small text-center"><a href="{{ route('tags.show',[tag.id]) }}">{{ 'showEverything'|_ }}</a></p>