Code cleanup.

This commit is contained in:
James Cole
2023-12-20 19:35:52 +01:00
parent c4f6366642
commit 64ec0cf62e
997 changed files with 12908 additions and 28136 deletions

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\System;
use Artisan;
use Cache;
use Exception;
use FireflyIII\Exceptions\FireflyException;
@@ -38,8 +37,6 @@ use phpseclib3\Crypt\RSA;
/**
* Class InstallController
*
*/
class InstallController extends Controller
{
@@ -90,11 +87,6 @@ class InstallController extends Controller
return view('install.index');
}
/**
* @param Request $request
*
* @return JsonResponse
*/
public function runCommand(Request $request): JsonResponse
{
$requestIndex = (int)$request->get('index');
@@ -112,6 +104,7 @@ class InstallController extends Controller
$command = $indexes[$requestIndex];
$parameters = $this->upgradeCommands[$command];
app('log')->debug(sprintf('Will now execute command "%s" with parameters', $command), $parameters);
try {
$result = $this->executeCommand($command, $parameters);
} catch (FireflyException $e) {
@@ -126,48 +119,21 @@ class InstallController extends Controller
if (false === $result) {
$response['errorMessage'] = $this->lastError;
$response['error'] = true;
return response()->json($response);
}
$response['hasNextCommand'] = array_key_exists($requestIndex + 1, $indexes);
$response['previous'] = $command;
}
return response()->json($response);
}
/**
* @param string $command
* @param array $args
*
* @return bool
* @throws FireflyException
*/
private function executeCommand(string $command, array $args): bool
{
app('log')->debug(sprintf('Will now call command %s with args.', $command), $args);
try {
if ('generate-keys' === $command) {
$this->keys();
}
if ('generate-keys' !== $command) {
Artisan::call($command, $args);
app('log')->debug(Artisan::output());
}
} catch (Exception $e) { // intentional generic exception
throw new FireflyException($e->getMessage(), 0, $e);
}
// clear cache as well.
Cache::clear();
app('preferences')->mark();
return true;
}
/**
* Create specific RSA keys.
*/
public function keys(): void
{
$key = RSA::createKey(4096);
[$publicKey, $privateKey] = [
@@ -182,4 +148,29 @@ class InstallController extends Controller
file_put_contents($publicKey, (string)$key->getPublicKey());
file_put_contents($privateKey, $key->toString('PKCS1'));
}
/**
* @throws FireflyException
*/
private function executeCommand(string $command, array $args): bool
{
app('log')->debug(sprintf('Will now call command %s with args.', $command), $args);
try {
if ('generate-keys' === $command) {
$this->keys();
}
if ('generate-keys' !== $command) {
\Artisan::call($command, $args);
app('log')->debug(\Artisan::output());
}
} catch (\Exception $e) { // intentional generic exception
throw new FireflyException($e->getMessage(), 0, $e);
}
// clear cache as well.
\Cache::clear();
app('preferences')->mark();
return true;
}
}