mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fix some commands.
This commit is contained in:
@@ -42,32 +42,41 @@ class ValidatesEnvironmentVariables extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'integrity:validates-environment-variables';
|
protected $signature = 'integrity:validates-environment-variables';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
*/
|
*/
|
||||||
public function handle(): int
|
public function handle(): int
|
||||||
{
|
{
|
||||||
$this->validateLanguage();
|
$result = $this->validateLanguage();
|
||||||
$this->validateGuard();
|
if (false === $result) {
|
||||||
$this->validateStaticToken();
|
return Command::FAILURE;
|
||||||
|
}
|
||||||
|
$result = $this->validateGuard();
|
||||||
|
if (false === $result) {
|
||||||
|
return Command::FAILURE;
|
||||||
|
}
|
||||||
|
$result = $this->validateStaticToken();
|
||||||
|
if (false === $result) {
|
||||||
|
return Command::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function validateLanguage(): void
|
private function validateLanguage(): bool
|
||||||
{
|
{
|
||||||
$language = config('firefly.default_language');
|
$language = config('firefly.default_language');
|
||||||
$locale = config('firefly.default_locale');
|
$locale = config('firefly.default_locale');
|
||||||
$options = array_keys(config('firefly.languages'));
|
$options = array_keys(config('firefly.languages'));
|
||||||
|
|
||||||
if (!in_array($language, $options, true)) {
|
if (!in_array($language, $options, true)) {
|
||||||
$this->friendlyError(sprintf('DEFAULT_LANGUAGE "%s" is not a valid language for Firefly III.', $language));
|
$this->friendlyError(sprintf('DEFAULT_LANGUAGE "%s" is not a valid language for Firefly III.', $language));
|
||||||
$this->friendlyError('Please check your .env file and make sure you use a valid setting.');
|
$this->friendlyError('Please check your .env file and make sure you use a valid setting.');
|
||||||
$this->friendlyError(sprintf('Valid languages are: %s', implode(', ', $options)));
|
$this->friendlyError(sprintf('Valid languages are: %s', implode(', ', $options)));
|
||||||
|
|
||||||
exit(1);
|
return false;
|
||||||
}
|
}
|
||||||
$options[] = 'equal';
|
$options[] = 'equal';
|
||||||
if (!in_array($locale, $options, true)) {
|
if (!in_array($locale, $options, true)) {
|
||||||
@@ -75,30 +84,31 @@ class ValidatesEnvironmentVariables extends Command
|
|||||||
$this->friendlyError('Please check your .env file and make sure you use a valid setting.');
|
$this->friendlyError('Please check your .env file and make sure you use a valid setting.');
|
||||||
$this->friendlyError(sprintf('Valid locales are: %s', implode(', ', $options)));
|
$this->friendlyError(sprintf('Valid locales are: %s', implode(', ', $options)));
|
||||||
|
|
||||||
exit(1);
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function validateGuard(): void
|
private function validateGuard(): bool
|
||||||
{
|
{
|
||||||
$guard = config('auth.defaults.guard');
|
$guard = config('auth.defaults.guard');
|
||||||
if ('web' !== $guard && 'remote_user_guard' !== $guard) {
|
if ('web' !== $guard && 'remote_user_guard' !== $guard) {
|
||||||
$this->friendlyError(sprintf('AUTHENTICATION_GUARD "%s" is not a valid guard for Firefly III.', $guard));
|
$this->friendlyError(sprintf('AUTHENTICATION_GUARD "%s" is not a valid guard for Firefly III.', $guard));
|
||||||
$this->friendlyError('Please check your .env file and make sure you use a valid setting.');
|
$this->friendlyError('Please check your .env file and make sure you use a valid setting.');
|
||||||
$this->friendlyError('Valid guards are: web, remote_user_guard');
|
$this->friendlyError('Valid guards are: web, remote_user_guard');
|
||||||
|
return false;
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function validateStaticToken(): void
|
private function validateStaticToken(): bool
|
||||||
{
|
{
|
||||||
$token = (string) config('firefly.static_cron_token');
|
$token = (string)config('firefly.static_cron_token');
|
||||||
if ('' !== $token && 32 !== strlen($token)) {
|
if ('' !== $token && 32 !== strlen($token)) {
|
||||||
$this->friendlyError('STATIC_CRON_TOKEN must be empty or a 32-character string.');
|
$this->friendlyError('STATIC_CRON_TOKEN must be empty or a 32-character string.');
|
||||||
$this->friendlyError('Please check your .env file and make sure you use a valid setting.');
|
$this->friendlyError('Please check your .env file and make sure you use a valid setting.');
|
||||||
|
return false;
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,12 +29,15 @@ use FireflyIII\Models\Attachment;
|
|||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Contracts\Encryption\DecryptException;
|
use Illuminate\Contracts\Encryption\DecryptException;
|
||||||
use Illuminate\Support\Facades\Crypt;
|
use Illuminate\Support\Facades\Crypt;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Safe\Exceptions\FileinfoException;
|
||||||
use function Safe\tempnam;
|
use Safe\Exceptions\FilesystemException;
|
||||||
|
use Safe\Exceptions\StringsException;
|
||||||
use function Safe\file_put_contents;
|
use function Safe\file_put_contents;
|
||||||
use function Safe\md5_file;
|
use function Safe\md5_file;
|
||||||
use function Safe\mime_content_type;
|
use function Safe\mime_content_type;
|
||||||
|
use function Safe\tempnam;
|
||||||
|
|
||||||
class ScansAttachments extends Command
|
class ScansAttachments extends Command
|
||||||
{
|
{
|
||||||
@@ -42,10 +45,13 @@ class ScansAttachments extends Command
|
|||||||
|
|
||||||
protected $description = 'Rescan all attachments and re-set the correct MD5 hash and mime.';
|
protected $description = 'Rescan all attachments and re-set the correct MD5 hash and mime.';
|
||||||
|
|
||||||
protected $signature = 'firefly-iii:scan-attachments';
|
protected $signature = 'firefly-iii:scan-attachments';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
|
* @throws FilesystemException
|
||||||
|
* @throws StringsException
|
||||||
|
* @throws FileinfoException
|
||||||
*/
|
*/
|
||||||
public function handle(): int
|
public function handle(): int
|
||||||
{
|
{
|
||||||
@@ -57,7 +63,7 @@ class ScansAttachments extends Command
|
|||||||
$fileName = $attachment->fileName();
|
$fileName = $attachment->fileName();
|
||||||
$encryptedContent = $disk->get($fileName);
|
$encryptedContent = $disk->get($fileName);
|
||||||
if (null === $encryptedContent) {
|
if (null === $encryptedContent) {
|
||||||
app('log')->error(sprintf('No content for attachment #%d under filename "%s"', $attachment->id, $fileName));
|
Log::error(sprintf('No content for attachment #%d under filename "%s"', $attachment->id, $fileName));
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -65,18 +71,13 @@ class ScansAttachments extends Command
|
|||||||
try {
|
try {
|
||||||
$decryptedContent = Crypt::decrypt($encryptedContent); // verified
|
$decryptedContent = Crypt::decrypt($encryptedContent); // verified
|
||||||
} catch (DecryptException $e) {
|
} catch (DecryptException $e) {
|
||||||
app('log')->error(sprintf('Could not decrypt data of attachment #%d: %s', $attachment->id, $e->getMessage()));
|
Log::error(sprintf('Could not decrypt data of attachment #%d: %s', $attachment->id, $e->getMessage()));
|
||||||
$decryptedContent = $encryptedContent;
|
$decryptedContent = $encryptedContent;
|
||||||
}
|
}
|
||||||
$tempFileName = tempnam(sys_get_temp_dir(), 'FireflyIII');
|
$tempFileName = tempnam(sys_get_temp_dir(), 'FireflyIII');
|
||||||
if (false === $tempFileName) {
|
|
||||||
app('log')->error(sprintf('Could not create temporary file for attachment #%d', $attachment->id));
|
|
||||||
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
file_put_contents($tempFileName, $decryptedContent);
|
file_put_contents($tempFileName, $decryptedContent);
|
||||||
$attachment->md5 = (string) md5_file($tempFileName);
|
$attachment->md5 = (string)md5_file($tempFileName);
|
||||||
$attachment->mime = (string) mime_content_type($tempFileName);
|
$attachment->mime = (string)mime_content_type($tempFileName);
|
||||||
$attachment->save();
|
$attachment->save();
|
||||||
$this->friendlyInfo(sprintf('Fixed attachment #%d', $attachment->id));
|
$this->friendlyInfo(sprintf('Fixed attachment #%d', $attachment->id));
|
||||||
}
|
}
|
||||||
|
@@ -835,11 +835,9 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
if (count($product['transactions']) > 1) {
|
if (count($product['transactions']) > 1) {
|
||||||
return $product['title'];
|
return $product['title'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'zzz';
|
return 'zzz';
|
||||||
}
|
}
|
||||||
|
return 'zzz';
|
||||||
exit('here we are 2');
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,10 +24,15 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Support\Request;
|
namespace FireflyIII\Support\Request;
|
||||||
|
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
|
|
||||||
trait GetFilterInstructions
|
trait GetFilterInstructions
|
||||||
{
|
{
|
||||||
private const string INVALID_FILTER = '%INVALID_JAMES_%';
|
private const string INVALID_FILTER = '%INVALID_JAMES_%';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws FireflyException
|
||||||
|
*/
|
||||||
final public function getFilterInstructions(string $key): array
|
final public function getFilterInstructions(string $key): array
|
||||||
{
|
{
|
||||||
$config = config(sprintf('firefly.filters.allowed.%s', $key));
|
$config = config(sprintf('firefly.filters.allowed.%s', $key));
|
||||||
@@ -48,7 +53,7 @@ trait GetFilterInstructions
|
|||||||
|
|
||||||
switch ($filterType) {
|
switch ($filterType) {
|
||||||
default:
|
default:
|
||||||
exit(sprintf('Do not support filter type "%s"', $filterType));
|
throw new FireflyException(sprintf('Do not support filter type "%s"', $filterType));
|
||||||
|
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
$filterValue = $this->booleanInstruction($filterValue);
|
$filterValue = $this->booleanInstruction($filterValue);
|
||||||
|
Reference in New Issue
Block a user