mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Make sure location data in request is processed in a unified way.
This commit is contained in:
@@ -344,4 +344,45 @@ class Request extends FormRequest
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the submitted Request data and add new or updated Location data to the array.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function appendLocationData(array $data): array
|
||||
{
|
||||
Log::debug('Now in appendLocationData()');
|
||||
$data['store_location'] = false;
|
||||
$data['update_location'] = false;
|
||||
$data['longitude'] = null;
|
||||
$data['latitude'] = null;
|
||||
$data['zoom_level'] = null;
|
||||
|
||||
// for a POST (store, all fields must be present and accounted for:
|
||||
if ('POST' === $this->method() && $this->has('longitude') && $this->has('latitude') && $this->has('zoom_level')) {
|
||||
Log::debug('Method is POST and all fields present.');
|
||||
$data['store_location'] = true;
|
||||
$data['longitude'] = '' === $this->string('longitude') ? null : $this->string('longitude');
|
||||
$data['latitude'] = '' === $this->string('latitude') ? null : $this->string('latitude');
|
||||
$data['zoom_level'] = '' === $this->string('zoom_level') ? null : $this->integer('zoom_level');
|
||||
}
|
||||
if ('PUT' === $this->method() && $this->has('longitude') && $this->has('latitude') && $this->has('zoom_level')) {
|
||||
Log::debug('Method is PUT and all fields present.');
|
||||
$data['update_location'] = true;
|
||||
$data['longitude'] = '' === $this->string('longitude') ? null : $this->string('longitude');
|
||||
$data['latitude'] = '' === $this->string('latitude') ? null : $this->string('latitude');
|
||||
$data['zoom_level'] = '' === $this->string('zoom_level') ? null : $this->integer('zoom_level');
|
||||
}
|
||||
if (null === $data['longitude'] || null === $data['latitude'] || null === $data['zoom_level']) {
|
||||
Log::debug('One of the fields is NULL, wont save.');
|
||||
$data['store_location'] = false;
|
||||
$data['update_location'] = false;
|
||||
}
|
||||
Log::debug(sprintf('Returning longitude: "%s", latitude: "%s", zoom level: "%s"', $data['longitude'], $data['latitude'], $data['zoom_level']));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user