James Cole 2023-12-24 15:53:24 +01:00
parent ebe1fd6142
commit 2b90c20db8
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
3 changed files with 60 additions and 29 deletions

View File

@ -15,10 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
uses: actions/checkout@v4
- name: Setup PHP with Xdebug
uses: shivammathur/setup-php@v2
with:

View File

@ -33,6 +33,7 @@ use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
/**
* Trait MetaCollection
@ -663,7 +664,7 @@ trait MetaCollection
public function setTag(Tag $tag): GroupCollectorInterface
{
$this->withTagInformation();
$this->query->where('tag_transaction_journal.tag_id', $tag->id);
$this->setTags(new Collection([$tag]));
return $this;
}
@ -673,9 +674,38 @@ trait MetaCollection
*/
public function setTags(Collection $tags): GroupCollectorInterface
{
Log::debug(sprintf('Now in setTags(%d tag(s))', $tags->count()));
$this->withTagInformation();
$this->tags = array_merge($this->tags, $tags->pluck('id')->toArray());
$this->query->whereIn('tag_transaction_journal.tag_id', $this->tags);
$this->query->whereNotNull('tag_transaction_journal.tag_id');
// this method adds a "postFilter" to the collector.
$list = $tags->pluck('tag')->toArray();
$filter = static function (array $object) use ($list): bool {
Log::debug(sprintf('Now in setTags(%s) filter', implode(', ', $list)));
$expectedTagCount = count($list);
$foundTagCount = 0;
foreach ($object['transactions'] as $transaction) {
$transactionTagCount = count($transaction['tags']);
app('log')->debug(sprintf('Transaction has %d tag(s)', $transactionTagCount));
if ($transactionTagCount < $expectedTagCount) {
app('log')->debug(sprintf('Transaction has %d tag(s), we expect %d tag(s), return false.', $transactionTagCount, $expectedTagCount));
return false;
}
foreach ($transaction['tags'] as $tag) {
Log::debug(sprintf('"%s" versus', strtolower($tag['name'])), $list);
if (in_array(strtolower($tag['name']), $list, true)) {
app('log')->debug(sprintf('Transaction has tag "%s" so count++.', $tag['name']));
++$foundTagCount;
}
}
}
Log::debug(sprintf('Found %d tags, need at least %d.', $foundTagCount, $expectedTagCount));
// found at least the expected tags.
return $foundTagCount >= $expectedTagCount;
};
$this->postFilters[] = $filter;
return $this;
}
@ -690,10 +720,14 @@ trait MetaCollection
// this method adds a "postFilter" to the collector.
$list = $tags->pluck('tag')->toArray();
$filter = static function (array $object) use ($list): bool {
Log::debug(sprintf('Now in setWithoutSpecificTags(%s) filter', implode(', ', $list)));
foreach ($object['transactions'] as $transaction) {
app('log')->debug(sprintf('Transaction has %d tag(s)', count($transaction['tags'])));
foreach ($transaction['tags'] as $tag) {
if (in_array($tag['name'], $list, true)) {
Log::debug(sprintf('"%s" versus', strtolower($tag['name'])), $list);
if (in_array(strtolower($tag['name']), $list, true)) {
app('log')->debug(sprintf('Transaction has tag "%s", but should not have it, return false.', $tag['name']));
return false;
}
}

View File

@ -927,7 +927,7 @@ class GroupCollector implements GroupCollectorInterface
{
$currentCollection = $collection;
// app('log')->debug(sprintf('GroupCollector: postFilterCollection has %d filter(s) and %d transaction(s).', count($this->postFilters), count($currentCollection)));
app('log')->debug(sprintf('GroupCollector: postFilterCollection has %d filter(s) and %d transaction(s).', count($this->postFilters), count($currentCollection)));
/**
* @var \Closure $function