1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Controller.php |
7
|
|
|
* Copyright (c) 2020 [email protected] |
8
|
|
|
* |
9
|
|
|
* This file is part of the Firefly III CSV importer |
10
|
|
|
* (https://github.com/firefly-iii/csv-importer). |
11
|
|
|
* |
12
|
|
|
* This program is free software: you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU Affero General Public License as |
14
|
|
|
* published by the Free Software Foundation, either version 3 of the |
15
|
|
|
* License, or (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* This program is distributed in the hope that it will be useful, |
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20
|
|
|
* GNU Affero General Public License for more details. |
21
|
|
|
* |
22
|
|
|
* You should have received a copy of the GNU Affero General Public License |
23
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
namespace App\Http\Controllers; |
27
|
|
|
|
28
|
|
|
use Artisan; |
29
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
30
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs; |
31
|
|
|
use Illuminate\Foundation\Validation\ValidatesRequests; |
32
|
|
|
use Illuminate\Routing\Controller as BaseController; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Class Controller |
36
|
|
|
*/ |
37
|
|
|
class Controller extends BaseController |
38
|
|
|
{ |
39
|
|
|
use AuthorizesRequests, DispatchesJobs, ValidatesRequests; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Controller constructor. |
43
|
|
|
*/ |
44
|
|
|
public function __construct() |
45
|
|
|
{ |
46
|
|
|
|
47
|
|
|
$variables = [ |
48
|
|
|
'FIREFLY_III_ACCESS_TOKEN' => 'csv_importer.access_token', |
49
|
|
|
'FIREFLY_III_URI' => 'csv_importer.uri', |
50
|
|
|
]; |
51
|
|
|
foreach ($variables as $env => $config) { |
52
|
|
|
|
53
|
|
|
$value = (string)config($config); |
54
|
|
|
if ('' === $value) { |
55
|
|
|
echo sprintf('Please set a valid value for "%s" in the env file.', $env); |
56
|
|
|
Artisan::call('config:clear'); |
57
|
|
|
exit; |
|
|
|
|
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
$path = config('csv_importer.upload_path'); |
61
|
|
|
$writable = is_dir($path) && is_writable($path); |
62
|
|
|
if (false === $writable) { |
63
|
|
|
echo sprintf('Make sure that directory "%s" exists and is writeable.', $path); |
64
|
|
|
exit; |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
app('view')->share('version', config('csv_importer.version')); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.