Skip to content

Firefly III: a personal finances manager

Fixed search in encrypted entries.

James Cole7ed662ecc213
diff --git a/app/Helpers/Reminders/ReminderHelper.php b/app/Helpers/Reminders/ReminderHelper.php
index ccfdc2d57a..d667213615 100644
--- a/app/Helpers/Reminders/ReminderHelper.php
+++ b/app/Helpers/Reminders/ReminderHelper.php
@@ -25,10 +25,7 @@ class ReminderHelper implements ReminderHelperInterface
*/
public function createReminder(PiggyBank $piggyBank, Carbon $start, Carbon $end)
{
- $reminder = Auth::user()->reminders()
- ->where('remindersable_id', $piggyBank->id)
- ->onDates($start, $end)
- ->first();
+ $reminder = Auth::user()->reminders()->where('remindersable_id', $piggyBank->id)->onDates($start, $end)->first();
if (is_null($reminder)) {
if (!is_null($piggyBank->targetdate)) {
@@ -134,7 +131,8 @@ class ReminderHelper implements ReminderHelperInterface
{
/** @var PiggyBank $piggyBank */
$piggyBank = $reminder->remindersable;
- if(is_null($piggyBank)) {
+
+ if (is_null($piggyBank)) {
return 'Piggy bank no longer exists.';
}
diff --git a/app/Http/Middleware/Reminders.php b/app/Http/Middleware/Reminders.php
index 4310bdfac9..5f031cacc2 100644
--- a/app/Http/Middleware/Reminders.php
+++ b/app/Http/Middleware/Reminders.php
@@ -9,7 +9,7 @@ use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\Reminder;
use Illuminate\Contracts\Auth\Guard;
use View;
-
+use Illuminate\Support\Collection;
/**
* Class Reminders
*
@@ -45,7 +45,7 @@ class Reminders
*/
public function handle($request, Closure $next)
{
- if ($this->auth->check()) {
+ if ($this->auth->check() && !$request->isJson()) {
// do reminders stuff.
$piggyBanks = $this->auth->user()->piggyBanks()->where('remind_me', 1)->get();
$today = new Carbon;
@@ -67,15 +67,14 @@ class Reminders
}
}
// delete invalid reminders
- $reminders = $this->auth->user()->reminders()->get();
- foreach($reminders as $reminder) {
- if(is_null($reminder->remindersable)) {
- $reminder->delete();
- }
+ $set = $this->auth->user()->reminders()->
+ leftJoin('piggy_banks','piggy_banks.id','=','remindersable_id')->
+ whereNull('piggy_banks.id')->get(['reminders.id']);
+ foreach($set as $reminder) {
+ $reminder->delete();
}
-
// get and list active reminders:
$reminders = $this->auth->user()->reminders()->today()->get();
$reminders->each(
@@ -86,6 +85,7 @@ class Reminders
View::share('reminders', $reminders);
}
+
return $next($request);
}
}
\ No newline at end of file
diff --git a/app/Support/Search/Search.php b/app/Support/Search/Search.php
index 7e0cd1de39..3548a1d1d7 100644
--- a/app/Support/Search/Search.php
+++ b/app/Support/Search/Search.php
@@ -3,11 +3,12 @@
namespace FireflyIII\Support\Search;
-use Illuminate\Support\Collection;
-use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
+use Auth;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
-
+use FireflyIII\Models\TransactionJournal;
+use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
+use Illuminate\Support\Collection;
/**
* Class Search
@@ -23,7 +24,7 @@ class Search implements SearchInterface
*/
public function searchAccounts(array $words)
{
- return \Auth::user()->accounts()->with('accounttype')->where(
+ return Auth::user()->accounts()->with('accounttype')->where(
function (EloquentBuilder $q) use ($words) {
foreach ($words as $word) {
$q->orWhere('name', 'LIKE', '%' . e($word) . '%');
@@ -40,7 +41,7 @@ class Search implements SearchInterface
public function searchBudgets(array $words)
{
/** @var Collection $set */
- $set = \Auth::user()->budgets()->get();
+ $set = Auth::user()->budgets()->get();
$newSet = $set->filter(
function (Budget $b) use ($words) {
$found = 0;
@@ -65,7 +66,7 @@ class Search implements SearchInterface
public function searchCategories(array $words)
{
/** @var Collection $set */
- $set = \Auth::user()->categories()->get();
+ $set = Auth::user()->categories()->get();
$newSet = $set->filter(
function (Category $c) use ($words) {
$found = 0;
@@ -101,12 +102,29 @@ class Search implements SearchInterface
*/
public function searchTransactions(array $words)
{
- return \Auth::user()->transactionjournals()->withRelevantData()->where(
+ // decrypted transaction journals:
+ $decrypted = Auth::user()->transactionjournals()->withRelevantData()->where('encrypted', 0)->where(
function (EloquentBuilder $q) use ($words) {
foreach ($words as $word) {
$q->orWhere('description', 'LIKE', '%' . e($word) . '%');
}
}
)->get();
+
+ // encrypted
+ $all = Auth::user()->transactionjournals()->withRelevantData()->where('encrypted', 1)->get();
+ $set = $all->filter(
+ function (TransactionJournal $journal) use ($words) {
+ foreach ($words as $word) {
+ $haystack = strtolower($journal->description);
+ $word = strtolower($word);
+ if (!(strpos($haystack, $word) === false)) {
+ return $journal;
+ }
+ }
+
+ }
+ );
+ return $set->merge($decrypted);
}
}
diff --git a/resources/views/search/index.blade.php b/resources/views/search/index.blade.php
index 3a2c4aa1aa..d70e500012 100644
--- a/resources/views/search/index.blade.php
+++ b/resources/views/search/index.blade.php
@@ -10,7 +10,7 @@
<i class="fa fa-repeat"></i> Transactions ({{$result['transactions']->count()}})
</div>
<div class="panel-body">
- @include('list.journals-small',['journals' => $result['transactions']])
+ @include('list.journals-tiny',['transactions' => $result['transactions']])
</div>
</div>
</div>