mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 16:57:09 +00:00
Various code cleanup
This commit is contained in:
@@ -57,8 +57,6 @@ class UpgradeDatabase extends Command
|
|||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$this->setTransactionIdentifier();
|
$this->setTransactionIdentifier();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,8 +83,18 @@ class UpgradeDatabase extends Command
|
|||||||
$journalIds = array_unique($result->pluck('id')->toArray());
|
$journalIds = array_unique($result->pluck('id')->toArray());
|
||||||
|
|
||||||
foreach ($journalIds as $journalId) {
|
foreach ($journalIds as $journalId) {
|
||||||
// grab all positive transactiosn from this journal that are not deleted.
|
$this->updateJournal($journalId);
|
||||||
// for each one, grab the negative opposing one which has 0 as an identifier and give it the same identifier.
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* grab all positive transactiosn from this journal that are not deleted. for each one, grab the negative opposing one
|
||||||
|
* which has 0 as an identifier and give it the same identifier.
|
||||||
|
*
|
||||||
|
* @param int $journalId
|
||||||
|
*/
|
||||||
|
private function updateJournal(int $journalId)
|
||||||
|
{
|
||||||
$identifier = 0;
|
$identifier = 0;
|
||||||
$processed = [];
|
$processed = [];
|
||||||
$transactions = Transaction::where('transaction_journal_id', $journalId)->where('amount', '>', 0)->get();
|
$transactions = Transaction::where('transaction_journal_id', $journalId)->where('amount', '>', 0)->get();
|
||||||
@@ -107,7 +115,8 @@ class UpgradeDatabase extends Command
|
|||||||
$this->error(sprintf('This field is required for Firefly III version %s to run.', config('firefly.version')));
|
$this->error(sprintf('This field is required for Firefly III version %s to run.', config('firefly.version')));
|
||||||
$this->error('Please run "php artisan migrate" to add this field to the table.');
|
$this->error('Please run "php artisan migrate" to add this field to the table.');
|
||||||
$this->info('Then, run "php artisan firefly:upgrade-database" to try again.');
|
$this->info('Then, run "php artisan firefly:upgrade-database" to try again.');
|
||||||
break 2;
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (!is_null($opposing)) {
|
if (!is_null($opposing)) {
|
||||||
// give both a new identifier:
|
// give both a new identifier:
|
||||||
@@ -122,5 +131,4 @@ class UpgradeDatabase extends Command
|
|||||||
$identifier++;
|
$identifier++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -76,15 +76,4 @@ class Kernel extends ConsoleKernel
|
|||||||
{
|
{
|
||||||
require base_path('routes/console.php');
|
require base_path('routes/console.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Define the application's command schedule.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function schedule(Schedule $schedule)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -72,6 +72,7 @@ class Handler extends ExceptionHandler
|
|||||||
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
|
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
|
||||||
*
|
*
|
||||||
* @param Exception $exception
|
* @param Exception $exception
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's exactly five.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@@ -98,8 +99,8 @@ class Handler extends ExceptionHandler
|
|||||||
];
|
];
|
||||||
|
|
||||||
// create job that will mail.
|
// create job that will mail.
|
||||||
$ip = $_SERVER['REMOTE_ADDR'] ?? '0.0.0.0';
|
$ipAddress = $_SERVER['REMOTE_ADDR'] ?? '0.0.0.0';
|
||||||
$job = new MailError($userData, env('SITE_OWNER', ''), $ip, $data);
|
$job = new MailError($userData, env('SITE_OWNER', ''), $ipAddress, $data);
|
||||||
dispatch($job);
|
dispatch($job);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -287,7 +287,7 @@ class JournalExportCollector extends BasicCollector implements CollectorInterfac
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||||
*/
|
*/
|
||||||
private function getWorkSet()
|
private function getWorkSet()
|
||||||
{
|
{
|
||||||
|
@@ -29,6 +29,7 @@ use Crypt;
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Class Entry
|
* Class Entry
|
||||||
|
* @SuppressWarnings(PHPMD.LongVariable)
|
||||||
*
|
*
|
||||||
* @package FireflyIII\Export\Entry
|
* @package FireflyIII\Export\Entry
|
||||||
*/
|
*/
|
||||||
@@ -72,33 +73,21 @@ final class Entry
|
|||||||
public static function fromObject($object): Entry
|
public static function fromObject($object): Entry
|
||||||
{
|
{
|
||||||
$entry = new self;
|
$entry = new self;
|
||||||
|
|
||||||
// journal information:
|
|
||||||
$entry->journal_id = $object->transaction_journal_id;
|
$entry->journal_id = $object->transaction_journal_id;
|
||||||
$entry->description = $object->journal_encrypted === 1 ? Crypt::decrypt($object->journal_description) : $object->journal_description;
|
$entry->description = self::decrypt($object->journal_encrypted, $object->journal_description);
|
||||||
$entry->amount = round($object->amount, 2); // always positive
|
$entry->amount = round($object->amount, 2); // always positive
|
||||||
$entry->date = $object->date;
|
$entry->date = $object->date;
|
||||||
$entry->transaction_type = $object->transaction_type;
|
$entry->transaction_type = $object->transaction_type;
|
||||||
$entry->currency_code = $object->transaction_currency_code;
|
$entry->currency_code = $object->transaction_currency_code;
|
||||||
|
|
||||||
// source information:
|
|
||||||
$entry->source_account_id = $object->account_id;
|
$entry->source_account_id = $object->account_id;
|
||||||
$entry->source_account_name = $object->account_name_encrypted === 1 ? Crypt::decrypt($object->account_name) : $object->account_name;
|
$entry->source_account_name = self::decrypt($object->account_name_encrypted, $object->account_name);
|
||||||
|
|
||||||
|
|
||||||
// destination information
|
|
||||||
$entry->destination_account_id = $object->opposing_account_id;
|
$entry->destination_account_id = $object->opposing_account_id;
|
||||||
$entry->destination_account_name = $object->opposing_account_encrypted === 1 ? Crypt::decrypt($object->opposing_account_name)
|
$entry->destination_account_name = self::decrypt($object->opposing_account_encrypted, $object->opposing_account_name);
|
||||||
: $object->opposing_account_name;
|
|
||||||
|
|
||||||
|
|
||||||
// category and budget
|
|
||||||
$entry->category_id = $object->category_id ?? '';
|
$entry->category_id = $object->category_id ?? '';
|
||||||
$entry->category_name = $object->category_name ?? '';
|
$entry->category_name = $object->category_name ?? '';
|
||||||
$entry->budget_id = $object->budget_id ?? '';
|
$entry->budget_id = $object->budget_id ?? '';
|
||||||
$entry->budget_name = $object->budget_name ?? '';
|
$entry->budget_name = $object->budget_name ?? '';
|
||||||
|
|
||||||
|
|
||||||
// update description when transaction description is different:
|
// update description when transaction description is different:
|
||||||
if (!is_null($object->description) && $object->description != $entry->description) {
|
if (!is_null($object->description) && $object->description != $entry->description) {
|
||||||
$entry->description = $entry->description . ' (' . $object->description . ')';
|
$entry->description = $entry->description . ' (' . $object->description . ')';
|
||||||
@@ -107,4 +96,19 @@ final class Entry
|
|||||||
return $entry;
|
return $entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $isEncrypted
|
||||||
|
* @param $value
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected static function decrypt(int $isEncrypted, $value)
|
||||||
|
{
|
||||||
|
if ($isEncrypted === 1) {
|
||||||
|
return Crypt::decrypt($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user