diff --git a/VERSION b/VERSION index 6d260c3..ecbc73c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.2.0 +v3.1.13 diff --git a/controllers/internals/Sended.php b/controllers/internals/Sended.php index a492aac..504cece 100644 --- a/controllers/internals/Sended.php +++ b/controllers/internals/Sended.php @@ -45,12 +45,11 @@ namespace controllers\internals; * @param bool $flash : Is the sms a flash * @param bool $mms : Is the sms a MMS. By default false. * @param array $medias : Array of medias to link to the MMS - * @param ?int $originating_scheduled : Id of the scheduled message that was responsible for sending this message. By default null. * @param string $status : Status of a the sms. By default \models\Sended::STATUS_UNKNOWN * * @return mixed : false on error, new sended id else */ - public function create(int $id_user, int $id_phone, $at, string $text, string $destination, string $uid, string $adapter, bool $flash = false, bool $mms = false, array $medias = [], ?int $originating_scheduled = null, ?string $status = \models\Sended::STATUS_UNKNOWN) + public function create(int $id_user, int $id_phone, $at, string $text, string $destination, string $uid, string $adapter, bool $flash = false, bool $mms = false, array $medias = [], ?string $status = \models\Sended::STATUS_UNKNOWN) { $sended = [ 'id_user' => $id_user, @@ -63,7 +62,6 @@ namespace controllers\internals; 'flash' => $flash, 'mms' => $mms, 'status' => $status, - 'originating_scheduled' => $originating_scheduled, ]; //Ensure atomicity @@ -107,22 +105,24 @@ namespace controllers\internals; 'status' => $status, ]; - $success = (bool) $this->get_model()->update_for_user($id_user, $id_sended, $sended); + return (bool) $this->get_model()->update_for_user($id_user, $id_sended, $sended); + } - if (!$success) - { - return $success; - } - - $webhook = [ - 'id' => $id_sended, + /** + * Update a sended status for a sended. + * + * @param int $id_sended : Sended id + * @param string $status : Status of a the sms (unknown, delivered, failed) + * + * @return bool : false on error, true on success + */ + public function update_status(int $id_sended, string $status): bool + { + $sended = [ 'status' => $status, ]; - $internal_webhook = new Webhook($this->bdd); - $internal_webhook->trigger($id_user, \models\Webhook::TYPE_SEND_SMS_STATUS_CHANGE, $webhook); - - return $success; + return (bool) $this->get_model()->update($id_sended, $sended); } /** @@ -231,7 +231,7 @@ namespace controllers\internals; * ?string 'error_message' => null if success, error message else * ] */ - public function send(\adapters\AdapterInterface $adapter, int $id_user, int $id_phone, string $text, string $destination, bool $flash = false, bool $mms = false, array $medias = [], $originating_scheduled = null, string $status = \models\Sended::STATUS_UNKNOWN): array + public function send(\adapters\AdapterInterface $adapter, int $id_user, int $id_phone, string $text, string $destination, bool $flash = false, bool $mms = false, array $medias = [], string $status = \models\Sended::STATUS_UNKNOWN): array { $return = [ 'error' => false, @@ -278,40 +278,23 @@ namespace controllers\internals; $return['error'] = true; $return['error_message'] = $response['error_message']; $status = \models\Sended::STATUS_FAILED; - $sended_id = $this->create($id_user, $id_phone, $at, $text, $destination, $response['uid'] ?? uniqid(), $adapter->meta_classname(), $flash, $mms, $medias, $originating_scheduled, $status); - - $sended = [ - 'id' => $sended_id, - 'at' => $at, - 'status' => $status, - 'text' => $text, - 'destination' => $destination, - 'origin' => $id_phone, - 'mms' => $mms, - 'medias' => $medias, - 'originating_scheduled' => $originating_scheduled, - ]; - - $internal_webhook = new Webhook($this->bdd); - $internal_webhook->trigger($id_user, \models\Webhook::TYPE_SEND_SMS, $sended); + $this->create($id_user, $id_phone, $at, $text, $destination, $response['uid'] ?? uniqid(), $adapter->meta_classname(), $flash, $mms, $medias, $status); return $return; } $internal_quota->consume_credit($id_user, $nb_credits); - $sended_id = $this->create($id_user, $id_phone, $at, $text, $destination, $response['uid'] ?? uniqid(), $adapter->meta_classname(), $flash, $mms, $medias, $originating_scheduled, $status); + $sended_id = $this->create($id_user, $id_phone, $at, $text, $destination, $response['uid'] ?? uniqid(), $adapter->meta_classname(), $flash, $mms, $medias, $status); $sended = [ 'id' => $sended_id, 'at' => $at, - 'status' => $status, 'text' => $text, 'destination' => $destination, 'origin' => $id_phone, 'mms' => $mms, 'medias' => $medias, - 'originating_scheduled' => $originating_scheduled, ]; $internal_webhook = new Webhook($this->bdd); diff --git a/daemons/Phone.php b/daemons/Phone.php index 1be7856..48b99e9 100644 --- a/daemons/Phone.php +++ b/daemons/Phone.php @@ -139,14 +139,14 @@ class Phone extends AbstractDaemon //Do message sending $this->logger->info('Try send message : ' . json_encode($message)); - $response = $internal_sended->send($this->adapter, $this->phone['id_user'], $this->phone['id'], $message['text'], $message['destination'], $message['flash'], $message['mms'], $message['medias'], $message['id_scheduled']); + $response = $internal_sended->send($this->adapter, $this->phone['id_user'], $this->phone['id'], $message['text'], $message['destination'], $message['flash'], $message['mms'], $message['medias']); if ($response['error']) { $this->logger->error('Failed send message : ' . json_encode($message) . ' with error : ' . $response['error_message']); continue; } - + $this->logger->info('Successfully send message : ' . json_encode($message)); } } diff --git a/db/migrations/20211017231147_add_scheduled_id_to_sended.php b/db/migrations/20211017231147_add_scheduled_id_to_sended.php deleted file mode 100644 index bc7f95a..0000000 --- a/db/migrations/20211017231147_add_scheduled_id_to_sended.php +++ /dev/null @@ -1,42 +0,0 @@ -table('sended'); - $table->addColumn('originating_scheduled', 'integer', [ - 'null' => true, - 'comment' => 'Id of the scheduled that was responsible for sending this message.', - 'after' => 'mms' - ]) - ->update(); - } -} diff --git a/db/migrations/20211018002819_add_webhook_type_send_sms_status_change.php b/db/migrations/20211018002819_add_webhook_type_send_sms_status_change.php deleted file mode 100644 index 9289ec8..0000000 --- a/db/migrations/20211018002819_add_webhook_type_send_sms_status_change.php +++ /dev/null @@ -1,16 +0,0 @@ -execute('ALTER TABLE `webhook` MODIFY `type` ENUM(\'send_sms\', \'send_sms_status_change\', \'receive_sms\', \'inbound_call\')'); - } - - public function down() - { - $this->execute('ALTER TABLE `webhook` MODIFY `type` ENUM(\'send_sms\', \'receive_sms\', \'inbound_call\')'); - } -} diff --git a/models/Webhook.php b/models/Webhook.php index f963df9..f55bf85 100644 --- a/models/Webhook.php +++ b/models/Webhook.php @@ -14,7 +14,6 @@ namespace models; class Webhook extends StandardModel { const TYPE_SEND_SMS = 'send_sms'; - const TYPE_SEND_SMS_STATUS_CHANGE = 'send_sms_status_change'; const TYPE_RECEIVE_SMS = 'receive_sms'; const TYPE_INBOUND_CALL = 'inbound_call'; const TYPE_QUOTA_LEVEL_ALERT = 'quota_level'; diff --git a/templates/contact/list.php b/templates/contact/list.php index 741df56..2284706 100644 --- a/templates/contact/list.php +++ b/templates/contact/list.php @@ -182,7 +182,7 @@ jQuery(document).ready(function() //Datatable jQuery('.datatable').DataTable({ "pageLength": 25, - "lengthMenu": [[25, 50, 100, 1000, 10000, Math.pow(10, 10)], [25, 50, 100, 1000, 10000, "All"]], + "lengthMenu": [[25, 50, 100, 1000, 10000, -1], [25, 50, 100, 1000, 10000, "All"]], "language": { "url": HTTP_PWD + "/assets/js/datatables/french.json", }, diff --git a/templates/event/list.php b/templates/event/list.php index 72de9f4..93d24c3 100644 --- a/templates/event/list.php +++ b/templates/event/list.php @@ -71,7 +71,7 @@ jQuery(document).ready(function () { jQuery('.datatable').DataTable({ "pageLength": 25, - "lengthMenu": [[25, 50, 100, 1000, 10000, Math.pow(10, 10)], [25, 50, 100, 1000, 10000, "All"]], + "lengthMenu": [[25, 50, 100, 1000, 10000, -1], [25, 50, 100, 1000, 10000, "All"]], "language": { "url": HTTP_PWD + "/assets/js/datatables/french.json", }, diff --git a/templates/received/list.php b/templates/received/list.php index 1024d12..a4c44e1 100644 --- a/templates/received/list.php +++ b/templates/received/list.php @@ -79,7 +79,7 @@ jQuery(document).ready(function () { jQuery('.datatable').DataTable({ "pageLength": 25, - "lengthMenu": [[25, 50, 100, 1000, 10000, Math.pow(10, 10)], [25, 50, 100, 1000, 10000, "All"]], + "lengthMenu": [[25, 50, 100, 1000, 10000, -1], [25, 50, 100, 1000, 10000, "All"]], "language": { "url": HTTP_PWD + "/assets/js/datatables/french.json", }, diff --git a/templates/sended/list.php b/templates/sended/list.php index 7f1ada0..d439af7 100644 --- a/templates/sended/list.php +++ b/templates/sended/list.php @@ -69,7 +69,7 @@ jQuery(document).ready(function () { jQuery('.datatable').DataTable({ "pageLength": 25, - "lengthMenu": [[25, 50, 100, 1000, 10000, Math.pow(10, 10)], [25, 50, 100, 1000, 10000, "All"]], + "lengthMenu": [[25, 50, 100, 1000, 10000, -1], [25, 50, 100, 1000, 10000]], "language": { "url": HTTP_PWD + "/assets/js/datatables/french.json", }, diff --git a/templates/webhook/add.php b/templates/webhook/add.php index e0ab6d5..6e53c43 100644 --- a/templates/webhook/add.php +++ b/templates/webhook/add.php @@ -47,7 +47,6 @@ diff --git a/templates/webhook/edit.php b/templates/webhook/edit.php index e297923..7808faf 100644 --- a/templates/webhook/edit.php +++ b/templates/webhook/edit.php @@ -50,8 +50,6 @@
diff --git a/templates/webhook/list.php b/templates/webhook/list.php index 05a66d9..c1e2e0f 100644 --- a/templates/webhook/list.php +++ b/templates/webhook/list.php @@ -90,8 +90,6 @@ jQuery(document).ready(function () switch (data) { case 'send_sms': return 'Envoi de SMS'; - case 'send_sms_status_change': - return 'Mise à jour du statut d\'un SMS envoyé'; case 'receive_sms': return 'Réception de SMS'; case 'inbound_call':