mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 04:03:26 +00:00
Cleanup code.
This commit is contained in:
@@ -46,14 +46,10 @@ class BudgetController extends Controller
|
|||||||
{
|
{
|
||||||
use BasicDataSupport;
|
use BasicDataSupport;
|
||||||
|
|
||||||
/** @var BudgetLimitRepositoryInterface */
|
private BudgetLimitRepositoryInterface $blRepository;
|
||||||
private $blRepository;
|
private NoBudgetRepositoryInterface $nbRepository;
|
||||||
/** @var NoBudgetRepositoryInterface */
|
private OperationsRepositoryInterface $opsRepository;
|
||||||
private $nbRepository;
|
private BudgetRepositoryInterface $repository;
|
||||||
/** @var OperationsRepositoryInterface */
|
|
||||||
private $opsRepository;
|
|
||||||
/** @var BudgetRepositoryInterface */
|
|
||||||
private $repository;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ExpenseReportController constructor.
|
* ExpenseReportController constructor.
|
||||||
@@ -506,8 +502,8 @@ class BudgetController extends Controller
|
|||||||
];
|
];
|
||||||
$report[$key]['entries'][$dateKey] = $report[$key] ['entries'][$dateKey] ?? '0';
|
$report[$key]['entries'][$dateKey] = $report[$key] ['entries'][$dateKey] ?? '0';
|
||||||
$report[$key]['entries'][$dateKey] = bcadd($journal['amount'], $report[$key] ['entries'][$dateKey]);
|
$report[$key]['entries'][$dateKey] = bcadd($journal['amount'], $report[$key] ['entries'][$dateKey]);
|
||||||
$report[$key]['sum'] = bcadd($report[$key] ['sum'], $journal['amount']);
|
$report[$key]['sum'] = bcadd($report[$key] ['sum'], $journal['amount']);
|
||||||
$report[$key]['avg'] = bcdiv($report[$key]['sum'], (string) count($periods));
|
$report[$key]['avg'] = bcdiv($report[$key]['sum'], (string) count($periods));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -45,15 +45,12 @@ use phpseclib\Crypt\RSA;
|
|||||||
class InstallController extends Controller
|
class InstallController extends Controller
|
||||||
{
|
{
|
||||||
use GetConfigurationData;
|
use GetConfigurationData;
|
||||||
/** @var string Forbidden error */
|
|
||||||
public const FORBIDDEN_ERROR = 'Internal PHP function "proc_close" is disabled for your installation. Auto-migration is not possible.';
|
|
||||||
/** @var string Basedir error */
|
|
||||||
public const BASEDIR_ERROR = 'Firefly III cannot execute the upgrade commands. It is not allowed to because of an open_basedir restriction.';
|
|
||||||
/** @var string Other errors */
|
|
||||||
public const OTHER_ERROR = 'An unknown error prevented Firefly III from executing the upgrade commands. Sorry.';
|
|
||||||
|
|
||||||
/** @var array All upgrade commands. */
|
public const FORBIDDEN_ERROR = 'Internal PHP function "proc_close" is disabled for your installation. Auto-migration is not possible.';
|
||||||
private $upgradeCommands;
|
public const BASEDIR_ERROR = 'Firefly III cannot execute the upgrade commands. It is not allowed to because of an open_basedir restriction.';
|
||||||
|
public const OTHER_ERROR = 'An unknown error prevented Firefly III from executing the upgrade commands. Sorry.';
|
||||||
|
private array $upgradeCommands;
|
||||||
|
private string $lastError;
|
||||||
|
|
||||||
|
|
||||||
/** @noinspection MagicMethodsValidityInspection */
|
/** @noinspection MagicMethodsValidityInspection */
|
||||||
@@ -111,6 +108,8 @@ class InstallController extends Controller
|
|||||||
// final command to set latest version in DB
|
// final command to set latest version in DB
|
||||||
'firefly-iii:set-latest-version' => ['--james-is-cool' => true],
|
'firefly-iii:set-latest-version' => ['--james-is-cool' => true],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$this->lastError = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -169,6 +168,10 @@ class InstallController extends Controller
|
|||||||
|
|
||||||
Log::debug(sprintf('Will now run commands. Request index is %d', $requestIndex));
|
Log::debug(sprintf('Will now run commands. Request index is %d', $requestIndex));
|
||||||
$index = 0;
|
$index = 0;
|
||||||
|
/**
|
||||||
|
* @var string $command
|
||||||
|
* @var array $args
|
||||||
|
*/
|
||||||
foreach ($this->upgradeCommands as $command => $args) {
|
foreach ($this->upgradeCommands as $command => $args) {
|
||||||
Log::debug(sprintf('Current command is "%s", index is %d', $command, $index));
|
Log::debug(sprintf('Current command is "%s", index is %d', $command, $index));
|
||||||
if ($index < $requestIndex) {
|
if ($index < $requestIndex) {
|
||||||
@@ -176,44 +179,51 @@ class InstallController extends Controller
|
|||||||
$index++;
|
$index++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ($index >= $requestIndex) {
|
$result = $this->executeCommand($command, $args);
|
||||||
Log::debug(sprintf('%d >= %d, will execute the command.', $index, $requestIndex));
|
if (false === $result) {
|
||||||
Log::debug(sprintf('Will now call command %s with args.', $command), $args);
|
$response['errorMessage'] = $this->lastError;
|
||||||
try {
|
$response['error'] = true;
|
||||||
if ('generate-keys' === $command) {
|
return response()->json($response);
|
||||||
$this->keys();
|
|
||||||
}
|
|
||||||
if ('generate-keys' !== $command) {
|
|
||||||
Artisan::call($command, $args);
|
|
||||||
Log::debug(Artisan::output());
|
|
||||||
}
|
|
||||||
} catch (Exception $e) {
|
|
||||||
Log::error($e->getMessage());
|
|
||||||
Log::error($e->getTraceAsString());
|
|
||||||
if (strpos($e->getMessage(), 'open_basedir restriction in effect')) {
|
|
||||||
$response['error'] = true;
|
|
||||||
$response['errorMessage'] = self::BASEDIR_ERROR;
|
|
||||||
|
|
||||||
return response()->json($response);
|
|
||||||
}
|
|
||||||
|
|
||||||
$response['error'] = true;
|
|
||||||
$response['errorMessage'] = self::OTHER_ERROR . ' ' . $e->getMessage();
|
|
||||||
|
|
||||||
return response()->json($response);
|
|
||||||
}
|
|
||||||
// clear cache as well.
|
|
||||||
Cache::clear();
|
|
||||||
Preferences::mark();
|
|
||||||
|
|
||||||
$index++;
|
|
||||||
$response['hasNextCommand'] = true;
|
|
||||||
$response['previous'] = $command;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
$index++;
|
||||||
|
$response['hasNextCommand'] = true;
|
||||||
|
$response['previous'] = $command;
|
||||||
}
|
}
|
||||||
$response['next'] = $index;
|
$response['next'] = $index;
|
||||||
|
|
||||||
return response()->json($response);
|
return response()->json($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $command
|
||||||
|
* @param array $args
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function executeCommand(string $command, array $args): bool
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
Log::debug(Artisan::output());
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Log::error($e->getMessage());
|
||||||
|
Log::error($e->getTraceAsString());
|
||||||
|
if (strpos($e->getMessage(), 'open_basedir restriction in effect')) {
|
||||||
|
$this->lastError = self::BASEDIR_ERROR;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$this->lastError = sprintf('%s %s', self::OTHER_ERROR, $e->getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// clear cache as well.
|
||||||
|
Cache::clear();
|
||||||
|
Preferences::mark();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user