Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Update code
James Cole7897ebc4d594
diff --git a/.ci/phpmd/composer.lock b/.ci/phpmd/composer.lockindex 65e83ba753..27b22b4f8f 100644--- a/.ci/phpmd/composer.lock+++ b/.ci/phpmd/composer.lock@@ -680,16 +680,16 @@},{"name": "symfony/polyfill-ctype",- "version": "v1.28.0",+ "version": "v1.29.0","source": {"type": "git","url": "https://github.com/symfony/polyfill-ctype.git",- "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb"+ "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4"},"dist": {"type": "zip",- "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb",- "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb",+ "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ef4d7e442ca910c4764bce785146269b30cb5fc4",+ "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4","shasum": ""},"require": {@@ -703,9 +703,6 @@},"type": "library","extra": {- "branch-alias": {- "dev-main": "1.28-dev"- },"thanks": {"name": "symfony/polyfill","url": "https://github.com/symfony/polyfill"@@ -742,7 +739,7 @@"portable"],"support": {- "source": "https://github.com/symfony/polyfill-ctype/tree/v1.28.0"+ "source": "https://github.com/symfony/polyfill-ctype/tree/v1.29.0"},"funding": [{@@ -758,20 +755,20 @@"type": "tidelift"}],- "time": "2023-01-26T09:26:14+00:00"+ "time": "2024-01-29T20:11:03+00:00"},{"name": "symfony/polyfill-mbstring",- "version": "v1.28.0",+ "version": "v1.29.0","source": {"type": "git","url": "https://github.com/symfony/polyfill-mbstring.git",- "reference": "42292d99c55abe617799667f454222c54c60e229"+ "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec"},"dist": {"type": "zip",- "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/42292d99c55abe617799667f454222c54c60e229",- "reference": "42292d99c55abe617799667f454222c54c60e229",+ "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9773676c8a1bb1f8d4340a62efe641cf76eda7ec",+ "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec","shasum": ""},"require": {@@ -785,9 +782,6 @@},"type": "library","extra": {- "branch-alias": {- "dev-main": "1.28-dev"- },"thanks": {"name": "symfony/polyfill","url": "https://github.com/symfony/polyfill"@@ -825,7 +819,7 @@"shim"],"support": {- "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.28.0"+ "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.29.0"},"funding": [{@@ -841,7 +835,7 @@"type": "tidelift"}],- "time": "2023-07-28T09:04:16+00:00"+ "time": "2024-01-29T20:11:03+00:00"},{"name": "symfony/service-contracts",diff --git a/app/Api/V2/Controllers/Transaction/List/TransactionController.php b/app/Api/V2/Controllers/Transaction/List/TransactionController.phpindex 5694816e04..04b0bf6598 100644--- a/app/Api/V2/Controllers/Transaction/List/TransactionController.php+++ b/app/Api/V2/Controllers/Transaction/List/TransactionController.php@@ -60,11 +60,8 @@ class TransactionController extends Controller$collector->setEnd($end);}- // $collector->dumpQuery();- // exit;-$paginator = $collector->getPaginatedGroups();- $params = $request->buildParams($pageSize);+ $params = $request->buildParams();$paginator->setPath(sprintf('%s?%s',@@ -119,6 +116,7 @@ class TransactionController extends Controllerreturn response()->json($this->jsonApiList('transactions', $paginator, new TransactionGroupTransformer()))- ->header('Content-Type', self::CONTENT_TYPE);+ ->header('Content-Type', self::CONTENT_TYPE)+ ;}}diff --git a/app/Handlers/Events/Model/RuleHandler.php b/app/Handlers/Events/Model/RuleHandler.phpindex 490a4ac72f..f7e7814cd1 100644--- a/app/Handlers/Events/Model/RuleHandler.php+++ b/app/Handlers/Events/Model/RuleHandler.php@@ -28,8 +28,8 @@ use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;use FireflyIII\Events\Model\Rule\RuleActionFailedOnObject;use FireflyIII\Notifications\User\RuleActionFailed;use GuzzleHttp\Exception\ClientException;+use Illuminate\Support\Facades\Log;use Illuminate\Support\Facades\Notification;-use Log;/*** Class RuleHandler@@ -57,6 +57,7 @@ class RuleHandler$ruleTitle = $rule->title;$ruleLink = route('rules.edit', [$rule->id]);$params = [$mainMessage, $groupTitle, $groupLink, $ruleTitle, $ruleLink];+try {Notification::send($user, new RuleActionFailed($params));} catch(ClientException $e) {@@ -85,6 +86,7 @@ class RuleHandler$ruleTitle = $rule->title;$ruleLink = route('rules.edit', [$rule->id]);$params = [$mainMessage, $groupTitle, $groupLink, $ruleTitle, $ruleLink];+try {Notification::send($user, new RuleActionFailed($params));} catch(ClientException $e) {diff --git a/app/Helpers/Collector/GroupCollector.php b/app/Helpers/Collector/GroupCollector.phpindex 6cd576aff4..b5d4dd42b2 100644--- a/app/Helpers/Collector/GroupCollector.php+++ b/app/Helpers/Collector/GroupCollector.php@@ -477,7 +477,7 @@ class GroupCollector implements GroupCollectorInterface}// OR filter the array according to the start and end row variableif (null !== $this->startRow && null !== $this->endRow) {- return $collection->slice((int)$this->startRow, (int)$this->endRow);+ return $collection->slice($this->startRow, $this->endRow);}return $collection;@@ -493,7 +493,7 @@ class GroupCollector implements GroupCollectorInterface$this->setLimit(50);}if(null !== $this->startRow && null !== $this->endRow) {- $total = (int)($this->endRow - $this->startRow);+ $total = $this->endRow - $this->startRow;return new LengthAwarePaginator($set, $this->total, $total, 1);}diff --git a/app/Services/FireflyIIIOrg/Update/UpdateRequest.php b/app/Services/FireflyIIIOrg/Update/UpdateRequest.phpindex cd2de665ee..16f56f4393 100644--- a/app/Services/FireflyIIIOrg/Update/UpdateRequest.php+++ b/app/Services/FireflyIIIOrg/Update/UpdateRequest.php@@ -44,7 +44,7 @@ class UpdateRequest implements UpdateRequestInterface];// try to get array from update server:- $updateInfo = $this->contactServer($channel);+ $updateInfo = $this->contactServer($channel);if ('error' === $updateInfo['level']) {app('log')->error('Update information contains an error.');app('log')->error($updateInfo['message']);@@ -61,14 +61,14 @@ class UpdateRequest implements UpdateRequestInterface{app('log')->debug(sprintf('Now in contactServer(%s)', $channel));// always fall back to current version:- $return = [+ $return = ['version' => config('firefly.version'),'date' => today(config('app.timezone'))->startOfDay(),'level' => 'error','message' => (string)trans('firefly.unknown_error'),];- $url = config('firefly.update_endpoint');+ $url = config('firefly.update_endpoint');app('log')->debug(sprintf('Going to call %s', $url));try {@@ -96,7 +96,7 @@ class UpdateRequest implements UpdateRequestInterfacereturn $return;}- $body = (string)$res->getBody();+ $body = (string)$res->getBody();try {$json = json_decode($body, true, 512, JSON_THROW_ON_ERROR);@@ -115,8 +115,8 @@ class UpdateRequest implements UpdateRequestInterface}// parse response a bit. No message yet.- $response = $json['firefly_iii'][$channel];- $date = Carbon::createFromFormat('Y-m-d', $response['date']);+ $response = $json['firefly_iii'][$channel];+ $date = Carbon::createFromFormat('Y-m-d', $response['date']);if (false === $date) {$date = today(config('app.timezone'));}@@ -129,15 +129,19 @@ class UpdateRequest implements UpdateRequestInterfacereturn $return;}+ /**+ * TODO make shorter+ *+ * @param array $information+ *+ * @return array+ */private function parseResult(array $information): array{app('log')->debug('Now in parseResult()', $information);- $return = [- 'level' => 'error',- 'message' => (string)trans('firefly.unknown_error'),- ];- $current = config('firefly.version');- $latest = $information['version'];+ $return = [];+ $current = config('firefly.version');+ $latest = $information['version'];// strip the 'v' from the version if it's there.if (str_starts_with($latest, 'v')) {@@ -145,22 +149,25 @@ class UpdateRequest implements UpdateRequestInterface}if (str_starts_with($current, 'develop')) {Log::debug(sprintf('User is running develop version "%s"', $current));- $parts = explode('/', $current);- $devDate = Carbon::createFromFormat('Y-m-d', $parts[1]);+ $parts = explode('/', $current);+ /** @var Carbon $devDate */+ $devDate = Carbon::createFromFormat('Y-m-d', $parts[1]);if ($devDate->lte($information['date'])) {Log::debug(sprintf('This development release is older, release = %s, latest version %s = %s', $devDate->format('Y-m-d'), $latest, $information['date']->format('Y-m-d')));$return['level'] = 'info';$return['message'] = (string)trans('firefly.update_current_dev_older', ['version' => $current, 'new_version' => $latest]);+return $return;}Log::debug(sprintf('This development release is newer, release = %s, latest version %s = %s', $devDate->format('Y-m-d'), $latest, $information['date']->format('Y-m-d')));$return['level'] = 'info';$return['message'] = (string)trans('firefly.update_current_dev_newer', ['version' => $current, 'new_version' => $latest]);+return $return;}- $compare = version_compare($latest, $current);+ $compare = version_compare($latest, $current);app('log')->debug(sprintf('Current version is "%s", latest is "%s", result is: %d', $current, $latest, $compare));@@ -183,10 +190,10 @@ class UpdateRequest implements UpdateRequestInterface// a newer version is available!/** @var Carbon $released */- $released = $information['date'];- $today = today(config('app.timezone'))->startOfDay();- $diff = $today->diffInDays($released);- $expectedDiff = config('firefly.update_minimum_age') ?? 6;+ $released = $information['date'];+ $today = today(config('app.timezone'))->startOfDay();+ $diff = $today->diffInDays($released);+ $expectedDiff = config('firefly.update_minimum_age') ?? 6;// it's still very fresh, and user wants a stable release:if ($diff <= $expectedDiff) {$return['level'] = 'info';@@ -217,13 +224,13 @@ class UpdateRequest implements UpdateRequestInterface// add warning in case of alpha or beta:// append warning if beta or alpha.- $isBeta = $information['is_beta'] ?? false;+ $isBeta = $information['is_beta'] ?? false;if (true === $isBeta) {$return['message'] = sprintf('%s %s', $return['message'], trans('firefly.update_version_beta'));app('log')->debug('New release is also a beta!');}- $isAlpha = $information['is_alpha'] ?? false;+ $isAlpha = $information['is_alpha'] ?? false;if (true === $isAlpha) {$return['message'] = sprintf('%s %s', $return['message'], trans('firefly.update_version_alpha'));app('log')->debug('New release is also a alpha!');diff --git a/app/TransactionRules/Actions/SetCategory.php b/app/TransactionRules/Actions/SetCategory.phpindex 40f605af66..8785ade043 100644--- a/app/TransactionRules/Actions/SetCategory.php+++ b/app/TransactionRules/Actions/SetCategory.php@@ -89,7 +89,7 @@ class SetCategory implements ActionInterface$oldCategory = $object->categories()->first();$oldCategoryName = $oldCategory?->name;if ((int)$oldCategory?->id === $category->id) {- //event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.already_linked_to_category', ['name' => $category->name])));+ // event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.already_linked_to_category', ['name' => $category->name])));return false;}