Ajout de la gestion des failed et des accusés de reception sur les messages de plus de 160 caractères
This commit is contained in:
parent
c8ffb73247
commit
1e001d3079
|
@ -85,7 +85,7 @@
|
||||||
'date' => htmlspecialchars($sended['at']),
|
'date' => htmlspecialchars($sended['at']),
|
||||||
'text' => htmlspecialchars($sended['content']),
|
'text' => htmlspecialchars($sended['content']),
|
||||||
'type' => 'sended',
|
'type' => 'sended',
|
||||||
'delivered' => ($sended['delivered'] ? true : false),
|
'status' => ($sended['delivered'] ? 'delivered' : ($sended['failed'] ? 'failed' : '')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -156,11 +156,13 @@
|
||||||
//Pour plus de précision, on remet la date à jour en réinstanciant l'objet DateTime (et on reformatte la date, bien entendu)
|
//Pour plus de précision, on remet la date à jour en réinstanciant l'objet DateTime (et on reformatte la date, bien entendu)
|
||||||
$now = new DateTime();
|
$now = new DateTime();
|
||||||
$now = $now->format('Y-m-d H:i:s');
|
$now = $now->format('Y-m-d H:i:s');
|
||||||
|
|
||||||
//On peut maintenant ajouter le SMS
|
//On peut maintenant ajouter le SMS
|
||||||
if (!$db->insertIntoTable('sendeds', ['at' => $now, 'target' => $number, 'content' => $scheduled['content']]))
|
if (!$db->insertIntoTable('sendeds', ['at' => $now, 'target' => $number, 'content' => $scheduled['content'], 'before_delivered' => ceil(mb_strlen($scheduled['content'])/160)]))
|
||||||
{
|
{
|
||||||
echo 'Impossible d\'inserer le sms pour le numero ' . $number . "\n";
|
echo 'Impossible d\'inserer le sms pour le numero ' . $number . "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$id_sended = $db->lastId();
|
$id_sended = $db->lastId();
|
||||||
|
|
||||||
//Commande qui envoie le SMS
|
//Commande qui envoie le SMS
|
||||||
|
@ -246,23 +248,42 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
//On gère les accusés de reception
|
//On gère les accusés de reception
|
||||||
if (trim($text) == 'Delivered')
|
if (trim($text) == 'Delivered' || trim($text) == 'Failed')
|
||||||
{
|
{
|
||||||
echo 'Delivered SMS for ' . $number . "\n";
|
echo 'Delivered or Failed SMS for ' . $number . "\n";
|
||||||
$this->wlog('Delivered SMS for ' . $number);
|
$this->wlog('Delivered or Failed SMS for ' . $number);
|
||||||
|
|
||||||
//On récupère les SMS par encore validé, uniquement sur les dernières 24h
|
//On récupère les SMS pas encore validé, uniquement sur les dernières 12h
|
||||||
$now = new DateTime();
|
$now = new DateTime();
|
||||||
$interval = new DateInterval('P1D');
|
$interval = new DateInterval('P12H');
|
||||||
$sinceDate = $now->sub($interval)->format('Y-m-d H:i:s');
|
$sinceDate = $now->sub($interval)->format('Y-m-d H:i:s');
|
||||||
|
|
||||||
if (!$sendeds = $db->getFromTableWhere('sendeds', ['target' => $number, 'delivered' => false, '>at' => $sinceDate], 'at', false, 1))
|
if (!$sendeds = $db->getFromTableWhere('sendeds', ['target' => $number, 'delivered' => false, 'failed' => false, '>at' => $sinceDate], 'at', false, 1))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$db->updateTableWhere('sendeds', ['delivered' => true], ['id' => $sendeds[0]['id']]);
|
$sended = $sendeds[0];
|
||||||
echo "Sended SMS id " . $sendeds[0]['id'] . " to delivered status\n";
|
|
||||||
|
//On gère les echecs
|
||||||
|
if (trim($text) == 'Failed')
|
||||||
|
{
|
||||||
|
$db->updateTableWhere('sendeds', ['before_delivered' => 0, 'failed' => true], ['id' => $sended['id']]);
|
||||||
|
echo "Sended SMS id " . $sended['id'] . " pass to failed status\n";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//On gère le cas des messages de plus de 160 caractères, lesquels impliquent plusieurs accusés
|
||||||
|
if ($sended['before_delivered'] > 1)
|
||||||
|
{
|
||||||
|
$db->updateTableWhere('sendeds', ['before_delivered' => $sended['before_delivered'] - 1], ['id' => $sended['id']]);
|
||||||
|
echo "Sended SMS id " . $sended['id'] . " before_delivered decrement\n";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Si tout est bon, que nous avons assez d'accusés, nous validons !
|
||||||
|
$db->updateTableWhere('sendeds', ['before_delivered' => 0, 'delivered' => true], ['id' => $sended['id']]);
|
||||||
|
echo "Sended SMS id " . $sended['id'] . " to delivered status\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,9 @@ CREATE TABLE IF NOT EXISTS sendeds
|
||||||
at DATETIME NOT NULL,
|
at DATETIME NOT NULL,
|
||||||
target VARCHAR(12) NOT NULL,
|
target VARCHAR(12) NOT NULL,
|
||||||
content VARCHAR(1000) NOT NULL,
|
content VARCHAR(1000) NOT NULL,
|
||||||
|
before_delivered INT NOT NULL,
|
||||||
delivered BOOLEAN NOT NULL DEFAULT FALSE,
|
delivered BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
failed BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
PRIMARY KEY (id)
|
PRIMARY KEY (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@
|
||||||
'<div class="clearfix message-container">' +
|
'<div class="clearfix message-container">' +
|
||||||
'<div class="discussion-message message-sended">' +
|
'<div class="discussion-message message-sended">' +
|
||||||
'<div class="discussion-message-text">' + message.text + '</div>' +
|
'<div class="discussion-message-text">' + message.text + '</div>' +
|
||||||
'<div class="discussion-message-date">' + message.date + (message.delivered ? ' <span class="fa fa-check-circle fa-fw text-success"></span>' : '' ) + '</div>' +
|
'<div class="discussion-message-date">' + message.date + (message.status ? (message.status == 'delivered' ? ' <span class="fa fa-check-circle fa-fw text-success"></span>' : '<span class="fa fa-times-circle fa-fw text-danger"></span>' ) : '' ) + '</div>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
'</div>';
|
'</div>';
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue