Skip to content

Commit b68bd13

Browse files
committed
store outgoing messages in 'sms77_message' table
1 parent 273de43 commit b68bd13

File tree

5 files changed

+248
-2
lines changed

5 files changed

+248
-2
lines changed

TableWrapper.php

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* NOTICE OF LICENSE
4+
*
5+
* This file is licenced under the Software License Agreement.
6+
* With the purchase or the installation of the software in your application
7+
* you accept the licence agreement.
8+
*
9+
* You must not modify, adapt or create derivative works of this source code
10+
*
11+
* @author sms77.io
12+
* @copyright 2019-present sms77 e.K.
13+
* @license LICENSE
14+
*/
15+
16+
class TableWrapper
17+
{
18+
const NAME = 'sms77_message';
19+
20+
static function execute($sql) {
21+
Db::getInstance()->execute($sql);
22+
}
23+
24+
static function create() {
25+
self::execute('
26+
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . self::NAME . '` (
27+
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
28+
`timestamp` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
29+
`response` TEXT NOT NULL,
30+
PRIMARY KEY (`id`),
31+
UNIQUE `SMS77_ID` (`sms77_id`)
32+
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;
33+
');
34+
}
35+
36+
static function drop() {
37+
self::execute('DROP TABLE `' . _DB_PREFIX_ . self::NAME . '`;');
38+
}
39+
40+
static function insert($data = []) {
41+
foreach ($data as $k => $v) {
42+
$data[$k] = Db::getInstance()->escape($v);
43+
}
44+
45+
Db::getInstance()->insert(self::NAME, $data, true);
46+
}
47+
}

Util.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ static function validateAndSend($msg, $number)
6363
}
6464
}
6565

66-
(new Client($apiKey, 'prestashop'))->sms($number, $msg, [
66+
$res = (new Client($apiKey, 'prestashop'))->sms($number, $msg, [
6767
'from' => Configuration::get(Constants::FROM),
68+
'json' => true,
6869
]);
70+
71+
TableWrapper::insert(['response' => json_decode($res)]);
6972
}
7073

7174
static function addWhereIfSet($where, $key, $field, $config) {

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"require": {
2525
"php": ">=5.6.0",
2626
"sms77/api": "1.1.0",
27-
"giggsey/libphonenumber-for-php": "8.12.1"
27+
"giggsey/libphonenumber-for-php": "8.12.1",
28+
"ext-json": "*"
2829
},
2930
"support": {
3031
"email": "[email protected]",

composer.lock

+190
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sms77.php

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
require_once dirname(__FILE__) . "/Form.php";
2020
require_once dirname(__FILE__) . "/Personalizer.php";
2121
require_once dirname(__FILE__) . "/Util.php";
22+
require_once dirname(__FILE__) . "/TableWrapper.php";
2223

2324
/**
2425
* @property PhoneNumberUtil phoneNumberUtil
@@ -105,6 +106,8 @@ public function hookActionOrderStatusPostUpdate(array $data)
105106

106107
public function install()
107108
{
109+
TableWrapper::create();
110+
108111
if (Shop::isFeatureActive()) {
109112
Shop::setContext(Shop::CONTEXT_ALL);
110113
}
@@ -121,6 +124,8 @@ public function install()
121124

122125
public function uninstall()
123126
{
127+
TableWrapper::drop();
128+
124129
foreach (array_keys($this->config) as $k) {
125130
Configuration::deleteByName($k);
126131
}

0 commit comments

Comments
 (0)