firefly-iii/app/Http/Controllers/Admin/UpdateController.php

115 lines
3.7 KiB
PHP
Raw Normal View History

2017-12-28 04:38:40 -06:00
<?php
/**
* UpdateController.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
2018-07-08 00:59:58 -05:00
/** @noinspection PhpMethodParametersCountMismatchInspection */
2017-12-28 04:38:40 -06:00
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Admin;
2017-12-28 11:39:17 -06:00
use FireflyConfig;
2018-07-08 00:59:58 -05:00
use FireflyIII\Helpers\Update\UpdateTrait;
2017-12-28 04:38:40 -06:00
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Middleware\IsDemoUser;
use FireflyIII\Http\Middleware\IsSandStormUser;
use Illuminate\Http\Request;
/**
* Class HomeController.
*/
class UpdateController extends Controller
{
2018-07-08 00:59:58 -05:00
use UpdateTrait;
2017-12-28 04:38:40 -06:00
/**
* ConfigurationController constructor.
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
2018-04-02 08:10:40 -05:00
app('view')->share('title', (string)trans('firefly.administration'));
2017-12-28 04:38:40 -06:00
app('view')->share('mainTitleIcon', 'fa-hand-spock-o');
return $next($request);
}
);
$this->middleware(IsDemoUser::class)->except(['index']);
$this->middleware(IsSandStormUser::class)->except(['index']);
}
/**
2018-07-21 01:06:24 -05:00
* Show page with update options.
*
2017-12-28 04:38:40 -06:00
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @throws \Psr\Container\NotFoundExceptionInterface
* @throws \Psr\Container\ContainerExceptionInterface
2017-12-28 04:38:40 -06:00
*/
public function index()
{
2018-07-15 02:38:49 -05:00
$subTitle = (string)trans('firefly.update_check_title');
2017-12-28 04:38:40 -06:00
$subTitleIcon = 'fa-star';
$permission = app('fireflyconfig')->get('permission_update_check', -1);
2017-12-28 04:38:40 -06:00
$selected = $permission->data;
$options = [
2018-07-15 02:38:49 -05: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 04:38:40 -06:00
];
return view('admin.update.index', compact('subTitle', 'subTitleIcon', 'selected', 'options'));
}
/**
2018-07-21 01:06:24 -05:00
* Post new settings.
*
2017-12-28 04:38:40 -06:00
* @param Request $request
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function post(Request $request)
{
2018-04-02 08:10:40 -05:00
$checkForUpdates = (int)$request->get('check_for_updates');
2017-12-28 11:39:17 -06:00
FireflyConfig::set('permission_update_check', $checkForUpdates);
2017-12-28 12:03:15 -06:00
FireflyConfig::set('last_update_check', time());
2018-04-22 10:10:11 -05:00
session()->flash('success', (string)trans('firefly.configuration_updated'));
2017-12-28 04:38:40 -06:00
return redirect(route('admin.update-check'));
}
/**
* Does a manual update check.
*/
public function updateCheck()
{
2018-07-08 00:59:58 -05:00
$latestRelease = $this->getLatestRelease();
$versionCheck = $this->versionCheck($latestRelease);
2018-07-26 21:46:21 -05:00
$resultString = $this->parseResult($versionCheck, $latestRelease);
2017-12-28 04:38:40 -06:00
2018-07-08 00:59:58 -05:00
if (0 !== $versionCheck && '' !== $resultString) {
// flash info
session()->flash('info', $resultString);
2017-12-28 04:38:40 -06:00
}
2018-07-08 00:59:58 -05:00
FireflyConfig::set('last_update_check', time());
2017-12-28 04:38:40 -06:00
2018-07-08 00:59:58 -05:00
return response()->json(['result' => $resultString]);
2017-12-28 04:38:40 -06:00
}
}