From a6b09acd5e78e448243357051a78c91caeec3b20 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 2 Jun 2018 18:19:35 +0200 Subject: [PATCH] Some last minute fixes. --- app/Factory/TransactionJournalMetaFactory.php | 1 + app/Http/Controllers/TagController.php | 4 ++-- app/Import/Storage/ImportArrayStorage.php | 23 ++++++++++++++++++- app/Models/TransactionJournalMeta.php | 1 + .../Journal/JournalRepository.php | 15 ++++++++++-- .../Internal/Support/JournalServiceTrait.php | 9 +++++++- app/Support/Navigation.php | 2 ++ config/firefly.php | 4 ---- public/index.php | 2 +- 9 files changed, 50 insertions(+), 11 deletions(-) diff --git a/app/Factory/TransactionJournalMetaFactory.php b/app/Factory/TransactionJournalMetaFactory.php index 4289b31b7a..2af8397c0a 100644 --- a/app/Factory/TransactionJournalMetaFactory.php +++ b/app/Factory/TransactionJournalMetaFactory.php @@ -71,6 +71,7 @@ class TransactionJournalMetaFactory } if (null === $entry) { + Log::debug(sprintf('Going to create new meta-data entry to store "%s".', $data['name'])); $entry = new TransactionJournalMeta(); $entry->transactionJournal()->associate($data['journal']); $entry->name = $data['name']; diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php index 8857bd8ea0..ae509f6b91 100644 --- a/app/Http/Controllers/TagController.php +++ b/app/Http/Controllers/TagController.php @@ -289,8 +289,8 @@ class TagController extends Controller { // get first and last tag date from tag: $range = Preferences::get('viewRange', '1M')->data; - $start = app('navigation')->startOfPeriod($this->repository->firstUseDate($tag), $range); - $end = app('navigation')->endOfPeriod($this->repository->lastUseDate($tag), $range); + $start = app('navigation')->startOfPeriod($this->repository->firstUseDate($tag), $range)->startOfMonth(); + $end = app('navigation')->endOfPeriod($this->repository->lastUseDate($tag), $range)->endOfMonth(); // properties for entries with their amounts. $cache = new CacheProperties; diff --git a/app/Import/Storage/ImportArrayStorage.php b/app/Import/Storage/ImportArrayStorage.php index 6db0712dd7..70d050c354 100644 --- a/app/Import/Storage/ImportArrayStorage.php +++ b/app/Import/Storage/ImportArrayStorage.php @@ -173,12 +173,15 @@ class ImportArrayStorage */ private function getHash(array $transaction): string { + unset($transaction['importHashV2']); $json = json_encode($transaction); if ($json === false) { throw new FireflyException('Could not encode import array. Please see the logs.', $transaction); // @codeCoverageIgnore } + $hash = hash('sha256', $json, false); + Log::debug(sprintf('The hash is: %s', $hash)); - return hash('sha256', $json, false); + return $hash; } /** @@ -227,6 +230,8 @@ class ImportArrayStorage { $entry = $this->journalRepos->findByHash($hash); if (null === $entry) { + Log::debug(sprintf('Found no transactions with hash %s.', $hash)); + return null; } Log::info(sprintf('Found a transaction journal with an existing hash: %s', $hash)); @@ -380,6 +385,22 @@ class ImportArrayStorage // now actually store them: $collection = new Collection; foreach ($toStore as $index => $store) { + + // do duplicate detection again! + $hash = $this->getHash($store); + $existingId = $this->hashExists($hash); + if (null !== $existingId) { + $this->logDuplicateObject($store, $existingId); + $this->repository->addErrorMessage( + $this->importJob, sprintf( + 'Row #%d ("%s") could not be imported. It already exists.', + $index, $store['description'] + ) + ); + continue; + } + + Log::debug(sprintf('Going to store entry %d of %d', $index + 1, $count)); // convert the date to an object: $store['date'] = Carbon::createFromFormat('Y-m-d', $store['date']); diff --git a/app/Models/TransactionJournalMeta.php b/app/Models/TransactionJournalMeta.php index 5016de36e2..e40624dda3 100644 --- a/app/Models/TransactionJournalMeta.php +++ b/app/Models/TransactionJournalMeta.php @@ -29,6 +29,7 @@ use FireflyIII\Models\TransactionJournal; /** * Class TransactionJournalMeta. + * @property string $name */ class TransactionJournalMeta extends Model { diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php index a1539b3c0a..e5dc693a60 100644 --- a/app/Repositories/Journal/JournalRepository.php +++ b/app/Repositories/Journal/JournalRepository.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Repositories\Journal; use Carbon\Carbon; +use DB; use Exception; use FireflyIII\Factory\TransactionJournalFactory; use FireflyIII\Factory\TransactionJournalMetaFactory; @@ -157,11 +158,21 @@ class JournalRepository implements JournalRepositoryInterface */ public function findByHash(string $hash): ?TransactionJournalMeta { - return TransactionJournalMeta + $jsonEncode = json_encode($hash); + $hashOfHash = hash('sha256', $jsonEncode); + Log::debug(sprintf('JSON encoded hash is: %s', $jsonEncode)); + Log::debug(sprintf('Hash of hash is: %s', $hashOfHash)); + + $result = TransactionJournalMeta ::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id') - ->where('data', json_encode($hash)) + ->where('hash', $hashOfHash) ->where('name', 'importHashV2') ->first(['journal_meta.*']); + if (null === $result) { + Log::debug('Result is null'); + } + + return $result; } /** diff --git a/app/Services/Internal/Support/JournalServiceTrait.php b/app/Services/Internal/Support/JournalServiceTrait.php index afd16844e5..e6ab014cab 100644 --- a/app/Services/Internal/Support/JournalServiceTrait.php +++ b/app/Services/Internal/Support/JournalServiceTrait.php @@ -28,6 +28,7 @@ use FireflyIII\Factory\TagFactory; use FireflyIII\Factory\TransactionJournalMetaFactory; use FireflyIII\Models\Note; use FireflyIII\Models\TransactionJournal; +use Log; /** * Trait JournalServiceTrait @@ -89,14 +90,20 @@ trait JournalServiceTrait */ protected function storeMeta(TransactionJournal $journal, array $data, string $field): void { + if (!isset($data[$field])) { + Log::debug(sprintf('Want to store meta-field "%s", but no value.', $field)); + return; } $set = [ 'journal' => $journal, 'name' => $field, - 'data' => $data[$field], + 'data' => (string)$data[$field], ]; + + Log::debug(sprintf('Going to store meta-field "%s", with value "%s".', $field, (string)$data[$field])); + /** @var TransactionJournalMetaFactory $factory */ $factory = app(TransactionJournalMetaFactory::class); $factory->updateOrCreate($set); diff --git a/app/Support/Navigation.php b/app/Support/Navigation.php index cbb4645d76..c2bfa7bf81 100644 --- a/app/Support/Navigation.php +++ b/app/Support/Navigation.php @@ -190,10 +190,12 @@ class Navigation return $currentEnd; } + if (!isset($functionMap[$repeatFreq])) { throw new FireflyException(sprintf('Cannot do endOfPeriod for $repeat_freq "%s"', $repeatFreq)); } $function = $functionMap[$repeatFreq]; + if (isset($modifierMap[$repeatFreq])) { $currentEnd->$function($modifierMap[$repeatFreq]); diff --git a/config/firefly.php b/config/firefly.php index 6a71f95dce..c0fe9ed9ea 100644 --- a/config/firefly.php +++ b/config/firefly.php @@ -158,10 +158,6 @@ return [ 'export_formats' => [ 'csv' => CsvExporter::class, ], - 'spectre' => [ - 'server' => 'https://www.saltedge.com', - ], - 'default_export_format' => 'csv', 'default_import_format' => 'csv', 'bill_periods' => ['weekly', 'monthly', 'quarterly', 'half-year', 'yearly'], diff --git a/public/index.php b/public/index.php index 86d14aca18..1a28dc9bab 100644 --- a/public/index.php +++ b/public/index.php @@ -57,6 +57,7 @@ require __DIR__ . '/../vendor/autoload.php'; /** @noinspection UsingInclusionOnceReturnValueInspection */ $app = require_once __DIR__ . '/../bootstrap/app.php'; + /* |-------------------------------------------------------------------------- | Run The Application @@ -74,7 +75,6 @@ $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); $response = $kernel->handle( $request = Illuminate\Http\Request::capture() ); - $response->send(); $kernel->terminate($request, $response);