Catch empty tags.

This commit is contained in:
James Cole
2015-04-28 21:01:54 +02:00
parent b747c50aa3
commit fd4e77ae0f

View File

@@ -70,10 +70,12 @@ class JournalRepository implements JournalRepositoryInterface
$tagRepository = App::make('FireflyIII\Repositories\Tag\TagRepositoryInterface'); $tagRepository = App::make('FireflyIII\Repositories\Tag\TagRepositoryInterface');
foreach ($array as $name) { foreach ($array as $name) {
if (strlen(trim($name)) > 0) {
$tag = Tag::firstOrCreateEncrypted(['tag' => $name, 'user_id' => $journal->user_id]); $tag = Tag::firstOrCreateEncrypted(['tag' => $name, 'user_id' => $journal->user_id]);
$tagRepository->connect($journal, $tag); $tagRepository->connect($journal, $tag);
} }
} }
}
/** /**
* @param array $data * @param array $data
@@ -217,10 +219,12 @@ class JournalRepository implements JournalRepositoryInterface
$tags = []; $tags = [];
$ids = []; $ids = [];
foreach ($array as $name) { foreach ($array as $name) {
if (strlen(trim($name)) > 0) {
$tag = Tag::firstOrCreateEncrypted(['tag' => $name, 'user_id' => $journal->user_id]); $tag = Tag::firstOrCreateEncrypted(['tag' => $name, 'user_id' => $journal->user_id]);
$tags[] = $tag; $tags[] = $tag;
$ids[] = $tag->id; $ids[] = $tag->id;
} }
}
// delete all tags connected to journal not in this array: // delete all tags connected to journal not in this array:
if (count($ids) > 0) { if (count($ids) > 0) {