Fix local update check.

This commit is contained in:
James Cole
2026-02-21 06:31:42 +01:00
parent 04c3bf966d
commit e23d0de8f9
5 changed files with 82 additions and 39 deletions
+7 -3
View File
@@ -24,7 +24,9 @@ declare(strict_types=1);
namespace FireflyIII\Helpers\Update;
use Carbon\Carbon;
use FireflyIII\Services\FireflyIIIOrg\Update\UpdateRequestInterface;
use FireflyIII\Services\FireflyIIIOrg\Update\UpdateResponse;
use FireflyIII\Support\Facades\FireflyConfig;
use Illuminate\Support\Facades\Log;
@@ -38,15 +40,17 @@ trait UpdateTrait
* 'message' => 'A new version is available.
* 'level' => 'info' / 'success' / 'error'
*/
public function getLatestRelease(): array
public function getLatestRelease(): UpdateResponse
{
Log::debug('Now in getLatestRelease()');
/** @var UpdateRequestInterface $checker */
$checker = app(UpdateRequestInterface::class);
$channelConfig = FireflyConfig::get('update_channel', 'stable');
$channel = (string) $channelConfig->data;
$channel = (string)$channelConfig->data;
$build = Carbon::createFromTimestamp(config('firefly.build_time'), config('app.timezone'));
$version = config('firefly.version');
return $checker->getUpdateInformation($channel);
return $checker->getUpdateInformation($version, $build, $channel);
}
}
+29 -14
View File
@@ -48,7 +48,7 @@ class UpdateController extends Controller
{
parent::__construct();
$this->middleware(static function ($request, $next) {
app('view')->share('title', (string) trans('firefly.system_settings'));
app('view')->share('title', (string)trans('firefly.system_settings'));
app('view')->share('mainTitleIcon', 'fa-hand-spock-o');
return $next($request);
@@ -61,24 +61,24 @@ class UpdateController extends Controller
*
* @return Factory|View
*/
public function index(): Factory|\Illuminate\Contracts\View\View
public function index(): Factory | \Illuminate\Contracts\View\View
{
$subTitle = (string) trans('firefly.update_check_title');
$subTitle = (string)trans('firefly.update_check_title');
$subTitleIcon = 'fa-star';
$permission = FireflyConfig::get('permission_update_check', -1);
$channel = FireflyConfig::get('update_channel', 'stable');
$selected = $permission->data;
$channelSelected = $channel->data;
$options = [
-1 => (string) trans('firefly.updates_ask_me_later'),
0 => (string) trans('firefly.updates_do_not_check'),
1 => (string) trans('firefly.updates_enable_check'),
-1 => (string)trans('firefly.updates_ask_me_later'),
0 => (string)trans('firefly.updates_do_not_check'),
1 => (string)trans('firefly.updates_enable_check'),
];
$channelOptions = [
'stable' => (string) trans('firefly.update_channel_stable'),
'beta' => (string) trans('firefly.update_channel_beta'),
'alpha' => (string) trans('firefly.update_channel_alpha'),
$channelOptions = [
'stable' => (string)trans('firefly.update_channel_stable'),
'beta' => (string)trans('firefly.update_channel_beta'),
'alpha' => (string)trans('firefly.update_channel_alpha'),
];
return view('settings.update.index', [
@@ -94,16 +94,16 @@ class UpdateController extends Controller
/**
* Post new settings.
*/
public function post(Request $request): Redirector|RedirectResponse
public function post(Request $request): Redirector | RedirectResponse
{
$checkForUpdates = (int) $request->get('check_for_updates');
$checkForUpdates = (int)$request->get('check_for_updates');
$channel = $request->get('update_channel');
$channel = in_array($channel, ['stable', 'beta', 'alpha'], true) ? $channel : 'stable';
FireflyConfig::set('permission_update_check', $checkForUpdates);
FireflyConfig::set('last_update_check', Carbon::now()->getTimestamp());
FireflyConfig::set('update_channel', $channel);
session()->flash('success', (string) trans('firefly.configuration_updated'));
session()->flash('success', (string)trans('firefly.configuration_updated'));
return redirect(route('settings.update-check'));
}
@@ -114,8 +114,23 @@ class UpdateController extends Controller
public function updateCheck(): RedirectResponse
{
$release = $this->getLatestRelease();
$level = 'info';
$message = trans('firefly.no_new_release_available');
if ('' !== $release->getError()) {
$level = 'error';
$message = $release->getError();
}
if ($release->isNewVersionAvailable()) {
// if running develop, slightly different message.
if (str_contains(config('firefly.version'), 'develop')) {
$message = trans('firefly.update_current_dev_older', ['version' => config('firefly.version'), 'new_version' => $release->getNewVersion()]);
}
if (!str_contains(config('firefly.version'), 'develop')) {
$message = trans('firefly.update_new_version_alert', ['your_version' => config('firefly.version'), 'new_version' => $release->getNewVersion(), 'date' => $release->getPublishedAt()->format('Y-m-d H:i:s')]);
}
}
session()->flash($release['level'], $release['message']);
session()->flash($level, $message);
return redirect(route('settings.update-check'));
}
@@ -45,8 +45,8 @@ class ChecksForNewVersion implements ShouldQueue
Log::debug(sprintf('Now in %s', __METHOD__));
// should not check for updates:
$permission = FireflyConfig::get('permission_update_check', -1);
$value = (int) $permission->data;
$permission = FireflyConfig::get('permission_update_check', -1);
$value = (int)$permission->data;
if (1 !== $value) {
Log::debug('Update check is not enabled.');
$this->warnToCheckForUpdates($event);
@@ -55,8 +55,8 @@ class ChecksForNewVersion implements ShouldQueue
}
/** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class);
$user = $event->user;
$repository = app(UserRepositoryInterface::class);
$user = $event->user;
if (!$repository->hasRole($user, 'owner')) {
Log::debug('User is not admin, done.');
@@ -75,9 +75,24 @@ class ChecksForNewVersion implements ShouldQueue
}
// last check time was more than a week ago.
Log::debug('Have not checked for a new version in a week!');
$release = $this->getLatestRelease();
$release = $this->getLatestRelease();
$level = 'info';
$message = trans('firefly.no_new_release_available');
if ('' !== $release->getError()) {
$level = 'error';
$message = $release->getError();
}
if ($release->isNewVersionAvailable()) {
// if running develop, slightly different message.
if (str_contains(config('firefly.version'), 'develop')) {
$message = trans('firefly.update_current_dev_older', ['version' => config('firefly.version'), 'new_version' => $release->getNewVersion()]);
}
if (!str_contains(config('firefly.version'), 'develop')) {
$message = trans('firefly.update_new_version_alert', ['your_version' => config('firefly.version'), 'new_version' => $release->getNewVersion(), 'date' => $release->getPublishedAt()->format('Y-m-d H:i:s')]);
}
}
session()->flash($release['level'], $release['message']);
session()->flash($level, $message);
FireflyConfig::set('last_update_check', Carbon::now()->getTimestamp());
}
@@ -89,8 +104,8 @@ class ChecksForNewVersion implements ShouldQueue
private function warnToCheckForUpdates(SystemRequestedVersionCheck $event): void
{
/** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class);
$user = $event->user;
$repository = app(UserRepositoryInterface::class);
$user = $event->user;
if (!$repository->hasRole($user, 'owner')) {
Log::debug('User is not admin, done.');
@@ -104,16 +119,16 @@ class ChecksForNewVersion implements ShouldQueue
Log::debug(sprintf('Last warning time is %d, current time is %d, difference is %d', $lastCheckTime->data, $now, $diff));
if ($diff < (604800 * 4)) {
Log::debug(sprintf(
'Warned about updates less than four weeks ago (on %s).',
Carbon::createFromTimestamp($lastCheckTime->data)->format('Y-m-d H:i:s')
));
'Warned about updates less than four weeks ago (on %s).',
Carbon::createFromTimestamp($lastCheckTime->data)->format('Y-m-d H:i:s')
));
return;
}
// last check time was more than a week ago.
Log::debug('Have warned about a new version in four weeks!');
session()->flash('info', (string) trans('firefly.disabled_but_check'));
session()->flash('info', (string)trans('firefly.disabled_but_check'));
FireflyConfig::set('last_update_warning', Carbon::now()->getTimestamp());
}
}
@@ -31,7 +31,7 @@ class GitHubUpdateRequest implements UpdateRequestInterface
private string $currentVersion = '1.0.0';
private Carbon $currentBuild;
private string $channel = 'stable';
private bool $localDebug = true;
private bool $localDebug = false;
#[\Override]
public function getUpdateInformation(string $currentVersion, Carbon $currentBuild, string $channel): UpdateResponse
+18 -9
View File
@@ -41,8 +41,8 @@ class UpdateCheckCronjob extends AbstractCronjob
Log::debug('Now in checkForUpdates()');
// should not check for updates:
$permission = FireflyConfig::get('permission_update_check', -1);
$value = (int) $permission->data;
$permission = FireflyConfig::get('permission_update_check', -1);
$value = (int)$permission->data;
if (1 !== $value) {
Log::debug('Update check is not enabled.');
// get stuff from job:
@@ -56,9 +56,9 @@ class UpdateCheckCronjob extends AbstractCronjob
// TODO this is duplicate.
/** @var Configuration $lastCheckTime */
$lastCheckTime = FireflyConfig::get('last_update_check', Carbon::now()->getTimestamp());
$now = Carbon::now()->getTimestamp();
$diff = $now - $lastCheckTime->data;
$lastCheckTime = FireflyConfig::get('last_update_check', Carbon::now()->getTimestamp());
$now = Carbon::now()->getTimestamp();
$diff = $now - $lastCheckTime->data;
Log::debug(sprintf('Last check time is %d, current time is %d, difference is %d', $lastCheckTime->data, $now, $diff));
if ($diff < 604800 && false === $this->force) {
// get stuff from job:
@@ -74,13 +74,13 @@ class UpdateCheckCronjob extends AbstractCronjob
}
// last check time was more than a week ago.
Log::debug('Have not checked for a new version in a week!');
$release = $this->getLatestRelease();
if ('error' === $release['level']) {
$release = $this->getLatestRelease();
if ('' !== $release->getError()) {
// get stuff from job:
$this->jobFired = true;
$this->jobErrored = true;
$this->jobSucceeded = false;
$this->message = $release['message'];
$this->message = $release->getError();
return;
}
@@ -88,6 +88,15 @@ class UpdateCheckCronjob extends AbstractCronjob
$this->jobFired = true;
$this->jobErrored = false;
$this->jobSucceeded = false;
$this->message = $release['message'];
$this->message = trans('firefly.no_new_release_available');;
if ($release->isNewVersionAvailable()) {
// if running develop, slightly different message.
if (str_contains(config('firefly.version'), 'develop')) {
$this->message = trans('firefly.update_current_dev_older', ['version' => config('firefly.version'), 'new_version' => $release->getNewVersion()]);
}
if (!str_contains(config('firefly.version'), 'develop')) {
$this->message = trans('firefly.update_new_version_alert', ['your_version' => config('firefly.version'), 'new_version' => $release->getNewVersion(), 'date' => $release->getPublishedAt()->format('Y-m-d H:i:s')]);
}
}
}
}