Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Verify sorting
James Cole4d34160edee9
diff --git a/app/Api/V1/Controllers/Models/Bill/ShowController.php b/app/Api/V1/Controllers/Models/Bill/ShowController.phpindex 48a73d7a8c..385066d96b 100644--- a/app/Api/V1/Controllers/Models/Bill/ShowController.php+++ b/app/Api/V1/Controllers/Models/Bill/ShowController.php@@ -71,6 +71,7 @@ class ShowController extends Controller*/public function index(): JsonResponse{+ $this->repository->correctOrder();$bills = $this->repository->getBills();$manager = $this->getManager();$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;diff --git a/app/Api/V1/Requests/Models/Webhook/UpdateRequest.php b/app/Api/V1/Requests/Models/Webhook/UpdateRequest.phpindex 9c039822f1..6b5f779043 100644--- a/app/Api/V1/Requests/Models/Webhook/UpdateRequest.php+++ b/app/Api/V1/Requests/Models/Webhook/UpdateRequest.php@@ -74,11 +74,20 @@ class UpdateRequest extends FormRequest];// this is the way.- $return = $this->getAllData($fields);- $return['trigger'] = $triggers[$return['trigger']] ?? 0;- $return['response'] = $responses[$return['response']] ?? 0;- $return['delivery'] = $deliveries[$return['delivery']] ?? 0;- $return['secret'] = null !== $this->get('secret');+ $return = $this->getAllData($fields);+ if (array_key_exists('trigger', $return)) {+ $return['trigger'] = $triggers[$return['trigger']] ?? 0;+ }+ if (array_key_exists('response', $return)) {+ $return['response'] = $responses[$return['response']] ?? 0;+ }+ if (array_key_exists('delivery', $return)) {+ $return['delivery'] = $deliveries[$return['delivery']] ?? 0;+ }+ $return['secret'] = null !== $this->get('secret');+ if (null !== $this->get('title')) {+ $return['title'] = $this->string('title');+ }return $return;}@@ -98,10 +107,10 @@ class UpdateRequest extends FormRequestreturn ['title' => sprintf('between:1,512|uniqueObjectForUser:webhooks,title,%d', $webhook->id),'active' => [new IsBoolean],- 'trigger' => sprintf('required|in:%s', $triggers),- 'response' => sprintf('required|in:%s', $responses),- 'delivery' => sprintf('required|in:%s', $deliveries),- 'url' => ['required', 'url', 'starts_with:https://', sprintf('uniqueExistingWebhook:%d', $webhook->id)],+ 'trigger' => sprintf('in:%s', $triggers),+ 'response' => sprintf('in:%s', $responses),+ 'delivery' => sprintf('in:%s', $deliveries),+ 'url' => ['url', 'starts_with:https://', sprintf('uniqueExistingWebhook:%d', $webhook->id)],];}}diff --git a/app/Repositories/Webhook/WebhookRepository.php b/app/Repositories/Webhook/WebhookRepository.phpindex 14de2dcb8e..6e1180233e 100644--- a/app/Repositories/Webhook/WebhookRepository.php+++ b/app/Repositories/Webhook/WebhookRepository.php@@ -102,6 +102,7 @@ class WebhookRepository implements WebhookRepositoryInterface$webhook->trigger = $data['trigger'] ?? $webhook->trigger;$webhook->response = $data['response'] ?? $webhook->response;$webhook->delivery = $data['delivery'] ?? $webhook->delivery;+ $webhook->title = $data['title'] ?? $webhook->title;$webhook->url = $data['url'] ?? $webhook->url;if (true === $data['secret']) {diff --git a/app/Services/Internal/Update/AccountUpdateService.php b/app/Services/Internal/Update/AccountUpdateService.phpindex 033567941b..955b068840 100644--- a/app/Services/Internal/Update/AccountUpdateService.php+++ b/app/Services/Internal/Update/AccountUpdateService.php@@ -23,6 +23,7 @@ declare(strict_types=1);namespace FireflyIII\Services\Internal\Update;+use DB;use FireflyIII\Models\Account;use FireflyIII\Models\AccountType;use FireflyIII\Models\Location;@@ -263,54 +264,30 @@ class AccountUpdateServicereturn $account;}// get account type ID's because a join and an update is hard:- $list = $this->getTypeIds([AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT]);$oldOrder = (int)$account->order;$newOrder = $data['order'];+ $list = $this->getTypeIds([AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT]);if (in_array($type, [AccountType::ASSET], true)) {$list = $this->getTypeIds([AccountType::ASSET]);}- if ($oldOrder > $newOrder) {- // say you move from 9 (old) to 3 (new)- // everything that's 3 or higher moves up one spot.- // that leaves a gap for nr 3 later on.- // 1 2 (!) 4 5 6 7 8 9 10 11 12 13 14- $this->user->accounts()- ->whereIn('accounts.account_type_id', $list)- ->where('accounts.order', '>=', $newOrder)- ->update(['accounts.order' => \DB::raw('accounts.order + 1')]);- // update the account and save it:- // nummer 9 (now 10!) will move to nr 3.- // a gap appears on spot 10.- // 1 2 3 4 5 6 7 8 9 11 12 13 14+ if ($newOrder > $oldOrder) {+ $this->user->accounts()->where('order', '<=', $newOrder)->where('order', '>', $oldOrder)+ ->where('accounts.id', '!=', $account->id)+ ->whereIn('accounts.account_type_id', $list)+ ->update(['order' => DB::raw('accounts.order-1')]);$account->order = $newOrder;$account->save();- // everything over 9 (old) drops one spot- // 1 2 3 4 5 6 7 8 9 10 11 12 13 14- $this->user->accounts()- ->whereIn('accounts.account_type_id', $list)- ->where('accounts.order', '>', $oldOrder)- ->update(['accounts.order' => \DB::raw('accounts.order - 1')]);-return $account;}- if ($oldOrder < $newOrder) {- // if it goes from 3 (old) to 9 (new),- // 1 2 3 4 5 6 7 8 9 10 11 12 13 14- // everything that is between 3 and 9 (incl) - 1 spot- // 1 2 2 3 4 5 6 7 8 10 11 12 13 14- $this->user->accounts()- ->whereIn('accounts.account_type_id', $list)- ->where('accounts.order', '>=', $oldOrder)- ->where('accounts.order', '<=', $newOrder)- ->update(['accounts.order' => \DB::raw('accounts.order - 1')]);- // then set order to 9- // 1 2 3 4 5 6 7 8 9 10 11 12 13 14- $account->order = $newOrder;- $account->save();- }+ $this->user->accounts()->where('order', '>=', $newOrder)->where('order', '<', $oldOrder)+ ->where('accounts.id', '!=', $account->id)+ ->whereIn('accounts.account_type_id', $list)+ ->update(['order' => DB::raw('accounts.order+1')]);+ $account->order = $newOrder;+ $account->save();return $account;}diff --git a/app/Support/Preferences.php b/app/Support/Preferences.phpindex 702dc20f6b..62bdbdefd7 100644--- a/app/Support/Preferences.php+++ b/app/Support/Preferences.php@@ -151,10 +151,6 @@ class Preferences*/public function getForUser(User $user, string $name, $default = null): ?Preference{- $fullName = sprintf('preference%s%s', $user->id, $name);- if (Cache::has($fullName)) {- return Cache::get($fullName);- }$preference = Preference::where('user_id', $user->id)->where('name', $name)->first(['id', 'name', 'data', 'updated_at', 'created_at']);if (null !== $preference && null === $preference->data) {try {@@ -166,7 +162,6 @@ class Preferences}if (null !== $preference) {- Cache::forever($fullName, $preference);return $preference;}@@ -185,32 +180,11 @@ class Preferences* @param null|string $default** @return \FireflyIII\Models\Preference|null+ * TODO remove me*/public function getFreshForUser(User $user, string $name, $default = null): ?Preference{- $fullName = sprintf('preference%s%s', $user->id, $name);- $preference = Preference::where('user_id', $user->id)->where('name', $name)->first(['id', 'name', 'data', 'updated_at', 'created_at']);- if (null !== $preference && null === $preference->data) {- try {- $preference->delete();- } catch (Exception $e) {- Log::debug(sprintf('Could not delete preference #%d: %s', $preference->id, $e->getMessage()));- }- $preference = null;- }-- if (null !== $preference) {- Cache::forever($fullName, $preference);-- return $preference;- }- // no preference found and default is null:- if (null === $default) {- // return NULL- return null;- }-- return $this->setForUser($user, $name, $default);+ return $this->getForUser($user, $name, $default);}/**diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.phpindex 67de90d5ee..dda899058a 100644--- a/app/Validation/FireflyValidator.php+++ b/app/Validation/FireflyValidator.php@@ -634,17 +634,33 @@ class FireflyValidator extends Validatorpublic function validateUniqueExistingWebhook($value, $parameters, $something): bool{$existingId = (int)($something[0] ?? 0);-+ $trigger = 0;+ $response = 0;+ $delivery = 0;+ $triggers = array_flip(config('firefly.webhooks.triggers'));+ $responses = array_flip(config('firefly.webhooks.responses'));+ $deliveries = array_flip(config('firefly.webhooks.deliveries'));if (auth()->check()) {- // possible values- $triggers = array_flip(config('firefly.webhooks.triggers'));- $responses = array_flip(config('firefly.webhooks.responses'));- $deliveries = array_flip(config('firefly.webhooks.deliveries'));+ // get existing webhook value:+ if(0!== $existingId) {+ /** @var Webhook $webhook */+ $webhook = auth()->user()->webhooks()->find($existingId);+ if(null === $webhook) {+ return false;+ }+ // set triggers etc.+ $trigger = $triggers[$webhook->trigger] ?? 0;+ $response = $responses[$webhook->response] ?? 0;+ $delivery = $deliveries[$webhook->delivery] ?? 0;+ }+ if(0=== $existingId) {+ $trigger = $triggers[$this->data['trigger']] ?? 0;+ $response = $responses[$this->data['response']] ?? 0;+ $delivery = $deliveries[$this->data['delivery']] ?? 0;+ }++- // integers- $trigger = $triggers[$this->data['trigger']] ?? 0;- $response = $responses[$this->data['response']] ?? 0;- $delivery = $deliveries[$this->data['delivery']] ?? 0;$url = $this->data['url'];$userId = auth()->user()->id;