mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Search for non-existing values now returns nothing.
This commit is contained in:
parent
0e5256c8ce
commit
6691062747
@ -767,4 +767,14 @@ class GroupCollector implements GroupCollectorInterface
|
||||
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function findNothing(): GroupCollectorInterface
|
||||
{
|
||||
$this->query->where('transaction_groups.id', -1);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,13 @@ interface GroupCollectorInterface
|
||||
*/
|
||||
public function amountLess(string $amount): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Ensure the search will find nothing at all, zero results.
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function findNothing(): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Get transactions where the amount is more than.
|
||||
*
|
||||
|
@ -345,6 +345,10 @@ class OperatorQuerySearch implements SearchInterface
|
||||
if (null !== $account) {
|
||||
$this->collector->setSourceAccounts(new Collection([$account]));
|
||||
}
|
||||
if (null === $account) {
|
||||
// since the source does not exist, cannot return results:
|
||||
$this->collector->findNothing();
|
||||
}
|
||||
break;
|
||||
case 'journal_id':
|
||||
$parts = explode(',', $value);
|
||||
@ -383,6 +387,9 @@ class OperatorQuerySearch implements SearchInterface
|
||||
if (null !== $account) {
|
||||
$this->collector->setDestinationAccounts(new Collection([$account]));
|
||||
}
|
||||
if (null === $account) {
|
||||
$this->collector->findNothing();
|
||||
}
|
||||
break;
|
||||
case 'account_id':
|
||||
$parts = explode(',', $value);
|
||||
@ -396,6 +403,9 @@ class OperatorQuerySearch implements SearchInterface
|
||||
if ($collection->count() > 0) {
|
||||
$this->collector->setAccounts($collection);
|
||||
}
|
||||
if (0 === $collection->count()) {
|
||||
$this->collector->findNothing();
|
||||
}
|
||||
break;
|
||||
//
|
||||
// cash account
|
||||
@ -436,12 +446,18 @@ class OperatorQuerySearch implements SearchInterface
|
||||
if (null !== $currency) {
|
||||
$this->collector->setCurrency($currency);
|
||||
}
|
||||
if (null === $currency) {
|
||||
$this->collector->findNothing();
|
||||
}
|
||||
break;
|
||||
case 'foreign_currency_is':
|
||||
$currency = $this->findCurrency($value);
|
||||
if (null !== $currency) {
|
||||
$this->collector->setForeignCurrency($currency);
|
||||
}
|
||||
if (null === $currency) {
|
||||
$this->collector->findNothing();
|
||||
}
|
||||
break;
|
||||
//
|
||||
// attachments
|
||||
@ -463,6 +479,9 @@ class OperatorQuerySearch implements SearchInterface
|
||||
if ($result->count() > 0) {
|
||||
$this->collector->setCategories($result);
|
||||
}
|
||||
if (0 === $result->count()) {
|
||||
$this->collector->findNothing();
|
||||
}
|
||||
break;
|
||||
//
|
||||
// budgets
|
||||
@ -478,6 +497,9 @@ class OperatorQuerySearch implements SearchInterface
|
||||
if ($result->count() > 0) {
|
||||
$this->collector->setBudgets($result);
|
||||
}
|
||||
if (0 === $result->count()) {
|
||||
$this->collector->findNothing();
|
||||
}
|
||||
break;
|
||||
//
|
||||
// bill
|
||||
@ -493,6 +515,9 @@ class OperatorQuerySearch implements SearchInterface
|
||||
if ($result->count() > 0) {
|
||||
$this->collector->setBills($result);
|
||||
}
|
||||
if (0 === $result->count()) {
|
||||
$this->collector->findNothing();
|
||||
}
|
||||
break;
|
||||
//
|
||||
// tags
|
||||
@ -508,6 +533,11 @@ class OperatorQuerySearch implements SearchInterface
|
||||
if ($result->count() > 0) {
|
||||
$this->collector->setTags($result);
|
||||
}
|
||||
// no tags found means search must result in nothing.
|
||||
if (0 === $result->count()) {
|
||||
Log::info(sprintf('No valid tags in "%s"-operator, so search will not return ANY results.', $operator));
|
||||
$this->collector->findNothing();
|
||||
}
|
||||
break;
|
||||
//
|
||||
// notes
|
||||
@ -698,10 +728,8 @@ class OperatorQuerySearch implements SearchInterface
|
||||
// get accounts:
|
||||
$accounts = $this->accountRepository->searchAccount($value, $searchTypes, 25);
|
||||
if (0 === $accounts->count()) {
|
||||
Log::debug('Found zero accounts, search for invalid account.');
|
||||
$account = new Account;
|
||||
$account->id = 0;
|
||||
$this->collector->$collectorMethod(new Collection([$account]));
|
||||
Log::debug('Found zero accounts, search for non existing account, NO results will be returned.');
|
||||
$this->collector->findNothing();
|
||||
|
||||
return;
|
||||
}
|
||||
@ -713,10 +741,8 @@ class OperatorQuerySearch implements SearchInterface
|
||||
);
|
||||
|
||||
if (0 === $filtered->count()) {
|
||||
Log::debug('Left with zero accounts, search for invalid account.');
|
||||
$account = new Account;
|
||||
$account->id = 0;
|
||||
$this->collector->$collectorMethod(new Collection([$account]));
|
||||
Log::debug('Left with zero accounts, so cannot find anything, NO results will be returned.');
|
||||
$this->collector->findNothing();
|
||||
|
||||
return;
|
||||
}
|
||||
@ -764,9 +790,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
$accounts = $this->accountRepository->searchAccountNr($value, $searchTypes, 25);
|
||||
if (0 === $accounts->count()) {
|
||||
Log::debug('Found zero accounts, search for invalid account.');
|
||||
$account = new Account;
|
||||
$account->id = 0;
|
||||
$this->collector->$collectorMethod(new Collection([$account]));
|
||||
$this->collector->findNothing();
|
||||
|
||||
return;
|
||||
}
|
||||
@ -791,9 +815,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
|
||||
if (0 === $filtered->count()) {
|
||||
Log::debug('Left with zero, search for invalid account');
|
||||
$account = new Account;
|
||||
$account->id = 0;
|
||||
$this->collector->$collectorMethod(new Collection([$account]));
|
||||
$this->collector->findNothing();
|
||||
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user