| 
									
										
										
										
											2017-12-28 11:38:40 +01:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-28 11:38:40 +01:00
										 |  |  | /** | 
					
						
							|  |  |  |  * UpdateController.php | 
					
						
							| 
									
										
										
										
											2020-01-31 07:32:04 +01:00
										 |  |  |  * Copyright (c) 2019 james@firefly-iii.org | 
					
						
							| 
									
										
										
										
											2017-12-28 11:38:40 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This file is part of Firefly III (https://github.com/firefly-iii). | 
					
						
							| 
									
										
										
										
											2017-12-28 11:38:40 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * 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. | 
					
						
							| 
									
										
										
										
											2017-12-28 11:38:40 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							| 
									
										
										
										
											2017-12-28 11:38:40 +01:00
										 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * GNU Affero General Public License for more details. | 
					
						
							| 
									
										
										
										
											2017-12-28 11:38:40 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * 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/>. | 
					
						
							| 
									
										
										
										
											2017-12-28 11:38:40 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | declare(strict_types=1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace FireflyIII\Http\Controllers\Admin; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-24 05:52:31 +02:00
										 |  |  | use Carbon\Carbon; | 
					
						
							| 
									
										
										
										
											2018-07-08 07:59:58 +02:00
										 |  |  | use FireflyIII\Helpers\Update\UpdateTrait; | 
					
						
							| 
									
										
										
										
											2017-12-28 11:38:40 +01:00
										 |  |  | use FireflyIII\Http\Controllers\Controller; | 
					
						
							|  |  |  | use FireflyIII\Http\Middleware\IsDemoUser; | 
					
						
							| 
									
										
										
										
											2020-03-17 15:01:00 +01:00
										 |  |  | use Illuminate\Contracts\View\Factory; | 
					
						
							| 
									
										
										
										
											2020-02-02 10:39:37 +01:00
										 |  |  | use Illuminate\Http\RedirectResponse; | 
					
						
							| 
									
										
										
										
											2017-12-28 11:38:40 +01:00
										 |  |  | use Illuminate\Http\Request; | 
					
						
							| 
									
										
										
										
											2020-03-17 15:01:00 +01:00
										 |  |  | use Illuminate\Routing\Redirector; | 
					
						
							|  |  |  | use Illuminate\View\View; | 
					
						
							| 
									
										
										
										
											2017-12-28 11:38:40 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Class HomeController. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class UpdateController extends Controller | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-08 07:59:58 +02:00
										 |  |  |     use UpdateTrait; | 
					
						
							| 
									
										
										
										
											2017-12-28 11:38:40 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * ConfigurationController constructor. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function __construct() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         parent::__construct(); | 
					
						
							|  |  |  |         $this->middleware( | 
					
						
							| 
									
										
										
										
											2019-10-26 14:42:51 +02:00
										 |  |  |             static function ($request, $next) { | 
					
						
							| 
									
										
										
										
											2025-01-18 17:20:21 +01:00
										 |  |  |                 app('view')->share('title', (string) trans('firefly.system_settings')); | 
					
						
							| 
									
										
										
										
											2017-12-28 11:38:40 +01:00
										 |  |  |                 app('view')->share('mainTitleIcon', 'fa-hand-spock-o'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return $next($request); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |         $this->middleware(IsDemoUser::class)->except(['index']); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-07-21 08:06:24 +02:00
										 |  |  |      * Show page with update options. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2020-03-17 15:01:00 +01:00
										 |  |  |      * @return Factory|View | 
					
						
							| 
									
										
										
										
											2017-12-28 11:38:40 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function index() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2024-12-22 08:43:12 +01:00
										 |  |  |         $subTitle        = (string) trans('firefly.update_check_title'); | 
					
						
							| 
									
										
										
										
											2019-10-26 14:42:51 +02:00
										 |  |  |         $subTitleIcon    = 'fa-star'; | 
					
						
							|  |  |  |         $permission      = app('fireflyconfig')->get('permission_update_check', -1); | 
					
						
							|  |  |  |         $channel         = app('fireflyconfig')->get('update_channel', 'stable'); | 
					
						
							|  |  |  |         $selected        = $permission->data; | 
					
						
							|  |  |  |         $channelSelected = $channel->data; | 
					
						
							|  |  |  |         $options         = [ | 
					
						
							| 
									
										
										
										
											2024-12-22 08:43:12 +01:00
										 |  |  |             -1 => (string) trans('firefly.updates_ask_me_later'), | 
					
						
							|  |  |  |             0  => (string) trans('firefly.updates_do_not_check'), | 
					
						
							|  |  |  |             1  => (string) trans('firefly.updates_enable_check'), | 
					
						
							| 
									
										
										
										
											2017-12-28 11:38:40 +01:00
										 |  |  |         ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-01 14:43:56 +01:00
										 |  |  |         $channelOptions  = [ | 
					
						
							| 
									
										
										
										
											2024-12-22 08:43:12 +01:00
										 |  |  |             'stable' => (string) trans('firefly.update_channel_stable'), | 
					
						
							|  |  |  |             'beta'   => (string) trans('firefly.update_channel_beta'), | 
					
						
							|  |  |  |             'alpha'  => (string) trans('firefly.update_channel_alpha'), | 
					
						
							| 
									
										
										
										
											2019-10-26 14:42:51 +02:00
										 |  |  |         ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-18 17:26:31 +01:00
										 |  |  |         return view('settings.update.index', compact('subTitle', 'subTitleIcon', 'selected', 'options', 'channelSelected', 'channelOptions')); | 
					
						
							| 
									
										
										
										
											2017-12-28 11:38:40 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-07-21 08:06:24 +02:00
										 |  |  |      * Post new settings. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |      * @return Redirector|RedirectResponse | 
					
						
							| 
									
										
										
										
											2017-12-28 11:38:40 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function post(Request $request) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2024-12-22 08:43:12 +01:00
										 |  |  |         $checkForUpdates = (int) $request->get('check_for_updates'); | 
					
						
							| 
									
										
										
										
											2019-10-26 14:42:51 +02:00
										 |  |  |         $channel         = $request->get('update_channel'); | 
					
						
							|  |  |  |         $channel         = in_array($channel, ['stable', 'beta', 'alpha'], true) ? $channel : 'stable'; | 
					
						
							| 
									
										
										
										
											2020-08-28 21:03:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-13 17:38:41 +01:00
										 |  |  |         app('fireflyconfig')->set('permission_update_check', $checkForUpdates); | 
					
						
							| 
									
										
										
										
											2025-05-24 05:52:31 +02:00
										 |  |  |         app('fireflyconfig')->set('last_update_check', Carbon::now()->getTimestamp()); | 
					
						
							| 
									
										
										
										
											2019-10-26 14:42:51 +02:00
										 |  |  |         app('fireflyconfig')->set('update_channel', $channel); | 
					
						
							| 
									
										
										
										
											2024-12-22 08:43:12 +01:00
										 |  |  |         session()->flash('success', (string) trans('firefly.configuration_updated')); | 
					
						
							| 
									
										
										
										
											2017-12-28 11:38:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-18 17:20:21 +01:00
										 |  |  |         return redirect(route('settings.update-check')); | 
					
						
							| 
									
										
										
										
											2017-12-28 11:38:40 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Does a manual update check. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-02-02 10:39:37 +01:00
										 |  |  |     public function updateCheck(): RedirectResponse | 
					
						
							| 
									
										
										
										
											2017-12-28 11:38:40 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-03-17 15:01:00 +01:00
										 |  |  |         $release = $this->getLatestRelease(); | 
					
						
							| 
									
										
										
										
											2019-10-30 20:02:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 10:39:37 +01:00
										 |  |  |         session()->flash($release['level'], $release['message']); | 
					
						
							| 
									
										
										
										
											2019-10-26 14:42:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-18 17:20:21 +01:00
										 |  |  |         return redirect(route('settings.update-check')); | 
					
						
							| 
									
										
										
										
											2017-12-28 11:38:40 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } |