Fix phone data to never be null

This commit is contained in:
osaajani 2020-01-06 23:36:56 +01:00
parent 89459a0285
commit 857f953a04
2 changed files with 5 additions and 5 deletions

View File

@ -65,10 +65,10 @@ namespace controllers\internals;
* @param int $id_user : User to insert phone for
* @param string $number : The number of the phone
* @param string $adapter : The adapter to use the phone
* @param ?string json $adapter_datas : A JSON string representing adapter's datas (for example credentials for an api)
* @param string json $adapter_datas : A JSON string representing adapter's datas (for example credentials for an api)
* @return bool : false on error, true on success
*/
public function create (int $id_user, string $number, string $adapter, ?string $adapter_datas) : bool
public function create (int $id_user, string $number, string $adapter, string $adapter_datas) : bool
{
$phone = [
'id_user' => $id_user,

View File

@ -101,7 +101,7 @@ class Phone extends \descartes\Controller
* @param $csrf : CSRF token
* @param string $_POST['number'] : Phone number
* @param string $_POST['adapter'] : Phone adapter
* @param boolean $_POST['adapter_datas'] : Phone adapter datas
* @param string $_POST['adapter_datas'] : Phone adapter datas
*/
public function create($csrf)
{
@ -114,7 +114,7 @@ class Phone extends \descartes\Controller
$id_user = $_SESSION['user']['id'];
$number = $_POST['number'] ?? false;
$adapter = $_POST['adapter'] ?? false;
$adapter_datas = !empty($_POST['adapter_datas']) ? $_POST['adapter_datas'] : null;
$adapter_datas = !empty($_POST['adapter_datas']) ? $_POST['adapter_datas'] : '{}';
if (!$number || !$adapter)
{
@ -156,7 +156,7 @@ class Phone extends \descartes\Controller
}
if (NULL !== $adapter_datas && NULL === json_decode($adapter_datas))
if (NULL === json_decode($adapter_datas))
{
\FlashMessage\FlashMessage::push('danger', 'La chaîne de configuration n\'est pas valide.');
return $this->redirect(\descartes\Router::url('Phone', 'add'));