mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-29 22:47:42 +00:00 
			
		
		
		
	Fix some things with the update checker.
This commit is contained in:
		| @@ -31,7 +31,7 @@ LOG_CHANNEL=stdout | |||||||
| # debug, info, notice, warning, error, critical, alert, emergency | # debug, info, notice, warning, error, critical, alert, emergency | ||||||
| # If you set it to debug your logs will grow large, and fast. If you set it to emergency probably | # If you set it to debug your logs will grow large, and fast. If you set it to emergency probably | ||||||
| # nothing will get logged, ever. | # nothing will get logged, ever. | ||||||
| APP_LOG_LEVEL=notice | APP_LOG_LEVEL=${APP_LOG_LEVEL} | ||||||
|  |  | ||||||
| # Database credentials. Make sure the database exists. I recommend a dedicated user for Firefly III | # Database credentials. Make sure the database exists. I recommend a dedicated user for Firefly III | ||||||
| # For other database types, please see the FAQ: http://firefly-iii.readthedocs.io/en/latest/support/faq.html | # For other database types, please see the FAQ: http://firefly-iii.readthedocs.io/en/latest/support/faq.html | ||||||
|   | |||||||
| @@ -28,6 +28,7 @@ namespace FireflyIII\Handlers\Events; | |||||||
| use FireflyConfig; | use FireflyConfig; | ||||||
| use FireflyIII\Events\RequestedVersionCheckStatus; | use FireflyIII\Events\RequestedVersionCheckStatus; | ||||||
| use FireflyIII\Helpers\Update\UpdateTrait; | use FireflyIII\Helpers\Update\UpdateTrait; | ||||||
|  | use FireflyIII\Models\Configuration; | ||||||
| use FireflyIII\Repositories\User\UserRepositoryInterface; | use FireflyIII\Repositories\User\UserRepositoryInterface; | ||||||
| use FireflyIII\User; | use FireflyIII\User; | ||||||
| use Log; | use Log; | ||||||
| @@ -50,9 +51,11 @@ class VersionCheckEventHandler | |||||||
|      */ |      */ | ||||||
|     public function checkForUpdates(RequestedVersionCheckStatus $event): void |     public function checkForUpdates(RequestedVersionCheckStatus $event): void | ||||||
|     { |     { | ||||||
|  |         Log::debug('Now in checkForUpdates()'); | ||||||
|         // in Sandstorm, cannot check for updates: |         // in Sandstorm, cannot check for updates: | ||||||
|         $sandstorm = 1 === (int)getenv('SANDSTORM'); |         $sandstorm = 1 === (int)getenv('SANDSTORM'); | ||||||
|         if (true === $sandstorm) { |         if (true === $sandstorm) { | ||||||
|  |             Log::debug('This is Sandstorm instance, done.'); | ||||||
|             return; // @codeCoverageIgnore |             return; // @codeCoverageIgnore | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -61,18 +64,19 @@ class VersionCheckEventHandler | |||||||
|         /** @var User $user */ |         /** @var User $user */ | ||||||
|         $user = $event->user; |         $user = $event->user; | ||||||
|         if (!$repository->hasRole($user, 'owner')) { |         if (!$repository->hasRole($user, 'owner')) { | ||||||
|  |             Log::debug('User is not admin, done.'); | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         /** @var Configuration $lastCheckTime */ | ||||||
|         $lastCheckTime = FireflyConfig::get('last_update_check', time()); |         $lastCheckTime = FireflyConfig::get('last_update_check', time()); | ||||||
|         $now           = time(); |         $now           = time(); | ||||||
|         $diff          = $now - $lastCheckTime->data; |         $diff          = $now - $lastCheckTime->data; | ||||||
|         Log::debug(sprintf('Difference is %d seconds.', $diff)); |         Log::debug(sprintf('Last check time is %d, current time is %d, difference is %d', $lastCheckTime->data, $now, $diff)); | ||||||
|         if ($diff < 604800) { |         if ($diff < 604800) { | ||||||
|             Log::debug(sprintf('Checked for updates less than a week ago (on %s).', date('Y-m-d H:i:s', $lastCheckTime->data))); |             Log::debug(sprintf('Checked for updates less than a week ago (on %s).', date('Y-m-d H:i:s', $lastCheckTime->data))); | ||||||
|  |  | ||||||
|             //return; |             return; | ||||||
|  |  | ||||||
|         } |         } | ||||||
|         // last check time was more than a week ago. |         // last check time was more than a week ago. | ||||||
|         Log::debug('Have not checked for a new version in a week!'); |         Log::debug('Have not checked for a new version in a week!'); | ||||||
|   | |||||||
| @@ -42,6 +42,7 @@ trait UpdateTrait | |||||||
|      */ |      */ | ||||||
|     public function getLatestRelease(): ?Release |     public function getLatestRelease(): ?Release | ||||||
|     { |     { | ||||||
|  |         Log::debug('Now in getLatestRelease()'); | ||||||
|         $return = null; |         $return = null; | ||||||
|         /** @var UpdateRequest $request */ |         /** @var UpdateRequest $request */ | ||||||
|         $request = app(UpdateRequest::class); |         $request = app(UpdateRequest::class); | ||||||
| @@ -53,11 +54,15 @@ trait UpdateTrait | |||||||
|  |  | ||||||
|         // get releases from array. |         // get releases from array. | ||||||
|         $releases = $request->getReleases(); |         $releases = $request->getReleases(); | ||||||
|  |  | ||||||
|  |         Log::debug(sprintf('Found %d releases', \count($releases))); | ||||||
|  |  | ||||||
|         if (\count($releases) > 0) { |         if (\count($releases) > 0) { | ||||||
|             // first entry should be the latest entry: |             // first entry should be the latest entry: | ||||||
|             /** @var Release $first */ |             /** @var Release $first */ | ||||||
|             $first  = reset($releases); |             $first  = reset($releases); | ||||||
|             $return = $first; |             $return = $first; | ||||||
|  |             Log::debug(sprintf('Number of releases found is larger than zero. Return %s ', $first->getTitle())); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return $return; |         return $return; | ||||||
| @@ -73,17 +78,21 @@ trait UpdateTrait | |||||||
|      */ |      */ | ||||||
|     public function parseResult(int $versionCheck, Release $release = null): string |     public function parseResult(int $versionCheck, Release $release = null): string | ||||||
|     { |     { | ||||||
|  |         Log::debug(sprintf('Now in parseResult(%d)', $versionCheck)); | ||||||
|         $current = (string)config('firefly.version'); |         $current = (string)config('firefly.version'); | ||||||
|         $return  = ''; |         $return  = ''; | ||||||
|         if ($versionCheck === -2) { |         if ($versionCheck === -2) { | ||||||
|  |             Log::debug('-2, so give error.'); | ||||||
|             $return = (string)trans('firefly.update_check_error'); |             $return = (string)trans('firefly.update_check_error'); | ||||||
|         } |         } | ||||||
|         if ($versionCheck === -1 && null !== $release) { |         if ($versionCheck === -1 && null !== $release) { | ||||||
|  |             Log::debug('New version!'); | ||||||
|             // there is a new FF version! |             // there is a new FF version! | ||||||
|             // has it been released for at least three days? |             // has it been released for at least three days? | ||||||
|             $today       = new Carbon; |             $today       = new Carbon; | ||||||
|             $releaseDate = $release->getUpdated(); |             $releaseDate = $release->getUpdated(); | ||||||
|             if ($today->diffInDays($releaseDate, true) > 3) { |             if ($today->diffInDays($releaseDate, true) > 3) { | ||||||
|  |                 Log::debug('New version is older than 3 days!'); | ||||||
|                 $monthAndDayFormat = (string)trans('config.month_and_day'); |                 $monthAndDayFormat = (string)trans('config.month_and_day'); | ||||||
|                 $return            = (string)trans( |                 $return            = (string)trans( | ||||||
|                     'firefly.update_new_version_alert', |                     'firefly.update_new_version_alert', | ||||||
| @@ -97,10 +106,12 @@ trait UpdateTrait | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (0 === $versionCheck) { |         if (0 === $versionCheck) { | ||||||
|  |             Log::debug('User is running current version.'); | ||||||
|             // you are running the current version! |             // you are running the current version! | ||||||
|             $return = (string)trans('firefly.update_current_version_alert', ['version' => $current]); |             $return = (string)trans('firefly.update_current_version_alert', ['version' => $current]); | ||||||
|         } |         } | ||||||
|         if (1 === $versionCheck && null !== $release) { |         if (1 === $versionCheck && null !== $release) { | ||||||
|  |             Log::debug('User is running NEWER version.'); | ||||||
|             // you are running a newer version! |             // you are running a newer version! | ||||||
|             $return = (string)trans('firefly.update_newer_version_alert', ['your_version' => $current, 'new_version' => $release->getTitle()]); |             $return = (string)trans('firefly.update_newer_version_alert', ['your_version' => $current, 'new_version' => $release->getTitle()]); | ||||||
|         } |         } | ||||||
| @@ -117,7 +128,9 @@ trait UpdateTrait | |||||||
|      */ |      */ | ||||||
|     public function versionCheck(Release $release = null): int |     public function versionCheck(Release $release = null): int | ||||||
|     { |     { | ||||||
|  |         Log::debug('Now in versionCheck()'); | ||||||
|         if (null === $release) { |         if (null === $release) { | ||||||
|  |             Log::debug('Release is null, return -2.'); | ||||||
|             return -2; |             return -2; | ||||||
|         } |         } | ||||||
|         $current = (string)config('firefly.version'); |         $current = (string)config('firefly.version'); | ||||||
|   | |||||||
| @@ -137,7 +137,7 @@ class DebugController extends Controller | |||||||
|         $appEnv         = env('APP_ENV', ''); |         $appEnv         = env('APP_ENV', ''); | ||||||
|         $appDebug       = var_export(env('APP_DEBUG', false), true); |         $appDebug       = var_export(env('APP_DEBUG', false), true); | ||||||
|         $logChannel     = env('LOG_CHANNEL', ''); |         $logChannel     = env('LOG_CHANNEL', ''); | ||||||
|         $appLogLevel    = env('APP_LOG_LEVEL', ''); |         $appLogLevel    = env('APP_LOG_LEVEL', 'info'); | ||||||
|         $packages       = $this->collectPackages(); |         $packages       = $this->collectPackages(); | ||||||
|         $cacheDriver    = env('CACHE_DRIVER', 'unknown'); |         $cacheDriver    = env('CACHE_DRIVER', 'unknown'); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -118,9 +118,11 @@ class FireflyConfig | |||||||
|     public function set(string $name, $value): Configuration |     public function set(string $name, $value): Configuration | ||||||
|     { |     { | ||||||
|         Log::debug('Set new value for ', ['name' => $name]); |         Log::debug('Set new value for ', ['name' => $name]); | ||||||
|  |         /** @var Configuration $config */ | ||||||
|         $config = Configuration::whereName($name)->first(); |         $config = Configuration::whereName($name)->first(); | ||||||
|         if (null === $config) { |         if (null === $config) { | ||||||
|             Log::debug('Does not exist yet ', ['name' => $name]); |             Log::debug('Does not exist yet ', ['name' => $name]); | ||||||
|  |             /** @var Configuration $item */ | ||||||
|             $item       = new Configuration; |             $item       = new Configuration; | ||||||
|             $item->name = $name; |             $item->name = $name; | ||||||
|             $item->data = $value; |             $item->data = $value; | ||||||
| @@ -130,7 +132,7 @@ class FireflyConfig | |||||||
|  |  | ||||||
|             return $item; |             return $item; | ||||||
|         } |         } | ||||||
|         Log::debug('Exists already ', ['name' => $name]); |         Log::debug('Exists already, overwrite value.', ['name' => $name]); | ||||||
|         $config->data = $value; |         $config->data = $value; | ||||||
|         $config->save(); |         $config->save(); | ||||||
|         Cache::forget('ff-config-' . $name); |         Cache::forget('ff-config-' . $name); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user