diff --git a/VERSION b/VERSION index d446e59..a4dae04 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.9.2 +v3.9.1 diff --git a/controllers/internals/Queue.php b/controllers/internals/Queue.php index 451e5dd..2275cb9 100644 --- a/controllers/internals/Queue.php +++ b/controllers/internals/Queue.php @@ -66,7 +66,7 @@ class Queue extends \descartes\InternalController * * @return mixed $message : The oldest message or null if no message found, can be anything * @param ?string $tag : A tag to associate to the message for routing purposes, if null will read from general queue - * @param mixed : The message return from the queue, can be anything, null if no message found + * @param mixed : The message to add to the queue, can be anything, the queue will have to treat it by itself */ public function read(?string $tag = null) { diff --git a/controllers/internals/Received.php b/controllers/internals/Received.php index 320a62d..6bace82 100644 --- a/controllers/internals/Received.php +++ b/controllers/internals/Received.php @@ -83,7 +83,7 @@ use Exception; $this->bdd->beginTransaction(); $id_received = $this->get_model()->insert($received); - if (!$id_received) + if (!$id_received) { $this->bdd->rollBack(); diff --git a/controllers/internals/StandardController.php b/controllers/internals/StandardController.php index 3d296cc..7018244 100644 --- a/controllers/internals/StandardController.php +++ b/controllers/internals/StandardController.php @@ -77,14 +77,12 @@ namespace controllers\internals; * @param int $id_user : User id * @param ?int $nb_entry : Number of entry to return * @param ?int $page : Pagination, used to calcul offset, $nb_entry * $page - * @param ?int $after_id : If provided use where id > $after_id instead of offset - * @param ?int $before_id : If provided use where id < $before_id instead of offset * * @return array : Entrys list */ - public function list_for_user(int $id_user, ?int $nb_entry = null, ?int $page = null, ?int $after_id = null, ?int $before_id = null) + public function list_for_user(int $id_user, ?int $nb_entry = null, ?int $page = null) { - return $this->get_model()->list_for_user($id_user, $nb_entry, $nb_entry * $page, $after_id, $before_id); + return $this->get_model()->list_for_user($id_user, $nb_entry, $nb_entry * $page); } /** diff --git a/controllers/publics/Api.php b/controllers/publics/Api.php index ae40c7f..6c25da5 100644 --- a/controllers/publics/Api.php +++ b/controllers/publics/Api.php @@ -126,13 +126,10 @@ namespace controllers\publics; * * @param string $entry_type : Type of entries we want to list ['sended', 'received', 'scheduled', 'contact', 'group', 'conditional_group', 'phone', 'phone_group', 'media'] * @param int $page : Pagination number, Default = 0. Group of 25 results. - * @param ?int $after_id : If provided use where id > $after_id instead of offset based on page, more performant - * @param ?int $before_id : If provided use where id < $before_id instead of offset based on page, more performant - * * * @return : List of entries */ - public function get_entries(string $entry_type, int $page = 0, ?int $after_id = null, ?int $before_id = null) + public function get_entries(string $entry_type, int $page = 0) { $entry_types = ['sended', 'received', 'scheduled', 'contact', 'group', 'conditional_group', 'phone', 'phone_group', 'media']; @@ -151,7 +148,7 @@ namespace controllers\publics; $page = (int) $page; $limit = 25; - $entries = $controller->list_for_user($this->user['id'], $limit, $page, $after_id, $before_id); + $entries = $controller->list_for_user($this->user['id'], $limit, $page); //Special case for scheduled, we must add numbers because its a join if ('scheduled' === $entry_type) @@ -224,16 +221,14 @@ namespace controllers\publics; $return = self::DEFAULT_RETURN; $return['response'] = $entries; - if (\count($entries) === $limit || ($entries && $before_id)) + if (\count($entries) === $limit) { - $last_entry = end($entries); - $return['next'] = \descartes\Router::url('Api', __FUNCTION__, ['entry_type' => $entry_type, 'after_id' => $last_entry['id']], ['api_key' => $this->user['api_key']]); + $return['next'] = \descartes\Router::url('Api', __FUNCTION__, ['entry_type' => $entry_type, 'page' => $page + 1], ['api_key' => $this->user['api_key']]); } - if ($page > 0 || ($entries && ($after_id || $before_id))) + if ($page > 0) { - $first_entry = $entries[0]; - $return['prev'] = \descartes\Router::url('Api', __FUNCTION__, ['entry_type' => $entry_type, 'before_id' => $first_entry['id']], ['api_key' => $this->user['api_key']]); + $return['prev'] = \descartes\Router::url('Api', __FUNCTION__, ['entry_type' => $entry_type, 'page' => $page - 1], ['api_key' => $this->user['api_key']]); } $this->auto_http_code(true); diff --git a/models/Call.php b/models/Call.php index 82eab5f..a09395d 100644 --- a/models/Call.php +++ b/models/Call.php @@ -26,13 +26,10 @@ namespace models; * @param int $id_user : user id * @param ?int $limit : Number of entry to return or null * @param ?int $offset : Number of entry to ignore or null - * @param ?int $after_id : If provided use where id > $after_id instead of offset - * @param ?int $before_id : If provided use where id < $before_id instead of offset - * * * @return array */ - public function list_for_user(int $id_user, $limit, $offset, ?int $after_id = null, ?int $before_id = null) + public function list_for_user(int $id_user, $limit, $offset) { $query = ' SELECT `call`.*, contact.name as contact_name, phone.name as phone_name @@ -45,37 +42,6 @@ namespace models; WHERE `call`.id_user = :id_user '; - $params = [ - 'id_user' => $id_user, - ]; - - if ($after_id || $before_id) - { - $offset = null; - } - - if ($after_id) - { - $query .= ' - AND `call`.id > :after_id - ORDER BY `call`.id - '; - $params['after_id'] = $after_id; - } - elseif ($before_id) - { - $query .= ' - AND `call`.id < :before_id - ORDER BY `call`.id DESC - '; - $params['before_id'] = $before_id; - } - else - { - $query .= ' ORDER BY `call`.id'; - } - - if (null !== $limit) { $limit = (int) $limit; @@ -88,10 +54,9 @@ namespace models; } } - if ($before_id) - { - return array_reverse($this->_run_query($query, $params)); - } + $params = [ + 'id_user' => $id_user, + ]; return $this->_run_query($query, $params); } diff --git a/models/Group.php b/models/Group.php index a30a853..d247b93 100644 --- a/models/Group.php +++ b/models/Group.php @@ -20,12 +20,10 @@ namespace models; * @param int $id_user : user id * @param ?int $limit : Number of entry to return or null * @param ?int $offset : Number of entry to ignore or null - * @param ?int $after_id : If provided use where id > $after_id instead of offset - * @param ?int $before_id : If provided use where id < $before_id instead of offset * * @return array */ - public function list_for_user(int $id_user, $limit, $offset, ?int $after_id = null, ?int $before_id = null) + public function list_for_user(int $id_user, $limit, $offset) { $query = ' SELECT g.*, COUNT(gc.id) as nb_contact @@ -33,43 +31,9 @@ namespace models; LEFT JOIN group_contact as gc ON g.id = gc.id_group WHERE id_user = :id_user + GROUP BY g.id '; - $params = [ - 'id_user' => $id_user, - ]; - - if ($after_id || $before_id) - { - $offset = null; - } - - if ($after_id) - { - $query .= ' - AND g.id > :after_id - GROUP BY g.id - ORDER BY g.id - '; - $params['after_id'] = $after_id; - } - elseif ($before_id) - { - $query .= ' - AND g.id < :before_id - GROUP BY g.id - ORDER BY g.id DESC - '; - $params['before_id'] = $before_id; - } - else - { - $query .= ' - GROUP BY g.id - ORDER BY g.id - '; - } - if (null !== $limit) { $limit = (int) $limit; @@ -82,11 +46,10 @@ namespace models; } } - if ($before_id) - { - return array_reverse($this->_run_query($query, $params)); - } - + $params = [ + 'id_user' => $id_user, + ]; + return $this->_run_query($query, $params); } diff --git a/models/PhoneGroup.php b/models/PhoneGroup.php index 3f31d49..0a71a24 100644 --- a/models/PhoneGroup.php +++ b/models/PhoneGroup.php @@ -20,12 +20,10 @@ namespace models; * @param int $id_user : user id * @param ?int $limit : Number of entry to return or null * @param ?int $offset : Number of entry to ignore or null - * @param ?int $after_id : If provided use where id > $after_id instead of offset - * @param ?int $before_id : If provided use where id < $before_id instead of offset * * @return array */ - public function list_for_user(int $id_user, $limit, $offset, ?int $after_id = null, ?int $before_id = null) + public function list_for_user(int $id_user, $limit, $offset) { $query = ' SELECT pg.*, COUNT(pgp.id) as nb_phone @@ -33,43 +31,9 @@ namespace models; LEFT JOIN phone_group_phone as pgp ON pg.id = pgp.id_phone_group WHERE pg.id_user = :id_user + GROUP BY pg.id '; - $params = [ - 'id_user' => $id_user, - ]; - - if ($after_id || $before_id) - { - $offset = null; - } - - if ($after_id) - { - $query .= ' - AND pg.id > :after_id - GROUP BY pg.id - ORDER BY g.id - '; - $params['after_id'] = $after_id; - } - elseif ($before_id) - { - $query .= ' - AND pg.id < :before_id - GROUP BY pg.id - ORDER BY g.id DESC - '; - $params['before_'] = $before_id; - } - else - { - $query .= ' - GROUP BY pg.id - ORDER BY pg.id - '; - } - if (null !== $limit) { $limit = (int) $limit; @@ -82,10 +46,9 @@ namespace models; } } - if ($before_id) - { - return array_reverse($this->_run_query($query, $params)); - } + $params = [ + 'id_user' => $id_user, + ]; return $this->_run_query($query, $params); } diff --git a/models/RedisQueue.php b/models/RedisQueue.php index 8c11833..95ac92d 100644 --- a/models/RedisQueue.php +++ b/models/RedisQueue.php @@ -70,7 +70,7 @@ class RedisQueue implements Queue * * @return mixed $message : The oldest message or null if no message found, can be anything * @param ?string $tag : A tag to associate to the message for routing purposes, if null will read from general queue - * @param mixed : The message return from the queue, can be anything, null if no message found + * @param mixed : The message to add to the queue, can be anything, the queue will have to treat it by itself */ public function read(?string $tag = null) { diff --git a/models/StandardModel.php b/models/StandardModel.php index 99a7c1b..45bf967 100644 --- a/models/StandardModel.php +++ b/models/StandardModel.php @@ -70,22 +70,12 @@ namespace models; * @param int $id_user : user id * @param int $limit : Number of entry to return * @param int $offset : Number of entry to ignore - * @param ?int $after_id : If provided use where id > $after_id instead of offset - * @param ?int $before_id : If provided use where id < $before_id instead of offset * * @return array */ - public function list_for_user(int $id_user, $limit, $offset, ?int $after_id = null, ?int $before_id = null) + public function list_for_user(int $id_user, $limit, $offset) { - if ($after_id !== null) { - return $this->_select($this->get_table_name(), ['id_user' => $id_user, '>id' => $after_id], 'id', false, $limit); - } - - if ($before_id !== null) { - return array_reverse($this->_select($this->get_table_name(), ['id_user' => $id_user, ' $before_id], 'id', true, $limit)); - } - - return $this->_select($this->get_table_name(), ['id_user' => $id_user], 'id', false, $limit, $offset); + return $this->_select($this->get_table_name(), ['id_user' => $id_user], null, false, $limit, $offset); } /** diff --git a/routes.php b/routes.php index 6cfe1ca..bff3f98 100644 --- a/routes.php +++ b/routes.php @@ -214,8 +214,6 @@ 'get_entries' => [ '/api/list/{entry_type}/', '/api/list/{entry_type}/{page}/', - '/api/list/{entry_type}/after/{after_id}/', - '/api/list/{entry_type}/before/{before_id}/', ], 'get_usage' => '/api/usage/', 'get_sms_status_stats' => '/api/stats/sms-status/',