mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fix #4199
This commit is contained in:
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Api\V1\Requests;
|
namespace FireflyIII\Api\V1\Requests;
|
||||||
|
|
||||||
use FireflyIII\Models\Location;
|
use FireflyIII\Models\Location;
|
||||||
|
use FireflyIII\Support\Request\AppendsLocationData;
|
||||||
use FireflyIII\Support\Request\ChecksLogin;
|
use FireflyIII\Support\Request\ChecksLogin;
|
||||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
@@ -35,8 +36,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
|||||||
*/
|
*/
|
||||||
class TagStoreRequest extends FormRequest
|
class TagStoreRequest extends FormRequest
|
||||||
{
|
{
|
||||||
use ConvertsDataTypes, ChecksLogin;
|
use ConvertsDataTypes, ChecksLogin, AppendsLocationData;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,20 +46,15 @@ class TagStoreRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function getAll(): array
|
public function getAll(): array
|
||||||
{
|
{
|
||||||
$hasLocation = false;
|
$data = [
|
||||||
if ($this->has('longitude') && $this->has('latitude') && $this->has('zoom_level')) {
|
|
||||||
$hasLocation = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
'tag' => $this->string('tag'),
|
'tag' => $this->string('tag'),
|
||||||
'date' => $this->date('date'),
|
'date' => $this->date('date'),
|
||||||
'description' => $this->string('description'),
|
'description' => $this->string('description'),
|
||||||
'has_location' => $hasLocation,
|
'has_location' => true,
|
||||||
'longitude' => $this->string('longitude'),
|
|
||||||
'latitude' => $this->string('latitude'),
|
|
||||||
'zoom_level' => $this->integer('zoom_level'),
|
|
||||||
];
|
];
|
||||||
|
$data = $this->appendLocationData($data, null);
|
||||||
|
|
||||||
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -25,6 +25,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Api\V1\Requests;
|
namespace FireflyIII\Api\V1\Requests;
|
||||||
|
|
||||||
use FireflyIII\Models\Location;
|
use FireflyIII\Models\Location;
|
||||||
|
use FireflyIII\Support\Request\AppendsLocationData;
|
||||||
use FireflyIII\Support\Request\ChecksLogin;
|
use FireflyIII\Support\Request\ChecksLogin;
|
||||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
@@ -36,8 +37,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
|||||||
*/
|
*/
|
||||||
class TagUpdateRequest extends FormRequest
|
class TagUpdateRequest extends FormRequest
|
||||||
{
|
{
|
||||||
use ConvertsDataTypes, ChecksLogin;
|
use ConvertsDataTypes, ChecksLogin, AppendsLocationData;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,20 +47,15 @@ class TagUpdateRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function getAll(): array
|
public function getAll(): array
|
||||||
{
|
{
|
||||||
$updateLocation = false;
|
$data = [
|
||||||
if ($this->has('longitude') && $this->has('latitude') && $this->has('zoom_level')) {
|
|
||||||
$updateLocation = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
'tag' => $this->string('tag'),
|
'tag' => $this->string('tag'),
|
||||||
'date' => $this->date('date'),
|
'date' => $this->date('date'),
|
||||||
'description' => $this->string('description'),
|
'description' => $this->string('description'),
|
||||||
'has_location' => $updateLocation,
|
'has_location' => true, // pretend location is present.
|
||||||
'longitude' => '' === $this->string('longitude') ? null : $this->string('longitude'),
|
|
||||||
'latitude' => '' === $this->string('latitude') ? null : $this->string('latitude'),
|
|
||||||
'zoom_level' => '' === $this->string('zoom_level') ? null : $this->integer('zoom_level'),
|
|
||||||
];
|
];
|
||||||
|
$data = $this->appendLocationData($data, null);
|
||||||
|
|
||||||
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -108,9 +108,6 @@ class AccountUpdateService
|
|||||||
*/
|
*/
|
||||||
private function updateLocation(Account $account, array $data): void {
|
private function updateLocation(Account $account, array $data): void {
|
||||||
$updateLocation = $data['update_location'] ?? false;
|
$updateLocation = $data['update_location'] ?? false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// location must be updated?
|
// location must be updated?
|
||||||
if (true === $updateLocation) {
|
if (true === $updateLocation) {
|
||||||
// if all set to NULL, delete
|
// if all set to NULL, delete
|
||||||
|
@@ -87,7 +87,7 @@ trait AppendsLocationData
|
|||||||
$latitudeKey = $this->getLocationKey($prefix, 'latitude');
|
$latitudeKey = $this->getLocationKey($prefix, 'latitude');
|
||||||
$zoomLevelKey = $this->getLocationKey($prefix, 'zoom_level');
|
$zoomLevelKey = $this->getLocationKey($prefix, 'zoom_level');
|
||||||
$hasLocationKey = $this->getLocationKey($prefix, 'has_location');
|
$hasLocationKey = $this->getLocationKey($prefix, 'has_location');
|
||||||
$hasLocation = $this->boolean($hasLocationKey);
|
$hasLocation = $this->boolean($hasLocationKey) || true === ($data['has_location'] ?? false);
|
||||||
|
|
||||||
// for a POST (store), all fields must be present and accounted for:
|
// for a POST (store), all fields must be present and accounted for:
|
||||||
if (
|
if (
|
||||||
@@ -115,6 +115,10 @@ trait AppendsLocationData
|
|||||||
}
|
}
|
||||||
if (false === $hasLocation || null === $data['longitude'] || null === $data['latitude'] || null === $data['zoom_level']) {
|
if (false === $hasLocation || null === $data['longitude'] || null === $data['latitude'] || null === $data['zoom_level']) {
|
||||||
Log::debug('One of the fields is NULL or hasLocation is false, wont save.');
|
Log::debug('One of the fields is NULL or hasLocation is false, wont save.');
|
||||||
|
Log::debug(sprintf('Longitude : %s', var_export($data['longitude'], true)));
|
||||||
|
Log::debug(sprintf('Latitude : %s', var_export($data['latitude'], true)));
|
||||||
|
Log::debug(sprintf('Zoom level : %s', var_export($data['zoom_level'], true)));
|
||||||
|
Log::debug(sprintf('Has location: %s', var_export($hasLocation, true)));
|
||||||
$data['store_location'] = false;
|
$data['store_location'] = false;
|
||||||
$data['update_location'] = true; // update is always true, but the values are null:
|
$data['update_location'] = true; // update is always true, but the values are null:
|
||||||
$data['longitude'] = null;
|
$data['longitude'] = null;
|
||||||
|
Reference in New Issue
Block a user