2018-01-03 19:17:30 +01:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* ListTransactionsRequest.php
|
2020-02-16 13:56:35 +01:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2018-01-03 19:17:30 +01:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2018-01-03 19:17:30 +01:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
2018-01-03 19:17:30 +01:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2018-01-03 19:17:30 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-02 06:37:26 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2018-01-03 19:17:30 +01:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-01-03 19:17:30 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace FireflyIII\Services\Spectre\Request;
|
|
|
|
|
|
2018-01-08 19:21:00 +01:00
|
|
|
use FireflyIII\Exceptions\FireflyException;
|
2018-01-03 19:17:30 +01:00
|
|
|
use FireflyIII\Services\Spectre\Object\Account;
|
|
|
|
|
use FireflyIII\Services\Spectre\Object\Transaction;
|
|
|
|
|
use Log;
|
2018-01-08 19:21:00 +01:00
|
|
|
|
2018-01-03 19:17:30 +01:00
|
|
|
/**
|
|
|
|
|
* Class ListTransactionsRequest
|
2020-03-15 15:31:51 +01:00
|
|
|
*
|
2019-07-31 16:53:09 +02:00
|
|
|
* @codeCoverageIgnore
|
2020-03-15 15:31:51 +01:00
|
|
|
* @deprecated
|
2018-01-03 19:17:30 +01:00
|
|
|
*/
|
|
|
|
|
class ListTransactionsRequest extends SpectreRequest
|
|
|
|
|
{
|
|
|
|
|
/** @var Account */
|
|
|
|
|
private $account;
|
|
|
|
|
/** @var array */
|
|
|
|
|
private $transactions = [];
|
|
|
|
|
|
|
|
|
|
/**
|
2018-01-08 19:21:00 +01:00
|
|
|
* @throws FireflyException
|
2019-08-17 10:47:29 +02:00
|
|
|
*
|
2018-01-03 19:17:30 +01:00
|
|
|
*/
|
|
|
|
|
public function call(): void
|
|
|
|
|
{
|
|
|
|
|
$hasNextPage = true;
|
|
|
|
|
$nextId = 0;
|
|
|
|
|
while ($hasNextPage) {
|
|
|
|
|
Log::debug(sprintf('Now calling ListTransactionsRequest for next_id %d', $nextId));
|
2018-01-08 19:21:00 +01:00
|
|
|
$parameters = ['from_id' => $nextId, 'account_id' => $this->account->getId()];
|
2018-04-27 13:07:46 +02:00
|
|
|
$uri = '/api/v4/transactions?' . http_build_query($parameters);
|
2018-01-03 19:17:30 +01:00
|
|
|
$response = $this->sendSignedSpectreGet($uri, []);
|
|
|
|
|
|
|
|
|
|
// count entries:
|
2019-05-30 12:31:19 +02:00
|
|
|
Log::debug(sprintf('Found %d entries in data-array', count($response['data'])));
|
2018-01-03 19:17:30 +01:00
|
|
|
|
|
|
|
|
// extract next ID
|
|
|
|
|
$hasNextPage = false;
|
2018-04-02 14:50:17 +02:00
|
|
|
if (isset($response['meta']['next_id']) && (int)$response['meta']['next_id'] > $nextId) {
|
2018-01-03 19:17:30 +01:00
|
|
|
$hasNextPage = true;
|
|
|
|
|
$nextId = $response['meta']['next_id'];
|
|
|
|
|
Log::debug(sprintf('Next ID is now %d.', $nextId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// store customers:
|
|
|
|
|
foreach ($response['data'] as $transactionArray) {
|
|
|
|
|
$this->transactions[] = new Transaction($transactionArray);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getTransactions(): array
|
|
|
|
|
{
|
|
|
|
|
return $this->transactions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param Account $account
|
|
|
|
|
*/
|
|
|
|
|
public function setAccount(Account $account): void
|
|
|
|
|
{
|
|
|
|
|
$this->account = $account;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-03-05 19:35:58 +01:00
|
|
|
}
|