mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Added a new helper function.
This commit is contained in:
parent
5073fd937c
commit
b5032a7597
@ -19,6 +19,7 @@ use DB;
|
|||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use Illuminate\Database\Query\JoinClause;
|
use Illuminate\Database\Query\JoinClause;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Steam;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class JournalExportCollector
|
* Class JournalExportCollector
|
||||||
@ -118,7 +119,7 @@ class JournalExportCollector extends BasicCollector implements CollectorInterfac
|
|||||||
);
|
);
|
||||||
$set->each(
|
$set->each(
|
||||||
function ($obj) {
|
function ($obj) {
|
||||||
$obj->name = $obj->encrypted === 1 ? Crypt::decrypt($obj->name) : $obj->name;
|
$obj->name = Steam::decrypt(intval($obj->encrypted), $obj->name);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$array = [];
|
$array = [];
|
||||||
@ -159,7 +160,7 @@ class JournalExportCollector extends BasicCollector implements CollectorInterfac
|
|||||||
);
|
);
|
||||||
$set->each(
|
$set->each(
|
||||||
function ($obj) {
|
function ($obj) {
|
||||||
$obj->name = $obj->encrypted === 1 ? Crypt::decrypt($obj->name) : $obj->name;
|
$obj->name = Steam::decrypt(intval($obj->encrypted), $obj->name);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$array = [];
|
$array = [];
|
||||||
@ -202,7 +203,7 @@ class JournalExportCollector extends BasicCollector implements CollectorInterfac
|
|||||||
);
|
);
|
||||||
$set->each(
|
$set->each(
|
||||||
function ($obj) {
|
function ($obj) {
|
||||||
$obj->name = $obj->encrypted === 1 ? Crypt::decrypt($obj->name) : $obj->name;
|
$obj->name = Steam::decrypt(intval($obj->encrypted), $obj->name);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$array = [];
|
$array = [];
|
||||||
@ -243,7 +244,7 @@ class JournalExportCollector extends BasicCollector implements CollectorInterfac
|
|||||||
);
|
);
|
||||||
$set->each(
|
$set->each(
|
||||||
function ($obj) {
|
function ($obj) {
|
||||||
$obj->name = $obj->encrypted === 1 ? Crypt::decrypt($obj->name) : $obj->name;
|
$obj->name = Steam::decrypt(intval($obj->encrypted), $obj->name);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$array = [];
|
$array = [];
|
||||||
|
@ -14,6 +14,7 @@ declare(strict_types = 1);
|
|||||||
namespace FireflyIII\Export\Entry;
|
namespace FireflyIII\Export\Entry;
|
||||||
|
|
||||||
use Crypt;
|
use Crypt;
|
||||||
|
use Steam;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To extend the exported object, in case of new features in Firefly III for example,
|
* To extend the exported object, in case of new features in Firefly III for example,
|
||||||
@ -73,15 +74,15 @@ final class Entry
|
|||||||
{
|
{
|
||||||
$entry = new self;
|
$entry = new self;
|
||||||
$entry->journal_id = $object->transaction_journal_id;
|
$entry->journal_id = $object->transaction_journal_id;
|
||||||
$entry->description = self::decrypt(intval($object->journal_encrypted), $object->journal_description);
|
$entry->description = Steam::decrypt(intval($object->journal_encrypted), $object->journal_description);
|
||||||
$entry->amount = $object->amount;
|
$entry->amount = $object->amount;
|
||||||
$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;
|
||||||
$entry->source_account_id = $object->account_id;
|
$entry->source_account_id = $object->account_id;
|
||||||
$entry->source_account_name = self::decrypt(intval($object->account_name_encrypted), $object->account_name);
|
$entry->source_account_name = Steam::decrypt(intval($object->account_name_encrypted), $object->account_name);
|
||||||
$entry->destination_account_id = $object->opposing_account_id;
|
$entry->destination_account_id = $object->opposing_account_id;
|
||||||
$entry->destination_account_name = self::decrypt(intval($object->opposing_account_encrypted), $object->opposing_account_name);
|
$entry->destination_account_name = Steam::decrypt(intval($object->opposing_account_encrypted), $object->opposing_account_name);
|
||||||
$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 ?? '';
|
||||||
@ -95,19 +96,5 @@ 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -170,10 +170,10 @@ class JournalCollector implements JournalCollectorInterface
|
|||||||
$set->each(
|
$set->each(
|
||||||
function (Transaction $transaction) {
|
function (Transaction $transaction) {
|
||||||
$transaction->date = new Carbon($transaction->date);
|
$transaction->date = new Carbon($transaction->date);
|
||||||
$transaction->description = $transaction->encrypted ? Crypt::decrypt($transaction->description) : $transaction->description;
|
$transaction->description = Steam::decrypt(intval($transaction->encrypted), $transaction->description);
|
||||||
|
|
||||||
if (!is_null($transaction->bill_name)) {
|
if (!is_null($transaction->bill_name)) {
|
||||||
$transaction->bill_name = $transaction->bill_name_encrypted ? Crypt::decrypt($transaction->bill_name) : $transaction->bill_name;
|
$transaction->bill_name = Steam::decrypt(intval($transaction->bill_name_encrypted), $transaction->bill_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -13,7 +13,6 @@ declare(strict_types = 1);
|
|||||||
|
|
||||||
namespace FireflyIII\Repositories\Journal;
|
namespace FireflyIII\Repositories\Journal;
|
||||||
|
|
||||||
use Crypt;
|
|
||||||
use DB;
|
use DB;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\PiggyBankEvent;
|
use FireflyIII\Models\PiggyBankEvent;
|
||||||
@ -23,6 +22,7 @@ use FireflyIII\User;
|
|||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Query\JoinClause;
|
use Illuminate\Database\Query\JoinClause;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Steam;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class JournalTasker
|
* Class JournalTasker
|
||||||
@ -113,7 +113,7 @@ class JournalTasker implements JournalTaskerInterface
|
|||||||
'source_amount' => $entry->amount,
|
'source_amount' => $entry->amount,
|
||||||
'description' => $entry->description,
|
'description' => $entry->description,
|
||||||
'source_account_id' => $entry->account_id,
|
'source_account_id' => $entry->account_id,
|
||||||
'source_account_name' => intval($entry->account_encrypted) === 1 ? Crypt::decrypt($entry->account_name) : $entry->account_name,
|
'source_account_name' => Steam::decrypt(intval($entry->account_encrypted), $entry->account_name),
|
||||||
'source_account_type' => $entry->account_type,
|
'source_account_type' => $entry->account_type,
|
||||||
'source_account_before' => $sourceBalance,
|
'source_account_before' => $sourceBalance,
|
||||||
'source_account_after' => bcadd($sourceBalance, $entry->amount),
|
'source_account_after' => bcadd($sourceBalance, $entry->amount),
|
||||||
@ -121,8 +121,7 @@ class JournalTasker implements JournalTaskerInterface
|
|||||||
'destination_amount' => bcmul($entry->amount, '-1'),
|
'destination_amount' => bcmul($entry->amount, '-1'),
|
||||||
'destination_account_id' => $entry->destination_account_id,
|
'destination_account_id' => $entry->destination_account_id,
|
||||||
'destination_account_type' => $entry->destination_account_type,
|
'destination_account_type' => $entry->destination_account_type,
|
||||||
'destination_account_name' =>
|
'destination_account_name' => Steam::decrypt(intval($entry->destination_account_encrypted), $entry->destination_account_name),
|
||||||
intval($entry->destination_account_encrypted) === 1 ? Crypt::decrypt($entry->destination_account_name) : $entry->destination_account_name,
|
|
||||||
'destination_account_before' => $destinationBalance,
|
'destination_account_before' => $destinationBalance,
|
||||||
'destination_account_after' => bcadd($destinationBalance, bcmul($entry->amount, '-1')),
|
'destination_account_after' => bcadd($destinationBalance, bcmul($entry->amount, '-1')),
|
||||||
'budget_id' => is_null($budget) ? 0 : $budget->id,
|
'budget_id' => is_null($budget) ? 0 : $budget->id,
|
||||||
|
@ -14,6 +14,7 @@ declare(strict_types = 1);
|
|||||||
namespace FireflyIII\Support;
|
namespace FireflyIII\Support;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Crypt;
|
||||||
use DB;
|
use DB;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
@ -180,6 +181,21 @@ class Steam
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $isEncrypted
|
||||||
|
* @param $value
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function decrypt(int $isEncrypted, string $value)
|
||||||
|
{
|
||||||
|
if ($isEncrypted === 1) {
|
||||||
|
return Crypt::decrypt($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $accounts
|
* @param array $accounts
|
||||||
*
|
*
|
||||||
|
@ -19,6 +19,7 @@ use FireflyIII\Models\AccountType;
|
|||||||
use FireflyIII\Models\Transaction as TransactionModel;
|
use FireflyIII\Models\Transaction as TransactionModel;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
|
use Steam;
|
||||||
use Twig_Extension;
|
use Twig_Extension;
|
||||||
use Twig_SimpleFilter;
|
use Twig_SimpleFilter;
|
||||||
use Twig_SimpleFunction;
|
use Twig_SimpleFunction;
|
||||||
@ -195,7 +196,7 @@ class Transaction extends Twig_Extension
|
|||||||
return new Twig_SimpleFunction(
|
return new Twig_SimpleFunction(
|
||||||
'transactionDestinationAccount', function (TransactionModel $transaction): string {
|
'transactionDestinationAccount', function (TransactionModel $transaction): string {
|
||||||
|
|
||||||
$name = intval($transaction->account_encrypted) === 1 ? Crypt::decrypt($transaction->account_name) : $transaction->account_name;
|
$name = Steam::decrypt(intval($transaction->account_encrypted), $transaction->account_name);
|
||||||
$id = intval($transaction->account_id);
|
$id = intval($transaction->account_id);
|
||||||
$type = $transaction->account_type;
|
$type = $transaction->account_type;
|
||||||
|
|
||||||
@ -217,7 +218,7 @@ class Transaction extends Twig_Extension
|
|||||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||||
->first(['transactions.account_id', 'accounts.encrypted', 'accounts.name', 'account_types.type']);
|
->first(['transactions.account_id', 'accounts.encrypted', 'accounts.name', 'account_types.type']);
|
||||||
$name = intval($other->encrypted) === 1 ? Crypt::decrypt($other->name) : $other->name;
|
$name = Steam::decrypt(intval($other->encrypted), $other->name);
|
||||||
$id = $other->account_id;
|
$id = $other->account_id;
|
||||||
$type = $other->type;
|
$type = $other->type;
|
||||||
}
|
}
|
||||||
@ -269,7 +270,7 @@ class Transaction extends Twig_Extension
|
|||||||
'transactionSourceAccount', function (TransactionModel $transaction): string {
|
'transactionSourceAccount', function (TransactionModel $transaction): string {
|
||||||
|
|
||||||
// if the amount is negative, assume that the current account (the one in $transaction) is indeed the source account.
|
// if the amount is negative, assume that the current account (the one in $transaction) is indeed the source account.
|
||||||
$name = intval($transaction->account_encrypted) === 1 ? Crypt::decrypt($transaction->account_name) : $transaction->account_name;
|
$name = Steam::decrypt(intval($transaction->account_encrypted), $transaction->account_name);
|
||||||
$id = intval($transaction->account_id);
|
$id = intval($transaction->account_id);
|
||||||
$type = $transaction->account_type;
|
$type = $transaction->account_type;
|
||||||
|
|
||||||
@ -289,7 +290,7 @@ class Transaction extends Twig_Extension
|
|||||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||||
->first(['transactions.account_id', 'accounts.encrypted', 'accounts.name', 'account_types.type']);
|
->first(['transactions.account_id', 'accounts.encrypted', 'accounts.name', 'account_types.type']);
|
||||||
$name = intval($other->encrypted) === 1 ? Crypt::decrypt($other->name) : $other->name;
|
$name = Steam::decrypt(intval($other->encrypted), $other->name);
|
||||||
$id = $other->account_id;
|
$id = $other->account_id;
|
||||||
$type = $other->type;
|
$type = $other->type;
|
||||||
}
|
}
|
||||||
@ -337,21 +338,6 @@ class Transaction extends Twig_Extension
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $isEncrypted
|
|
||||||
* @param string $value
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function encrypted(int $isEncrypted, string $value): string
|
|
||||||
{
|
|
||||||
if ($isEncrypted === 1) {
|
|
||||||
return Crypt::decrypt($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionModel $transaction
|
* @param TransactionModel $transaction
|
||||||
*
|
*
|
||||||
@ -361,14 +347,14 @@ class Transaction extends Twig_Extension
|
|||||||
{
|
{
|
||||||
// journal has a budget:
|
// journal has a budget:
|
||||||
if (isset($transaction->transaction_journal_budget_id)) {
|
if (isset($transaction->transaction_journal_budget_id)) {
|
||||||
$name = $this->encrypted(intval($transaction->transaction_journal_budget_encrypted), $transaction->transaction_journal_budget_name);
|
$name = Steam::decrypt(intval($transaction->transaction_journal_budget_encrypted), $transaction->transaction_journal_budget_name);
|
||||||
|
|
||||||
return sprintf('<a href="%s" title="%s">%s</a>', route('budgets.show', [$transaction->transaction_journal_budget_id]), $name, $name);
|
return sprintf('<a href="%s" title="%s">%s</a>', route('budgets.show', [$transaction->transaction_journal_budget_id]), $name, $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// transaction has a budget
|
// transaction has a budget
|
||||||
if (isset($transaction->transaction_budget_id)) {
|
if (isset($transaction->transaction_budget_id)) {
|
||||||
$name = $this->encrypted(intval($transaction->transaction_budget_encrypted), $transaction->transaction_budget_name);
|
$name = Steam::decrypt(intval($transaction->transaction_budget_encrypted), $transaction->transaction_budget_name);
|
||||||
|
|
||||||
return sprintf('<a href="%s" title="%s">%s</a>', route('budgets.show', [$transaction->transaction_budget_id]), $name, $name);
|
return sprintf('<a href="%s" title="%s">%s</a>', route('budgets.show', [$transaction->transaction_budget_id]), $name, $name);
|
||||||
}
|
}
|
||||||
@ -400,14 +386,14 @@ class Transaction extends Twig_Extension
|
|||||||
{
|
{
|
||||||
// journal has a category:
|
// journal has a category:
|
||||||
if (isset($transaction->transaction_journal_category_id)) {
|
if (isset($transaction->transaction_journal_category_id)) {
|
||||||
$name = $this->encrypted(intval($transaction->transaction_journal_category_encrypted), $transaction->transaction_journal_category_name);
|
$name = Steam::decrypt(intval($transaction->transaction_journal_category_encrypted), $transaction->transaction_journal_category_name);
|
||||||
|
|
||||||
return sprintf('<a href="%s" title="%s">%s</a>', route('categories.show', [$transaction->transaction_journal_category_id]), $name, $name);
|
return sprintf('<a href="%s" title="%s">%s</a>', route('categories.show', [$transaction->transaction_journal_category_id]), $name, $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// transaction has a category:
|
// transaction has a category:
|
||||||
if (isset($transaction->transaction_category_id)) {
|
if (isset($transaction->transaction_category_id)) {
|
||||||
$name = $this->encrypted(intval($transaction->transaction_category_encrypted), $transaction->transaction_category_name);
|
$name = Steam::decrypt(intval($transaction->transaction_category_encrypted), $transaction->transaction_category_name);
|
||||||
|
|
||||||
return sprintf('<a href="%s" title="%s">%s</a>', route('categories.show', [$transaction->transaction_category_id]), $name, $name);
|
return sprintf('<a href="%s" title="%s">%s</a>', route('categories.show', [$transaction->transaction_category_id]), $name, $name);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user