Skip to content

Commit 49fe5e0

Browse files
committed
introducing import from log
1 parent 193aa44 commit 49fe5e0

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

utils/importFromLog.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
require __DIR__ . '/../vendor/autoload.php';
3+
4+
$filename='logfile.log';
5+
$API_KEY = 'random';
6+
$BOT_NAME = 'bot_name';
7+
8+
define('PHPUNIT_TESTSUITE', 'some value');
9+
10+
$CREDENTIALS = array('host'=>'localhost', 'user'=>'', 'password'=>'', 'database'=>'');
11+
12+
$update = null;
13+
try {
14+
// Create Telegram API object
15+
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
16+
$telegram->enableMySQL($CREDENTIALS);
17+
foreach (new SplFileObject($filename) as $current_line) {
18+
$json_decoded = json_decode($update, true);
19+
if (!is_null($json_decoded)) {
20+
echo $update . "\n\n";
21+
$update = null;
22+
if (empty($json_decoded)) {
23+
echo "Empty update: \n";
24+
echo $update . "\n\n";
25+
continue;
26+
}
27+
$telegram->processUpdate(new Longman\TelegramBot\Entities\Update($json_decoded, $BOT_NAME));
28+
}
29+
$update .= $current_line;
30+
}
31+
32+
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
33+
// log telegram errors
34+
echo $e;
35+
}

0 commit comments

Comments
 (0)