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
4d43241f
Commit
4d43241f
authored
Sep 05, 2015
by
MBoretto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check mysql connection before execute a command that need it
parent
a4f2c71f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
8 deletions
+71
-8
SendtoallCommand.php
src/Admin/SendtoallCommand.php
+14
-0
Command.php
src/Command.php
+18
-0
Telegram.php
src/Telegram.php
+39
-8
No files found.
src/Admin/SendtoallCommand.php
View file @
4d43241f
...
...
@@ -23,7 +23,21 @@ class SendtoallCommand extends Command
protected
$version
=
'1.2.0'
;
protected
$enabled
=
true
;
protected
$public
=
true
;
//need Mysql
protected
$need_mysql
=
true
;
public
function
executeFail
()
{
//Database not setted or without connection
//Preparing message
$message
=
$this
->
getMessage
();
$chat_id
=
$message
->
getChat
()
->
getId
();
$data
=
array
();
$data
[
'chat_id'
]
=
$chat_id
;
$data
[
'text'
]
=
'Sorry no database connection, unable to execute '
.
$this
->
name
.
' command.'
;
return
Request
::
sendMessage
(
$data
);
}
public
function
execute
()
{
...
...
src/Command.php
View file @
4d43241f
...
...
@@ -23,6 +23,7 @@ abstract class Command
protected
$description
=
'Command help'
;
protected
$usage
=
'Command usage'
;
protected
$version
=
'1.0.0'
;
protected
$need_mysql
=
false
;
protected
$enabled
=
true
;
protected
$name
=
''
;
...
...
@@ -42,8 +43,25 @@ abstract class Command
return
$this
;
}
public
function
preExecute
()
{
if
(
!
$this
->
need_mysql
|
$this
->
need_mysql
&
$this
->
telegram
->
isDbEnabled
()
&
$this
->
telegram
->
isDbConnected
()
)
{
return
$this
->
execute
();
}
return
$this
->
executeFail
();
}
abstract
public
function
execute
();
//this methods is executed if $need_mysql is true but DB connection for some reason is not avaiable
public
function
executeFail
(){
}
public
function
getUpdate
()
{
return
$this
->
update
;
...
...
src/Telegram.php
View file @
4d43241f
...
...
@@ -86,7 +86,7 @@ class Telegram
*
* @var boolean
*/
protected
$mysql_enabled
;
protected
$mysql_enabled
=
false
;
/**
* MySQL credentials
...
...
@@ -345,13 +345,11 @@ class Telegram
return
$this
->
executeCommand
(
'Newchattitle'
,
$update
);
break
;
case
'delete_chat_photo'
:
// trigger delete_chat_photo
return
$this
->
executeCommand
(
'Deletechatphoto'
,
$update
);
break
;
case
'group_chat_created'
:
// trigger group_chat_created
return
$this
->
executeCommand
(
'Groupchatcreated'
,
$update
);
...
...
@@ -378,8 +376,9 @@ class Telegram
return
false
;
}
return
$class
->
execute
();
//execute methods will be execute after preexecution
//this for prevent to execute db query witout connection
return
$class
->
preExecute
();
}
/**
...
...
@@ -507,16 +506,45 @@ class Telegram
}
/**
*
Insert request in db
*
check id user require the db connection
*
* @return bool
*/
// protected function insertRequest(Update $update)
public
function
insertRequest
(
Update
$update
)
public
function
isDbEnabled
()
{
if
(
$this
->
mysql_enabled
)
{
return
true
;
}
else
{
return
false
;
}
}
/**
* check if database Connection has been created
*
* @return bool
*/
public
function
isDbConnected
()
{
if
(
empty
(
$this
->
pdo
))
{
return
false
;
}
else
{
return
true
;
}
}
/**
* Insert request in db
*
* @return bool
*/
public
function
insertRequest
(
Update
$update
)
{
if
(
!
$this
->
isDbConnected
())
{
return
false
;
}
$message
=
$update
->
getMessage
();
...
...
@@ -686,6 +714,9 @@ class Telegram
++
$a
;
}
}
$query
.=
' ORDER BY '
.
TB_CHATS
.
'.`updated_at` ASC'
;
//echo $query."\n";
$sth
=
$this
->
pdo
->
prepare
(
$query
);
...
...
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