Skip to content

Firefly III: a personal finances manager

Fixed a bug in tag creation.

James Cole2111873bcf6b
diff --git a/app/Import/Converter/TagsComma.php b/app/Import/Converter/TagsComma.php
index 63c8e3e85c..4ae1b10646 100644
--- a/app/Import/Converter/TagsComma.php
+++ b/app/Import/Converter/TagsComma.php
@@ -35,6 +35,7 @@ class TagsComma extends BasicConverter implements ConverterInterface
if (strlen($value) === 0) {
$this->setCertainty(0);
+
return new Collection;
}
$parts = array_unique(explode(',', $value));
@@ -63,22 +64,23 @@ class TagsComma extends BasicConverter implements ConverterInterface
Log::debug('Found tag by name ', ['id' => $tag->id]);
$set->push($tag);
- continue;
}
- // create new tag
- $tag = $repository->store(
- [
- 'tag' => $part,
- 'date' => null,
- 'description' => $part,
- 'latitude' => null,
- 'longitude' => null,
- 'zoomLevel' => null,
- 'tagMode' => 'nothing',
- ]
- );
- Log::debug('Created new tag', ['name' => $part, 'id' => $tag->id]);
- $set->push($tag);
+ if (is_null($tag->id)) {
+ // create new tag
+ $tag = $repository->store(
+ [
+ 'tag' => $part,
+ 'date' => null,
+ 'description' => $part,
+ 'latitude' => null,
+ 'longitude' => null,
+ 'zoomLevel' => null,
+ 'tagMode' => 'nothing',
+ ]
+ );
+ Log::debug('Created new tag', ['name' => $part, 'id' => $tag->id]);
+ $set->push($tag);
+ }
}
$this->setCertainty(100);
diff --git a/app/Import/Converter/TagsSpace.php b/app/Import/Converter/TagsSpace.php
index c5c5f9a505..6f61d192c6 100644
--- a/app/Import/Converter/TagsSpace.php
+++ b/app/Import/Converter/TagsSpace.php
@@ -35,6 +35,7 @@ class TagsSpace extends BasicConverter implements ConverterInterface
if (strlen($value) === 0) {
$this->setCertainty(0);
+
return new Collection;
}
$parts = array_unique(explode(' ', $value));
@@ -63,22 +64,23 @@ class TagsSpace extends BasicConverter implements ConverterInterface
Log::debug('Found tag by name ', ['id' => $tag->id]);
$set->push($tag);
- continue;
}
- // create new tag
- $tag = $repository->store(
- [
- 'tag' => $part,
- 'date' => null,
- 'description' => $part,
- 'latitude' => null,
- 'longitude' => null,
- 'zoomLevel' => null,
- 'tagMode' => 'nothing',
- ]
- );
- Log::debug('Created new tag', ['name' => $part, 'id' => $tag->id]);
- $set->push($tag);
+ if (is_null($tag->id)) {
+ // create new tag
+ $tag = $repository->store(
+ [
+ 'tag' => $part,
+ 'date' => null,
+ 'description' => $part,
+ 'latitude' => null,
+ 'longitude' => null,
+ 'zoomLevel' => null,
+ 'tagMode' => 'nothing',
+ ]
+ );
+ Log::debug('Created new tag', ['name' => $part, 'id' => $tag->id]);
+ $set->push($tag);
+ }
}
$this->setCertainty(100);
diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php
index d83f9ce17f..a794d3f6f7 100644
--- a/app/Repositories/Tag/TagRepository.php
+++ b/app/Repositories/Tag/TagRepository.php
@@ -106,9 +106,9 @@ class TagRepository implements TagRepositoryInterface
{
$tags = $this->user->tags()->get();
/** @var Tag $tag */
- foreach ($tags as $tag) {
- if ($tag->tag === $tag) {
- return $tag;
+ foreach ($tags as $databaseTag) {
+ if ($databaseTag->tag === $tag) {
+ return $databaseTag;
}
}