Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
TelegramBot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
TelegramBot
Commits
e9be41ef
Unverified
Commit
e9be41ef
authored
Aug 27, 2016
by
Armando Lüscher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Various little code and comment updates.
parent
f1909df0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
18 deletions
+19
-18
DB.php
src/DB.php
+19
-18
No files found.
src/DB.php
View file @
e9be41ef
...
@@ -105,9 +105,12 @@ class DB
...
@@ -105,9 +105,12 @@ class DB
* @return PDO PDO database object
* @return PDO PDO database object
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
static
function
externalInitialize
(
$external_pdo_connection
,
Telegram
$telegram
,
$table_prefix
=
null
)
public
static
function
externalInitialize
(
{
$external_pdo_connection
,
if
(
empty
(
$external_pdo_connection
))
{
Telegram
$telegram
,
$table_prefix
=
null
)
{
if
(
$external_pdo_connection
===
null
)
{
throw
new
TelegramException
(
'MySQL external connection not provided!'
);
throw
new
TelegramException
(
'MySQL external connection not provided!'
);
}
}
...
@@ -122,7 +125,7 @@ class DB
...
@@ -122,7 +125,7 @@ class DB
}
}
/**
/**
* Define all the table with the proper prefix
* Define all the table
s
with the proper prefix
*/
*/
protected
static
function
defineTables
()
protected
static
function
defineTables
()
{
{
...
@@ -152,11 +155,7 @@ class DB
...
@@ -152,11 +155,7 @@ class DB
*/
*/
public
static
function
isDbConnected
()
public
static
function
isDbConnected
()
{
{
if
(
empty
(
self
::
$pdo
))
{
return
self
::
$pdo
!==
null
;
return
false
;
}
else
{
return
true
;
}
}
}
/**
/**
...
@@ -185,10 +184,10 @@ class DB
...
@@ -185,10 +184,10 @@ class DB
}
}
$sth
=
self
::
$pdo
->
prepare
(
$sql
);
$sth
=
self
::
$pdo
->
prepare
(
$sql
);
$sth
->
bindParam
(
':limit'
,
$limit
,
\
PDO
::
PARAM_INT
);
$sth
->
bindParam
(
':limit'
,
$limit
,
PDO
::
PARAM_INT
);
$sth
->
execute
();
$sth
->
execute
();
return
$sth
->
fetchAll
(
\
PDO
::
FETCH_ASSOC
);
return
$sth
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
}
catch
(
PDOException
$e
)
{
}
catch
(
PDOException
$e
)
{
throw
new
TelegramException
(
$e
->
getMessage
());
throw
new
TelegramException
(
$e
->
getMessage
());
}
}
...
@@ -249,6 +248,8 @@ class DB
...
@@ -249,6 +248,8 @@ class DB
/**
/**
* Convert array of Entity items to a JSON array
* Convert array of Entity items to a JSON array
*
*
* @todo Find a better way, as json_* functions are very heavy
*
* @param array $entities
* @param array $entities
* @param mixed $default
* @param mixed $default
*
*
...
@@ -631,8 +632,8 @@ class DB
...
@@ -631,8 +632,8 @@ class DB
}
}
try
{
try
{
$sth
=
self
::
$pdo
->
prepare
(
$sth
=
self
::
$pdo
->
prepare
(
'
'
INSERT IGNORE INTO `'
.
TB_CALLBACK_QUERY
.
'`
INSERT IGNORE INTO `'
.
TB_CALLBACK_QUERY
.
'`
(`id`, `user_id`, `chat_id`, `message_id`, `inline_message_id`, `data`, `created_at`)
(`id`, `user_id`, `chat_id`, `message_id`, `inline_message_id`, `data`, `created_at`)
VALUES
VALUES
(:callback_query_id, :user_id, :chat_id, :message_id, :inline_message_id, :data, :created_at)
(:callback_query_id, :user_id, :chat_id, :message_id, :inline_message_id, :data, :created_at)
...
@@ -736,11 +737,11 @@ class DB
...
@@ -736,11 +737,11 @@ class DB
}
}
//New and left chat member
//New and left chat member
if
(
$new_chat_member
)
{
if
(
$new_chat_member
instanceof
User
)
{
//Insert the new chat user
//Insert the new chat user
self
::
insertUser
(
$new_chat_member
,
$date
,
$chat
);
self
::
insertUser
(
$new_chat_member
,
$date
,
$chat
);
$new_chat_member
=
$new_chat_member
->
getId
();
$new_chat_member
=
$new_chat_member
->
getId
();
}
elseif
(
$left_chat_member
)
{
}
elseif
(
$left_chat_member
instanceof
User
)
{
//Insert the left chat user
//Insert the left chat user
self
::
insertUser
(
$left_chat_member
,
$date
,
$chat
);
self
::
insertUser
(
$left_chat_member
,
$date
,
$chat
);
$left_chat_member
=
$left_chat_member
->
getId
();
$left_chat_member
=
$left_chat_member
->
getId
();
...
@@ -807,12 +808,12 @@ class DB
...
@@ -807,12 +808,12 @@ class DB
$sth
->
bindParam
(
':forward_from_chat'
,
$forward_from_chat
,
PDO
::
PARAM_INT
);
$sth
->
bindParam
(
':forward_from_chat'
,
$forward_from_chat
,
PDO
::
PARAM_INT
);
$sth
->
bindParam
(
':forward_date'
,
$forward_date
,
PDO
::
PARAM_STR
);
$sth
->
bindParam
(
':forward_date'
,
$forward_date
,
PDO
::
PARAM_STR
);
$reply_chat_id
=
null
;
$reply_
to_
chat_id
=
null
;
if
(
$reply_to_message_id
)
{
if
(
$reply_to_message_id
)
{
$reply_chat_id
=
$chat_id
;
$reply_
to_
chat_id
=
$chat_id
;
}
}
$sth
->
bindParam
(
':reply_to_chat'
,
$reply_chat_id
,
PDO
::
PARAM_INT
);
$sth
->
bindParam
(
':reply_to_chat'
,
$reply_
to_
chat_id
,
PDO
::
PARAM_INT
);
$sth
->
bindParam
(
':reply_to_message'
,
$reply_to_message_id
,
PDO
::
PARAM_INT
);
$sth
->
bindParam
(
':reply_to_message'
,
$reply_to_message_id
,
PDO
::
PARAM_INT
);
$sth
->
bindParam
(
':text'
,
$text
,
PDO
::
PARAM_STR
);
$sth
->
bindParam
(
':text'
,
$text
,
PDO
::
PARAM_STR
);
$sth
->
bindParam
(
':entities'
,
$entities
,
PDO
::
PARAM_STR
);
$sth
->
bindParam
(
':entities'
,
$entities
,
PDO
::
PARAM_STR
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment