Skip to content

Firefly III: a personal finances manager

Rebuild update request to use GitHub API.

James Cole04c3bf966d45
diff --git a/app/Console/Commands/Tools/ChecksForUpdates.php b/app/Console/Commands/Tools/ChecksForUpdates.php
new file mode 100644
index 0000000000..021bb6d8e1
--- /dev/null
+++ b/app/Console/Commands/Tools/ChecksForUpdates.php
@@ -0,0 +1,87 @@
+<?php
+/*
+ * ChecksForUpdates.php
+ * Copyright (c) 2026 [email protected]
+ *
+ * This file is part of Firefly III (https://github.com/firefly-iii).
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+namespace FireflyIII\Console\Commands\Tools;
+
+use Carbon\Carbon;
+use FireflyIII\Console\Commands\ShowsFriendlyMessages;
+use FireflyIII\Services\FireflyIIIOrg\Update\UpdateRequestInterface;
+use FireflyIII\Support\Facades\FireflyConfig;
+use Illuminate\Console\Command;
+
+class ChecksForUpdates extends Command
+{
+ use ShowsFriendlyMessages;
+
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'firefly-iii:check-for-updates {--force}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Checks for Firefly III updates';
+
+ /**
+ * Execute the console command.
+ */
+ public function handle(): int
+ {
+ $build = Carbon::createFromTimestamp(config('firefly.build_time'), config('app.timezone'));
+ $version = config('firefly.version');
+
+ $this->friendlyLine(sprintf('You are running version "%s", built on %s', $version, $build->format('Y-m-d H:i')));
+ $permission = FireflyConfig::get('permission_update_check', -1)->data;
+ if (1 !== $permission && false === $this->option('force')) {
+ $this->friendlyWarning('Checking for updates is disabled. To overrule, use --force.');
+ return Command::SUCCESS;
+ }
+ if (str_contains(config('firefly.version'), 'develop')) {
+ $this->friendlyWarning('You are running a development version.');
+ }
+
+ /** @var UpdateRequestInterface $request */
+ $request = app(UpdateRequestInterface::class);
+ // stable, alpha or beta
+ $info = $request->getUpdateInformation($version, $build, 'stable');
+
+ if ('' !== $info->getError()) {
+ $this->friendlyError($info->getError());
+ return Command::FAILURE;
+ }
+ if (!$info->isNewVersionAvailable()) {
+ $this->friendlyInfo(trans('firefly.no_new_release_available'));
+ return Command::SUCCESS;
+ }
+ // if running develop, slightly different message.
+ if (str_contains($version, 'develop')) {
+ $this->friendlyInfo(trans('firefly.update_current_dev_older', ['version' => $version, 'new_version' => $info->getNewVersion()]));
+ return Command::SUCCESS;
+ }
+ $this->friendlyInfo(trans('firefly.update_new_version_alert', ['your_version' => $version, 'new_version' => $info->getNewVersion(), 'date' => $info->getPublishedAt()->format('Y-m-d H:i:s')]));
+ return Command::SUCCESS;
+ }
+}
diff --git a/app/Providers/FireflyServiceProvider.php b/app/Providers/FireflyServiceProvider.php
index 90038ffb64..fafcce5bfb 100644
--- a/app/Providers/FireflyServiceProvider.php
+++ b/app/Providers/FireflyServiceProvider.php
@@ -53,6 +53,7 @@ use FireflyIII\Repositories\UserGroup\UserGroupRepository;
use FireflyIII\Repositories\UserGroup\UserGroupRepositoryInterface;
use FireflyIII\Repositories\Webhook\WebhookRepository;
use FireflyIII\Repositories\Webhook\WebhookRepositoryInterface;
+use FireflyIII\Services\FireflyIIIOrg\Update\GitHubUpdateRequest;
use FireflyIII\Services\FireflyIIIOrg\Update\UpdateRequest;
use FireflyIII\Services\FireflyIIIOrg\Update\UpdateRequestInterface;
use FireflyIII\Services\Password\PwndVerifierV2;
@@ -191,7 +192,8 @@ class FireflyServiceProvider extends ServiceProvider
$this->app->bind(PopupReportInterface::class, PopupReport::class);
$this->app->bind(ReportHelperInterface::class, ReportHelper::class);
$this->app->bind(FiscalHelperInterface::class, FiscalHelper::class);
- $this->app->bind(UpdateRequestInterface::class, UpdateRequest::class);
+ //$this->app->bind(UpdateRequestInterface::class, UpdateRequest::class);
+ $this->app->bind(UpdateRequestInterface::class, GitHubUpdateRequest::class);
// webhooks:
$this->app->bind(MessageGeneratorInterface::class, StandardMessageGenerator::class);
diff --git a/app/Services/FireflyIIIOrg/Update/GitHubUpdateRequest.php b/app/Services/FireflyIIIOrg/Update/GitHubUpdateRequest.php
new file mode 100644
index 0000000000..a6bbdbf29c
--- /dev/null
+++ b/app/Services/FireflyIIIOrg/Update/GitHubUpdateRequest.php
@@ -0,0 +1,198 @@
+<?php
+/*
+ * GitHubUpdateRequest.php
+ * Copyright (c) 2026 [email protected]
+ *
+ * This file is part of Firefly III (https://github.com/firefly-iii).
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+namespace FireflyIII\Services\FireflyIIIOrg\Update;
+
+use Carbon\Carbon;
+use GuzzleHttp\Client;
+use GuzzleHttp\Exception\ClientException;
+use Illuminate\Support\Facades\Log;
+
+class GitHubUpdateRequest implements UpdateRequestInterface
+{
+ private string $currentVersion = '1.0.0';
+ private Carbon $currentBuild;
+ private string $channel = 'stable';
+ private bool $localDebug = true;
+
+ #[\Override]
+ public function getUpdateInformation(string $currentVersion, Carbon $currentBuild, string $channel): UpdateResponse
+ {
+ $this->currentVersion = $currentVersion;
+ $this->channel = $channel;
+ $this->currentBuild = $currentBuild;
+ Log::debug(sprintf('Now in getUpdateInformation(%s, %s)', $currentVersion, $channel));
+
+ $response = new UpdateResponse();
+ $releases = $this->getReleases();
+ $filtered = $this->filterReleases($releases);
+
+ Log::debug(sprintf('Left with %d release(s) to compare', count($filtered)));
+
+ if (0 === count($filtered)) {
+ $response->setNewVersionAvailable(false);
+ return $response;
+ }
+
+ $newest = $this->getNewest($filtered);
+
+ Log::debug(sprintf('Newest release is "%s" released on %s', $newest['version'], $newest['published_at']->format('Y-m-d H:i')));
+
+ $response->setNewVersion($newest['version']);
+ $response->setPublishedAt($newest['published_at']);
+
+ // main question, is this release newer than the current one?
+ // if current version is "develop", compare date.
+ if (str_contains($currentVersion, 'develop')) {
+ Log::debug(sprintf('Compare with current version "%s", built on %s', $currentVersion, $currentBuild->format('Y-m-d H:i')));
+ if ($currentBuild->gt($newest['published_at'])) {
+ Log::debug(sprintf('Current build %s is older than newest build %s, so a new release is available.', $currentBuild->format('Y-m-d H:i'), $newest['published_at']->format('Y-m-d H:i')));
+ $response->setNewVersionAvailable(true);
+ return $response;
+ }
+ if ($currentBuild->lt($newest['published_at'])) {
+ Log::debug(sprintf('Current build %s is newer than newest build %s, so NO new release is available.', $currentBuild->format('Y-m-d H:i'), $newest['published_at']->format('Y-m-d H:i')));
+ $response->setNewVersionAvailable(false);
+ return $response;
+ }
+ return $response;
+ }
+
+ // if not, compare version.
+ $res = version_compare($newest['version'], $currentVersion);
+ if ($res < 1) {
+ $response->setNewVersionAvailable(false);
+ return $response;
+ }
+ if (1 === $res) {
+ $response->setNewVersionAvailable(true);
+ return $response;
+ }
+
+ return $response;
+ }
+
+ private function filterReleases(array $releases): array
+ {
+ $return = [];
+ /** @var array $release */
+ foreach ($releases as $release) {
+ if ($release['published_at']->lte($this->currentBuild)) {
+ Log::debug(sprintf('Skip older version "%s"', $release['version']));
+ continue;
+ }
+ // if channel is stable, and version is "alpha", continue.
+ // if channel is stable, and version is "beta", continue.
+ // if channel is beta, and version is "alpha", continue.
+ if (($this->channel === 'stable' || $this->channel === 'beta') && str_contains($release['version'], 'alpha')) {
+ Log::debug(sprintf('Skip version "%s"', $release['version']));
+ continue;
+ }
+ if ($this->channel === 'stable' && str_contains($release['version'], 'beta')) {
+ Log::debug(sprintf('Skip version "%s"', $release['version']));
+ continue;
+ }
+ $return[] = $release;
+ }
+ return $return;
+ }
+
+ private function getNewest(array $releases): array
+ {
+ $latest = [
+ 'version' => '1.0.0',
+ 'published_at' => now()->startOfYear(),
+ ];
+ foreach ($releases as $release) {
+ Log::debug(sprintf('Comparing current version "%s" with latest version "%s"', $release['version'], $latest['version']));
+ if (str_contains($release['version'], 'develop') || str_contains($latest['version'], 'develop')) {
+ Log::debug('Compare based on build time.');
+ // compare build times.
+ if ($latest['published_at']->lt($release['published_at'])) {
+ Log::debug(sprintf('Current date "%s" is newer than latest date "%s"', $release['published_at']->format('Y-m-d H:i'), $latest['published_at']->format('Y-m-d H:i')));
+ $latest = $release;
+ }
+ }
+ if (!str_contains($release['version'], 'develop') && !str_contains($latest['version'], 'develop')) {
+ Log::debug('[a] Compare based on version.');
+ // compare version.
+ $res = version_compare($release['version'], $latest['version']);
+ if (1 === $res) {
+ Log::debug(sprintf('Version "%s" is newer than version "%s".', $release['version'], $latest['version']));
+ $latest = $release;
+ }
+ }
+ }
+ Log::debug(sprintf('Latest version seems to be "%s", released at %s', $latest['version'], $latest['published_at']->format('Y-m-d H:i')));
+ return $latest;
+ }
+
+ private function getReleases(): array
+ {
+ $client = new Client();
+ $opts = [
+ 'headers' => [
+ 'User-Agent' => 'FireflyIII/' . config('firefly.version'),
+ ],
+ ];
+ $return = [];
+ $body = '';
+ if ($this->localDebug && file_exists('json.json')) {
+ $body = file_get_contents('json.json');
+ }
+ if (!$this->localDebug) {
+
+ try {
+ $res = $client->get('https://api.github.com/repos/firefly-iii/firefly-iii/releases', $opts);
+ } catch (ClientException $e) {
+ Log::error($e->getMessage());
+ return [];
+ }
+ Log::debug('Successfully contacted GitHub');
+ $body = (string)$res->getBody();
+ }
+
+ if (!json_validate($body)) {
+ Log::debug('GitHub returned invalid JSON');
+ return [];
+ }
+ $json = json_decode($body, true);
+ /** @var array $release */
+ foreach ($json as $release) {
+ $version = $release['tag_name'];
+ $version = 'v' === $version[0] ? substr($version, 1) : $version;
+ $published = Carbon::parse($release['published_at']);
+
+ // always skip "develop" releases, unless user is also running develop.
+ if (str_contains($version, 'develop') && !str_contains($this->currentVersion, 'develop')) {
+ Log::debug(sprintf('Skip version "%s"', $release['tag_name']));
+ continue;
+ }
+
+ $return[] = [
+ 'version' => $version,
+ 'published_at' => $published,
+ ];
+ }
+
+ return $return;
+ }
+}
diff --git a/app/Services/FireflyIIIOrg/Update/UpdateRequestInterface.php b/app/Services/FireflyIIIOrg/Update/UpdateRequestInterface.php
index f0e51d43be..f4fa2170e4 100644
--- a/app/Services/FireflyIIIOrg/Update/UpdateRequestInterface.php
+++ b/app/Services/FireflyIIIOrg/Update/UpdateRequestInterface.php
@@ -24,10 +24,12 @@ declare(strict_types=1);
namespace FireflyIII\Services\FireflyIIIOrg\Update;
+use Carbon\Carbon;
+
/**
* Interface UpdateRequestInterface
*/
interface UpdateRequestInterface
{
- public function getUpdateInformation(string $channel): array;
+ public function getUpdateInformation(string $currentVersion, Carbon $currentBuild, string $channel): UpdateResponse;
}
diff --git a/app/Services/FireflyIIIOrg/Update/UpdateResponse.php b/app/Services/FireflyIIIOrg/Update/UpdateResponse.php
new file mode 100644
index 0000000000..3590921574
--- /dev/null
+++ b/app/Services/FireflyIIIOrg/Update/UpdateResponse.php
@@ -0,0 +1,75 @@
+<?php
+/*
+ * UpdateResponse.php
+ * Copyright (c) 2026 [email protected]
+ *
+ * This file is part of Firefly III (https://github.com/firefly-iii).
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+namespace FireflyIII\Services\FireflyIIIOrg\Update;
+
+use Carbon\Carbon;
+
+class UpdateResponse
+{
+ private bool $newVersionAvailable = false;
+ private string $error = '';
+ private string $newVersion = '1.0.0';
+ private Carbon $publishedAt;
+
+ public function getPublishedAt(): Carbon
+ {
+ return $this->publishedAt;
+ }
+
+ public function setPublishedAt(Carbon $publishedAt): void
+ {
+ $this->publishedAt = $publishedAt;
+ }
+
+
+ public function isNewVersionAvailable(): bool
+ {
+ return $this->newVersionAvailable;
+ }
+
+ public function setNewVersionAvailable(bool $newVersionAvailable): void
+ {
+ $this->newVersionAvailable = $newVersionAvailable;
+ }
+
+ public function getNewVersion(): string
+ {
+ return $this->newVersion;
+ }
+
+ public function setNewVersion(string $newVersion): void
+ {
+ $this->newVersion = $newVersion;
+ }
+
+ public function getError(): string
+ {
+ return $this->error;
+ }
+
+ public function setError(string $error): void
+ {
+ $this->error = $error;
+ }
+
+
+}
diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php
index 63324441de..4f92c59610 100644
--- a/resources/lang/en_US/firefly.php
+++ b/resources/lang/en_US/firefly.php
@@ -331,6 +331,7 @@ return [
'update_newer_version_alert' => 'You are running :your_version, which is newer than the latest release, :new_version.',
'update_check_error' => 'An error occurred while checking for updates: :error',
'unknown_error' => 'Unknown error. Sorry about that.',
+ 'no_new_release_available' => 'There is no newer release available. You are up to date.',
'disabled_but_check' => 'You disabled update checking. So don\'t forget to check for updates yourself every now and then. Thank you!',
'admin_update_channel_title' => 'Update channel',
'admin_update_channel_explain' => 'Firefly III has three update "channels" which determine how ahead of the curve you are in terms of features, enhancements and bugs. Use the "beta" channel if you\'re adventurous and the "alpha" when you like to live life dangerously.',