* account_id parsing simplified
* income category -> id replacement works now
This commit is contained in:
parent
5d09d96cf2
commit
b99d07627b
@ -290,7 +290,6 @@ class KoinService
|
|||||||
$body = $httpResponse->getBody();
|
$body = $httpResponse->getBody();
|
||||||
|
|
||||||
$this->getCsrfToken($body);
|
$this->getCsrfToken($body);
|
||||||
$this->getAccountId($body);
|
|
||||||
|
|
||||||
$httpResponse = $this->httpClient
|
$httpResponse = $this->httpClient
|
||||||
->post(self::BASE_URI . "/site/login", [
|
->post(self::BASE_URI . "/site/login", [
|
||||||
@ -307,9 +306,10 @@ class KoinService
|
|||||||
/**
|
/**
|
||||||
* @param $htmlData
|
* @param $htmlData
|
||||||
*/
|
*/
|
||||||
private function loadFormData($htmlData)
|
private function loadFormData(string $htmlData)
|
||||||
{
|
{
|
||||||
$documentXpath = $this->getCsrfToken($htmlData);
|
$documentXpath = $this->getCsrfToken($htmlData);
|
||||||
|
$this->getAccountId($documentXpath);
|
||||||
|
|
||||||
/** @var \DOMNodeList $expenseOptionElements */
|
/** @var \DOMNodeList $expenseOptionElements */
|
||||||
$expenseOptionElements = $documentXpath->query('//select[@id="transaction-category_id"]/optgroup[@label="Kiadás"]/option');
|
$expenseOptionElements = $documentXpath->query('//select[@id="transaction-category_id"]/optgroup[@label="Kiadás"]/option');
|
||||||
@ -333,7 +333,7 @@ class KoinService
|
|||||||
* @param $html
|
* @param $html
|
||||||
* @return \DOMXPath
|
* @return \DOMXPath
|
||||||
*/
|
*/
|
||||||
private function getCsrfToken($html): \DOMXPath
|
private function getCsrfToken(string $html): \DOMXPath
|
||||||
{
|
{
|
||||||
$xmlErrorHandling = libxml_use_internal_errors(TRUE);
|
$xmlErrorHandling = libxml_use_internal_errors(TRUE);
|
||||||
$domDocument = new \DOMDocument();
|
$domDocument = new \DOMDocument();
|
||||||
@ -354,26 +354,14 @@ class KoinService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse account:id from html
|
* Parse account_id from html
|
||||||
*
|
* @param \DOMXPath $documentXpath
|
||||||
* @param $html
|
|
||||||
* @return \DOMXPath
|
|
||||||
*/
|
*/
|
||||||
private function getAccountId($html): \DOMXPath
|
private function getAccountId(\DOMXPath $documentXpath)
|
||||||
{
|
{
|
||||||
$xmlErrorHandling = libxml_use_internal_errors(TRUE);
|
|
||||||
$domDocument = new \DOMDocument();
|
|
||||||
$domDocument->loadHTML($html);
|
|
||||||
libxml_clear_errors();
|
|
||||||
libxml_use_internal_errors($xmlErrorHandling);
|
|
||||||
|
|
||||||
$documentXpath = new \DOMXPath($domDocument);
|
|
||||||
/** @var \DOMElement $accountIdElement */
|
/** @var \DOMElement $accountIdElement */
|
||||||
$accountIdElement = $documentXpath->query('//input[@id="transaction-account_id"]')->item(0);
|
$accountIdElement = $documentXpath->query('//input[@id="transaction-account_id"]')->item(0);
|
||||||
|
$this->accountId = $accountIdElement->getAttribute("value");
|
||||||
$this->csrfParam = $accountIdElement->getAttribute("value");
|
|
||||||
|
|
||||||
return $documentXpath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -413,11 +401,16 @@ class KoinService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns the category id from the human readable name
|
||||||
|
* Income is scanned first, if there is a duplicate type it will be treated as income
|
||||||
* @param string $category
|
* @param string $category
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function getCategoryId(string $category): string
|
private function getCategoryId(string $category): string
|
||||||
{
|
{
|
||||||
|
if (in_array($category, array_keys($this->incomeCategories))) {
|
||||||
|
return $this->incomeCategories[$category];
|
||||||
|
}
|
||||||
if (in_array($category, array_keys($this->expenseCategories))) {
|
if (in_array($category, array_keys($this->expenseCategories))) {
|
||||||
return $this->expenseCategories[$category];
|
return $this->expenseCategories[$category];
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user