Compare commits

..

No commits in common. "580d9595b34c6893727a125ada01f35116ab8e98" and "04b0f1267a51dd02b257c0d4e4a89140068dcf67" have entirely different histories.

11 changed files with 29 additions and 157 deletions

View file

@ -1 +1 @@
v3.9.2 v3.9.1

View file

@ -66,7 +66,7 @@ class Queue extends \descartes\InternalController
* *
* @return mixed $message : The oldest message or null if no message found, can be anything * @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 ?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) public function read(?string $tag = null)
{ {

View file

@ -77,14 +77,12 @@ namespace controllers\internals;
* @param int $id_user : User id * @param int $id_user : User id
* @param ?int $nb_entry : Number of entry to return * @param ?int $nb_entry : Number of entry to return
* @param ?int $page : Pagination, used to calcul offset, $nb_entry * $page * @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 * @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);
} }
/** /**

View file

@ -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 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 $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 * @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']; $entry_types = ['sended', 'received', 'scheduled', 'contact', 'group', 'conditional_group', 'phone', 'phone_group', 'media'];
@ -151,7 +148,7 @@ namespace controllers\publics;
$page = (int) $page; $page = (int) $page;
$limit = 25; $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 //Special case for scheduled, we must add numbers because its a join
if ('scheduled' === $entry_type) if ('scheduled' === $entry_type)
@ -224,16 +221,14 @@ namespace controllers\publics;
$return = self::DEFAULT_RETURN; $return = self::DEFAULT_RETURN;
$return['response'] = $entries; $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, 'page' => $page + 1], ['api_key' => $this->user['api_key']]);
$return['next'] = \descartes\Router::url('Api', __FUNCTION__, ['entry_type' => $entry_type, 'after_id' => $last_entry['id']], ['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, 'page' => $page - 1], ['api_key' => $this->user['api_key']]);
$return['prev'] = \descartes\Router::url('Api', __FUNCTION__, ['entry_type' => $entry_type, 'before_id' => $first_entry['id']], ['api_key' => $this->user['api_key']]);
} }
$this->auto_http_code(true); $this->auto_http_code(true);

View file

@ -26,13 +26,10 @@ namespace models;
* @param int $id_user : user id * @param int $id_user : user id
* @param ?int $limit : Number of entry to return or null * @param ?int $limit : Number of entry to return or null
* @param ?int $offset : Number of entry to ignore 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 * @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 = ' $query = '
SELECT `call`.*, contact.name as contact_name, phone.name as phone_name SELECT `call`.*, contact.name as contact_name, phone.name as phone_name
@ -45,37 +42,6 @@ namespace models;
WHERE `call`.id_user = :id_user 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) if (null !== $limit)
{ {
$limit = (int) $limit; $limit = (int) $limit;
@ -88,10 +54,9 @@ namespace models;
} }
} }
if ($before_id) $params = [
{ 'id_user' => $id_user,
return array_reverse($this->_run_query($query, $params)); ];
}
return $this->_run_query($query, $params); return $this->_run_query($query, $params);
} }

View file

@ -20,12 +20,10 @@ namespace models;
* @param int $id_user : user id * @param int $id_user : user id
* @param ?int $limit : Number of entry to return or null * @param ?int $limit : Number of entry to return or null
* @param ?int $offset : Number of entry to ignore 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 * @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 = ' $query = '
SELECT g.*, COUNT(gc.id) as nb_contact SELECT g.*, COUNT(gc.id) as nb_contact
@ -33,43 +31,9 @@ namespace models;
LEFT JOIN group_contact as gc LEFT JOIN group_contact as gc
ON g.id = gc.id_group ON g.id = gc.id_group
WHERE id_user = :id_user 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) if (null !== $limit)
{ {
$limit = (int) $limit; $limit = (int) $limit;
@ -82,10 +46,9 @@ namespace models;
} }
} }
if ($before_id) $params = [
{ 'id_user' => $id_user,
return array_reverse($this->_run_query($query, $params)); ];
}
return $this->_run_query($query, $params); return $this->_run_query($query, $params);
} }

View file

@ -20,12 +20,10 @@ namespace models;
* @param int $id_user : user id * @param int $id_user : user id
* @param ?int $limit : Number of entry to return or null * @param ?int $limit : Number of entry to return or null
* @param ?int $offset : Number of entry to ignore 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 * @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 = ' $query = '
SELECT pg.*, COUNT(pgp.id) as nb_phone SELECT pg.*, COUNT(pgp.id) as nb_phone
@ -33,43 +31,9 @@ namespace models;
LEFT JOIN phone_group_phone as pgp LEFT JOIN phone_group_phone as pgp
ON pg.id = pgp.id_phone_group ON pg.id = pgp.id_phone_group
WHERE pg.id_user = :id_user 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) if (null !== $limit)
{ {
$limit = (int) $limit; $limit = (int) $limit;
@ -82,10 +46,9 @@ namespace models;
} }
} }
if ($before_id) $params = [
{ 'id_user' => $id_user,
return array_reverse($this->_run_query($query, $params)); ];
}
return $this->_run_query($query, $params); return $this->_run_query($query, $params);
} }

View file

@ -70,7 +70,7 @@ class RedisQueue implements Queue
* *
* @return mixed $message : The oldest message or null if no message found, can be anything * @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 ?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) public function read(?string $tag = null)
{ {

View file

@ -70,22 +70,12 @@ namespace models;
* @param int $id_user : user id * @param int $id_user : user id
* @param int $limit : Number of entry to return * @param int $limit : Number of entry to return
* @param int $offset : Number of entry to ignore * @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 * @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], null, false, $limit, $offset);
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, '<id' => $before_id], 'id', true, $limit));
}
return $this->_select($this->get_table_name(), ['id_user' => $id_user], 'id', false, $limit, $offset);
} }
/** /**

View file

@ -214,8 +214,6 @@
'get_entries' => [ 'get_entries' => [
'/api/list/{entry_type}/', '/api/list/{entry_type}/',
'/api/list/{entry_type}/{page}/', '/api/list/{entry_type}/{page}/',
'/api/list/{entry_type}/after/{after_id}/',
'/api/list/{entry_type}/before/{before_id}/',
], ],
'get_usage' => '/api/usage/', 'get_usage' => '/api/usage/',
'get_sms_status_stats' => '/api/stats/sms-status/', 'get_sms_status_stats' => '/api/stats/sms-status/',