Add a test adapter and add deletion of sendeds scheduled sms
This commit is contained in:
parent
99cdf6516a
commit
9eb701ba98
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
namespace adapters;
|
||||
|
||||
/**
|
||||
* Interface for phones adapters
|
||||
* Phone's adapters allow RaspiSMS to use a platform to communicate with a phone number.
|
||||
* Its an adapter between internal and external code, as an API, command line software, physical modem, etc.
|
||||
*
|
||||
* All Phone Adapters must implement this interface
|
||||
*/
|
||||
class TestAdapter implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* Classname of the adapter
|
||||
*/
|
||||
public static function meta_classname() : string { return __CLASS__; }
|
||||
|
||||
/**
|
||||
* Name of the adapter.
|
||||
* It should probably be the name of the service it adapt (e.g : Gammu SMSD, OVH SMS, SIM800L, etc.)
|
||||
*/
|
||||
public static function meta_name() : string { return 'Test'; }
|
||||
|
||||
/**
|
||||
* Description of the adapter.
|
||||
* A short description of the service the adapter implements.
|
||||
*/
|
||||
public static function meta_description() : string { return 'A test adaptater that do not actually send or receive any message.'; }
|
||||
|
||||
/**
|
||||
* Description of the datas expected by the adapter to help the user. (e.g : A list of expecteds Api credentials fields, with name and value)
|
||||
*/
|
||||
public static function meta_datas_help() : string { return 'No datas.'; }
|
||||
|
||||
/**
|
||||
* Does the implemented service support flash smss
|
||||
*/
|
||||
public static function meta_support_flash() : bool { return true ; }
|
||||
|
||||
|
||||
/**
|
||||
* Phone number using the adapter
|
||||
*/
|
||||
private $number;
|
||||
|
||||
/**
|
||||
* Datas used to configure interaction with the implemented service. (e.g : Api credentials, ports numbers, etc.).
|
||||
*/
|
||||
private $datas;
|
||||
|
||||
|
||||
/**
|
||||
* Adapter constructor, called when instanciated by RaspiSMS
|
||||
* @param string $number : Phone number the adapter is used for
|
||||
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
|
||||
*/
|
||||
public function __construct (string $number, string $datas)
|
||||
{
|
||||
$this->number = $number;
|
||||
$this->datas = $datas;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method called to send a SMS to a number
|
||||
* @param string $destination : Phone number to send the sms to
|
||||
* @param string $text : Text of the SMS to send
|
||||
* @param bool $flash : Is the SMS a Flash SMS
|
||||
* @return bool : True if send, False else
|
||||
*/
|
||||
public function send (string $destination, string $text, boolean $flash) : boolean
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method called to read SMSs of the number
|
||||
* @param float $since : Unix microtime representation of the date from wich we want to read the SMSs
|
||||
* @return array : Array of the sms reads
|
||||
*/
|
||||
public function read (float $since) : array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
|
@ -217,7 +217,7 @@ namespace controllers\internals;
|
|||
|
||||
/**
|
||||
* Get all messages to send and the number to use to send theme
|
||||
* @return array : [['text', 'origin', 'destination', 'flash'], ...]
|
||||
* @return array : [['id_scheduled', 'text', 'origin', 'destination', 'flash'], ...]
|
||||
*/
|
||||
public function get_smss_to_send ()
|
||||
{
|
||||
|
@ -266,6 +266,7 @@ namespace controllers\internals;
|
|||
foreach ($numbers as $number)
|
||||
{
|
||||
$message = [
|
||||
'id_scheduled' => $scheduled['id'],
|
||||
'origin' => $scheduled['origin'],
|
||||
'destination' => $number['number'],
|
||||
'flash' => $scheduled['flash'],
|
||||
|
@ -326,6 +327,7 @@ namespace controllers\internals;
|
|||
$added_contacts[$contact['id']] = true;
|
||||
|
||||
$message = [
|
||||
'id_scheduled' => $scheduled['id'],
|
||||
'origin' => $scheduled['origin'],
|
||||
'destination' => $number['number'],
|
||||
'flash' => $scheduled['flash'],
|
||||
|
@ -373,8 +375,8 @@ namespace controllers\internals;
|
|||
|
||||
return $smss_to_send;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return numbers for a scheduled message
|
||||
|
|
|
@ -32,10 +32,10 @@ namespace controllers\internals;
|
|||
* @param string $origin : Number of the sender
|
||||
* @param string $destination : Number of the receiver
|
||||
* @param bool $flash : Is the sms a flash
|
||||
* @param ?string $status : Status of a the sms. By default null -> unknown
|
||||
* @param string $status : Status of a the sms. By default 'unknown'
|
||||
* @return bool : false on error, new sended id else
|
||||
*/
|
||||
public function create ($at, string $text, string $origin, string $destination, bool $flash = false, ?string $status = null) : bool
|
||||
public function create ($at, string $text, string $origin, string $destination, bool $flash = false, ?string $status = 'unknown') : bool
|
||||
{
|
||||
$sended = [
|
||||
'at' => $at,
|
||||
|
|
|
@ -93,6 +93,17 @@ namespace controllers\internals;
|
|||
{
|
||||
return $this->get_model()->delete_for_user($id_user, $id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a entry by his id
|
||||
* @param int $id : Entry id
|
||||
* @return int : Number of removed rows
|
||||
*/
|
||||
public function delete (int $id)
|
||||
{
|
||||
return $this->get_model()->delete($id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -234,7 +234,7 @@ namespace controllers\publics;
|
|||
$id_user = $_SESSION['user']['id'];
|
||||
$at = $_POST['at'] ?? false;
|
||||
$text = $_POST['text'] ?? false;
|
||||
$flash = $_POST['flash'] ?? false;
|
||||
$flash = (bool) ($_POST['flash'] ?? false);
|
||||
$origin = empty($_POST['origin']) ? null : $_POST['origin'];
|
||||
$numbers = $_POST['numbers'] ?? [];
|
||||
$contacts = $_POST['contacts'] ?? [];
|
||||
|
@ -337,7 +337,7 @@ namespace controllers\publics;
|
|||
$at = $scheduled['at'] ?? false;
|
||||
$text = $scheduled['text'] ?? false;
|
||||
$origin = empty($scheduled['origin']) ? null : $scheduled['origin'];
|
||||
$flash = $scheduled['flash'] ?? false;
|
||||
$flash = (bool) ($scheduled['flash'] ?? false);
|
||||
$numbers = $scheduled['numbers'] ?? [];
|
||||
$contacts = $scheduled['contacts'] ?? [];
|
||||
$groups = $scheduled['groups'] ?? [];
|
||||
|
|
|
@ -52,11 +52,23 @@ class Phone extends AbstractDaemon
|
|||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, 'UTF8');
|
||||
$internal_sended = new \controllers\internals\Sended($bdd);
|
||||
|
||||
//If message received, update last message time
|
||||
$this->last_message_at = microtime(true);
|
||||
|
||||
$this->logger->debug(json_encode($message));
|
||||
//Register message as sended
|
||||
$now = new \DateTime();
|
||||
$now = $now->format('Y-m-d H:i:s');
|
||||
$internal_sended->create($now, $message['text'], $message['origin'], $message['destination'], $message['flash']);
|
||||
|
||||
//Close bdd
|
||||
$bdd = null;
|
||||
$internal_sended = null;
|
||||
|
||||
$this->logger->info('Send message : ' . json_encode($message));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -52,10 +52,8 @@ class Server extends AbstractDaemon
|
|||
continue;
|
||||
}
|
||||
|
||||
exec('php ' . PWD . '/console.php controllers/internals/Console.php phone number=\'' . $phone['number'] . '\' > /dev/null &');
|
||||
$this->logger->info('Command : ' . 'php ' . PWD . '/console.php controllers/internals/Console.php phone number=\'' . $phone['number'] . '\' > /dev/null &');
|
||||
//Create a new daemon for the phone
|
||||
//$phone = new \daemons\Phone($phone);
|
||||
exec('php ' . PWD . '/console.php controllers/internals/Console.php phone number=\'' . $phone['number'] . '\' > /dev/null &');
|
||||
}
|
||||
|
||||
$queues = [];
|
||||
|
@ -85,8 +83,10 @@ class Server extends AbstractDaemon
|
|||
];
|
||||
|
||||
msg_send($queue, SEND_MSG, $msg);
|
||||
}
|
||||
|
||||
//Delete the scheduled sms after sending
|
||||
$this->internal_scheduled->delete($sms['id_scheduled']);
|
||||
}
|
||||
|
||||
sleep(0.5);
|
||||
}
|
||||
|
|
|
@ -121,6 +121,17 @@ namespace models;
|
|||
{
|
||||
return $this->_delete($this->get_table_name(), ['id_user' => $id_user, 'id' => $id]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a entry by his id
|
||||
* @param int $id : Entry id
|
||||
* @return int : Number of removed rows
|
||||
*/
|
||||
public function delete(int $id)
|
||||
{
|
||||
return $this->_delete($this->get_table_name(), ['id' => $id]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue