Clean up methods.

This commit is contained in:
James Cole 2024-02-20 20:05:43 +01:00
parent 8f14979717
commit 950e39b753
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
2 changed files with 39 additions and 38 deletions

View File

@ -38,10 +38,6 @@ class TransactionController extends Controller
public function listByCount(ListByCountRequest $request): JsonResponse public function listByCount(ListByCountRequest $request): JsonResponse
{ {
// collect transactions: // collect transactions:
$pageSize = $this->parameters->get('limit');
$page = $request->getPage();
$page = max($page, 1);
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setUserGroup(auth()->user()->userGroup) $collector->setUserGroup(auth()->user()->userGroup)

View File

@ -44,7 +44,7 @@ class UpdateRequest implements UpdateRequestInterface
]; ];
// try to get array from update server: // try to get array from update server:
$updateInfo = $this->contactServer($channel); $updateInfo = $this->contactServer($channel);
if ('error' === $updateInfo['level']) { if ('error' === $updateInfo['level']) {
app('log')->error('Update information contains an error.'); app('log')->error('Update information contains an error.');
app('log')->error($updateInfo['message']); app('log')->error($updateInfo['message']);
@ -61,14 +61,14 @@ class UpdateRequest implements UpdateRequestInterface
{ {
app('log')->debug(sprintf('Now in contactServer(%s)', $channel)); app('log')->debug(sprintf('Now in contactServer(%s)', $channel));
// always fall back to current version: // always fall back to current version:
$return = [ $return = [
'version' => config('firefly.version'), 'version' => config('firefly.version'),
'date' => today(config('app.timezone'))->startOfDay(), 'date' => today(config('app.timezone'))->startOfDay(),
'level' => 'error', 'level' => 'error',
'message' => (string)trans('firefly.unknown_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)); app('log')->debug(sprintf('Going to call %s', $url));
try { try {
@ -96,7 +96,7 @@ class UpdateRequest implements UpdateRequestInterface
return $return; return $return;
} }
$body = (string)$res->getBody(); $body = (string)$res->getBody();
try { try {
$json = json_decode($body, true, 512, JSON_THROW_ON_ERROR); $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. // parse response a bit. No message yet.
$response = $json['firefly_iii'][$channel]; $response = $json['firefly_iii'][$channel];
$date = Carbon::createFromFormat('Y-m-d', $response['date']); $date = Carbon::createFromFormat('Y-m-d', $response['date']);
if (false === $date) { if (false === $date) {
$date = today(config('app.timezone')); $date = today(config('app.timezone'));
} }
@ -135,36 +135,19 @@ class UpdateRequest implements UpdateRequestInterface
private function parseResult(array $information): array private function parseResult(array $information): array
{ {
app('log')->debug('Now in parseResult()', $information); app('log')->debug('Now in parseResult()', $information);
$return = []; $return = [];
$current = config('firefly.version'); $current = (string)config('firefly.version');
$latest = $information['version']; $latest = $information['version'];
// strip the 'v' from the version if it's there. // strip the 'v' from the version if it's there.
if (str_starts_with($latest, 'v')) { if (str_starts_with($latest, 'v')) {
$latest = substr($latest, 1); $latest = substr($latest, 1);
} }
if (str_starts_with($current, 'develop')) { if (str_starts_with($current, 'develop')) {
Log::debug(sprintf('User is running develop version "%s"', $current)); return $this->parseDevelopResult($current, $latest, $information);
$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)); app('log')->debug(sprintf('Current version is "%s", latest is "%s", result is: %d', $current, $latest, $compare));
@ -187,10 +170,10 @@ class UpdateRequest implements UpdateRequestInterface
// a newer version is available! // a newer version is available!
/** @var Carbon $released */ /** @var Carbon $released */
$released = $information['date']; $released = $information['date'];
$today = today(config('app.timezone'))->startOfDay(); $today = today(config('app.timezone'))->startOfDay();
$diff = $today->diffInDays($released); $diff = $today->diffInDays($released);
$expectedDiff = config('firefly.update_minimum_age') ?? 6; $expectedDiff = config('firefly.update_minimum_age') ?? 6;
// it's still very fresh, and user wants a stable release: // it's still very fresh, and user wants a stable release:
if ($diff <= $expectedDiff) { if ($diff <= $expectedDiff) {
$return['level'] = 'info'; $return['level'] = 'info';
@ -221,13 +204,13 @@ class UpdateRequest implements UpdateRequestInterface
// add warning in case of alpha or beta: // add warning in case of alpha or beta:
// append warning if beta or alpha. // append warning if beta or alpha.
$isBeta = $information['is_beta'] ?? false; $isBeta = $information['is_beta'] ?? false;
if (true === $isBeta) { if (true === $isBeta) {
$return['message'] = sprintf('%s %s', $return['message'], trans('firefly.update_version_beta')); $return['message'] = sprintf('%s %s', $return['message'], trans('firefly.update_version_beta'));
app('log')->debug('New release is also a beta!'); app('log')->debug('New release is also a beta!');
} }
$isAlpha = $information['is_alpha'] ?? false; $isAlpha = $information['is_alpha'] ?? false;
if (true === $isAlpha) { if (true === $isAlpha) {
$return['message'] = sprintf('%s %s', $return['message'], trans('firefly.update_version_alpha')); $return['message'] = sprintf('%s %s', $return['message'], trans('firefly.update_version_alpha'));
app('log')->debug('New release is also a alpha!'); app('log')->debug('New release is also a alpha!');
@ -239,4 +222,26 @@ class UpdateRequest implements UpdateRequestInterface
return $return; return $return;
} }
private function parseDevelopResult(string $current, string $latest, array $information): array
{
Log::debug(sprintf('User is running develop version "%s"', $current));
$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;
}
} }