This commit is contained in:
James Cole
2023-01-18 07:05:04 +01:00
parent a95104d16a
commit 30af48a859
2 changed files with 10 additions and 10 deletions

View File

@@ -29,10 +29,8 @@ bcscale(12);
* Keep in mind that running this script is entirely AT YOUR OWN RISK with ZERO GUARANTEES.
*/
define('FIREFLY_III_URL', 'http://firefly.sd.home');
define('FIREFLY_III_TOKEN',
'ey...'
);
const FIREFLY_III_URL = 'http://firefly.sd.home';
const FIREFLY_III_TOKEN = 'ey...';
/*
* HERE BE MONSTERS
@@ -83,7 +81,7 @@ foreach ($groups as $group) {
continue;
}
// get the main transaction (we know its one)
// get the main transaction (we know it's one)
$transaction = $group['attributes']['transactions'][0];
// maybe already has a link to existing auto-save?
@@ -93,8 +91,8 @@ foreach ($groups as $group) {
foreach ($links as $link) {
$opposingTransactionId = getOpposingTransaction($transaction['transaction_journal_id'], $link);
// if the opposing transaction is a transfer, and it's a autosave link (recognized by the tag)
// we dont need to create another one.
// if the opposing transaction is a transfer, and it's an autosave link (recognized by the tag)
// we don't need to create another one.
$opposingTransaction = getTransaction($opposingTransactionId);
if (isAutoSaveTransaction($opposingTransaction)) {
@@ -110,6 +108,8 @@ foreach ($groups as $group) {
/**
* @param array $group
* @param array $arguments
*
* @throws JsonException
*/
function createAutoSaveTransaction(array $group, array $arguments): void
{
@@ -243,7 +243,7 @@ function getOpposingTransaction(int $transactionId, array $link): int
function getLinks(array $transaction): array
{
$journalId = $transaction['transaction_journal_id'];
$links = getCurlRequest(sprintf('/api/v1/transactions/%d/transaction_links', $journalId));
$links = getCurlRequest(sprintf('/api/v1/transaction-journals/%d/links', $journalId));
if (count($links['data']) > 0) {
return $links['data'];
@@ -427,7 +427,7 @@ function getArguments(array $arguments): array
/** @var string $argument */
foreach ($arguments as $argument) {
foreach ($fields as $field) {
if (0 === strpos($argument, sprintf('--%s=', $field))) {
if (str_starts_with($argument, sprintf('--%s=', $field))) {
$result[$field] = (int) str_replace(sprintf('--%s=', $field), '', $argument);
if ('amount' === $field) {
$result[$field] = (float) str_replace(sprintf('--%s=', $field), '', $argument);

View File

@@ -29,7 +29,7 @@ This little script can automatically create these transactions for you, so you d
## Installation
Just grab `autosave.php` and save it wherever. You will need php 7.4 with the BCMath, curl and JSON extensions. This is pretty common and it shouldn't be a problem.
Just grab `autosave.php` and save it wherever. You will need PHP 8.0 with the BCMath, curl and JSON extensions. This is pretty common, and it shouldn't be a problem.
Open the file and edit the Firefly III URL and add a Personal Access Token.